Skip to content

Instantly share code, notes, and snippets.

@RohitSurwase
Last active August 23, 2018 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RohitSurwase/36c8c392c10d157ecbb223d89105b9eb to your computer and use it in GitHub Desktop.
Save RohitSurwase/36c8c392c10d157ecbb223d89105b9eb to your computer and use it in GitHub Desktop.
Activity showing key points of View layer in MVP
//Activity/Fragment/View implements interface
class MainActivity : AppCompatActivity(), MainView {
// Initialize Presenter (also Model in the constructor of Presenter) & has object of Presenter
private lateinit var mainPresenter: MainPresenter
override fun onCreate(savedInstanceState: Bundle?) {
//...
mainPresenter = MainPresenter(this, MainInteractor())
mainPresenter.getData()
}
//...
override fun setData(arrUpdates: List<DataItem>) {
// Show data on UI
}
override fun setDataError(strError: String) {
// Show error on UI
}
override fun onDestroy() {
// Destroy View
mainPresenter.onDestroy()
super.onDestroy()
}
}
===================================
// Interface (acts as a contract between View and Presenter)
interface MainView {
fun showProgress()
fun hideProgress()
fun setData(arrUpdates: List<DataItem>)
fun setDataError(strError: String)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment