-
-
Save RohitSurwase/36c8c392c10d157ecbb223d89105b9eb to your computer and use it in GitHub Desktop.
Activity showing key points of View 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
//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