Skip to content

Instantly share code, notes, and snippets.

@jeremyrempel
Created February 18, 2019 17:19
Show Gist options
  • Select an option

  • Save jeremyrempel/8e68182c2446386ce62f64d90d4b4807 to your computer and use it in GitHub Desktop.

Select an option

Save jeremyrempel/8e68182c2446386ce62f64d90d4b4807 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity(), PhotoView {
override var isUpdating: Boolean by Delegates.observable(false) { _, _, isLoading ->
if (isLoading) {
progressBar.visibility = View.VISIBLE
button.visibility = View.GONE
imageView.visibility = View.GONE
text.visibility = View.GONE
} else {
progressBar.visibility = View.GONE
button.visibility = View.VISIBLE
imageView.visibility = View.VISIBLE
text.visibility = View.VISIBLE
}
}
private val actions: PhotoActions by lazy {
PhotoPresenter(Dispatchers.Main, this)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button.setOnClickListener {
actions.onRequestData()
}
}
override fun onUpdate(data: PhotoResponse) {
text.text = data.description
Glide
.with(this)
.load(data.urls.thumb)
.thumbnail(.25f)
.into(imageView)
}
override fun showError(error: Throwable) {
text.text = error.toString()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment