- This project is deprecated. Please use https://github.com/Shhatrat/BoilerplateKKMVP2Welcome to my boilerplate Android project. Firstly, why I named it KKMVP?
Kotlin
Koin
ModelViewPresenter
Repository contains branches:
addon/RestApisimple example and logic for using REST api.addon/BaseViewssimple classes (such as adapters) for reducing boilerplate codeaddon/AndroidWearsimple boilerplate for standalone Android Wear appaddon/Realmsimple example of using Realm DBaddon/Roomsimple example of using Room DB
You can easily merge it into master.
- MVP with contracts
- 100% Kotlin
- AndroidX
- Retrofit2 and OkHttp
addon/RestApi - RxJava2
- Koin (DI)
- Support libraries
- Picasso
- Realm
addon/Realm - Room
addon/Room - Android O support
This pattern allow us to easy hermetization beetween Views and Presenters.
interface ExampleContract{
interface IView: MvpView{
fun showDataFromRest(value: String)
}
interface IPresenter<in T:MvpView>: Presenter<T>{
fun getDataFromRest("time please")
}
}
Interface IView should be implement by inheritance BaseActivity or BaseFragment class. This solution forces us to attach and detach presenter object in proper moment of Activity of Fragment lifecycle.
interface BasePresenterHandle{
fun attachPresenter()
fun detachPresenter()
}
Interface IPresenter should be implement by inheritance BasePresenter class. BasePresenter contains subscriptions variable (CompositeDisposable), every RxJava's Disposable should be add to it (preventing memory leaks).
Every Presenter's interface should be bind to implmentation by factory in mvpModule file.
...
factory { ApiPresenter(get()) } bind ApiContract.IPresenter::class
...
then, presenter in IView implementation should be injected this way:
private val presenter by inject<ExContract.IPresenter<ExContract.IView>>()
override fun attachPresenter() {
presenter.attachView(this)
}
override fun detachPresenter() {
presenter.detachView()
}
See com.shhatrat.boilerplate_kkmvp.ui.ex for more details and example.
- clone this repository
- optionally merge branches which you need
- in
app/build.gradlechangeapplicationIdto your package - in
strings.xmlchangeapp_name - change
Boilerplate.ktclass name to other - change
com.shhatrat.boilerplate_kkmbppackage to your package - remove
.gitfiles and directories
- example
example/pollutionApp