Created
February 18, 2019 17:19
-
-
Save jeremyrempel/8e68182c2446386ce62f64d90d4b4807 to your computer and use it in GitHub Desktop.
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
| 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