cool hit counter MVPArmsMVP rapid integration framework_Intefrankly

MVPArmsMVP rapid integration framework

Original article address:



  • In the Android tech scene this yearMVP,Dagger2,Rxjava,Retrofit These words are so hot that opening a technical forum is full of articles about these technologies,Github It's also filled with all kinds of people who take Developed based on MVP + Retrofit + RxJava + Dagger2 + MaterialDesign xxxx Open source projects with the title orDemo.
  • But people are so passionate about open source projects like this, and keep doing the same thing over and over againTeach everyone to use of way harmony skills Ever thought of relying on a third-party library to quickly build such frameworks?

What is MVPArms?

  • MVPArms be An integrated, extensiveAndroid mainstream frameworks, and all useDagger2 management, and provideAPI will all storehouse Connects for ease of use, Details are also provided of Wiki Document.
  • It allows for the development of back of all sports event I don't even have to repeat myself. of copy and paste (as in "copy and paste")( Used such frameworks of Friends should know, such storehouse All rely on other of storehouse, Even if abuild.gradle It's all a big waste of time.), One dependency saves a lot of hassle, And for the novice these frames are difficult of not just beAPI of use, harder of be How do they fit together?, Tackle a variety of scenarios of use.
  • For a new oneAndroid projects, in particular proficiency in the use ofDagger2 harmonyRxjava of developers, All you have to do is put this sports eventClone Come on down,Demo merely realize Got a page, Delete this page, Add all neededRetrofit API, you of The framework is set up., You can then just use theDemo The package structure is also suitable for later extensions.


Extensions, check it out:


  • Generic framework, suitable for all types of projects, support for large projects, compatible with component-based development, can be used as a component-based Base storehouse
  • Base The base class (BaseActivity, BaseFragment, BaseApplication ...)
  • MVP The base class (IModel, IVIew, IPresenter ...)
  • The frame is highly customizable (ConfigModule), able to (located) at No modification to the framework source code of In the case of the Retoift, Okhttp, RxCache, Gson Customization of framework-specific properties, such as BaseApplication, BaseActivity, BaseFragment of Insert any code in the corresponding life cycle, And the framework is unique of ConfigModule configuration class, able to (located) at No modification to the framework source code of circumstances because of The framework easily extends any added functionality
  • ingenious RxLifeCycle Application method, which can be used without inheriting RxLifeCycle offered Activity harmony Fragment of circumstances, normal use RxLifeCycle All functions of the
  • ingenious builder model Module (GlobalConfigModule ), can be implemented using Dagger2 to any position in the frame empty into Custom Parameters, Easily expandable with any custom parameter
  • Global use Dagger2 Management (use all modules with Dagger2 Connected, never simply used)
  • Globally listen to the entire App all Activity and Fragment (including three-party libraries), and can insert arbitrary code into its lifecycle
  • Global Listening Http Request (Request parameters, Headers ...), Response ( Server returns of result, Headers , time-consuming ...) and other information (including Glide request), the json can be parsed and the corresponding global operations and data encryption can be done based on the status code, Cookie Operations such as management
  • Global management of all Activity ( Including tripartite storehouse of Activity ), which can be achieved throughout the App Anywhere, Exit All Activity, and Get it to the front desk. Activity do a correspondence of operations( If you can (located) at App Any position to do pop-ups Dialog of operations)
  • security situation Rxjava error handling, Automatic retry after error, Capture the entire application of all mistakes
  • security situation UI adaptive
  • The picture load class ImageLoader Use the policy pattern and builder pattern, easy to switch between image loading framework, easy to extend the functionality
  • Web request log printing encapsulation( After providing resolution of server of Request Information harmony server of Response Information, Press Customizable of Output print log in any format, A nice built-in of Print format template)
  • caching mechanism encapsulation of its own components within the framework (the framework can cache content components are provided with interfaces for external developers to customize the caching mechanism)
  • Code Generation Plugin (MVPArms The whole family bucket generates all the class files needed in one click)
  • Demo Modify the package name and you can use it directly, Quick Access( old sports event To access, please click below of steps)


MVPArms welcomeStar harmonyFork



Package Structure




For detailed usage, please refer toWiki, hereunder only be easy of Introducing.MVP


depending onGoogle official (relating a government office) ofMVP sports event , can be found atContract defined inMVP interfaces, Ease of administration, This framework usesDagger empty intoPresenter No definition requiredPresenter interface, soContract Only definedModel harmonyView interfaces

public interface UserContract {
     // For frequently used methods about the UI can be defined in the BaseView, such as displaying hidden progress bars, and displaying text messages
    interface View extends BaseView {
        void setAdapter(DefaultAdapter adapter);
        void startLoadMore();
        void endLoadMore();
     //Model layer to define the interface, the external only need to care about the data returned by the model, do not need to care about the internal details, and whether to use the cache
    interface Model {
        Observable<List<User>> getUsers(int lastIdQueried, boolean update);


Generally letActivity perhapsFragment realizeContract defined in ofView Interface, forPresenter Call the corresponding method actionUI,BaseActivity default empty intoPresenter , if you want to usePresenter, must be specified Presenter's Paradigm, harmony realizesetupActivityComponent in order to providePresenter neededComponent harmonyModule

public class UserActivity extends WEActivity<UserPresenter> implements UserContract.View {

    protected void setupActivityComponent(AppComponent appComponent) {
                .userModule(new UserModule(this))


    protected View initView() {
        return LayoutInflater.from(this).inflate(R.layout.activity_user, null, false);

    protected void initData() {


Model realizeContract ofModel interface, and inherits fromBaseModel ,designated paradigm type because ofServiceManager harmonyCacheManager, and then by twoManager Get what you need.Service harmonyCache because ofPresenter provide needed data( be No use of cache is optional,Presenter No need to concern yourself with details)

public class UserModel extends BaseModel<ServiceManager,CacheManager> implements UserContract.Model{
    private CommonService mCommonService;
    private CommonCache mCommonCache;

    public UserModel(ServiceManager serviceManager, CacheManager cacheManager) {
        super(serviceManager, cacheManager);
        this.mCommonService = mServiceManager.getCommonService();
        this.mCommonCache = mCacheManager.getCommonCache();
    public Observable<List<User>> getUsers(int lastIdQueried, boolean update) {


Presenter (located) atMVP The role of the majority of the in for the by fromModel layer interface to get the data, before calling theView layer interface to display data, first implementingBasePresenter ,designatedModel harmonyView of paradigm type, Be careful to always specifyContract The interface defined in ,Presenter neededModel harmonyView , all usingDagger2 empty into, It's easy to test and unroot., how? empty into?

public class UserPresenter extends BasePresenter<UserContract.Model, UserContract.View> {

    public UserPresenter(UserContract.Model model, UserContract.View rootView) {
        super(model, rootView);
    // Define the business method here, corresponding user of interactivity
    public void requestUsers(final boolean pullToRefresh) {


Thanks to all the three-party libraries used in this frameworkAuthor , as well as all the other services provided forOpen Sourece Be a selfless contributorDeveloper harmonyOrganizations I will also give back to the open source community in my spare time

  1. Mvp Officially produced by GoogleMvp Architecture project with several different architecture branches (this is the Dagger branch).
  2. Dagger2Google depending onSquare ofDagger1 produce an item of depend on empty into framework, pass (a bill or inspection)Apt Compile-time code generation, Better performance than using runtime reflection techniques of depend on empty into framework.
  3. Rxjava Provides an elegant responsive Api to address asynchronous requests and event handling.
  4. RxAndroid Responsive Api for Android.
  5. Rxlifecycle (located) atAndroid use onrxjava all know of A pit., just (emphasis) be life cycle of Unsubscribe, This framework is implemented by binding theactivity harmonyfragment of Life cycle perfect solution.
  6. RxCache be Using annotations because ofRetrofit Adding a secondary cache( RAM, discs) of buffer memory storehouse.
  7. RxErroHandler be Rxjava of error handling storehouse, able to (located) at Retry after an error.
  8. RxPermissions For processingAndroid Runtime permissions of responsive storehouse.
  9. RetrofitSquare produce an item of Network requests storehouse, maximum of Reducedhttp requesting of code harmony steps.
  10. Okhttp The same Square production, not much introduction, do Android should know .
  11. Autolayout Hong Yang Da Shen ofAndroid Full-size adaptation frame.
  12. GsonGoogle official (relating a government office) ofJson Convert framework.
  13. ButterknifeJakeWharton From the Gods ofview empty into framework.
  14. Androideventbus A light-weight use of annotations ofEventbus.
  15. Timber JakeWharton gods produced Log framework container, very little internal code, but the idea is very good .
  16. Glide This library is the default package image loading library for this framework, you can refer to the example to change to other libraries, Api andPicasso Pretty much, the caching mechanism is better thanPicasso complex, fast, suitable for processing large image streams, supports gif imagesFresco It's too big! The advantage is great below 5.0, and systems above 5.0 use memory management by default andFresco Similarly.
  17. LeakCanary Square has produced a special test forAndroid harmonyJava The memory leak is indicated by the notification bar.

Hello My name is Jessyan, if you like my articles, you can follow me on the following platforms?

1、The midset audition comparison video is online so put on your headphones and hear which one you like best
2、Artificial intelligence rules deduction system I am not able to see
3、How to avoid overdesign and premature optimization of database subdatabase and subtable
4、The worlds first female AI anchor called News Reporter was born in Japan
5、Shima teamed up with Leach for a shockingly big layout All manufacturers alert for a Category 12 typhoon warning

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送