Last active
December 13, 2020 14:28
-
-
Save jobinlawrance/3f84ba33d273fd6aa91b765611674ab3 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
import org.koin.androidx.viewmodel.ext.android.viewModel | |
... | |
class HomeActivity: AppCompatActivity() { | |
private val homeViewModel by viewModel<HomeViewModel>() | |
override fun onCreate(..) { | |
... | |
homeViewModel.getResultFromApi() | |
.observe(this, Observer { result -> | |
displayResult(result) | |
}) | |
} | |
private fun displayResult(result: Result<String>) { | |
when(result) { | |
Result.InProgress -> { | |
progressbar.visibility = View.VISIBLE | |
} | |
is Result.Success -> { | |
progressbar.visibility = View.GONE | |
succssTextView.visibility = View.VISIBLE | |
succssTextView.text = result.data | |
} | |
is Result.Error -> { | |
progressbar.visibility = View.GONE | |
failureTextView.visibility = View.VISIBLE | |
failureTextView.text = "Oops, there's some issue, try again later!" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment