Min SDK Version 15
Target SDK Version 27
Check the compileSdkVersion, and buildToolsVersion to be the latest
Build Tools Version 27.0.3
Java 1.8
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.derohimat:android-base-mvp:1.0'
}
Step 3. Add this library for version 0.4 and up
//----- The core of Reactive Programming
compile 'io.reactivex:rxjava:1.2.5'
compile 'io.reactivex:rxandroid:1.2.1'
Step 4. Change extends MvpView
to extends BaseView
Step 5. Modify applicationId "net.derohimat.samplebasemvp" to your package name
Step 6. Profit
Step 7. Star this repository :)
Imagine you have to implement a sign in screen.
- Create a new package under ui called signin
- Create an new Activity called
ActivitySignIn
. You could also use a Fragment. - Define the view interface that your Activity is going to implement. Create a new interface called
SignInView
that extendsBaseView
. Add the methods that you think will be necessary, e.g.showSignInSuccessful()
- Create a
SignInPresenter
class that extendsBasePresenter<SignInView>
- Implement the methods in
SignInPresenter
that your Activity requires to perform the necessary actions, e.g.signIn(String email)
. Once the sign in action finishes you should callgetView().showSignInSuccessful()
. - Create a
SignInPresenterTest
and write unit tests forsignIn(email)
. Remember to mock theSignInView
and also the DataManager. - Make your
ActivitySignIn implement SignInView
and implement the required methods likeshowSignInSuccessful()
- In your activity, inject a new instance of
SignInPresenter
and callpresenter.attachView(this)
from onCreate andpresenter.detachView()
fromonDestroy()
. Also, set up a click listener in your button that callspresenter.signIn(email)
.
https://github.com/AndreiD/UltimateAndroidTemplateRx
https://github.com/zetbaitsu/Benih
Copyright 2016 Deni Rohimat
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.