Skip to content

Instantly share code, notes, and snippets.

@surajsau
Last active July 18, 2019 13:32
Show Gist options
  • Save surajsau/e91f91d73ae6cc9ab5f76d858f701361 to your computer and use it in GitHub Desktop.
Save surajsau/e91f91d73ae6cc9ab5f76d858f701361 to your computer and use it in GitHub Desktop.
MVP to MVVM: Lose Coupling Preview
class MainActivity : AppCompatActivity() {
val presenter: MainPresenter by currentScope.inject()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
presenter.progressVisibilityObserver.observe {
..do something
}
}
}
class MainViewModel(val service: GithubService) {
/*
no instance of view present in the presenter.
Hence, this can be plug-n-played to any UI Controller
*/
val progressVisibilityObserver = DataObserver<Int>()
..
private fun onSearchResultReceived(apiResponse: ApiResponse?) {
progressVisibilityObserver.value = 0
..
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment