Commit 34c57df75c9e95b5c426900330b4992752994cc9
1 parent
2dec5d36
Exists in
yxb_dev
and in
2 other branches
no message
Showing
15 changed files
with
171 additions
and
70 deletions
Show diff stats
app/src/main/AndroidManifest.xml
... | ... | @@ -37,7 +37,7 @@ |
37 | 37 | |
38 | 38 | |
39 | 39 | <application |
40 | - android:name=".MyApplication" | |
40 | + android:name=".AppContext" | |
41 | 41 | android:allowBackup="true" |
42 | 42 | android:icon="@mipmap/ic_launcher" |
43 | 43 | android:label="@string/app_name" |
... | ... | @@ -45,7 +45,7 @@ |
45 | 45 | android:supportsRtl="true" |
46 | 46 | android:theme="@style/AppTheme"> |
47 | 47 | |
48 | - <activity android:name=".ui.MainActivity"> | |
48 | + <activity android:name=".ui.activity.LoginAndRegistActivity"> | |
49 | 49 | <intent-filter> |
50 | 50 | <action android:name="android.intent.action.MAIN" /> |
51 | 51 | |
... | ... | @@ -54,7 +54,7 @@ |
54 | 54 | </activity> |
55 | 55 | <!--<activity android:name=".ui.activity.LoginAndRegistActivity" />--> |
56 | 56 | <activity android:name=".ui.activity.StartActivity"></activity> |
57 | - <activity android:name=".ui.activity.LoginAndRegistActivity" | |
57 | + <activity android:name=".ui.MainActivity" | |
58 | 58 | android:screenOrientation="portrait" |
59 | 59 | /> |
60 | 60 | </application> | ... | ... |
app/src/main/java/com/shunzhi/parent/AppConfig.java
... | ... | @@ -41,12 +41,6 @@ public class AppConfig { |
41 | 41 | return appConfig; |
42 | 42 | } |
43 | 43 | |
44 | - | |
45 | - | |
46 | - | |
47 | - | |
48 | - | |
49 | - | |
50 | 44 | //默认下载保存的路径 |
51 | 45 | public final static String DEFAULT_SAVE_DOWNLOAD_PATH = Environment |
52 | 46 | .getExternalStorageDirectory() |
... | ... | @@ -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 | 65 | if (TextUtils.isEmpty(value)) { |
72 | 66 | editor.putString(key, value); |
73 | 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 | -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 @@ |
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 | 8 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; |
9 | 9 | |
10 | 10 | import io.reactivex.Observable; |
11 | +import okhttp3.RequestBody; | |
11 | 12 | |
12 | 13 | /** |
13 | 14 | * Created by Administrator on 2018/3/6 0006. |
... | ... | @@ -24,13 +25,13 @@ public class LoginAndRegisterModel extends BaseModel implements LoginAndRegiste |
24 | 25 | |
25 | 26 | @Override |
26 | 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 | 29 | .compose(RxHelper.<JsonObject>rxSchedulerHelper()); |
29 | 30 | } |
30 | 31 | |
31 | 32 | @Override |
32 | 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 | 35 | .compose(RxHelper.<JsonObject>rxSchedulerHelper()); |
35 | 36 | } |
36 | 37 | ... | ... |
app/src/main/java/com/shunzhi/parent/presenter/loginandregister/LoginAndRegisterPresenter.java
1 | 1 | package com.shunzhi.parent.presenter.loginandregister; |
2 | 2 | |
3 | 3 | import android.text.TextUtils; |
4 | +import android.util.Log; | |
4 | 5 | |
5 | 6 | import com.google.gson.JsonObject; |
6 | 7 | import com.share.mvpsdk.helper.RetrofitCreateHelper; |
8 | +import com.share.mvpsdk.utils.OkHttpExceptionUtil; | |
7 | 9 | import com.share.mvpsdk.utils.ToastUtils; |
8 | 10 | import com.shunzhi.parent.AppConfig; |
9 | 11 | import com.shunzhi.parent.AppContext; |
... | ... | @@ -14,6 +16,7 @@ import java.util.regex.Matcher; |
14 | 16 | import java.util.regex.Pattern; |
15 | 17 | |
16 | 18 | import io.reactivex.functions.Consumer; |
19 | +import retrofit2.HttpException; | |
17 | 20 | |
18 | 21 | /** |
19 | 22 | * Created by Administrator on 2018/3/6 0006. |
... | ... | @@ -36,21 +39,27 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre |
36 | 39 | mRxManager.register(mIModel.getLoginResult(loginName, loginPwd).subscribe(new Consumer<JsonObject>() { |
37 | 40 | @Override |
38 | 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 | 57 | }, new Consumer<Throwable>() { |
51 | 58 | @Override |
52 | 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 | 119 | |
111 | 120 | @Override |
112 | 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 | 33 | |
34 | 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 | 38 | @Override |
38 | 39 | protected void initView(Bundle savedInstanceState) { |
39 | 40 | |
... | ... | @@ -77,11 +78,11 @@ public class MainActivity extends BaseCompatActivity { |
77 | 78 | fragments[REPORT_INDEX] = reportFragment; |
78 | 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 | 86 | .show(cePingFragment) |
86 | 87 | .hide(consultFragment) |
87 | 88 | .hide(reportFragment) | ... | ... |
app/src/main/java/com/shunzhi/parent/ui/fragment/CePingFragment.java
1 | 1 | package com.shunzhi.parent.ui.fragment; |
2 | 2 | |
3 | -import android.content.Context; | |
4 | -import android.net.Uri; | |
5 | 3 | import android.os.Bundle; |
6 | -import android.support.v4.app.Fragment; | |
7 | -import android.view.LayoutInflater; | |
4 | +import android.support.annotation.NonNull; | |
5 | +import android.support.annotation.Nullable; | |
8 | 6 | import android.view.View; |
9 | -import android.view.ViewGroup; | |
10 | 7 | |
8 | +import com.share.mvpsdk.base.BasePresenter; | |
9 | +import com.share.mvpsdk.base.fragment.BaseMVPCompatFragment; | |
11 | 10 | import com.shunzhi.parent.R; |
12 | 11 | |
13 | -public class CePingFragment extends Fragment { | |
12 | +public class CePingFragment extends BaseMVPCompatFragment { | |
14 | 13 | |
15 | 14 | @Override |
16 | - public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
17 | - Bundle savedInstanceState) { | |
18 | - // Inflate the layout for this fragment | |
19 | - 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; | |
20 | 28 | } |
21 | 29 | } | ... | ... |
1.37 KB
1.36 KB
... | ... | @@ -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
mvpsdk/src/main/java/com/share/mvpsdk/helper/RetrofitCreateHelper.java
1 | 1 | package com.share.mvpsdk.helper; |
2 | 2 | |
3 | 3 | |
4 | +import android.util.Log; | |
5 | + | |
4 | 6 | import com.share.mvpsdk.helper.okhttp.CacheInterceptor; |
5 | 7 | import com.share.mvpsdk.helper.okhttp.HttpCache; |
6 | 8 | import com.share.mvpsdk.helper.okhttp.TrustManager; |
7 | 9 | import com.share.mvpsdk.utils.StringUtils; |
10 | +import com.share.mvpsdk.utils.ToastUtils; | |
8 | 11 | |
12 | +import java.io.IOException; | |
9 | 13 | import java.util.concurrent.TimeUnit; |
10 | 14 | |
15 | +import okhttp3.Interceptor; | |
11 | 16 | import okhttp3.OkHttpClient; |
17 | +import okhttp3.Request; | |
18 | +import okhttp3.Response; | |
12 | 19 | import okhttp3.logging.HttpLoggingInterceptor; |
13 | 20 | import retrofit2.Retrofit; |
14 | 21 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; |
... | ... | @@ -27,7 +34,8 @@ public class RetrofitCreateHelper { |
27 | 34 | private static final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor() |
28 | 35 | .setLevel(HttpLoggingInterceptor.Level.BODY); |
29 | 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 | 39 | //SSL证书 |
32 | 40 | .sslSocketFactory(TrustManager.getUnsafeOkHttpClient()) |
33 | 41 | .hostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) |
... | ... | @@ -43,7 +51,7 @@ public class RetrofitCreateHelper { |
43 | 51 | .writeTimeout(TIMEOUT_READ, TimeUnit.SECONDS) |
44 | 52 | //失败重连 |
45 | 53 | .retryOnConnectionFailure(true) |
46 | - .build(); | |
54 | + .build();*/ | |
47 | 55 | public static RetrofitCreateHelper getInstance(){ |
48 | 56 | if (null==retrofitCreateHelper){ |
49 | 57 | synchronized (RetrofitCreateHelper.class){ |
... | ... | @@ -52,31 +60,68 @@ public class RetrofitCreateHelper { |
52 | 60 | } |
53 | 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 | 81 | Authorization=token; |
57 | 82 | Retrofit retrofit = new Retrofit.Builder() |
58 | 83 | .baseUrl(url) |
59 | - .client(okHttpClient) | |
84 | + .client(okhttpClientBuilder.build()) | |
60 | 85 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) |
61 | 86 | .addConverterFactory(GsonConverterFactory.create()) |
62 | 87 | .build(); |
63 | 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 | 116 | Authorization= StringUtils.getSign(); |
68 | - Retrofit retrofit = new Retrofit.Builder() | |
117 | + Retrofit retrofit=new Retrofit.Builder() | |
118 | + .client(okhttpClientBuilder.build()) | |
69 | 119 | .baseUrl(url) |
70 | - .client(okHttpClient) | |
71 | 120 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) |
72 | 121 | .addConverterFactory(GsonConverterFactory.create()) |
73 | 122 | .build(); |
74 | 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 @@ |
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 | +} | ... | ... |