Skip to content

Instantly share code, notes, and snippets.

@surajsau
Last active July 18, 2019 11:57
Show Gist options
  • Save surajsau/ed1fd51d12db980dfe47a4e579ef189b to your computer and use it in GitHub Desktop.
Save surajsau/ed1fd51d12db980dfe47a4e579ef189b to your computer and use it in GitHub Desktop.
MVP to MVVM: New Data Observer implementation
class MainPresenter(val service: GithubService) {
.
.
val progressVisibilityObserver = DataObserver<Int>()
private fun onSearchResultReceived(apiResponse: ApiResponse?) {
.
.
progressVisibilityObserver.value = 0
}
}
class MainActivity : AppCompatActivity() {
.
.
val presenter: MainPresenter by currentScope.inject()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
.
.
presenter.progressVisibilityObserver.observe {
when(it) {
0 -> progress_circular.hide()
1 -> progress_circular.show()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment