├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── lp
│ │ └── mvp_network
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── lp
│ │ │ └── mvp_network
│ │ │ ├── App.java
│ │ │ ├── activity
│ │ │ ├── MainActivity.java
│ │ │ ├── MainBean.java
│ │ │ ├── MainPresenter.java
│ │ │ ├── MainView.java
│ │ │ ├── MvcActivity.java
│ │ │ └── file
│ │ │ │ ├── FileActivity.java
│ │ │ │ ├── FilePresenter.java
│ │ │ │ └── FileView.java
│ │ │ ├── api
│ │ │ ├── ApiDns.java
│ │ │ ├── ApiRetrofit.java
│ │ │ └── ApiServer.java
│ │ │ ├── base
│ │ │ ├── ApiException.java
│ │ │ ├── BaseActivity.java
│ │ │ ├── BaseContent.java
│ │ │ ├── BaseFragment.java
│ │ │ ├── convert
│ │ │ │ ├── MyGsonConverterFactory.java
│ │ │ │ ├── MyGsonRequestBodyConverter.java
│ │ │ │ └── MyGsonResponseBodyConverter.java
│ │ │ ├── cookie
│ │ │ │ ├── CookieManger.java
│ │ │ │ ├── OkHttpCookies.java
│ │ │ │ └── PersistentCookieStore.java
│ │ │ ├── file
│ │ │ │ ├── FileObserver.java
│ │ │ │ ├── FileUtil.java
│ │ │ │ ├── ProgressRequestBody.java
│ │ │ │ └── ProgressResponseBody.java
│ │ │ ├── gson
│ │ │ │ ├── DoubleDefaultAdapter.java
│ │ │ │ ├── IntegerDefaultAdapter.java
│ │ │ │ ├── LongDefaultAdapter.java
│ │ │ │ └── StringNullAdapter.java
│ │ │ └── mvp
│ │ │ │ ├── BaseModel.java
│ │ │ │ ├── BaseObserver.java
│ │ │ │ ├── BaseObserverFlowable.java
│ │ │ │ ├── BasePresenter.java
│ │ │ │ ├── BasePresenterFlowable.java
│ │ │ │ └── BaseView.java
│ │ │ ├── bean
│ │ │ └── TextBean.java
│ │ │ ├── second2demo
│ │ │ ├── BaseActivity.java
│ │ │ ├── BaseFragment.java
│ │ │ ├── activity
│ │ │ │ ├── SecondActivity.java
│ │ │ │ ├── SecondPresenter.java
│ │ │ │ └── SecondView.java
│ │ │ ├── api
│ │ │ │ └── ApiRetrofit.java
│ │ │ ├── bean
│ │ │ │ ├── Bean1.java
│ │ │ │ ├── Bean2.java
│ │ │ │ └── Bean3.java
│ │ │ └── mvp
│ │ │ │ ├── BaseModel.java
│ │ │ │ ├── BaseObserver.java
│ │ │ │ ├── BasePresenter.java
│ │ │ │ └── BaseView.java
│ │ │ ├── utils
│ │ │ ├── KeyBoardUtils.java
│ │ │ ├── L.java
│ │ │ ├── NetWorkUtils.java
│ │ │ ├── RetrofitUtil.java
│ │ │ └── StatusBarUtil.java
│ │ │ └── view
│ │ │ ├── LoadingDialog.java
│ │ │ └── ProgressDialog.java
│ └── res
│ │ ├── anim
│ │ ├── dialog_enter.xml
│ │ └── dialog_exit.xml
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── ic_launcher_background.xml
│ │ ├── loading_bg.9.png
│ │ ├── logo.jpg
│ │ └── progressbar_round.xml
│ │ ├── layout
│ │ ├── activity_file.xml
│ │ ├── activity_main.xml
│ │ ├── app_title.xml
│ │ ├── dialog_loading.xml
│ │ ├── dialog_msg.xml
│ │ └── progress_uptade.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── ids.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── lp
│ └── mvp_network
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LPTim/MVP-Retrofit2-okhttp3-Rxjava2/e5fd2ed4b6c797124882a0657b62bb26472564af/README.md
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.lp.mvp_network"
7 | minSdkVersion 16
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | repositories {
22 | maven { url 'https://jitpack.io' }
23 | jcenter()
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 | implementation 'com.android.support:appcompat-v7:27.1.1'
29 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
30 | testImplementation 'junit:junit:4.12'
31 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
33 |
34 | //网络请求
35 | implementation 'com.squareup.okhttp3:okhttp:3.11.0'
36 | implementation 'com.squareup.retrofit2:retrofit:2.4.0'
37 | //ConverterFactory的Gson依赖包
38 | implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
39 | //CallAdapterFactory的Rx依赖包
40 | implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
41 |
42 | implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
43 | //cookie管理
44 | implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
45 | //日志
46 | implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
47 |
48 | //日志
49 | implementation 'com.orhanobut:logger:2.2.0'
50 | //toast
51 | implementation 'com.hjq:toast:5.8'
52 |
53 | //水波纹
54 | implementation 'com.scwang.wave:MultiWaveHeader:1.0.0-alpha-1'
55 | //权限申请
56 | implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.5@aar'
57 | //下载动画
58 | implementation 'com.github.Ajian-studio:GADownloading:v1.0.2'
59 | //工具类
60 | implementation 'com.blankj:utilcode:1.23.7'
61 | }
62 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/lp/mvp_network/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.lp.mvp_network;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.lp.mvp_network", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
30 |
33 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lp/mvp_network/App.java:
--------------------------------------------------------------------------------
1 | package com.lp.mvp_network;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | import com.hjq.toast.ToastUtils;
7 | import com.orhanobut.logger.AndroidLogAdapter;
8 | import com.orhanobut.logger.FormatStrategy;
9 | import com.orhanobut.logger.Logger;
10 | import com.orhanobut.logger.PrettyFormatStrategy;
11 |
12 | /**
13 | * File descripition: 运用此项目时,修改地方如下
14 | *
15 | * 1.BaseContent 中 baseUrl修改
16 | * 2.BaseContent 中 basecode修改
17 | * 3.BaseModel 中 各字段参数名 修改为接口对应
18 | * 备注:(接口如果复杂,自己修改不了,可以联系我)
19 | *
20 | *
21 | * @author lp
22 | * @date 2018/10/11
23 | */
24 |
25 | public class App extends Application {
26 | private static Context mContext;
27 |
28 | @Override
29 | public void onCreate() {
30 | super.onCreate();
31 |
32 | // 在 Application 中初始化
33 | ToastUtils.init(this);
34 |
35 | mContext = this;
36 | initLogger();
37 | }
38 |
39 | public static Context getContext() {
40 | return mContext;
41 | }
42 |
43 | private void initLogger() {
44 | FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
45 | .showThreadInfo(false) // 是否显示线程信息 默认显示 上图Thread Infrom的位置
46 | .methodCount(0) // 展示方法的行数 默认是2 上图Method的行数
47 | .methodOffset(7) // 内部方法调用向上偏移的行数 默认是0
48 | // .logStrategy(customLog) // 改变log打印的策略一种是写本地,一种是logcat显示 默认是后者(当然也可以自己定义)
49 | .tag("mvp_network_tag") // 自定义全局tag 默认:PRETTY_LOGGER
50 | .build();
51 | Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy) {
52 | @Override
53 | public boolean isLoggable(int priority, String tag) {
54 | return true;
55 | }
56 | });
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lp/mvp_network/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.lp.mvp_network.activity;
2 |
3 | import android.view.View;
4 | import android.widget.TextView;
5 |
6 | import com.lp.mvp_network.R;
7 | import com.lp.mvp_network.activity.file.FileActivity;
8 | import com.lp.mvp_network.base.BaseActivity;
9 | import com.lp.mvp_network.base.BaseContent;
10 | import com.lp.mvp_network.base.mvp.BaseModel;
11 | import com.lp.mvp_network.bean.TextBean;
12 | import com.lp.mvp_network.utils.L;
13 | import com.lp.mvp_network.utils.RetrofitUtil;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | public class MainActivity extends BaseActivity implements MainView, View.OnClickListener {
19 | private TextView mTvText;
20 |
21 | private List mainBeans;
22 |
23 | @Override
24 | protected MainPresenter createPresenter() {
25 | return new MainPresenter(this);
26 | }
27 |
28 | @Override
29 | protected int getLayoutId() {
30 | return R.layout.activity_main;
31 | }
32 |
33 |
34 | @Override
35 | public void onErrorCode(BaseModel model) {
36 | // super.onErrorCode(model);
37 | //我要自定义
38 | //实现自己的逻辑
39 | }
40 |
41 |
42 | @Override
43 | public void showError(String msg) {
44 | if (msg.contains("重新登录")) {
45 | //处理自己定制逻辑
46 | } else {
47 | super.showError(msg);
48 | }
49 |
50 | }
51 |
52 |
53 | @Override
54 | protected void initData() {
55 | findViewById(R.id.btn_first).setOnClickListener(this);
56 | findViewById(R.id.btn_second).setOnClickListener(this);
57 | findViewById(R.id.btn_second_2).setOnClickListener(this);
58 | findViewById(R.id.btn_third).setOnClickListener(this);
59 | findViewById(R.id.btn_forth).setOnClickListener(this);
60 | findViewById(R.id.btn_fifth).setOnClickListener(this);
61 | findViewById(R.id.btn_six).setOnClickListener(this);
62 | findViewById(R.id.btn_down).setOnClickListener(this);
63 | mTvText = findViewById(R.id.tv_text);
64 |
65 | mainBeans = new ArrayList<>();
66 |
67 |
68 | }
69 |
70 | @Override
71 | public void onMainSuccess(BaseModel> o) {
72 | // Log.e(o.getErrmsg(), "");
73 | // Log.e(o.getErrcode() + "", "");
74 | // mainBeans.addAll(o.getData());
75 | // Log.e("sm", mainBeans.toString() + "");
76 | // mTvText.setText(o.getData().toString());
77 | }
78 |
79 | @Override
80 | public void onTextSuccess(BaseModel o) {
81 | mTvText.setText(o.getResult().getData().toString());
82 | }
83 |
84 | @Override
85 | public void onClick(View v) {
86 | switch (v.getId()) {
87 | //默认请求
88 | case R.id.btn_first:
89 | mPresenter.getTextApi();
90 | break;
91 | //上传图片
92 | case R.id.btn_second:
93 | showToast("添加本地图片url,再进行测试");
94 | // upLoadImage();
95 | break;
96 | //上传文件进度测试
97 | case R.id.btn_second_2:
98 | mPresenter.upLoadVideoApi(BaseContent.baseFileName+"ceshi.mp4");
99 | break;
100 | //mvc测试
101 | case R.id.btn_third:
102 | startActivity(MvcActivity.class);
103 | break;
104 | //多基类测试
105 | case R.id.btn_forth:
106 | mPresenter.getTableListApi();
107 | break;
108 | //多基类测试
109 | case R.id.btn_fifth:
110 | mPresenter.getRestrictionsApi();
111 | break;
112 | //多基类测试
113 | case R.id.btn_six:
114 | mPresenter.getCheShiApi();
115 | break;
116 | //文件上传测试
117 | case R.id.btn_down:
118 | startActivity(FileActivity.class);
119 | break;
120 | }
121 | }
122 |
123 | private void upLoadImage() {
124 | /**
125 | * 俩个参数 一个是图片集合路径 一个是和后台约定的Key,如果后台不需要,随便写都行
126 | */
127 | List strings = new ArrayList<>();
128 | for (int i = 0; i < 10; i++) {
129 | strings.add("tupian.lujing");
130 | }
131 | mPresenter.upLoadImgApi(
132 | "title",
133 | "content",
134 | RetrofitUtil.filesToMultipartBodyParts(RetrofitUtil.initImages(strings), "tupian.key"));
135 |
136 | }
137 |
138 | @Override
139 | public void onUpLoadImgSuccess(BaseModel