) ((ParameterizedType) (o.getClass()
13 | .getGenericSuperclass())).getActualTypeArguments()[i])
14 | .newInstance();
15 | } catch (InstantiationException e) {
16 | e.printStackTrace();
17 | } catch (IllegalAccessException e) {
18 | e.printStackTrace();
19 | } catch (ClassCastException e) {
20 | e.printStackTrace();
21 | }
22 | return null;
23 | }
24 |
25 | public static Class> forName(String className) {
26 | try {
27 | return Class.forName(className);
28 | } catch (ClassNotFoundException e) {
29 | e.printStackTrace();
30 | }
31 | return null;
32 | }
33 | }
--------------------------------------------------------------------------------
/mvp/src/main/java/com/example/mvp/base/BaseMvpActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.mvp.base;
2 |
3 | import android.app.ProgressDialog;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 |
8 | import com.example.mvp.util.TUtil;
9 |
10 | public abstract class BaseMvpActivity extends AppCompatActivity{
11 | public P presenter;
12 | public ProgressDialog progressDialog;
13 |
14 | public abstract int getLayoutId();
15 |
16 | @Override
17 | protected void onCreate(@Nullable Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(getLayoutId());
20 | init();
21 | initData();
22 | findView();
23 | initView();
24 | }
25 |
26 | protected void init(){
27 | progressDialog = new ProgressDialog(this);
28 | presenter=TUtil.getT(this,0);
29 | presenter.setView(this);
30 | }
31 |
32 | protected abstract void initView();
33 |
34 | protected abstract void initData();
35 |
36 | protected abstract void findView();
37 |
38 | @Override
39 | protected void onDestroy() {
40 | super.onDestroy();
41 | presenter.unSubscription();//在activity销毁的时候,取消当前Activity的所有订阅
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/myrxjava/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/mvp/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 |
6 |
7 |
8 | defaultConfig {
9 | applicationId "com.example.mvp"
10 | minSdkVersion 15
11 | targetSdkVersion 27
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(include: ['*.jar'], dir: 'libs')
30 | implementation 'com.android.support:appcompat-v7:27.1.1'
31 | implementation 'com.android.support.constraint:constraint-layout:1.1.0'
32 | testImplementation 'junit:junit:4.12'
33 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
35 | implementation 'com.google.code.gson:gson:2.8.0'
36 | implementation 'com.squareup.okhttp3:okhttp:3.9.1'
37 | implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
38 | implementation 'com.squareup.retrofit2:retrofit:2.3.0'
39 |
40 | //rxjava
41 | implementation 'io.reactivex.rxjava2:rxjava:2.1.14'
42 | //rxandorid
43 | implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
44 |
45 | //callAdapter转换器
46 | implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
47 | //converter转换器
48 | implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/myrxjava/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 |
6 |
7 |
8 | defaultConfig {
9 | applicationId "com.example.myrxjava"
10 | minSdkVersion 15
11 | targetSdkVersion 26
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | final RX_VERSION = '1.1.0'
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 |
32 | implementation 'com.android.support:appcompat-v7:26.1.0'
33 | implementation 'com.android.support.constraint:constraint-layout:1.1.0'
34 | testImplementation 'junit:junit:4.12'
35 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
36 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
37 |
38 | implementation 'com.google.code.gson:gson:2.8.0'
39 | implementation 'com.squareup.okhttp3:okhttp:3.9.1'
40 | implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
41 | implementation 'com.squareup.retrofit2:retrofit:2.3.0'
42 | implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
43 | implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
44 | implementation 'io.reactivex.rxjava2:rxjava:2.1.14'
45 | implementation 'io.reactivex:rxandroid:1.2.1'
46 |
47 |
48 | compile 'com.google.dagger:dagger:2.9'
49 | annotationProcessor 'com.google.dagger:dagger-compiler:2.9'
50 | }
51 |
--------------------------------------------------------------------------------
/mvp/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/myrxjava/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/myrxjava/src/main/java/com/example/myrxjava/ui/login/LoginPresenter.java:
--------------------------------------------------------------------------------
1 | package com.example.myrxjava.ui.login;
2 |
3 | import android.text.TextUtils;
4 | import android.util.Log;
5 |
6 | import com.example.myrxjava.api.LoginApi;
7 | import com.example.myrxjava.constract.LoginContract;
8 | import com.example.myrxjava.entity.UserInfo;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | import javax.inject.Inject;
14 |
15 |
16 | import rx.Observer;
17 | import rx.android.schedulers.AndroidSchedulers;
18 | import rx.schedulers.Schedulers;
19 |
20 | /**
21 | * Created by wenyingzhi on 2018/4/23.
22 | */
23 |
24 | public class LoginPresenter extends LoginContract.LoginBasePresenter {
25 |
26 | @Inject
27 | public LoginApi loginApi;
28 |
29 | @Inject
30 | public LoginPresenter() {
31 |
32 | }
33 |
34 | @Override
35 | public void login() {
36 | String pass = mView.getPass();
37 | String user = mView.getUser();
38 | if (TextUtils.isEmpty(pass)) {
39 | mView.showToastMsg("请输入账号!");
40 | } else if (TextUtils.isEmpty(user)) {
41 | mView.showToastMsg("请输入密码!");
42 | } else {
43 | mView.showLoadDialog();
44 | Map parameters = new HashMap<>();
45 | parameters.put("username", user);
46 | parameters.put("password", pass);
47 | parameters.put("enews", "login");
48 | parameters.put("lifetime", "315360000");
49 |
50 | loginApi.login(parameters)
51 | .subscribeOn(Schedulers.io())
52 | .observeOn(AndroidSchedulers.mainThread())
53 | .subscribe(new Observer() {
54 | @Override
55 | public void onCompleted() {
56 | mView.hideDialog();
57 | }
58 |
59 | @Override
60 | public void onError(Throwable e) {
61 | mView.hideDialog();
62 | mView.showErrorMsg("请求网络失败!");
63 | Log.d("wyz", "e::" + e.getMessage());
64 | }
65 |
66 | @Override
67 | public void onNext(UserInfo info) {
68 | Log.d("wyz", "请求数据:" + info);
69 | mView.hideDialog();
70 | mView.loginSuccess(info);
71 | }
72 | });
73 | }
74 |
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/mvp/src/main/java/com/example/mvp/ui/login/LoginPresenter.java:
--------------------------------------------------------------------------------
1 | package com.example.mvp.ui.login;
2 |
3 | import android.text.TextUtils;
4 | import android.util.Log;
5 |
6 | import com.example.mvp.R;
7 | import com.example.mvp.api.LoginApi;
8 | import com.example.mvp.base.BaseObserver;
9 | import com.example.mvp.contract.LoginContract;
10 | import com.example.mvp.entity.UserInfo;
11 | import com.example.mvp.helper.RetrofitCreateHelper;
12 |
13 | import java.util.HashMap;
14 | import java.util.Map;
15 |
16 | import io.reactivex.android.schedulers.AndroidSchedulers;
17 | import io.reactivex.schedulers.Schedulers;
18 |
19 |
20 | public class LoginPresenter extends LoginContract.LoginPresenter {
21 | @Override
22 | public void login() {
23 | String pass = mView.getPass();
24 | String user = mView.getUser();
25 | if (TextUtils.isEmpty(pass)) {
26 | mView.showToastMsg("请输入账号!");
27 | } else if (TextUtils.isEmpty(user)) {
28 | mView.showToastMsg("请输入密码!");
29 | } else {
30 | mView.showLoadDialog();
31 | Map parameters = new HashMap<>();
32 | parameters.put("username", user);
33 | parameters.put("password", pass);
34 | parameters.put("enews", "login");
35 | parameters.put("lifetime", "315360000");
36 | RetrofitCreateHelper.getHelper()
37 | .createApi(LoginApi.class)
38 | .login(parameters)
39 | .subscribeOn(Schedulers.io())
40 | .observeOn(AndroidSchedulers.mainThread())
41 | .subscribe(new BaseObserver(mCompositeDisposable) {
42 |
43 | @Override
44 | public void onError(Throwable e) {
45 | mView.hideDialog();
46 | mView.showErrorMsg("请求网络失败!");
47 | mView.loginError("登陆失败");
48 | Log.d("wyz", "e::" + e.getMessage());
49 | }
50 |
51 | @Override
52 | public void onComplete() {
53 | mView.hideDialog();
54 | }
55 |
56 | @Override
57 | public void onNext(UserInfo info) {
58 | Log.d("wyz", "请求数据:" + info);
59 | mView.hideDialog();
60 | mView.loginSucccess(info);
61 | }
62 | });
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/mvp/src/main/java/com/example/mvp/ui/login/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.mvp.ui.login;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.EditText;
9 | import android.widget.Toast;
10 |
11 | import com.example.mvp.R;
12 | import com.example.mvp.app.App;
13 | import com.example.mvp.base.BaseMvpActivity;
14 | import com.example.mvp.base.BaseMvpPresenter;
15 | import com.example.mvp.contract.LoginContract;
16 | import com.example.mvp.entity.UserInfo;
17 | import com.example.mvp.util.ToastUtil;
18 |
19 | public class LoginActivity extends BaseMvpActivity implements LoginContract.LoginView{
20 |
21 | private EditText etPass;
22 | private EditText etUser;
23 |
24 | @Override
25 | public int getLayoutId() {
26 | return R.layout.activity_login;
27 | }
28 |
29 | @Override
30 | protected void initView() {
31 | progressDialog.setTitle("请稍后");
32 | progressDialog.setMessage("正在加载。。。");
33 | }
34 |
35 | @Override
36 | protected void initData() {
37 |
38 | }
39 |
40 |
41 | @Override
42 | protected void findView() {
43 | Button btLogin = findViewById(R.id.bt_login);
44 | etPass = findViewById(R.id.et_pass);
45 | etUser = findViewById(R.id.et_user);
46 |
47 | btLogin.setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View view) {
50 | presenter.login();
51 | }
52 | });
53 | }
54 |
55 |
56 | @Override
57 | public void showLoadDialog() {
58 | progressDialog.show();
59 | }
60 |
61 | @Override
62 | public void showErrorMsg(String msg) {
63 | Log.d("wyz", "数据错误`消息:" + msg+" ");
64 | ToastUtil.showToast(msg);
65 | }
66 |
67 | @Override
68 | public void showToastMsg(String msg) {
69 | Log.d("wyz", "数据消息:" + msg+" ");
70 | ToastUtil.showToast(msg);
71 | }
72 |
73 | @Override
74 | public void hideDialog() {
75 | progressDialog.hide();
76 | }
77 |
78 |
79 |
80 | @Override
81 | public String getUser() {
82 | return etUser.getText().toString();
83 | }
84 |
85 | @Override
86 | public String getPass() {
87 | return etPass.getText().toString();
88 | }
89 |
90 | @Override
91 | public void loginSucccess(UserInfo userInfo) {
92 | ToastUtil.showToast("UserInfo:" +userInfo);
93 | }
94 |
95 | @Override
96 | public void loginError(String msg) {
97 |
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/myrxjava/src/main/java/com/example/myrxjava/ui/login/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.myrxjava.ui.login;
2 |
3 | import android.util.Log;
4 | import android.view.View;
5 | import android.widget.Button;
6 | import android.widget.EditText;
7 | import android.widget.Toast;
8 |
9 | import com.example.myrxjava.R;
10 | import com.example.myrxjava.app.App;
11 | import com.example.myrxjava.base.BaseActivity;
12 |
13 |
14 | import com.example.myrxjava.constract.LoginContract;
15 | import com.example.myrxjava.entity.UserInfo;
16 | import com.example.myrxjava.inject.component.DaggerLoginActivityComponent;
17 |
18 | import javax.inject.Inject;
19 |
20 | public class LoginActivity extends BaseActivity implements LoginContract.LoginMvpView{
21 | @Inject
22 | public LoginPresenter loginPresenter;
23 | @Inject
24 | public Toast toast;
25 |
26 | private EditText etPass;
27 | private EditText etUser;
28 |
29 | @Override
30 | public int getLayoutId() {
31 | return R.layout.activity_main;
32 | }
33 |
34 | @Override
35 | protected void initView() {
36 | progressDialog.setTitle("请稍后");
37 | progressDialog.setMessage("正在加载。。。");
38 | }
39 |
40 | @Override
41 | protected void initData() {
42 | DaggerLoginActivityComponent.builder().appComponent(App.appComponent).build().inject(this);
43 | loginPresenter.setMvpView(this);
44 | }
45 |
46 |
47 | @Override
48 | protected void findView() {
49 | Button btLogin = findViewById(R.id.bt_login);
50 | etPass = findViewById(R.id.et_pass);
51 | etUser = findViewById(R.id.et_user);
52 |
53 | btLogin.setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View view) {
56 | loginPresenter.login();
57 | }
58 | });
59 | }
60 |
61 |
62 | @Override
63 | public void showLoadDialog() {
64 | progressDialog.show();
65 | }
66 |
67 | @Override
68 | public void showErrorMsg(String msg) {
69 | Log.d("wyz", "数据错误`消息:" + msg+" "+toast);
70 | toast.setText(msg);
71 | toast.show();
72 | }
73 |
74 | @Override
75 | public void showToastMsg(String msg) {
76 | Log.d("wyz", "数据消息:" + msg+" "+toast);
77 | toast.setText(msg);
78 | toast.show();
79 | }
80 |
81 | @Override
82 | public void hideDialog() {
83 | progressDialog.hide();
84 | }
85 |
86 | @Override
87 | public void loginSuccess(UserInfo userInfo) {
88 | toast.setText("UserInfo:" +userInfo);
89 | toast.show();
90 | }
91 |
92 | @Override
93 | public String getUser() {
94 | return etUser.getText().toString();
95 | }
96 |
97 | @Override
98 | public String getPass() {
99 | return etPass.getText().toString();
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/myrxjava/src/main/java/com/example/myrxjava/inject/module/ApiModule.java:
--------------------------------------------------------------------------------
1 | package com.example.myrxjava.inject.module;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 | import android.widget.Toast;
6 |
7 |
8 | import java.io.File;
9 | import java.io.IOException;
10 | import java.security.cert.CertificateException;
11 |
12 | import javax.inject.Inject;
13 | import javax.inject.Singleton;
14 | import javax.net.ssl.SSLContext;
15 | import javax.net.ssl.SSLSocketFactory;
16 | import javax.net.ssl.TrustManager;
17 | import javax.net.ssl.X509TrustManager;
18 |
19 | import dagger.Module;
20 | import dagger.Provides;
21 |
22 | import okhttp3.Cache;
23 | import okhttp3.Interceptor;
24 | import okhttp3.OkHttpClient;
25 | import okhttp3.Request;
26 | import okhttp3.Response;
27 | import retrofit2.Retrofit;
28 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
29 | import retrofit2.converter.gson.GsonConverterFactory;
30 |
31 | /**
32 | * 访问网络的Module
33 | */
34 | @Module
35 | @Singleton
36 | public class ApiModule {
37 | public static final String BASE_URL = "https://www.iqshw.com/";
38 |
39 | @Provides
40 | public Interceptor providesIntercepter() {
41 | return new Interceptor() {
42 | @Override
43 | public Response intercept(Chain chain) throws IOException {
44 | Request request = chain.request();
45 | Response response = chain.proceed(request);
46 |
47 | String chainControl = request.cacheControl().toString();
48 | if (TextUtils.isEmpty(chainControl)) {
49 | chainControl = "public, max-age=60, max-stale=240000";
50 | }
51 |
52 | return response.newBuilder()
53 | .addHeader("Chain-Control", chainControl)
54 | .removeHeader("Pragma")
55 | .build();
56 | }
57 | };
58 | }
59 |
60 | @Provides
61 | public Cache providesCache(Context context) {
62 | File httpCacheFile = context.getExternalCacheDir().getAbsoluteFile();
63 | return new Cache(httpCacheFile, 1024 * 10 * 1024);
64 | }
65 |
66 |
67 | @Provides
68 | @Singleton
69 | public OkHttpClient providesOkHttpClient(Interceptor interceptor, Cache cache) {
70 |
71 | OkHttpClient client = new OkHttpClient.Builder()
72 | .cache(cache)
73 | .addInterceptor(interceptor)
74 | .build();
75 |
76 | return client;
77 | }
78 |
79 |
80 |
81 | @Provides
82 | @Singleton
83 | public Retrofit providesRetrofit(OkHttpClient client) {
84 | Retrofit retrofit = new Retrofit.Builder()
85 | .baseUrl(BASE_URL)
86 | .client(client)
87 | .addConverterFactory(GsonConverterFactory.create())
88 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
89 | .build();
90 | return retrofit;
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/mvp/src/main/java/com/example/mvp/helper/RetrofitCreateHelper.java:
--------------------------------------------------------------------------------
1 | package com.example.mvp.helper;
2 |
3 |
4 |
5 | import android.content.Context;
6 | import android.text.TextUtils;
7 |
8 | import com.example.mvp.app.App;
9 |
10 | import java.io.File;
11 | import java.io.IOException;
12 | import java.util.concurrent.TimeUnit;
13 |
14 | import okhttp3.Cache;
15 | import okhttp3.Interceptor;
16 | import okhttp3.OkHttpClient;
17 | import okhttp3.Request;
18 | import okhttp3.Response;
19 | import okhttp3.internal.cache.CacheInterceptor;
20 | import okhttp3.logging.HttpLoggingInterceptor;
21 | import retrofit2.Retrofit;
22 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
23 | import retrofit2.converter.gson.GsonConverterFactory;
24 |
25 | /**
26 | * Created by Horrarndoo on 2017/9/7.
27 | *
28 | */
29 |
30 | public class RetrofitCreateHelper {
31 |
32 | public static final String BASE_URL = "https://www.iqshw.com/";
33 | private Retrofit retrofit;
34 |
35 | //郁闷还要写单利 dagger2 1个注解就oK
36 | private RetrofitCreateHelper(){
37 | createRetrofit();
38 | }
39 |
40 | public static RetrofitCreateHelper getHelper() {
41 | return Holder.holder;
42 | }
43 |
44 | public static class Holder{
45 | public static RetrofitCreateHelper holder=new RetrofitCreateHelper();
46 | }
47 |
48 |
49 |
50 | private Interceptor getIntercepter() {
51 | return new Interceptor() {
52 | @Override
53 | public Response intercept(Chain chain) throws IOException {
54 | Request request = chain.request();
55 | Response response = chain.proceed(request);
56 |
57 | String chainControl = request.cacheControl().toString();
58 | if (TextUtils.isEmpty(chainControl)) {
59 | chainControl = "public, max-age=60, max-stale=240000";
60 | }
61 |
62 | return response.newBuilder()
63 | .addHeader("Chain-Control", chainControl)
64 | .removeHeader("Pragma")
65 | .build();
66 | }
67 | };
68 | }
69 |
70 | private Cache getCache(Context context) {
71 | File httpCacheFile = context.getExternalCacheDir().getAbsoluteFile();
72 | return new Cache(httpCacheFile, 1024 * 10 * 1024);
73 | }
74 |
75 |
76 | public OkHttpClient getHttpClient(Interceptor interceptor, Cache cache) {
77 |
78 | OkHttpClient client = new OkHttpClient.Builder()
79 | .cache(cache)
80 | .addInterceptor(interceptor)
81 | .build();
82 |
83 | return client;
84 | }
85 |
86 | private void createRetrofit(){
87 | //这里我感受到了Dagger2的好处了
88 | retrofit = new Retrofit.Builder()
89 | .baseUrl(BASE_URL)
90 | .client(getHttpClient(getIntercepter(),getCache(App.getAppContext())))//这里我感受到了Dagger2的好处了
91 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
92 | .addConverterFactory(GsonConverterFactory.create())
93 | .build();
94 |
95 | }
96 |
97 | public T createApi(Class clazz) {
98 | return retrofit.create(clazz);
99 | }
100 | }
101 |
102 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/mvp/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/myrxjava/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------