Last active
July 18, 2019 11:57
-
-
Save surajsau/ed1fd51d12db980dfe47a4e579ef189b to your computer and use it in GitHub Desktop.
MVP to MVVM: New Data Observer implementation
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 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