Last active
July 18, 2019 13:32
-
-
Save surajsau/e91f91d73ae6cc9ab5f76d858f701361 to your computer and use it in GitHub Desktop.
MVP to MVVM: Lose Coupling Preview
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() { | |
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