Skip to content

Instantly share code, notes, and snippets.

@pauloaapereira
Last active May 16, 2021 16:34
Show Gist options
  • Save pauloaapereira/ca55f7991bb1857bb2ea6403f1696d02 to your computer and use it in GitHub Desktop.
Save pauloaapereira/ca55f7991bb1857bb2ea6403f1696d02 to your computer and use it in GitHub Desktop.
Android SOLID Error Handling
@Parcelize
class InternetError(private val showWarning: Boolean) : ErrorViewWithWarning {
@IgnoredOnParcel
override var warning: Snackbar? = null
override fun setupView(binding: FragmentErrorBinding) {
binding.apply {
errorTitle.setText(R.string.key_error)
errorDescription.setText(R.string.key_internet_error)
errorImage.setImageResource(R.drawable.ic_internet)
}
if (showWarning) {
showWarning(binding.root)
}
}
override fun showWarning(root: View) {
warning = Snackbar.make(root, "Internet error!", Snackbar.LENGTH_SHORT)
warning?.show()
}
override fun dismissWarning() {
warning?.dismiss()
warning = null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment