Min SDK Version 21
Target SDK Version 28
Check the compileSdkVersion, and buildToolsVersion to be the latest
Build Tools Version 28.0.3
Java 1.8
- Download or cline this project then change package id (id.example.mvp) to your package id
- You can change package ID easily using this script
- Open the project in Android Studio
- Profit
Imagine you have to implement a sign in screen.
- Create a new package under
featuredirectory calledsignin - Create an new Activity called
SignInActivity - Create a new interface called
SignInViewthat extendsMvpView. Add functions likefun showSignInSuccessfull() - Create a
SignInPresenterclass that extendsBasePresenter<SignInView>. - Create a
SignInModuleclass that will provide presenter class. Sample code:
@Module
class SignInModule {
@PerFeature
@Provides
fun providesSignInPresenter(dataManager: DataManager): SignInPresenter = SignInPresenter(dataManager)
}
- Implement functions in
SignInPresenterthat your Activity requires to perform the necessary actions, e.g.signIn(email: String). Once the sign in action finishes you should callmvpView?.showSignInSuccessful(). - Create a
SignInPresenterTestand write unit tests forsignIn(email). Remember to mock theSignInViewand also the DataManager. - Make your activity implement
SignInViewand implement the required functions likeshowSignInSuccessful() - In your activity, inject a new instance of
SignInPresenterand callpresenter.attachView(this)from override functionattachView()andpresenter.detachView()from override functiondetachView(). InonCreate()inject that activity, like this:AndroidInjection.inject(this) - Open file
FeatureModule.ktin directorycore/di/moduleand add abstract function for SignInActivity.
@PerFeature
@ContributesAndroidInjector(modules = [SignInModule::class])
abstract fun bindSignInActivity(): SignInActivity