-
-
Save RohitSurwase/6f33cdc51c6ab6a9f622b6ace0e9e4ba to your computer and use it in GitHub Desktop.
Class showing the key points of Presenter layer in MVP
This file contains 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
// 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