Commit 5d31a3b812f2ed65d57e6aba8ff2586c1b5c1b1d
Exists in
yxb_dev
and in
2 other branches
Merge branch 'yxb_dev' of http://git.shunzhi.net/taohd/parentwork into yxb_dev
Showing
15 changed files
with
171 additions
and
68 deletions
Show diff stats
app/src/main/AndroidManifest.xml
@@ -37,7 +37,7 @@ | @@ -37,7 +37,7 @@ | ||
37 | 37 | ||
38 | 38 | ||
39 | <application | 39 | <application |
40 | - android:name=".MyApplication" | 40 | + android:name=".AppContext" |
41 | android:allowBackup="true" | 41 | android:allowBackup="true" |
42 | android:icon="@mipmap/ic_launcher" | 42 | android:icon="@mipmap/ic_launcher" |
43 | android:label="@string/app_name" | 43 | android:label="@string/app_name" |
@@ -45,7 +45,7 @@ | @@ -45,7 +45,7 @@ | ||
45 | android:supportsRtl="true" | 45 | android:supportsRtl="true" |
46 | android:theme="@style/AppTheme"> | 46 | android:theme="@style/AppTheme"> |
47 | 47 | ||
48 | - <activity android:name=".ui.MainActivity"> | 48 | + <activity android:name=".ui.activity.LoginAndRegistActivity"> |
49 | <intent-filter> | 49 | <intent-filter> |
50 | <action android:name="android.intent.action.MAIN" /> | 50 | <action android:name="android.intent.action.MAIN" /> |
51 | 51 | ||
@@ -54,7 +54,7 @@ | @@ -54,7 +54,7 @@ | ||
54 | </activity> | 54 | </activity> |
55 | <!--<activity android:name=".ui.activity.LoginAndRegistActivity" />--> | 55 | <!--<activity android:name=".ui.activity.LoginAndRegistActivity" />--> |
56 | <activity android:name=".ui.activity.StartActivity"></activity> | 56 | <activity android:name=".ui.activity.StartActivity"></activity> |
57 | - <activity android:name=".ui.activity.LoginAndRegistActivity" | 57 | + <activity android:name=".ui.MainActivity" |
58 | android:screenOrientation="portrait" | 58 | android:screenOrientation="portrait" |
59 | /> | 59 | /> |
60 | <activity android:name=".ui.activity.MyChildActivity" | 60 | <activity android:name=".ui.activity.MyChildActivity" |
app/src/main/java/com/shunzhi/parent/AppConfig.java
@@ -41,12 +41,6 @@ public class AppConfig { | @@ -41,12 +41,6 @@ public class AppConfig { | ||
41 | return appConfig; | 41 | return appConfig; |
42 | } | 42 | } |
43 | 43 | ||
44 | - | ||
45 | - | ||
46 | - | ||
47 | - | ||
48 | - | ||
49 | - | ||
50 | //默认下载保存的路径 | 44 | //默认下载保存的路径 |
51 | public final static String DEFAULT_SAVE_DOWNLOAD_PATH = Environment | 45 | public final static String DEFAULT_SAVE_DOWNLOAD_PATH = Environment |
52 | .getExternalStorageDirectory() | 46 | .getExternalStorageDirectory() |
@@ -66,8 +60,8 @@ public class AppConfig { | @@ -66,8 +60,8 @@ public class AppConfig { | ||
66 | } | 60 | } |
67 | 61 | ||
68 | //保存键值对 | 62 | //保存键值对 |
69 | - public void set(Context context, String key, String value) { | ||
70 | - SharedPreferences.Editor editor = getSharedPreferences(context).edit(); | 63 | + public void set(String key, String value) { |
64 | + SharedPreferences.Editor editor = getSharedPreferences(AppContext.getContext()).edit(); | ||
71 | if (TextUtils.isEmpty(value)) { | 65 | if (TextUtils.isEmpty(value)) { |
72 | editor.putString(key, value); | 66 | editor.putString(key, value); |
73 | } else { | 67 | } else { |
app/src/main/java/com/shunzhi/parent/AppContext.java
app/src/main/java/com/shunzhi/parent/MyApplication.java
@@ -1,17 +0,0 @@ | @@ -1,17 +0,0 @@ | ||
1 | -package com.shunzhi.parent; | ||
2 | - | ||
3 | -import com.share.mvpsdk.global.GlobalApplication; | ||
4 | - | ||
5 | -/** | ||
6 | - * Created by ToaHanDong on 2018/3/2. | ||
7 | - */ | ||
8 | - | ||
9 | -public class MyApplication extends GlobalApplication { | ||
10 | - | ||
11 | - | ||
12 | - @Override | ||
13 | - public void onCreate() { | ||
14 | - super.onCreate(); | ||
15 | - | ||
16 | - } | ||
17 | -} |
app/src/main/java/com/shunzhi/parent/contract/loginandregister/ceping/CepingMainContract.java
0 → 100644
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +package com.shunzhi.parent.contract.loginandregister.ceping; | ||
2 | + | ||
3 | +import com.share.mvpsdk.base.BasePresenter; | ||
4 | +import com.share.mvpsdk.base.IBaseFragment; | ||
5 | +import com.share.mvpsdk.base.IBaseModel; | ||
6 | + | ||
7 | +/** | ||
8 | + * Created by ToaHanDong on 2018/3/8. | ||
9 | + */ | ||
10 | + | ||
11 | +public interface CepingMainContract { | ||
12 | + | ||
13 | + public abstract class CePingMainPresenter extends BasePresenter<ICePingMainModel,ICePingMainView>{ | ||
14 | + public abstract void getHotContents(); | ||
15 | + } | ||
16 | + | ||
17 | + interface ICePingMainModel extends IBaseModel { | ||
18 | + | ||
19 | + } | ||
20 | + | ||
21 | + | ||
22 | + interface ICePingMainView extends IBaseFragment { | ||
23 | + void showHotContents(); | ||
24 | + } | ||
25 | +} |
app/src/main/java/com/shunzhi/parent/model/loginandregister/LoginAndRegisterModel.java
@@ -8,6 +8,7 @@ import com.shunzhi.parent.api.LoginRegisterApi; | @@ -8,6 +8,7 @@ import com.shunzhi.parent.api.LoginRegisterApi; | ||
8 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; | 8 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; |
9 | 9 | ||
10 | import io.reactivex.Observable; | 10 | import io.reactivex.Observable; |
11 | +import okhttp3.RequestBody; | ||
11 | 12 | ||
12 | /** | 13 | /** |
13 | * Created by Administrator on 2018/3/6 0006. | 14 | * Created by Administrator on 2018/3/6 0006. |
@@ -24,13 +25,13 @@ public class LoginAndRegisterModel extends BaseModel implements LoginAndRegiste | @@ -24,13 +25,13 @@ public class LoginAndRegisterModel extends BaseModel implements LoginAndRegiste | ||
24 | 25 | ||
25 | @Override | 26 | @Override |
26 | public Observable<JsonObject> getLoginResult(String loginName, String loginPwd) { | 27 | public Observable<JsonObject> getLoginResult(String loginName, String loginPwd) { |
27 | - return RetrofitCreateHelper.loginApi(LoginRegisterApi.class,LoginRegisterApi.url).loginResult("password",loginName,loginPwd) | 28 | + return RetrofitCreateHelper.getInstance().login(LoginRegisterApi.class,LoginRegisterApi.url).loginResult("password",loginName,loginPwd) |
28 | .compose(RxHelper.<JsonObject>rxSchedulerHelper()); | 29 | .compose(RxHelper.<JsonObject>rxSchedulerHelper()); |
29 | } | 30 | } |
30 | 31 | ||
31 | @Override | 32 | @Override |
32 | public Observable<JsonObject> getRegisterResult(String adminName, String idCode, String password) { | 33 | public Observable<JsonObject> getRegisterResult(String adminName, String idCode, String password) { |
33 | - return RetrofitCreateHelper.createApi(LoginRegisterApi.class,LoginRegisterApi.url).registerResult("idcode",adminName,idCode,password) | 34 | + return RetrofitCreateHelper.getInstance().createApi(LoginRegisterApi.class,LoginRegisterApi.url).registerResult("idcode",adminName,idCode,password) |
34 | .compose(RxHelper.<JsonObject>rxSchedulerHelper()); | 35 | .compose(RxHelper.<JsonObject>rxSchedulerHelper()); |
35 | } | 36 | } |
36 | 37 |
app/src/main/java/com/shunzhi/parent/presenter/loginandregister/LoginAndRegisterPresenter.java
1 | package com.shunzhi.parent.presenter.loginandregister; | 1 | package com.shunzhi.parent.presenter.loginandregister; |
2 | 2 | ||
3 | import android.text.TextUtils; | 3 | import android.text.TextUtils; |
4 | +import android.util.Log; | ||
4 | 5 | ||
5 | import com.google.gson.JsonObject; | 6 | import com.google.gson.JsonObject; |
6 | import com.share.mvpsdk.helper.RetrofitCreateHelper; | 7 | import com.share.mvpsdk.helper.RetrofitCreateHelper; |
8 | +import com.share.mvpsdk.utils.OkHttpExceptionUtil; | ||
7 | import com.share.mvpsdk.utils.ToastUtils; | 9 | import com.share.mvpsdk.utils.ToastUtils; |
8 | import com.shunzhi.parent.AppConfig; | 10 | import com.shunzhi.parent.AppConfig; |
9 | import com.shunzhi.parent.AppContext; | 11 | import com.shunzhi.parent.AppContext; |
@@ -14,6 +16,7 @@ import java.util.regex.Matcher; | @@ -14,6 +16,7 @@ import java.util.regex.Matcher; | ||
14 | import java.util.regex.Pattern; | 16 | import java.util.regex.Pattern; |
15 | 17 | ||
16 | import io.reactivex.functions.Consumer; | 18 | import io.reactivex.functions.Consumer; |
19 | +import retrofit2.HttpException; | ||
17 | 20 | ||
18 | /** | 21 | /** |
19 | * Created by Administrator on 2018/3/6 0006. | 22 | * Created by Administrator on 2018/3/6 0006. |
@@ -36,21 +39,27 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre | @@ -36,21 +39,27 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre | ||
36 | mRxManager.register(mIModel.getLoginResult(loginName, loginPwd).subscribe(new Consumer<JsonObject>() { | 39 | mRxManager.register(mIModel.getLoginResult(loginName, loginPwd).subscribe(new Consumer<JsonObject>() { |
37 | @Override | 40 | @Override |
38 | public void accept(JsonObject jsonObject) throws Exception { | 41 | public void accept(JsonObject jsonObject) throws Exception { |
39 | - if (jsonObject != null && !TextUtils.isEmpty(jsonObject.get("access_token").getAsString())) { | ||
40 | - AppConfig.getAppConfig(AppContext.getInstance()).set(AppContext.getInstance() | ||
41 | - , AppConfig.ACCESS_TOKEN, jsonObject.get("access_token").getAsString()); | ||
42 | - AppConfig.getAppConfig(AppContext.getInstance()).set(AppContext.getInstance(), AppConfig.LOGIN_NAME,loginName); | ||
43 | - AppConfig.getAppConfig(AppContext.getInstance()).set(AppContext.getInstance(), AppConfig.LOGIN_PWD, loginPwd); | ||
44 | - RetrofitCreateHelper.getInstance().setAuthorization("Bearer "+jsonObject.get("access_token").getAsString()); | ||
45 | - getUserInfo(); | ||
46 | - } else { | ||
47 | - ToastUtils.showToast(jsonObject.get("error").getAsString()); | 42 | + try { |
43 | + if (jsonObject != null && !TextUtils.isEmpty(jsonObject.get("access_token").getAsString())) { | ||
44 | + AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.ACCESS_TOKEN, jsonObject.get("access_token").getAsString()); | ||
45 | + AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.LOGIN_NAME,loginName); | ||
46 | + AppConfig.getAppConfig(AppContext.getInstance()).set(AppConfig.LOGIN_PWD, loginPwd); | ||
47 | + RetrofitCreateHelper.getInstance().setAuthorization("Bearer "+jsonObject.get("access_token").getAsString()); | ||
48 | + getUserInfo(); | ||
49 | + } else { | ||
50 | + ToastUtils.showToast(jsonObject.get("error").getAsString()); | ||
51 | + } | ||
52 | + }catch (Exception e){ | ||
53 | + e.printStackTrace(); | ||
54 | + ToastUtils.showToast("登录失败:"+e.toString()); | ||
48 | } | 55 | } |
49 | } | 56 | } |
50 | }, new Consumer<Throwable>() { | 57 | }, new Consumer<Throwable>() { |
51 | @Override | 58 | @Override |
52 | public void accept(Throwable throwable) throws Exception { | 59 | public void accept(Throwable throwable) throws Exception { |
53 | - ToastUtils.showToast(throwable.getMessage()); | 60 | + if (null!=throwable) |
61 | + OkHttpExceptionUtil.handOkHttpException((HttpException) throwable); | ||
62 | +// ToastUtils.showToast(throwable.getMessage()); | ||
54 | } | 63 | } |
55 | })); | 64 | })); |
56 | 65 | ||
@@ -110,7 +119,7 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre | @@ -110,7 +119,7 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre | ||
110 | 119 | ||
111 | @Override | 120 | @Override |
112 | public void getUserInfo() { | 121 | public void getUserInfo() { |
113 | - | 122 | + Log.d("77777","getUserInfo="); |
114 | } | 123 | } |
115 | 124 | ||
116 | 125 |
app/src/main/java/com/shunzhi/parent/ui/MainActivity.java
@@ -33,7 +33,8 @@ public class MainActivity extends BaseCompatActivity { | @@ -33,7 +33,8 @@ public class MainActivity extends BaseCompatActivity { | ||
33 | 33 | ||
34 | private int CEPING_INDEX = 0, CONSULT_INDEX = 1, REPORT_INDEX = 2, MINE_INDEX = 3; | 34 | private int CEPING_INDEX = 0, CONSULT_INDEX = 1, REPORT_INDEX = 2, MINE_INDEX = 3; |
35 | 35 | ||
36 | - FragmentTransaction fragmentTransaction=null; | 36 | + FragmentTransaction fragmentTransaction = null; |
37 | + | ||
37 | @Override | 38 | @Override |
38 | protected void initView(Bundle savedInstanceState) { | 39 | protected void initView(Bundle savedInstanceState) { |
39 | 40 | ||
@@ -77,11 +78,11 @@ public class MainActivity extends BaseCompatActivity { | @@ -77,11 +78,11 @@ public class MainActivity extends BaseCompatActivity { | ||
77 | fragments[REPORT_INDEX] = reportFragment; | 78 | fragments[REPORT_INDEX] = reportFragment; |
78 | fragments[MINE_INDEX] = mineFragment; | 79 | fragments[MINE_INDEX] = mineFragment; |
79 | 80 | ||
80 | - fragmentTransaction=getSupportFragmentManager().beginTransaction(); | ||
81 | - fragmentTransaction.add(R.id.frame,cePingFragment) | ||
82 | - .add(R.id.frame,consultFragment) | ||
83 | - .add(R.id.frame,reportFragment) | ||
84 | - .add(R.id.frame,mineFragment) | 81 | + fragmentTransaction = getSupportFragmentManager().beginTransaction(); |
82 | + fragmentTransaction.add(R.id.frame, cePingFragment) | ||
83 | + .add(R.id.frame, consultFragment) | ||
84 | + .add(R.id.frame, reportFragment) | ||
85 | + .add(R.id.frame, mineFragment) | ||
85 | .show(cePingFragment) | 86 | .show(cePingFragment) |
86 | .hide(consultFragment) | 87 | .hide(consultFragment) |
87 | .hide(reportFragment) | 88 | .hide(reportFragment) |
app/src/main/java/com/shunzhi/parent/ui/fragment/CePingFragment.java
1 | package com.shunzhi.parent.ui.fragment; | 1 | package com.shunzhi.parent.ui.fragment; |
2 | 2 | ||
3 | import android.os.Bundle; | 3 | import android.os.Bundle; |
4 | -import android.support.v4.app.Fragment; | ||
5 | -import android.view.LayoutInflater; | 4 | +import android.support.annotation.NonNull; |
5 | +import android.support.annotation.Nullable; | ||
6 | import android.view.View; | 6 | import android.view.View; |
7 | -import android.view.ViewGroup; | ||
8 | 7 | ||
8 | +import com.share.mvpsdk.base.BasePresenter; | ||
9 | +import com.share.mvpsdk.base.fragment.BaseMVPCompatFragment; | ||
9 | import com.shunzhi.parent.R; | 10 | import com.shunzhi.parent.R; |
10 | 11 | ||
11 | -public class CePingFragment extends Fragment { | 12 | +public class CePingFragment extends BaseMVPCompatFragment { |
12 | 13 | ||
13 | @Override | 14 | @Override |
14 | - public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
15 | - Bundle savedInstanceState) { | ||
16 | - // Inflate the layout for this fragment | ||
17 | - return inflater.inflate(R.layout.fragment_ce_ping, container, false); | 15 | + public int getLayoutId() { |
16 | + return R.layout.fragment_ce_ping; | ||
17 | + } | ||
18 | + | ||
19 | + @Override | ||
20 | + public void initUI(View view, @Nullable Bundle savedInstanceState) { | ||
21 | + | ||
22 | + } | ||
23 | + | ||
24 | + @NonNull | ||
25 | + @Override | ||
26 | + public BasePresenter initPresenter() { | ||
27 | + return null; | ||
18 | } | 28 | } |
19 | } | 29 | } |
1.37 KB
1.36 KB
@@ -0,0 +1,6 @@ | @@ -0,0 +1,6 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
3 | + <item android:drawable="@drawable/report_select" android:state_selected="true"/> | ||
4 | + <item android:drawable="@drawable/report_select" android:state_pressed="true"/> | ||
5 | + <item android:drawable="@drawable/report_normal"/> | ||
6 | +</selector> |
app/src/main/res/menu/bottom_navigationview.xml
@@ -14,7 +14,7 @@ | @@ -14,7 +14,7 @@ | ||
14 | 14 | ||
15 | 15 | ||
16 | <item android:id="@+id/menu_item_report" | 16 | <item android:id="@+id/menu_item_report" |
17 | - android:icon="@drawable/selector_ceping" | 17 | + android:icon="@drawable/selector_report" |
18 | android:title="报告" | 18 | android:title="报告" |
19 | ></item> | 19 | ></item> |
20 | 20 |
mvpsdk/src/main/java/com/share/mvpsdk/helper/RetrofitCreateHelper.java
1 | package com.share.mvpsdk.helper; | 1 | package com.share.mvpsdk.helper; |
2 | 2 | ||
3 | 3 | ||
4 | +import android.util.Log; | ||
5 | + | ||
4 | import com.share.mvpsdk.helper.okhttp.CacheInterceptor; | 6 | import com.share.mvpsdk.helper.okhttp.CacheInterceptor; |
5 | import com.share.mvpsdk.helper.okhttp.HttpCache; | 7 | import com.share.mvpsdk.helper.okhttp.HttpCache; |
6 | import com.share.mvpsdk.helper.okhttp.TrustManager; | 8 | import com.share.mvpsdk.helper.okhttp.TrustManager; |
7 | import com.share.mvpsdk.utils.StringUtils; | 9 | import com.share.mvpsdk.utils.StringUtils; |
10 | +import com.share.mvpsdk.utils.ToastUtils; | ||
8 | 11 | ||
12 | +import java.io.IOException; | ||
9 | import java.util.concurrent.TimeUnit; | 13 | import java.util.concurrent.TimeUnit; |
10 | 14 | ||
15 | +import okhttp3.Interceptor; | ||
11 | import okhttp3.OkHttpClient; | 16 | import okhttp3.OkHttpClient; |
17 | +import okhttp3.Request; | ||
18 | +import okhttp3.Response; | ||
12 | import okhttp3.logging.HttpLoggingInterceptor; | 19 | import okhttp3.logging.HttpLoggingInterceptor; |
13 | import retrofit2.Retrofit; | 20 | import retrofit2.Retrofit; |
14 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; | 21 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; |
@@ -27,7 +34,8 @@ public class RetrofitCreateHelper { | @@ -27,7 +34,8 @@ public class RetrofitCreateHelper { | ||
27 | private static final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor() | 34 | private static final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor() |
28 | .setLevel(HttpLoggingInterceptor.Level.BODY); | 35 | .setLevel(HttpLoggingInterceptor.Level.BODY); |
29 | private static CacheInterceptor cacheInterceptor = new CacheInterceptor(); | 36 | private static CacheInterceptor cacheInterceptor = new CacheInterceptor(); |
30 | - private static OkHttpClient okHttpClient = new OkHttpClient.Builder() | 37 | + private static OkHttpClient.Builder okhttpClientBuilder=null; |
38 | + /*private static OkHttpClient okHttpClient = new OkHttpClient.Builder() | ||
31 | //SSL证书 | 39 | //SSL证书 |
32 | .sslSocketFactory(TrustManager.getUnsafeOkHttpClient()) | 40 | .sslSocketFactory(TrustManager.getUnsafeOkHttpClient()) |
33 | .hostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) | 41 | .hostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) |
@@ -43,7 +51,7 @@ public class RetrofitCreateHelper { | @@ -43,7 +51,7 @@ public class RetrofitCreateHelper { | ||
43 | .writeTimeout(TIMEOUT_READ, TimeUnit.SECONDS) | 51 | .writeTimeout(TIMEOUT_READ, TimeUnit.SECONDS) |
44 | //失败重连 | 52 | //失败重连 |
45 | .retryOnConnectionFailure(true) | 53 | .retryOnConnectionFailure(true) |
46 | - .build(); | 54 | + .build();*/ |
47 | public static RetrofitCreateHelper getInstance(){ | 55 | public static RetrofitCreateHelper getInstance(){ |
48 | if (null==retrofitCreateHelper){ | 56 | if (null==retrofitCreateHelper){ |
49 | synchronized (RetrofitCreateHelper.class){ | 57 | synchronized (RetrofitCreateHelper.class){ |
@@ -52,31 +60,68 @@ public class RetrofitCreateHelper { | @@ -52,31 +60,68 @@ public class RetrofitCreateHelper { | ||
52 | } | 60 | } |
53 | return retrofitCreateHelper; | 61 | return retrofitCreateHelper; |
54 | } | 62 | } |
55 | - public static <T> T createApi(Class<T> clazz, String url) { | 63 | + |
64 | + public RetrofitCreateHelper(){ | ||
65 | + if (null==okhttpClientBuilder)okhttpClientBuilder=new OkHttpClient.Builder(); | ||
66 | + okhttpClientBuilder.connectTimeout(10000,TimeUnit.SECONDS); | ||
67 | + okhttpClientBuilder.addInterceptor(new Interceptor() { | ||
68 | + @Override | ||
69 | + public Response intercept(Chain chain) throws IOException { | ||
70 | + Request original = chain.request(); | ||
71 | + Request.Builder requestBuilder = original.newBuilder().header("Authorization", Authorization); | ||
72 | + Request request = requestBuilder.build(); | ||
73 | + return chain.proceed(request); | ||
74 | + } | ||
75 | + }); | ||
76 | + okhttpClientBuilder.addNetworkInterceptor(cacheInterceptor); | ||
77 | + okhttpClientBuilder.addInterceptor(interceptor); | ||
78 | + } | ||
79 | + | ||
80 | + public <T> T createApi(Class<T> clazz, String url) { | ||
56 | Authorization=token; | 81 | Authorization=token; |
57 | Retrofit retrofit = new Retrofit.Builder() | 82 | Retrofit retrofit = new Retrofit.Builder() |
58 | .baseUrl(url) | 83 | .baseUrl(url) |
59 | - .client(okHttpClient) | 84 | + .client(okhttpClientBuilder.build()) |
60 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | 85 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) |
61 | .addConverterFactory(GsonConverterFactory.create()) | 86 | .addConverterFactory(GsonConverterFactory.create()) |
62 | .build(); | 87 | .build(); |
63 | return retrofit.create(clazz); | 88 | return retrofit.create(clazz); |
64 | } | 89 | } |
65 | 90 | ||
66 | - public static <T> T loginApi(Class<T> clazz, String url) { | 91 | +// public static <T> T loginApi(Class<T> clazz, String url) { |
92 | +// Authorization= StringUtils.getSign(); | ||
93 | +// okHttpClient.newBuilder().addInterceptor(new Interceptor() { | ||
94 | +// @Override | ||
95 | +// public Response intercept(Chain chain) throws IOException { | ||
96 | +// Request original = chain.request(); | ||
97 | +// Request.Builder requestBuilder = original.newBuilder().header("Authorization", Authorization); | ||
98 | +// Request request = requestBuilder.build(); | ||
99 | +// return chain.proceed(request); | ||
100 | +// } | ||
101 | +// }); | ||
102 | +// Log.d("77777","Authorization="+Authorization); | ||
103 | +// Retrofit retrofit = new Retrofit.Builder() | ||
104 | +// .baseUrl(url) | ||
105 | +// .client(okHttpClient) | ||
106 | +// .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | ||
107 | +// .addConverterFactory(GsonConverterFactory.create()) | ||
108 | +// .build(); | ||
109 | +// return retrofit.create(clazz); | ||
110 | +// } | ||
111 | + public void setAuthorization(String Authorization){ | ||
112 | + this.token=Authorization; | ||
113 | + } | ||
114 | + | ||
115 | + public <T> T login(Class<T> clazz,String url){ | ||
67 | Authorization= StringUtils.getSign(); | 116 | Authorization= StringUtils.getSign(); |
68 | - Retrofit retrofit = new Retrofit.Builder() | 117 | + Retrofit retrofit=new Retrofit.Builder() |
118 | + .client(okhttpClientBuilder.build()) | ||
69 | .baseUrl(url) | 119 | .baseUrl(url) |
70 | - .client(okHttpClient) | ||
71 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | 120 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) |
72 | .addConverterFactory(GsonConverterFactory.create()) | 121 | .addConverterFactory(GsonConverterFactory.create()) |
73 | .build(); | 122 | .build(); |
74 | return retrofit.create(clazz); | 123 | return retrofit.create(clazz); |
75 | } | 124 | } |
76 | - public void setAuthorization(String Authorization){ | ||
77 | - this.token=Authorization; | ||
78 | - } | ||
79 | - | ||
80 | 125 | ||
81 | 126 | ||
82 | 127 |
mvpsdk/src/main/java/com/share/mvpsdk/utils/OkHttpExceptionUtil.java
0 → 100644
@@ -0,0 +1,30 @@ | @@ -0,0 +1,30 @@ | ||
1 | +package com.share.mvpsdk.utils; | ||
2 | + | ||
3 | +import android.support.annotation.NonNull; | ||
4 | +import android.util.Log; | ||
5 | + | ||
6 | +import org.json.JSONObject; | ||
7 | + | ||
8 | +import okhttp3.ResponseBody; | ||
9 | +import retrofit2.HttpException; | ||
10 | +import retrofit2.Response; | ||
11 | + | ||
12 | +/** | ||
13 | + * Created by 10501 on 2017/7/18. | ||
14 | + */ | ||
15 | + | ||
16 | +public class OkHttpExceptionUtil { | ||
17 | + public static void handOkHttpException(@NonNull HttpException e){ | ||
18 | + Response response = e.response(); | ||
19 | + if (response==null)return; | ||
20 | + ResponseBody responseBody = response.errorBody(); | ||
21 | + if (responseBody==null)return; | ||
22 | + try { | ||
23 | + JSONObject json = new JSONObject(responseBody.string()); | ||
24 | + Log.d("77777",json.toString()); | ||
25 | + ToastUtils.showToast(json.optString("error")); | ||
26 | + } catch (Exception e1) { | ||
27 | + e1.printStackTrace(); | ||
28 | + } | ||
29 | + } | ||
30 | +} |