- This project is deprecated. Please use https://github.com/Shhatrat/BoilerplateKKMVP2
Welcome to my boilerplate Android project. Firstly, why I named it KKMVP?
Kotlin
Koin
ModelViewPresenter
Repository contains branches:
addon/RestApi
simple example and logic for using REST api.addon/BaseViews
simple classes (such as adapters) for reducing boilerplate codeaddon/AndroidWear
simple boilerplate for standalone Android Wear appaddon/Realm
simple example of using Realm DBaddon/Room
simple 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.gradle
changeapplicationId
to your package - in
strings.xml
changeapp_name
- change
Boilerplate.kt
class name to other - change
com.shhatrat.boilerplate_kkmbp
package to your package - remove
.git
files and directories
- example
example/pollutionApp