Android Framework Builds Retrofit2+RxJava+Glide+MVP

Keywords: Android github Retrofit Google

github address: Click to jump to Github

Reason

  • In order to facilitate the use of future projects
  • The project is still using relatively old things, such as mvc,volley, etc. In the process of building, we also learn some new technology.

How to Use And Pictures

Download and change the package name to be a new project.




I don't need to upload pictures, but I don't know why I want to upload points.
The data source is showapi official address: ShowAPi

Building process

Let's first introduce the version numbers of various third-party libraries used.

It's all in A. build file.

ext{

    dependVersion = [
            rxJava          : "2.1.11",
            rxAndroid       : "2.0.1",
            retrofit        :  "2.4.0",
            glide           : "4.6.1",
            support_version : "27.0.2"
    ]
    supportLib=[
            v7              : "com.android.support:appcompat-v7:$dependVersion.support_version",
            design          : "com.android.support:design:$dependVersion.support_version",
            recyclerview    : "com.android.support:recyclerview-v7:$dependVersion.support_version",
            cardview        : "com.android.support:cardview-v7:$dependVersion.support_version",
            annotations     : "com.android.support:support-annotations:$dependVersion.support_version"
    ]

    rxJava = [
            rxJava          : "io.reactivex.rxjava2:rxjava:$dependVersion.rxJava",
            rxAndroid       : "io.reactivex.rxjava2:rxandroid:$dependVersion.rxAndroid"
    ]
    retrofit=[
            retrofit        : "com.squareup.retrofit2:retrofit:$dependVersion.retrofit",
            retrofit_gson   : "com.squareup.retrofit2:converter-gson:$dependVersion.retrofit",
            retrofit_rxjava : "com.squareup.retrofit2:adapter-rxjava2:$dependVersion.retrofit",
            retrofit_log    : "com.squareup.okhttp3:logging-interceptor:3.4.1"
    ]
    glide=[
            glide           :"com.github.bumptech.glide:glide:$dependVersion.glide",
            glide_ok        :"com.github.bumptech.glide:okhttp3-integration:$dependVersion.glide",
    ]
    glideCompiler ="com.github.bumptech.glide:compiler:$dependVersion.glide"//There's no need to just write without quotation

    rxJavaLibs = rxJava.values()
    retrofitLibs = retrofit.values()
    glideLibs = glide.values()
    supportLibs = supportLib.values()
}

Code that calls the method of the upper code

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.project"
        minSdkVersion 17
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '26.0.2'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    //Official library
    implementation rootProject.ext.supportLibs
    //Analytic Library
    implementation 'com.google.code.gson:gson:2.6.2'
    //RxJava
    implementation rootProject.ext.rxJavaLibs
    //Retrofit
    implementation rootProject.ext.retrofitLibs
    //Glide
    implementation rootProject.ext.glideLibs
    //SmartRefresh
    implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-1'
    //Leakcanary
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'
    //Log log printing
    implementation 'com.orhanobut:logger:2.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation project(':utilcode')
}

Detailed things can be seen on git clone down the project itself.

SmartRefreshLayout
A hot third-party drop-down refreshes the third-party dependency libraries loaded by the pull-up.
Address: SmartRefreshLayout

Then there's the core class.

  • ApiService: Class for storing interfaces
  • Retrofit Manager: You know a lot about bb by name
    It is also simple to use this type of approach:
RetrofitManager.getApiService()
                .getShowApiGifData(page,max_Results)
                .compose(new IoToMainTransformer());
  • Three base Classes of MVP (under base Package)
    • IBasePresenter
    • IBaseView
    • BasePresenter
      Use mode under mvp package. There are a lot of self-google articles on the Internet that don't quite understand this aspect.

Tool class

Finally, the tool class is the main thing that this project builds so fast. It's very worrying. According to the nature of the dead horse and the living horse doctor, we found a dependency library on github. A comprehensive util tool class library for thieves and chickens is basically all you can think of. When I found this tool library, ne came to mind. The picture is a short video of a tremolo boy, you can see: Point me, please.
github address: Class AndroidUtil
But it is recommended that you download the code and put it into the project. What are your own unique requirements that can be added directly to the code?
For example, what Sp stores login information, and then one click empties the function and so on.

Tail language

All the introductions are finished. Now the project is only preliminary completed, if any technology is relatively new and better, I will replace what is now, if you like, star t my project, oh, the next plan is:

  • Write a tool class of Progress, a lot of network clearance requests are done by clicking the button.
  • Encapsulate a progress bar for Glide loading pictures
  • Choose a better third-party Recycler View Adapter tool library
  • And so on.

Of course, you can also fork maintenance together, or give some suggestions, in order to achieve a quick handwriting project. Many people have great power. After all, the blogger's brain capacity is this. ne is not Einstein. He is still not comprehensive enough.

Finally, send the project address again: Point ne (three tones) point ne (three tones)

Posted by midi_mick on Tue, 11 Dec 2018 01:03:06 -0800