Created
June 26, 2016 11:00
-
-
Save AAverin/7779ee4309381e2841954f5c8824a27d to your computer and use it in GitHub Desktop.
gist for CleanAndroidCode article series https://medium.com/@anton.averin.dev/keep-your-droid-clean-e9c093140eb6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class UIResolution @Inject constructor(val uiResolver: UIResolver) : ResolutionByCase() { | |
override fun onConnectivityAvailable() { | |
uiResolver.hidePersistentSnackBar() | |
} | |
override fun onConnectivityUnavailable() { | |
uiResolver.showPersistentSnackBar(R.string.error_no_network_connection) | |
} | |
override fun onNotFound() { | |
uiResolver.showSnackBar(R.string.error_not_found) | |
} | |
override fun onServiceUnavailable() { | |
uiResolver.showSnackBar(R.string.error_service_unavailable) | |
} | |
override fun onInternalServerError() { | |
uiResolver.showSnackBar(R.string.error_http_exception) | |
} | |
override fun onGenericRxException(t: Throwable) { | |
t.printStackTrace() | |
} | |
override fun onNetworkLocationError() { | |
uiResolver.showSnackBar(R.string.error_enable_gps) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ActivityScope | |
class UIResolver @Inject constructor(var baseActivity: BaseActivity) { | |
private val snackbarRoot: ViewGroup | |
init { | |
snackbarRoot = baseActivity.findViewById(R.id.content) as ViewGroup | |
} | |
private var persistentSnackbar: Snackbar? = null | |
fun showSnackBar(messageResource: Int) { | |
Snackbar.make(snackbarRoot, messageResource, Snackbar.LENGTH_LONG).show() | |
} | |
fun showPersistentSnackBar(messageResource: Int) { | |
persistentSnackbar = Snackbar.make(snackbarRoot, messageResource, Snackbar.LENGTH_INDEFINITE) | |
persistentSnackbar?.show() | |
} | |
fun hidePersistentSnackBar() { | |
persistentSnackbar?.dismiss() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment