Commit 118e25c4fd58179732aae3aac4594ffe105ef2f4
1 parent
d8b159ee
Exists in
yxb_dev
and in
2 other branches
no message
Showing
13 changed files
with
415 additions
and
64 deletions
Show diff stats
.idea/modules.xml
@@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
5 | <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> | 5 | <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> |
6 | <module fileurl="file://$PROJECT_DIR$/mvpsdk/mvpsdk.iml" filepath="$PROJECT_DIR$/mvpsdk/mvpsdk.iml" /> | 6 | <module fileurl="file://$PROJECT_DIR$/mvpsdk/mvpsdk.iml" filepath="$PROJECT_DIR$/mvpsdk/mvpsdk.iml" /> |
7 | <module fileurl="file://$PROJECT_DIR$/parentwork.iml" filepath="$PROJECT_DIR$/parentwork.iml" /> | 7 | <module fileurl="file://$PROJECT_DIR$/parentwork.iml" filepath="$PROJECT_DIR$/parentwork.iml" /> |
8 | + <module fileurl="file://$PROJECT_DIR$/roundedimageview-2.2.1/roundedimageview-2.2.1.iml" filepath="$PROJECT_DIR$/roundedimageview-2.2.1/roundedimageview-2.2.1.iml" /> | ||
8 | </modules> | 9 | </modules> |
9 | </component> | 10 | </component> |
10 | </project> | 11 | </project> |
11 | \ No newline at end of file | 12 | \ No newline at end of file |
app/src/main/AndroidManifest.xml
@@ -2,6 +2,40 @@ | @@ -2,6 +2,40 @@ | ||
2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
3 | package="com.shunzhi.parent"> | 3 | package="com.shunzhi.parent"> |
4 | 4 | ||
5 | + <uses-permission android:name="android.permission.GET_TASKS" /> | ||
6 | + <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> | ||
7 | + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
8 | + <!-- Android 6.0版本可去除,用于选举信息(通道复用)的同步 --> | ||
9 | + <uses-permission android:name="android.permission.WRITE_SETTINGS" /> | ||
10 | + <!-- 进行网络访问和网络状态监控相关的权限声明 --> | ||
11 | + <uses-permission android:name="android.permission.INTERNET" /> | ||
12 | + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
13 | + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
14 | + <!-- 允许对sd卡进行读写操作 --> | ||
15 | + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
16 | + <!-- 网络库使用,当网络操作时需要确保事务完成不被杀掉 --> | ||
17 | + <uses-permission android:name="android.permission.WAKE_LOCK" /> | ||
18 | + <!-- 用于读取手机硬件信息等,用于机型过滤 --> | ||
19 | + <uses-permission android:name="android.permission.READ_PHONE_STATE" /> | ||
20 | + <!-- 选举使用,当应用有删除或者更新时需要重新选举,复用推送通道 --> | ||
21 | + <uses-permission android:name="android.permission.BROADCAST_PACKAGE_CHANGED" /> | ||
22 | + <uses-permission android:name="android.permission.BROADCAST_PACKAGE_REPLACED" /> | ||
23 | + <uses-permission android:name="android.permission.RESTART_PACKAGES" /> | ||
24 | + <!-- 补偿通道小米PUSH使用,不用可去除 --> | ||
25 | + <!-- <uses-permission android:name="android.permission.GET_TASKS" /> --> | ||
26 | + <!-- 补偿通道GCM使用,不使用可去除 --> | ||
27 | + <uses-permission android:name="android.permission.GET_ACCOUNTS" /> | ||
28 | + <!-- 允许监听启动完成事件 --> | ||
29 | + <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> | ||
30 | + <!-- 允许访问震动器 --> | ||
31 | + <uses-permission android:name="android.permission.VIBRATE" /> | ||
32 | + <!-- 允许task重排序 --> | ||
33 | + <uses-permission android:name="android.permission.REORDER_TASKS" /> | ||
34 | + | ||
35 | + | ||
36 | + | ||
37 | + | ||
38 | + | ||
5 | <application | 39 | <application |
6 | android:name=".MyApplication" | 40 | android:name=".MyApplication" |
7 | android:allowBackup="true" | 41 | android:allowBackup="true" |
@@ -10,6 +44,7 @@ | @@ -10,6 +44,7 @@ | ||
10 | android:roundIcon="@mipmap/ic_launcher_round" | 44 | android:roundIcon="@mipmap/ic_launcher_round" |
11 | android:supportsRtl="true" | 45 | android:supportsRtl="true" |
12 | android:theme="@style/AppTheme"> | 46 | android:theme="@style/AppTheme"> |
47 | + | ||
13 | <activity android:name=".ui.activity.LoginAndRegistActivity"> | 48 | <activity android:name=".ui.activity.LoginAndRegistActivity"> |
14 | <intent-filter> | 49 | <intent-filter> |
15 | <action android:name="android.intent.action.MAIN" /> | 50 | <action android:name="android.intent.action.MAIN" /> |
@@ -0,0 +1,82 @@ | @@ -0,0 +1,82 @@ | ||
1 | +package com.shunzhi.parent; | ||
2 | + | ||
3 | +import android.content.Context; | ||
4 | +import android.content.SharedPreferences; | ||
5 | +import android.os.Environment; | ||
6 | +import android.preference.PreferenceManager; | ||
7 | +import android.text.TextUtils; | ||
8 | + | ||
9 | +import java.io.File; | ||
10 | + | ||
11 | +/** | ||
12 | + * Created by Administrator on 2018/3/7 0007. | ||
13 | + */ | ||
14 | + | ||
15 | +public class AppConfig { | ||
16 | + //保存键值对 | ||
17 | + public static String SCHOOL_ID = "school_id"; | ||
18 | + public static String LOGIN_NAME = "login_name"; | ||
19 | + public static String LOGIN_PWD = "login_pwd"; | ||
20 | + public static String ACCESS_TOKEN = "access_token"; | ||
21 | + | ||
22 | + //默认日志保存的路径 | ||
23 | + public final static String DEFAULT_SAVE_LOG_PATH = Environment | ||
24 | + .getExternalStorageDirectory() | ||
25 | + + File.separator | ||
26 | + + "Eboardmenwei" | ||
27 | + + File.separator | ||
28 | + + "logs" | ||
29 | + + File.separator; | ||
30 | + | ||
31 | + | ||
32 | + | ||
33 | + private static AppConfig appConfig = null; | ||
34 | + private static Context mContext = null; | ||
35 | + | ||
36 | + public static AppConfig getAppConfig(Context context) { | ||
37 | + if (appConfig == null) { | ||
38 | + appConfig = new AppConfig(); | ||
39 | + mContext = context; | ||
40 | + } | ||
41 | + return appConfig; | ||
42 | + } | ||
43 | + | ||
44 | + | ||
45 | + | ||
46 | + | ||
47 | + | ||
48 | + | ||
49 | + | ||
50 | + //默认下载保存的路径 | ||
51 | + public final static String DEFAULT_SAVE_DOWNLOAD_PATH = Environment | ||
52 | + .getExternalStorageDirectory() | ||
53 | + + File.separator | ||
54 | + + "Eboard" | ||
55 | + + File.separator | ||
56 | + + "download" | ||
57 | + + File.separator; | ||
58 | + | ||
59 | + //得到保存的值 | ||
60 | + public String get(String key) { | ||
61 | + return getSharedPreferences(mContext).getString(key, null); | ||
62 | + } | ||
63 | + | ||
64 | + private SharedPreferences getSharedPreferences(Context context) { | ||
65 | + return PreferenceManager.getDefaultSharedPreferences(context); | ||
66 | + } | ||
67 | + | ||
68 | + //保存键值对 | ||
69 | + public void set(Context context, String key, String value) { | ||
70 | + SharedPreferences.Editor editor = getSharedPreferences(context).edit(); | ||
71 | + if (TextUtils.isEmpty(value)) { | ||
72 | + editor.putString(key, value); | ||
73 | + } else { | ||
74 | + editor.putString(key, value.trim()); | ||
75 | + } | ||
76 | + editor.commit(); | ||
77 | + } | ||
78 | + | ||
79 | + | ||
80 | + | ||
81 | + | ||
82 | +} |
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +package com.shunzhi.parent; | ||
2 | + | ||
3 | +import com.share.mvpsdk.global.GlobalApplication; | ||
4 | + | ||
5 | +/** | ||
6 | + * Created by Administrator on 2018/3/7 0007. | ||
7 | + */ | ||
8 | + | ||
9 | +public class AppContext extends GlobalApplication { | ||
10 | + private static AppContext appContext; | ||
11 | + | ||
12 | + | ||
13 | + @Override | ||
14 | + public void onCreate() { | ||
15 | + appContext=this; | ||
16 | + super.onCreate(); | ||
17 | + } | ||
18 | + | ||
19 | + public static AppContext getInstance() { | ||
20 | + return appContext; | ||
21 | + } | ||
22 | + | ||
23 | + | ||
24 | + | ||
25 | + | ||
26 | +} |
app/src/main/java/com/shunzhi/parent/api/LoginRegisterApi.java
0 → 100644
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +package com.shunzhi.parent.api; | ||
2 | + | ||
3 | +import com.google.gson.JsonObject; | ||
4 | + | ||
5 | +import io.reactivex.Observable; | ||
6 | +import retrofit2.http.Field; | ||
7 | +import retrofit2.http.FormUrlEncoded; | ||
8 | +import retrofit2.http.POST; | ||
9 | + | ||
10 | +/** | ||
11 | + * Created by Administrator on 2018/3/7 0007. | ||
12 | + */ | ||
13 | + | ||
14 | +public interface LoginRegisterApi { | ||
15 | + String url="http://campus.myjxt.com/"; | ||
16 | + | ||
17 | + | ||
18 | + @FormUrlEncoded | ||
19 | + @POST("Token") | ||
20 | + Observable<JsonObject> loginResult( | ||
21 | + @Field("grant_type") String grant_type, @Field("username") String username | ||
22 | + , @Field("password") String password); | ||
23 | + | ||
24 | + @FormUrlEncoded | ||
25 | + @POST("api/Account/CurrentInfo") | ||
26 | + Observable<JsonObject> registerResult( | ||
27 | + @Field("grant_type") String grant_type, @Field("username") String username | ||
28 | + , @Field("idcode") String idCode,@Field("password") String password); | ||
29 | + | ||
30 | + @FormUrlEncoded | ||
31 | + @POST("api/Account/CurrentInfo") | ||
32 | + Observable<JsonObject> getUserInfo(@Field("grant_type") String grant_type); | ||
33 | + | ||
34 | +} |
app/src/main/java/com/shunzhi/parent/model/loginandregister/LoginAndRegisterModel.java
@@ -2,6 +2,9 @@ package com.shunzhi.parent.model.loginandregister; | @@ -2,6 +2,9 @@ package com.shunzhi.parent.model.loginandregister; | ||
2 | 2 | ||
3 | import com.google.gson.JsonObject; | 3 | import com.google.gson.JsonObject; |
4 | import com.share.mvpsdk.base.BaseModel; | 4 | import com.share.mvpsdk.base.BaseModel; |
5 | +import com.share.mvpsdk.helper.RetrofitCreateHelper; | ||
6 | +import com.share.mvpsdk.helper.RxHelper; | ||
7 | +import com.shunzhi.parent.api.LoginRegisterApi; | ||
5 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; | 8 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; |
6 | 9 | ||
7 | import io.reactivex.Observable; | 10 | import io.reactivex.Observable; |
@@ -20,13 +23,15 @@ public class LoginAndRegisterModel extends BaseModel implements LoginAndRegiste | @@ -20,13 +23,15 @@ public class LoginAndRegisterModel extends BaseModel implements LoginAndRegiste | ||
20 | 23 | ||
21 | 24 | ||
22 | @Override | 25 | @Override |
23 | - public Observable<JsonObject> getLoginResult(String loginName, String loginPed) { | ||
24 | - return null; | 26 | + public Observable<JsonObject> getLoginResult(String loginName, String loginPwd) { |
27 | + return RetrofitCreateHelper.loginApi(LoginRegisterApi.class,LoginRegisterApi.url).loginResult("password",loginName,loginPwd) | ||
28 | + .compose(RxHelper.<JsonObject>rxSchedulerHelper()); | ||
25 | } | 29 | } |
26 | 30 | ||
27 | @Override | 31 | @Override |
28 | public Observable<JsonObject> getRegisterResult(String adminName, String idCode, String password) { | 32 | public Observable<JsonObject> getRegisterResult(String adminName, String idCode, String password) { |
29 | - return null; | 33 | + return RetrofitCreateHelper.createApi(LoginRegisterApi.class,LoginRegisterApi.url).registerResult("idcode",adminName,idCode,password) |
34 | + .compose(RxHelper.<JsonObject>rxSchedulerHelper()); | ||
30 | } | 35 | } |
31 | 36 | ||
32 | @Override | 37 | @Override |
app/src/main/java/com/shunzhi/parent/model/loginandregister/loginAndRegisterModel.java
@@ -1,37 +0,0 @@ | @@ -1,37 +0,0 @@ | ||
1 | -package com.shunzhi.parent.model.loginandregister; | ||
2 | - | ||
3 | -import com.google.gson.JsonObject; | ||
4 | -import com.share.mvpsdk.base.BaseModel; | ||
5 | -import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; | ||
6 | - | ||
7 | -import io.reactivex.Observable; | ||
8 | - | ||
9 | -/** | ||
10 | - * Created by Administrator on 2018/3/6 0006. | ||
11 | - */ | ||
12 | - | ||
13 | -public class LoginAndRegisterModel extends BaseModel implements LoginAndRegisterContract.ILoginModel { | ||
14 | - | ||
15 | - | ||
16 | - | ||
17 | - public static LoginAndRegisterModel newInstance() { | ||
18 | - return new LoginAndRegisterModel(); | ||
19 | - } | ||
20 | - | ||
21 | - | ||
22 | - @Override | ||
23 | - public Observable<JsonObject> getLoginResult(String loginName, String loginPed) { | ||
24 | - return null; | ||
25 | - } | ||
26 | - | ||
27 | - @Override | ||
28 | - public Observable<JsonObject> getRegisterResult(String adminName, String idCode, String password) { | ||
29 | - return null; | ||
30 | - } | ||
31 | - | ||
32 | - @Override | ||
33 | - public Observable<JsonObject> getidCodeResult(String phoneNumber) { | ||
34 | - return null; | ||
35 | - } | ||
36 | - | ||
37 | -} |
app/src/main/java/com/shunzhi/parent/presenter/loginandregister/LoginAndRegisterPresenter.java
@@ -2,39 +2,110 @@ package com.shunzhi.parent.presenter.loginandregister; | @@ -2,39 +2,110 @@ package com.shunzhi.parent.presenter.loginandregister; | ||
2 | 2 | ||
3 | import android.text.TextUtils; | 3 | import android.text.TextUtils; |
4 | 4 | ||
5 | +import com.google.gson.JsonObject; | ||
6 | +import com.share.mvpsdk.helper.RetrofitCreateHelper; | ||
5 | import com.share.mvpsdk.utils.ToastUtils; | 7 | import com.share.mvpsdk.utils.ToastUtils; |
8 | +import com.shunzhi.parent.AppConfig; | ||
9 | +import com.shunzhi.parent.AppContext; | ||
6 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; | 10 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; |
7 | import com.shunzhi.parent.model.loginandregister.LoginAndRegisterModel; | 11 | import com.shunzhi.parent.model.loginandregister.LoginAndRegisterModel; |
8 | 12 | ||
13 | +import java.util.regex.Matcher; | ||
14 | +import java.util.regex.Pattern; | ||
15 | + | ||
16 | +import io.reactivex.functions.Consumer; | ||
17 | + | ||
9 | /** | 18 | /** |
10 | * Created by Administrator on 2018/3/6 0006. | 19 | * Created by Administrator on 2018/3/6 0006. |
11 | */ | 20 | */ |
12 | 21 | ||
13 | public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPresenter { | 22 | public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPresenter { |
23 | + | ||
24 | + public static final String REGEX_MOBILE = "^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$"; | ||
25 | + | ||
14 | @Override | 26 | @Override |
15 | - public void loginResult(String loginName, String loginPwd) { | ||
16 | - if (TextUtils.isEmpty(loginName)){ | ||
17 | - ToastUtils.showToast("登录名不能为空"); | 27 | + public void loginResult(final String loginName, final String loginPwd) { |
28 | + if (!isMate(loginName, REGEX_MOBILE)) { | ||
29 | + ToastUtils.showToast("请输入正确的手机号!!"); | ||
18 | return; | 30 | return; |
19 | - }else if(TextUtils.isEmpty(loginPwd)){ | ||
20 | - ToastUtils.showToast("密码不能为空"); | 31 | + } |
32 | + | ||
33 | + if (mIModel == null || mIView == null) { | ||
21 | return; | 34 | return; |
22 | } | 35 | } |
36 | + mRxManager.register(mIModel.getLoginResult(loginName, loginPwd).subscribe(new Consumer<JsonObject>() { | ||
37 | + @Override | ||
38 | + 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()); | ||
48 | + } | ||
49 | + } | ||
50 | + }, new Consumer<Throwable>() { | ||
51 | + @Override | ||
52 | + public void accept(Throwable throwable) throws Exception { | ||
53 | + ToastUtils.showToast(throwable.getMessage()); | ||
54 | + } | ||
55 | + })); | ||
23 | 56 | ||
24 | } | 57 | } |
25 | 58 | ||
26 | @Override | 59 | @Override |
27 | public void registerResult(String adminName, String idCode, String password) { | 60 | public void registerResult(String adminName, String idCode, String password) { |
61 | + if (!isMate(adminName, REGEX_MOBILE)) { | ||
62 | + ToastUtils.showToast("请输入正确的手机号!!"); | ||
63 | + return; | ||
64 | + } | ||
65 | + if (mIModel == null || mIView == null) { | ||
66 | + return; | ||
67 | + } | ||
68 | + mIView.getUserInfo(); | ||
69 | + mRxManager.register(mIModel.getRegisterResult(adminName, idCode, password).subscribe(new Consumer<JsonObject>() { | ||
70 | + @Override | ||
71 | + public void accept(JsonObject jsonObject) throws Exception { | ||
72 | + //TODO 注册成功返回 | ||
28 | 73 | ||
29 | 74 | ||
75 | + } | ||
76 | + }, new Consumer<Throwable>() { | ||
77 | + @Override | ||
78 | + public void accept(Throwable throwable) throws Exception { | ||
79 | + ToastUtils.showToast(throwable.getMessage()); | ||
80 | + } | ||
81 | + })); | ||
82 | + | ||
30 | } | 83 | } |
31 | 84 | ||
32 | @Override | 85 | @Override |
33 | public void idCodeResult(String phoneNumber) { | 86 | public void idCodeResult(String phoneNumber) { |
34 | - if(TextUtils.isEmpty(phoneNumber)){ | ||
35 | - ToastUtils.showToast("请先输入手机号"); | 87 | + if (!isMate(phoneNumber, REGEX_MOBILE)) { |
88 | + ToastUtils.showToast("请输入正确的手机号!!"); | ||
89 | + return; | ||
90 | + } | ||
91 | + if (mIModel == null || mIView == null) { | ||
36 | return; | 92 | return; |
37 | } | 93 | } |
94 | + mRxManager.register(mIModel.getidCodeResult(phoneNumber).subscribe(new Consumer<JsonObject>() { | ||
95 | + @Override | ||
96 | + public void accept(JsonObject jsonObject) throws Exception { | ||
97 | + //TODO 获取验证码返回 | ||
98 | + | ||
99 | + | ||
100 | + } | ||
101 | + }, new Consumer<Throwable>() { | ||
102 | + @Override | ||
103 | + public void accept(Throwable throwable) throws Exception { | ||
104 | + ToastUtils.showToast(throwable.getMessage()); | ||
105 | + } | ||
106 | + })); | ||
107 | + | ||
108 | + | ||
38 | } | 109 | } |
39 | 110 | ||
40 | @Override | 111 | @Override |
@@ -52,4 +123,11 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre | @@ -52,4 +123,11 @@ public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPre | ||
52 | public void onStart() { | 123 | public void onStart() { |
53 | 124 | ||
54 | } | 125 | } |
126 | + | ||
127 | + | ||
128 | + public boolean isMate(String str, String rulStr) { | ||
129 | + Pattern pattern = Pattern.compile(rulStr); | ||
130 | + Matcher matcher = pattern.matcher(str); | ||
131 | + return matcher.matches(); | ||
132 | + } | ||
55 | } | 133 | } |
app/src/main/java/com/shunzhi/parent/ui/MainActivity.java
1 | package com.shunzhi.parent.ui; | 1 | package com.shunzhi.parent.ui; |
2 | 2 | ||
3 | -import android.support.annotation.NonNull; | ||
4 | -import android.support.design.widget.BottomNavigationView; | ||
5 | -import android.support.v7.app.AppCompatActivity; | ||
6 | import android.os.Bundle; | 3 | import android.os.Bundle; |
4 | +import android.support.design.widget.BottomNavigationView; | ||
7 | 5 | ||
8 | -import com.share.mvpsdk.base.BasePresenter; | ||
9 | import com.share.mvpsdk.base.activity.BaseCompatActivity; | 6 | import com.share.mvpsdk.base.activity.BaseCompatActivity; |
10 | -import com.share.mvpsdk.base.activity.BaseMVPCompatActivity; | ||
11 | import com.share.mvpsdk.helper.BottomNavigationViewHelper; | 7 | import com.share.mvpsdk.helper.BottomNavigationViewHelper; |
12 | import com.shunzhi.parent.R; | 8 | import com.shunzhi.parent.R; |
13 | 9 |
app/src/main/java/com/shunzhi/parent/ui/fragment/loginandregistfragment/LoginAndRegistFragment.java
1 | package com.shunzhi.parent.ui.fragment.loginandregistfragment; | 1 | package com.shunzhi.parent.ui.fragment.loginandregistfragment; |
2 | 2 | ||
3 | +import android.content.Intent; | ||
3 | import android.os.Bundle; | 4 | import android.os.Bundle; |
4 | import android.support.annotation.NonNull; | 5 | import android.support.annotation.NonNull; |
5 | import android.support.annotation.Nullable; | 6 | import android.support.annotation.Nullable; |
7 | +import android.text.Editable; | ||
8 | +import android.text.TextUtils; | ||
9 | +import android.text.TextWatcher; | ||
10 | +import android.util.Log; | ||
11 | +import android.view.Gravity; | ||
6 | import android.view.View; | 12 | import android.view.View; |
13 | +import android.view.ViewGroup; | ||
7 | import android.widget.EditText; | 14 | import android.widget.EditText; |
15 | +import android.widget.ImageView; | ||
8 | import android.widget.LinearLayout; | 16 | import android.widget.LinearLayout; |
17 | +import android.widget.PopupWindow; | ||
9 | import android.widget.TextView; | 18 | import android.widget.TextView; |
10 | 19 | ||
11 | import com.makeramen.roundedimageview.RoundedImageView; | 20 | import com.makeramen.roundedimageview.RoundedImageView; |
12 | import com.share.mvpsdk.base.BasePresenter; | 21 | import com.share.mvpsdk.base.BasePresenter; |
13 | import com.share.mvpsdk.base.fragment.BaseMVPCompatFragment; | 22 | import com.share.mvpsdk.base.fragment.BaseMVPCompatFragment; |
23 | +import com.share.mvpsdk.utils.ToastUtils; | ||
14 | import com.shunzhi.parent.R; | 24 | import com.shunzhi.parent.R; |
15 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; | 25 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; |
16 | import com.shunzhi.parent.presenter.loginandregister.LoginAndRegisterPresenter; | 26 | import com.shunzhi.parent.presenter.loginandregister.LoginAndRegisterPresenter; |
27 | +import com.shunzhi.parent.ui.activity.LoginAndRegistActivity; | ||
17 | 28 | ||
18 | 29 | ||
19 | public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegisterContract.LoginPresenter, LoginAndRegisterContract.ILoginModel> | 30 | public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegisterContract.LoginPresenter, LoginAndRegisterContract.ILoginModel> |
@@ -22,8 +33,10 @@ public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegist | @@ -22,8 +33,10 @@ public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegist | ||
22 | public RoundedImageView roundedImageView; | 33 | public RoundedImageView roundedImageView; |
23 | public EditText phoneNumber, idCode, password; | 34 | public EditText phoneNumber, idCode, password; |
24 | public TextView get_idCode, loginAndRegister, tv_info, tv_goto; | 35 | public TextView get_idCode, loginAndRegister, tv_info, tv_goto; |
25 | - public LinearLayout phoneLayout, idCodeLayout, passwordLayout; | 36 | + public LinearLayout phoneLayout, idCodeLayout, passwordLayout,main_login; |
37 | + public ImageView img_eye; | ||
26 | public static String typepage; | 38 | public static String typepage; |
39 | + public boolean open = false; | ||
27 | 40 | ||
28 | 41 | ||
29 | public static LoginAndRegistFragment getInstance(String type) { | 42 | public static LoginAndRegistFragment getInstance(String type) { |
@@ -46,7 +59,7 @@ public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegist | @@ -46,7 +59,7 @@ public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegist | ||
46 | 59 | ||
47 | @Override | 60 | @Override |
48 | public void initUI(View view, @Nullable Bundle savedInstanceState) { | 61 | public void initUI(View view, @Nullable Bundle savedInstanceState) { |
49 | - | 62 | + main_login = view.findViewById(R.id.main_login); |
50 | roundedImageView = view.findViewById(R.id.photoImage); | 63 | roundedImageView = view.findViewById(R.id.photoImage); |
51 | phoneNumber = view.findViewById(R.id.et_phoneNumber); | 64 | phoneNumber = view.findViewById(R.id.et_phoneNumber); |
52 | idCode = view.findViewById(R.id.et_idCode); | 65 | idCode = view.findViewById(R.id.et_idCode); |
@@ -58,15 +71,20 @@ public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegist | @@ -58,15 +71,20 @@ public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegist | ||
58 | phoneLayout = view.findViewById(R.id.phoneLayout); | 71 | phoneLayout = view.findViewById(R.id.phoneLayout); |
59 | idCodeLayout = view.findViewById(R.id.idCodeLayout); | 72 | idCodeLayout = view.findViewById(R.id.idCodeLayout); |
60 | passwordLayout = view.findViewById(R.id.passwordLayout); | 73 | passwordLayout = view.findViewById(R.id.passwordLayout); |
74 | + img_eye = view.findViewById(R.id.img_eye); | ||
61 | get_idCode.setOnClickListener(this); | 75 | get_idCode.setOnClickListener(this); |
62 | tv_goto.setOnClickListener(this); | 76 | tv_goto.setOnClickListener(this); |
63 | loginAndRegister.setOnClickListener(this); | 77 | loginAndRegister.setOnClickListener(this); |
64 | - if (typepage.equals("登录")) { | 78 | + img_eye.setOnClickListener(this); |
79 | + phoneNumber.addTextChangedListener(textWatcher); | ||
80 | + idCode.addTextChangedListener(textWatcher); | ||
81 | + password.addTextChangedListener(textWatcher); | ||
82 | + if ("登录".equals(typepage)) { | ||
65 | idCodeLayout.setVisibility(View.GONE); | 83 | idCodeLayout.setVisibility(View.GONE); |
66 | loginAndRegister.setText("登录"); | 84 | loginAndRegister.setText("登录"); |
67 | tv_info.setText("还没有账号"); | 85 | tv_info.setText("还没有账号"); |
68 | tv_goto.setText("注册"); | 86 | tv_goto.setText("注册"); |
69 | - }else if(typepage.equals("注册")){ | 87 | + } else if ("注册".equals(typepage)) { |
70 | idCodeLayout.setVisibility(View.VISIBLE); | 88 | idCodeLayout.setVisibility(View.VISIBLE); |
71 | loginAndRegister.setText("注册"); | 89 | loginAndRegister.setText("注册"); |
72 | tv_info.setText("已注册,直接登录"); | 90 | tv_info.setText("已注册,直接登录"); |
@@ -77,26 +95,79 @@ public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegist | @@ -77,26 +95,79 @@ public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegist | ||
77 | 95 | ||
78 | @Override | 96 | @Override |
79 | public void getUserInfo() { | 97 | public void getUserInfo() { |
98 | + Log.e("sss","sss"); | ||
99 | + PopupWindow popupWindow=new PopupWindow(); | ||
100 | + popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); | ||
101 | + popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); | ||
102 | + TextView textView=new TextView(getActivity()); | ||
103 | + textView.setText("注册成功"); | ||
104 | + popupWindow.setContentView(textView); | ||
105 | + popupWindow.showAtLocation(main_login, Gravity.CENTER,0,0); | ||
106 | + | ||
107 | + | ||
80 | 108 | ||
81 | } | 109 | } |
82 | 110 | ||
83 | @Override | 111 | @Override |
84 | public void onClick(View v) { | 112 | public void onClick(View v) { |
85 | if (v == loginAndRegister) { | 113 | if (v == loginAndRegister) { |
114 | + ToastUtils.showToast("onClick"); | ||
86 | if (loginAndRegister.getText().toString().trim().equals("登录")) { | 115 | if (loginAndRegister.getText().toString().trim().equals("登录")) { |
87 | - mPresenter.loginResult(phoneNumber.getText().toString(), password.getText().toString()); | 116 | + mPresenter.loginResult(phoneNumber.getText().toString(), password.getText().toString()); |
88 | } else if (loginAndRegister.getText().toString().trim().equals("注册")) { | 117 | } else if (loginAndRegister.getText().toString().trim().equals("注册")) { |
89 | - mPresenter.registerResult(phoneNumber.getText().toString(), idCode.getText().toString(), password.getText().toString()); | 118 | + mPresenter.registerResult(phoneNumber.getText().toString(), idCode.getText().toString(), password.getText().toString()); |
90 | } | 119 | } |
91 | 120 | ||
92 | } else if (v == tv_goto) { | 121 | } else if (v == tv_goto) { |
93 | - if (tv_goto.equals("登录")) { | ||
94 | - | ||
95 | - } else if (tv_goto.equals("注册")) { | 122 | + if (tv_goto.getText().toString().equals("登录")) { |
123 | + startActivity(new Intent().putExtra("type", "登录").setClass(getActivity(), LoginAndRegistActivity.class)); | ||
96 | 124 | ||
125 | + } else if (tv_goto.getText().toString().equals("注册")) { | ||
126 | + startActivity(new Intent().putExtra("type", "注册").setClass(getActivity(), LoginAndRegistActivity.class)); | ||
97 | } | 127 | } |
128 | + getActivity().finish(); | ||
98 | } else if (v == get_idCode) { | 129 | } else if (v == get_idCode) { |
99 | mPresenter.idCodeResult(phoneNumber.getText().toString()); | 130 | mPresenter.idCodeResult(phoneNumber.getText().toString()); |
131 | + } else if (v == img_eye) { | ||
132 | + if (open) { | ||
133 | + img_eye.setImageResource(R.drawable.eye_close); | ||
134 | + password.setInputType(0x81); | ||
135 | + open = false; | ||
136 | + } else { | ||
137 | + img_eye.setImageResource(R.drawable.eye_open); | ||
138 | + password.setInputType(0x90); | ||
139 | + open = true; | ||
140 | + } | ||
141 | + password.setSelection(password.getText().toString().length()); | ||
100 | } | 142 | } |
101 | } | 143 | } |
144 | + TextWatcher textWatcher = new TextWatcher() { | ||
145 | + @Override | ||
146 | + public void beforeTextChanged(CharSequence s, int start, int count, int after) { | ||
147 | + | ||
148 | + } | ||
149 | + | ||
150 | + @Override | ||
151 | + public void onTextChanged(CharSequence s, int start, int before, int count) { | ||
152 | + if (loginAndRegister.getText().toString().trim().equals("登录")) { | ||
153 | + if (!TextUtils.isEmpty(phoneNumber.getText().toString()) && !TextUtils.isEmpty(password.getText().toString())) { | ||
154 | + loginAndRegister.setEnabled(true); | ||
155 | + } else { | ||
156 | + loginAndRegister.setEnabled(false); | ||
157 | + } | ||
158 | + } else if (loginAndRegister.getText().toString().trim().equals("注册")) { | ||
159 | + if (!TextUtils.isEmpty(phoneNumber.getText().toString()) && !TextUtils.isEmpty(idCode.getText().toString()) && !TextUtils.isEmpty(password.getText().toString())) { | ||
160 | + loginAndRegister.setEnabled(true); | ||
161 | + } else { | ||
162 | + loginAndRegister.setEnabled(false); | ||
163 | + } | ||
164 | + } | ||
165 | + } | ||
166 | + | ||
167 | + @Override | ||
168 | + public void afterTextChanged(Editable s) { | ||
169 | + | ||
170 | + } | ||
171 | + }; | ||
172 | + | ||
102 | } | 173 | } |
app/src/main/res/layout/fragment_login_and_regist.xml
@@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
7 | 7 | ||
8 | 8 | ||
9 | <LinearLayout | 9 | <LinearLayout |
10 | + android:id="@+id/main_login" | ||
10 | android:layout_width="match_parent" | 11 | android:layout_width="match_parent" |
11 | android:layout_height="match_parent" | 12 | android:layout_height="match_parent" |
12 | android:orientation="vertical"> | 13 | android:orientation="vertical"> |
@@ -43,6 +44,7 @@ | @@ -43,6 +44,7 @@ | ||
43 | android:layout_height="50dp" | 44 | android:layout_height="50dp" |
44 | android:background="@null" | 45 | android:background="@null" |
45 | android:hint="请输入手机号码" | 46 | android:hint="请输入手机号码" |
47 | + android:maxLength="11" | ||
46 | android:textColorHint="@color/hintTextColor" | 48 | android:textColorHint="@color/hintTextColor" |
47 | android:textSize="@dimen/sp_16" /> | 49 | android:textSize="@dimen/sp_16" /> |
48 | 50 | ||
@@ -113,7 +115,9 @@ | @@ -113,7 +115,9 @@ | ||
113 | android:layout_height="50dp" | 115 | android:layout_height="50dp" |
114 | android:layout_weight="1" | 116 | android:layout_weight="1" |
115 | android:background="@null" | 117 | android:background="@null" |
116 | - android:hint="请设置密码:6~8个字符" | 118 | + android:hint="请设置密码:6~16个字符" |
119 | + android:maxLength="16" | ||
120 | + android:inputType="textPassword" | ||
117 | android:textColorHint="@color/hintTextColor" | 121 | android:textColorHint="@color/hintTextColor" |
118 | android:textSize="@dimen/sp_16" /> | 122 | android:textSize="@dimen/sp_16" /> |
119 | 123 | ||
@@ -144,6 +148,7 @@ | @@ -144,6 +148,7 @@ | ||
144 | android:paddingBottom="10dp" | 148 | android:paddingBottom="10dp" |
145 | android:paddingTop="10dp" | 149 | android:paddingTop="10dp" |
146 | android:text="注册" | 150 | android:text="注册" |
151 | + android:enabled="false" | ||
147 | android:textColor="@color/white" | 152 | android:textColor="@color/white" |
148 | android:textSize="@dimen/sp_16" /> | 153 | android:textSize="@dimen/sp_16" /> |
149 | 154 |
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 | - | ||
5 | import com.share.mvpsdk.helper.okhttp.CacheInterceptor; | 4 | import com.share.mvpsdk.helper.okhttp.CacheInterceptor; |
6 | import com.share.mvpsdk.helper.okhttp.HttpCache; | 5 | import com.share.mvpsdk.helper.okhttp.HttpCache; |
7 | import com.share.mvpsdk.helper.okhttp.TrustManager; | 6 | import com.share.mvpsdk.helper.okhttp.TrustManager; |
7 | +import com.share.mvpsdk.utils.StringUtils; | ||
8 | 8 | ||
9 | import java.util.concurrent.TimeUnit; | 9 | import java.util.concurrent.TimeUnit; |
10 | 10 | ||
@@ -22,6 +22,8 @@ import retrofit2.converter.gson.GsonConverterFactory; | @@ -22,6 +22,8 @@ import retrofit2.converter.gson.GsonConverterFactory; | ||
22 | public class RetrofitCreateHelper { | 22 | public class RetrofitCreateHelper { |
23 | private static final int TIMEOUT_READ = 20; | 23 | private static final int TIMEOUT_READ = 20; |
24 | private static final int TIMEOUT_CONNECTION = 10; | 24 | private static final int TIMEOUT_CONNECTION = 10; |
25 | + private static String Authorization="",token=""; | ||
26 | + private static RetrofitCreateHelper retrofitCreateHelper=null; | ||
25 | private static final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor() | 27 | private static final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor() |
26 | .setLevel(HttpLoggingInterceptor.Level.BODY); | 28 | .setLevel(HttpLoggingInterceptor.Level.BODY); |
27 | private static CacheInterceptor cacheInterceptor = new CacheInterceptor(); | 29 | private static CacheInterceptor cacheInterceptor = new CacheInterceptor(); |
@@ -42,8 +44,16 @@ public class RetrofitCreateHelper { | @@ -42,8 +44,16 @@ public class RetrofitCreateHelper { | ||
42 | //失败重连 | 44 | //失败重连 |
43 | .retryOnConnectionFailure(true) | 45 | .retryOnConnectionFailure(true) |
44 | .build(); | 46 | .build(); |
45 | - | 47 | + public static RetrofitCreateHelper getInstance(){ |
48 | + if (null==retrofitCreateHelper){ | ||
49 | + synchronized (RetrofitCreateHelper.class){ | ||
50 | + if (null==retrofitCreateHelper)retrofitCreateHelper=new RetrofitCreateHelper(); | ||
51 | + } | ||
52 | + } | ||
53 | + return retrofitCreateHelper; | ||
54 | + } | ||
46 | public static <T> T createApi(Class<T> clazz, String url) { | 55 | public static <T> T createApi(Class<T> clazz, String url) { |
56 | + Authorization=token; | ||
47 | Retrofit retrofit = new Retrofit.Builder() | 57 | Retrofit retrofit = new Retrofit.Builder() |
48 | .baseUrl(url) | 58 | .baseUrl(url) |
49 | .client(okHttpClient) | 59 | .client(okHttpClient) |
@@ -52,5 +62,23 @@ public class RetrofitCreateHelper { | @@ -52,5 +62,23 @@ public class RetrofitCreateHelper { | ||
52 | .build(); | 62 | .build(); |
53 | return retrofit.create(clazz); | 63 | return retrofit.create(clazz); |
54 | } | 64 | } |
65 | + | ||
66 | + public static <T> T loginApi(Class<T> clazz, String url) { | ||
67 | + Authorization= StringUtils.getSign(); | ||
68 | + Retrofit retrofit = new Retrofit.Builder() | ||
69 | + .baseUrl(url) | ||
70 | + .client(okHttpClient) | ||
71 | + .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | ||
72 | + .addConverterFactory(GsonConverterFactory.create()) | ||
73 | + .build(); | ||
74 | + return retrofit.create(clazz); | ||
75 | + } | ||
76 | + public void setAuthorization(String Authorization){ | ||
77 | + this.token=Authorization; | ||
78 | + } | ||
79 | + | ||
80 | + | ||
81 | + | ||
82 | + | ||
55 | } | 83 | } |
56 | 84 |
mvpsdk/src/main/java/com/share/mvpsdk/utils/StringUtils.java
1 | package com.share.mvpsdk.utils; | 1 | package com.share.mvpsdk.utils; |
2 | 2 | ||
3 | import android.text.TextUtils; | 3 | import android.text.TextUtils; |
4 | +import android.util.Base64; | ||
4 | 5 | ||
5 | import java.util.regex.Matcher; | 6 | import java.util.regex.Matcher; |
6 | import java.util.regex.Pattern; | 7 | import java.util.regex.Pattern; |
@@ -122,4 +123,30 @@ public class StringUtils { | @@ -122,4 +123,30 @@ public class StringUtils { | ||
122 | } | 123 | } |
123 | return true; | 124 | return true; |
124 | } | 125 | } |
126 | + | ||
127 | + private final static String appSecret = "f71467cfd98d"; | ||
128 | + public static String getSign(){ | ||
129 | + String sign = ""; | ||
130 | + try { | ||
131 | + String clientid = MD5(System.currentTimeMillis() + new int[(int) (Math.random() * 100)].toString()); | ||
132 | + sign = "Basic " + Base64.encodeToString((clientid + ":" + MD5(clientid + appSecret)).getBytes("ASCII"), Base64.NO_WRAP); | ||
133 | + } catch (Exception err) { | ||
134 | + err.printStackTrace(); | ||
135 | + } | ||
136 | + return sign; | ||
137 | + } | ||
138 | + | ||
139 | + public static String MD5(String str) { | ||
140 | + try { | ||
141 | + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); | ||
142 | + byte[] array = md.digest(str.getBytes("utf-8")); | ||
143 | + StringBuffer sb = new StringBuffer(); | ||
144 | + for (int i = 0; i < array.length; ++i) { | ||
145 | + sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); | ||
146 | + } | ||
147 | + return sb.toString().toUpperCase(); | ||
148 | + } catch (Exception e) { | ||
149 | + } | ||
150 | + return ""; | ||
151 | + } | ||
125 | } | 152 | } |