Skip to content

Instantly share code, notes, and snippets.

@RohitSurwase
Last active August 23, 2018 22:22
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/6f33cdc51c6ab6a9f622b6ace0e9e4ba to your computer and use it in GitHub Desktop.
Save RohitSurwase/6f33cdc51c6ab6a9f622b6ace0e9e4ba to your computer and use it in GitHub Desktop.
Class showing the key points of Presenter layer in MVP
// Presenter has the object of both View and Model(Interactor)
// Implements OnFinishedListener to listen for Interactor response
class MainPresenter(private var mainView: MainView?, private val mainInteractor: MainInteractor)
: MainInteractor.OnFinishedListener {
fun getData() {
mainView?.showProgress()
mainInteractor.requestGetDataAPI(this)
}
override fun onResultSuccess(arrUpdates: List<DataItem>) {
mainView?.hideProgress()
mainView?.setData(arrUpdates)
}
override fun onResultFail(strError: String) {
mainView?.hideProgress()
mainView?.setDataError(strError)
}
// Destroy View when Activity destroyed
fun onDestroy() {
mainView = null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment