Commit aee2ca753c4969a260521fa0b1310137e128965e

Authored by shixianjie
1 parent 7243a5da59
Exists in master

家长与教师分开登录

app/src/main/AndroidManifest.xml
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:tools="http://schemas.android.com/tools" 3 xmlns:tools="http://schemas.android.com/tools"
4 package="com.hjx.parent"> 4 package="com.hjx.parent"
5 tools:ignore="LockedOrientationActivity">
5 6
6 7
8 <uses-feature
9 android:name="android.hardware.camera"
10 android:required="false" />
11
7 <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" /> 12 <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
8 <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <!-- 允许程序改变网络链接状态 --> 13 <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <!-- 允许程序改变网络链接状态 -->
9 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 允许程序访问访问WIFI网络状态信息 --> 14 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 允许程序访问访问WIFI网络状态信息 -->
10 <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <!-- 允许程序改变WIFI链接状态 --> 15 <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <!-- 允许程序改变WIFI链接状态 -->
11 <!-- 6.0系统需要添加权限才能获得wifi列表 --> 16 <!-- 6.0系统需要添加权限才能获得wifi列表 -->
12 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 17 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
13 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 18 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
14 <uses-permission android:name="android.permission.INTERNET" /> 19 <uses-permission android:name="android.permission.INTERNET" />
15 <uses-permission android:name="android.permission.RECORD_AUDIO" /> 20 <uses-permission android:name="android.permission.RECORD_AUDIO" />
16 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 21 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
17 22
18 <uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> 23 <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
19 <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 24 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
20 <uses-permission android:name="android.permission.WAKE_LOCK" /> 25 <uses-permission android:name="android.permission.WAKE_LOCK" />
21 <uses-permission android:name="android.permission.CAMERA" /> 26 <uses-permission android:name="android.permission.CAMERA" />
22 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 27 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
23 <uses-permission android:name="android.permission.VIBRATE" /> 28 <uses-permission android:name="android.permission.VIBRATE" />
24 <uses-permission 29 <uses-permission
25 android:name="android.permission.WRITE_EXTERNAL_STORAGE" 30 android:name="android.permission.WRITE_EXTERNAL_STORAGE"
26 tools:ignore="ScopedStorage" /> 31 tools:ignore="ScopedStorage" />
27 <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> 32 <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
28 <uses-permission android:name="android.permission.GET_PACKAGE_SIZE" /> 33 <uses-permission android:name="android.permission.GET_PACKAGE_SIZE" />
29 34
30 <uses-permission 35 <uses-permission
31 android:name="android.permission.MANAGE_EXTERNAL_STORAGE" 36 android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
32 tools:ignore="ScopedStorage" /> 37 tools:ignore="ScopedStorage" />
33 38
34 <application 39 <application
35 android:name=".App" 40 android:name=".App"
36 android:allowBackup="true" 41 android:allowBackup="true"
37 android:icon="@mipmap/icon" 42 android:icon="@mipmap/icon"
38 android:label="@string/app_name" 43 android:label="@string/app_name"
39 android:networkSecurityConfig="@xml/network_security_config" 44 android:networkSecurityConfig="@xml/network_security_config"
40 android:supportsRtl="true" 45 android:supportsRtl="true"
41 android:theme="@style/AppTheme"> 46 android:theme="@style/AppTheme">
42 <activity 47 <activity
43 android:name=".LoginActivity" 48 android:name=".LoginActivity"
44 android:exported="true" 49 android:exported="true"
45 android:screenOrientation="portrait" 50 android:screenOrientation="portrait"
46 android:theme="@style/ThemeSplash"> 51 android:theme="@style/ThemeSplash">
47 <intent-filter>
48 <action android:name="android.intent.action.MAIN" />
49 <category android:name="android.intent.category.LAUNCHER" />
50 </intent-filter>
51 </activity> 52 </activity>
52 <activity 53 <activity
53 android:name=".MainActivity" 54 android:name=".MainActivity"
54 android:launchMode="singleTask" 55 android:launchMode="singleTask"
55 android:screenOrientation="portrait" /> 56 android:screenOrientation="portrait" />
56 <activity 57 <activity
57 android:name=".RegisterActivity" 58 android:name=".RegisterActivity"
58 android:screenOrientation="portrait" 59 android:screenOrientation="portrait"
59 android:theme="@style/ThemeSplash" /> 60 android:theme="@style/ThemeSplash" />
60 <activity 61 <activity
61 android:name=".UserActivity" 62 android:name=".UserActivity"
62 android:screenOrientation="portrait" /> 63 android:screenOrientation="portrait" />
63 <activity 64 <activity
64 android:name=".YinsiActivity" 65 android:name=".YinsiActivity"
65 android:screenOrientation="portrait" /> 66 android:screenOrientation="portrait" />
66 <activity 67 <activity
67 android:name=".QRActivity" 68 android:name=".QRActivity"
68 android:screenOrientation="portrait" /> 69 android:screenOrientation="portrait" />
69 <activity 70 <activity
70 android:name=".AddStudentActivity" 71 android:name=".AddStudentActivity"
71 android:screenOrientation="portrait" /> 72 android:screenOrientation="portrait" />
72 <activity 73 <activity
73 android:name=".NickActivity" 74 android:name=".NickActivity"
74 android:screenOrientation="portrait" /> 75 android:screenOrientation="portrait" />
75 <activity 76 <activity
76 android:name=".SexActivity" 77 android:name=".SexActivity"
77 android:screenOrientation="portrait" /> 78 android:screenOrientation="portrait" />
78 <activity 79 <activity
79 android:name=".NianActivity" 80 android:name=".NianActivity"
80 android:screenOrientation="portrait" /> 81 android:screenOrientation="portrait" />
81 <activity 82 <activity
82 android:name=".ShenActivity" 83 android:name=".ShenActivity"
83 android:screenOrientation="portrait" /> 84 android:screenOrientation="portrait" />
84 <activity 85 <activity
85 android:name=".UserAgreementActivity" 86 android:name=".UserAgreementActivity"
86 android:screenOrientation="portrait" /> 87 android:screenOrientation="portrait" />
87 <activity 88 <activity
88 android:name=".AccountActivity" 89 android:name=".AccountActivity"
89 android:screenOrientation="portrait" /> 90 android:screenOrientation="portrait" />
90 91
91 <activity 92 <activity
92 android:name=".ChangePwdActivity" 93 android:name=".ChangePwdActivity"
93 android:screenOrientation="portrait" /> 94 android:screenOrientation="portrait" />
94 <activity 95 <activity
95 android:name=".EditStudentActivity" 96 android:name=".EditStudentActivity"
96 android:screenOrientation="portrait" /> 97 android:screenOrientation="portrait" />
97 <activity 98 <activity
98 android:name=".ChooseActivity" 99 android:name=".ChooseActivity"
99 android:screenOrientation="portrait" /> 100 android:screenOrientation="portrait" />
100 <activity 101 <activity
101 android:name=".AddTeacherActivity" 102 android:name=".AddTeacherActivity"
102 android:screenOrientation="portrait" /> 103 android:screenOrientation="portrait" />
103 <activity 104 <activity
104 android:name=".ErrorBookActivity" 105 android:name=".ErrorBookActivity"
105 android:screenOrientation="portrait" /> 106 android:screenOrientation="portrait" />
106 <activity 107 <activity
107 android:name=".ImageActivity" 108 android:name=".ImageActivity"
108 android:screenOrientation="portrait" /> 109 android:screenOrientation="portrait" />
109 <activity 110 <activity
110 android:name=".ImageEditActivity" 111 android:name=".ImageEditActivity"
111 android:screenOrientation="portrait" /> 112 android:screenOrientation="portrait" />
112 <activity 113 <activity
113 android:name=".ImageSelectActivity" 114 android:name=".ImageSelectActivity"
114 android:screenOrientation="portrait" /> 115 android:screenOrientation="portrait" />
115 <activity 116 <activity
116 android:name=".AddSuccessActivity" 117 android:name=".AddSuccessActivity"
117 android:screenOrientation="portrait" /> 118 android:screenOrientation="portrait" />
118 <activity 119 <activity
119 android:name=".ErrorListActivity" 120 android:name=".ErrorListActivity"
120 android:screenOrientation="portrait" /> 121 android:screenOrientation="portrait" />
121 <activity 122 <activity
122 android:name=".ErrorDetailActivity" 123 android:name=".ErrorDetailActivity"
123 android:screenOrientation="portrait" /> 124 android:screenOrientation="portrait" />
124 <activity 125 <activity
125 android:name=".TeacherChooseActivity" 126 android:name=".TeacherChooseActivity"
126 android:screenOrientation="portrait" /> 127 android:screenOrientation="portrait" />
127 <activity 128 <activity
128 android:name=".TeacherMainActivity" 129 android:name=".TeacherMainActivity"
129 android:screenOrientation="portrait" /> 130 android:screenOrientation="portrait" />
130 <activity android:name=".StuHomeworkActivity" /> 131 <activity android:name=".StuHomeworkActivity" />
131 <activity android:name=".HomeworkDetailActivity" /> 132 <activity android:name=".HomeworkDetailActivity" />
132 <activity android:name=".HomeworkSelectActivity" /> 133 <activity android:name=".HomeworkSelectActivity" />
133 <activity android:name=".HomeworkFeedbackActivity" /> 134 <activity android:name=".HomeworkFeedbackActivity" />
134 <activity android:name=".HomeworkTopicActivity" /> 135 <activity android:name=".HomeworkTopicActivity" />
135 <activity android:name=".HomeworkShareActivity" /> 136 <activity android:name=".HomeworkShareActivity" />
136 <activity android:name=".HuyouDetailActivity" /> 137 <activity android:name=".HuyouDetailActivity" />
138 <activity android:name=".SmsLoginActivity"
139 android:exported="true"
140 android:screenOrientation="portrait"
141 android:theme="@style/ThemeSplash">
142 <intent-filter>
143 <action android:name="android.intent.action.MAIN" />
144 <category android:name="android.intent.category.LAUNCHER" />
145 </intent-filter>
146 </activity>
137 147
138 <provider 148 <provider
139 android:name="androidx.core.content.FileProvider" 149 android:name="androidx.core.content.FileProvider"
140 android:authorities="com.hjx.parent.fileprovider" 150 android:authorities="com.hjx.parent.fileprovider"
141 android:exported="false" 151 android:exported="false"
142 android:grantUriPermissions="true" 152 android:grantUriPermissions="true"
143 tools:replace="android:authorities"> 153 tools:replace="android:authorities">
144 <meta-data 154 <meta-data
145 android:name="android.support.FILE_PROVIDER_PATHS" 155 android:name="android.support.FILE_PROVIDER_PATHS"
146 android:resource="@xml/file_provider_paths" 156 android:resource="@xml/file_provider_paths"
147 tools:replace="android:resource" /> 157 tools:replace="android:resource" />
app/src/main/java/com/hjx/parent/AccountActivity.java
1 package com.hjx.parent; 1 package com.hjx.parent;
2 2
3 import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK; 3 import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
4 import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; 4 import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
5 5
6 import android.app.AlertDialog; 6 import android.app.AlertDialog;
7 import android.content.DialogInterface; 7 import android.content.DialogInterface;
8 import android.content.Intent; 8 import android.content.Intent;
9 import android.graphics.Bitmap; 9 import android.graphics.Bitmap;
10 import android.net.NetworkRequest; 10 import android.net.NetworkRequest;
11 import android.net.Uri; 11 import android.net.Uri;
12 import android.os.Build; 12 import android.os.Build;
13 import android.os.Bundle; 13 import android.os.Bundle;
14 import android.os.Environment; 14 import android.os.Environment;
15 import android.provider.MediaStore; 15 import android.provider.MediaStore;
16 import android.text.TextUtils; 16 import android.text.TextUtils;
17 import android.util.Log; 17 import android.util.Log;
18 import android.view.LayoutInflater; 18 import android.view.LayoutInflater;
19 import android.view.View; 19 import android.view.View;
20 import android.widget.ImageView; 20 import android.widget.ImageView;
21 import android.widget.TextView; 21 import android.widget.TextView;
22 import android.widget.Toast; 22 import android.widget.Toast;
23 23
24 import androidx.core.content.FileProvider; 24 import androidx.core.content.FileProvider;
25 25
26 import com.bumptech.glide.Glide; 26 import com.bumptech.glide.Glide;
27 import com.bumptech.glide.load.resource.bitmap.RoundedCorners; 27 import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
28 import com.bumptech.glide.request.RequestOptions; 28 import com.bumptech.glide.request.RequestOptions;
29 import com.google.android.material.bottomsheet.BottomSheetDialog; 29 import com.google.android.material.bottomsheet.BottomSheetDialog;
30 import com.hjq.permissions.OnPermissionCallback; 30 import com.hjq.permissions.OnPermissionCallback;
31 import com.hjq.permissions.Permission; 31 import com.hjq.permissions.Permission;
32 import com.hjq.permissions.XXPermissions; 32 import com.hjq.permissions.XXPermissions;
33 import com.prws.common.base.BaseActivity; 33 import com.prws.common.base.BaseActivity;
34 import com.prws.common.base.BasePresenter; 34 import com.prws.common.base.BasePresenter;
35 import com.prws.common.bean.ResponseResult; 35 import com.prws.common.bean.ResponseResult;
36 import com.prws.common.net.NetWorks; 36 import com.prws.common.net.NetWorks;
37 import com.prws.common.utils.LogUtil; 37 import com.prws.common.utils.LogUtil;
38 import com.prws.common.utils.ScreenUtils; 38 import com.prws.common.utils.ScreenUtils;
39 import com.prws.common.utils.SharedPreferencesUtil; 39 import com.prws.common.utils.SharedPreferencesUtil;
40 40
41 import org.json.JSONObject; 41 import org.json.JSONObject;
42 42
43 import java.io.File; 43 import java.io.File;
44 import java.io.FileOutputStream; 44 import java.io.FileOutputStream;
45 import java.io.IOException; 45 import java.io.IOException;
46 import java.util.HashMap; 46 import java.util.HashMap;
47 import java.util.List; 47 import java.util.List;
48 import java.util.Map; 48 import java.util.Map;
49 49
50 import butterknife.BindView; 50 import butterknife.BindView;
51 import butterknife.OnClick; 51 import butterknife.OnClick;
52 import io.reactivex.Observer; 52 import io.reactivex.Observer;
53 import io.reactivex.disposables.Disposable; 53 import io.reactivex.disposables.Disposable;
54 import okhttp3.ResponseBody; 54 import okhttp3.ResponseBody;
55 55
56 public class AccountActivity extends BaseActivity { 56 public class AccountActivity extends BaseActivity {
57 57
58 58
59 @Override 59 @Override
60 protected int layoutResId() { 60 protected int layoutResId() {
61 return R.layout.activity_setac; 61 return R.layout.activity_setac;
62 } 62 }
63 63
64 @Override 64 @Override
65 public Object getContract() { 65 public Object getContract() {
66 return null; 66 return null;
67 } 67 }
68 68
69 @Override 69 @Override
70 public BasePresenter getPresenter() { 70 public BasePresenter getPresenter() {
71 return null; 71 return null;
72 } 72 }
73 73
74 private static int CAMERA_REQUEST_CODE = 343; 74 private static int CAMERA_REQUEST_CODE = 343;
75 private static int ALBUM_REQUEST_CODE = 456; 75 private static int ALBUM_REQUEST_CODE = 456;
76 private static int CROP_REQUEST_CODE = 234; 76 private static int CROP_REQUEST_CODE = 234;
77 private File tempFile; 77 private File tempFile;
78 private String path; 78 private String path;
79 TextView tv_6; 79 TextView tv_6;
80 @BindView(R.id.iv_3) 80 @BindView(R.id.iv_3)
81 ImageView iv_3; 81 ImageView iv_3;
82 82
83 @Override 83 @Override
84 protected void initView() { 84 protected void initView() {
85 tv_6 = findViewById(R.id.tv_6); 85 tv_6 = findViewById(R.id.tv_6);
86 String phone = (String) SharedPreferencesUtil.getData("phone", ""); 86 String phone = (String) SharedPreferencesUtil.getData("phone", "");
87 String photo = (String) SharedPreferencesUtil.getData("photo", ""); 87 String photo = (String) SharedPreferencesUtil.getData("photo", "");
88 if (!TextUtils.isEmpty(photo)) { 88 if (!TextUtils.isEmpty(photo)) {
89 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AccountActivity.this, 45)); 89 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AccountActivity.this, 45));
90 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); 90 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
91 Glide.with(AccountActivity.this).load(photo).apply(options).into(iv_3); 91 Glide.with(AccountActivity.this).load(photo).apply(options).into(iv_3);
92 } 92 }
93 if (phone != null && phone.length() > 0) 93 if (phone != null && phone.length() > 0)
94 tv_6.setText(phone); 94 tv_6.setText(phone);
95 } 95 }
96 96
97 @Override 97 @Override
98 protected void initListener() { 98 protected void initListener() {
99 findViewById(R.id.iv_back).setOnClickListener(view -> onBackPressed()); 99 findViewById(R.id.iv_back).setOnClickListener(view -> onBackPressed());
100 findViewById(R.id.tv_7).setOnClickListener(view -> startActivity(ChangePwdActivity.class)); 100 findViewById(R.id.tv_7).setOnClickListener(view -> startActivity(ChangePwdActivity.class));
101 } 101 }
102 102
103 @Override 103 @Override
104 protected void initData() { 104 protected void initData() {
105 105
106 } 106 }
107 107
108 @Override 108 @Override
109 public void onNetChanged(int netWorkState) { 109 public void onNetChanged(int netWorkState) {
110 110
111 } 111 }
112 112
113 private void uploadAvatar(File file) { 113 private void uploadAvatar(File file) {
114 114
115 NetWorks.uploadAvatar(file, new Observer<ResponseResult<Map<String, String>>>() { 115 NetWorks.uploadAvatar(file, new Observer<ResponseResult<Map<String, String>>>() {
116 @Override 116 @Override
117 public void onSubscribe(Disposable d) { 117 public void onSubscribe(Disposable d) {
118 118
119 } 119 }
120 120
121 @Override 121 @Override
122 public void onNext(ResponseResult<Map<String, String>> responseBody) { 122 public void onNext(ResponseResult<Map<String, String>> responseBody) {
123 if (responseBody.getData() != null && responseBody.getCode() == 200) { 123 if (responseBody.getData() != null && responseBody.getCode() == 200) {
124 path = responseBody.getData().get("imageUrl"); 124 path = responseBody.getData().get("imageUrl");
125 editUser(path); 125 editUser(path);
126 } 126 }
127 } 127 }
128 128
129 @Override 129 @Override
130 public void onError(Throwable e) { 130 public void onError(Throwable e) {
131 e.toString(); 131 e.toString();
132 } 132 }
133 133
134 @Override 134 @Override
135 public void onComplete() { 135 public void onComplete() {
136 136
137 } 137 }
138 }); 138 });
139 } 139 }
140 140
141 public void editUser(String path) { 141 public void editUser(String path) {
142 Map map = new HashMap(); 142 Map map = new HashMap();
143 map.put("userId", SharedPreferencesUtil.getData("userId", "")); 143 map.put("userId", SharedPreferencesUtil.getData("userId", ""));
144 map.put("photo", path); 144 map.put("photo", path);
145 145
146 NetWorks.editUser(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { 146 NetWorks.editUser(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() {
147 @Override 147 @Override
148 public void onSubscribe(Disposable d) { 148 public void onSubscribe(Disposable d) {
149 149
150 } 150 }
151 151
152 @Override 152 @Override
153 public void onNext(ResponseBody responseBody) { 153 public void onNext(ResponseBody responseBody) {
154 try { 154 try {
155 String str = responseBody.string().toString(); 155 String str = responseBody.string().toString();
156 LogUtil.e(TAG, "----" + str); 156 LogUtil.e(TAG, "----" + str);
157 JSONObject jo = new JSONObject(str); 157 JSONObject jo = new JSONObject(str);
158 boolean isSucceed = jo.getBoolean("success"); 158 boolean isSucceed = jo.getBoolean("success");
159 if (isSucceed) { 159 if (isSucceed) {
160 SharedPreferencesUtil.putData("photo", path); 160 SharedPreferencesUtil.putData("photo", path);
161 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AccountActivity.this, 45)); 161 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AccountActivity.this, 45));
162 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); 162 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
163 Glide.with(AccountActivity.this).load(path).apply(options).into(iv_3); 163 Glide.with(AccountActivity.this).load(path).apply(options).into(iv_3);
164 Toast.makeText(AccountActivity.this, "修改成功", Toast.LENGTH_SHORT).show(); 164 Toast.makeText(AccountActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
165 } else { 165 } else {
166 Toast.makeText(AccountActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); 166 Toast.makeText(AccountActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show();
167 } 167 }
168 } catch (Exception e) { 168 } catch (Exception e) {
169 e.printStackTrace(); 169 e.printStackTrace();
170 Toast.makeText(AccountActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); 170 Toast.makeText(AccountActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show();
171 } 171 }
172 } 172 }
173 173
174 @Override 174 @Override
175 public void onError(Throwable e) { 175 public void onError(Throwable e) {
176 176
177 } 177 }
178 178
179 @Override 179 @Override
180 public void onComplete() { 180 public void onComplete() {
181 181
182 } 182 }
183 }); 183 });
184 } 184 }
185 185
186 public File saveImage(String name, Bitmap bmp) { 186 public File saveImage(String name, Bitmap bmp) {
187 File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath()); 187 File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath());
188 if (!appDir.exists()) { 188 if (!appDir.exists()) {
189 appDir.mkdir(); 189 appDir.mkdir();
190 } 190 }
191 String fileName = name + ".jpg"; 191 String fileName = name + ".jpg";
192 File file = new File(appDir, fileName); 192 File file = new File(appDir, fileName);
193 try { 193 try {
194 FileOutputStream fos = new FileOutputStream(file); 194 FileOutputStream fos = new FileOutputStream(file);
195 bmp.compress(Bitmap.CompressFormat.PNG, 100, fos); 195 bmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
196 fos.flush(); 196 fos.flush();
197 fos.close(); 197 fos.close();
198 return file; 198 return file;
199 } catch (IOException e) { 199 } catch (IOException e) {
200 Log.d("dsadsadsa", e.getLocalizedMessage()); 200 Log.d("dsadsadsa", e.getLocalizedMessage());
201 e.printStackTrace(); 201 e.printStackTrace();
202 } 202 }
203 return null; 203 return null;
204 } 204 }
205 205
206 @Override 206 @Override
207 protected void onActivityResult(int requestCode, int resultCode, Intent intent) { 207 protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
208 super.onActivityResult(requestCode, resultCode, intent); 208 super.onActivityResult(requestCode, resultCode, intent);
209 if (requestCode == CAMERA_REQUEST_CODE) { 209 if (requestCode == CAMERA_REQUEST_CODE) {
210 if (resultCode == RESULT_OK) { 210 if (resultCode == RESULT_OK) {
211 //用相机返回的照片去调用剪裁也需要对Uri进行处理 211 //用相机返回的照片去调用剪裁也需要对Uri进行处理
212 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 212 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
213 Uri contentUri = FileProvider.getUriForFile(this, 213 Uri contentUri = FileProvider.getUriForFile(this,
214 this.getPackageName() + ".fileprovider", tempFile); 214 this.getPackageName() + ".fileprovider", tempFile);
215 cropPhoto(contentUri); 215 cropPhoto(contentUri);
216 } else { 216 } else {
217 cropPhoto(Uri.fromFile(tempFile)); 217 cropPhoto(Uri.fromFile(tempFile));
218 } 218 }
219 } 219 }
220 } else if (requestCode == ALBUM_REQUEST_CODE) { 220 } else if (requestCode == ALBUM_REQUEST_CODE) {
221 if (resultCode == RESULT_OK) { 221 if (resultCode == RESULT_OK) {
222 Uri uri = intent.getData(); 222 Uri uri = intent.getData();
223 cropPhoto(uri); 223 cropPhoto(uri);
224 } 224 }
225 } else if (requestCode == CROP_REQUEST_CODE) { 225 } else if (requestCode == CROP_REQUEST_CODE) {
226 if (intent == null) { 226 if (intent == null) {
227 return; 227 return;
228 } 228 }
229 Bundle bundle = intent.getExtras(); 229 Bundle bundle = intent.getExtras();
230 if (bundle != null) { 230 if (bundle != null) {
231 //在这里获得了剪裁后的Bitmap对象,可以用于上传 231 //在这里获得了剪裁后的Bitmap对象,可以用于上传
232 Bitmap image = bundle.getParcelable("data"); 232 Bitmap image = bundle.getParcelable("data");
233 //设置到ImageView上 233 //设置到ImageView上
234 //也可以进行一些保存、压缩等操作后上传 234 //也可以进行一些保存、压缩等操作后上传
235 File file = saveImage("head_output", image); 235 File file = saveImage("head_output", image);
236 uploadAvatar(file); 236 uploadAvatar(file);
237 // Log.d("dsadsadsa",path); 237 // Log.d("dsadsadsa",path);
238 } 238 }
239 } 239 }
240 } 240 }
241 241
242 private void getPicFromCamera() { 242 private void getPicFromCamera() {
243 //用于保存调用相机拍照后所生成的文件 243 //用于保存调用相机拍照后所生成的文件
244 tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"); 244 tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg");
245 //跳转到调用系统相机 245 //跳转到调用系统相机
246 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 246 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
247 //判断版本 247 //判断版本
248 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri 248 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri
249 intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); 249 intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
250 Uri contentUri = FileProvider.getUriForFile(this, 250 Uri contentUri = FileProvider.getUriForFile(this,
251 this.getPackageName() + ".fileprovider", tempFile); 251 this.getPackageName() + ".fileprovider", tempFile);
252 intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri); 252 intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);
253 } else { //否则使用Uri.fromFile(file)方法获取Uri 253 } else { //否则使用Uri.fromFile(file)方法获取Uri
254 intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); 254 intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));
255 } 255 }
256 startActivityForResult(intent, CAMERA_REQUEST_CODE); 256 startActivityForResult(intent, CAMERA_REQUEST_CODE);
257 } 257 }
258 258
259 private void cropPhoto(Uri uri) { 259 private void cropPhoto(Uri uri) {
260 Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg")); 260 Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"));
261 Intent intent = new Intent("com.android.camera.action.CROP"); 261 Intent intent = new Intent("com.android.camera.action.CROP");
262 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 262 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
263 //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片 263 //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片
264 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 264 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
265 } 265 }
266 intent.setDataAndType(uri, "image/*"); 266 intent.setDataAndType(uri, "image/*");
267 intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪 267 intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪
268 intent.putExtra("scale", true);// 设置缩放 268 intent.putExtra("scale", true);// 设置缩放
269 intent.putExtra("scaleUpIfNeeded", true);// 去黑边 269 intent.putExtra("scaleUpIfNeeded", true);// 去黑边
270 intent.putExtra("aspectX", 1); 270 intent.putExtra("aspectX", 1);
271 intent.putExtra("aspectY", 1); 271 intent.putExtra("aspectY", 1);
272 //上述两个属性控制裁剪框的缩放比例。 272 //上述两个属性控制裁剪框的缩放比例。
273 //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。 273 //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。
274 intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。 274 intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。
275 intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存, 275 intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存,
276 intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式 276 intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式
277 intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap 277 intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap
278 intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径 278 intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径
279 startActivityForResult(intent, CROP_REQUEST_CODE); 279 startActivityForResult(intent, CROP_REQUEST_CODE);
280 } 280 }
281 281
282 /** 282 /**
283 * 从相册获取图片 283 * 从相册获取图片
284 */ 284 */
285 private void getPicFromAlbm() { 285 private void getPicFromAlbm() {
286 Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); 286 Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
287 photoPickerIntent.setType("image/*"); 287 photoPickerIntent.setType("image/*");
288 startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE); 288 startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE);
289 } 289 }
290 290
291 @OnClick(R.id.iv_3) 291 @OnClick(R.id.iv_3)
292 public void showButtonDialog(View view) { 292 public void showButtonDialog(View view) {
293 BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); 293 BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog);
294 View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null); 294 View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null);
295 dialog.setContentView(bottomView); 295 dialog.setContentView(bottomView);
296 bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { 296 bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() {
297 @Override 297 @Override
298 public void onClick(View view) { 298 public void onClick(View view) {
299 dialog.dismiss(); 299 dialog.dismiss();
300 if (!XXPermissions.isGranted(AccountActivity.this, Permission.CAMERA)) { 300 if (!XXPermissions.isGranted(AccountActivity.this, Permission.CAMERA)) {
301 XXPermissions.with(AccountActivity.this) 301 XXPermissions.with(AccountActivity.this)
302 // 申请多个权限 302 // 申请多个权限
303 .permission(Permission.CAMERA) 303 .permission(Permission.CAMERA)
304 .request(new OnPermissionCallback() { 304 .request(new OnPermissionCallback() {
305 @Override 305 @Override
306 public void onGranted(List<String> permissions, boolean all) { 306 public void onGranted(List<String> permissions, boolean all) {
307 if (all) { 307 if (all) {
308 //开启扫码界面 308 //开启扫码界面
309 getPicFromCamera(); 309 getPicFromCamera();
310 } else { 310 } else {
311 Toast.makeText(AccountActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show(); 311 Toast.makeText(AccountActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show();
312 } 312 }
313 } 313 }
314 314
315 @Override 315 @Override
316 public void onDenied(List<String> permissions, boolean never) { 316 public void onDenied(List<String> permissions, boolean never) {
317 XXPermissions.startPermissionActivity(AccountActivity.this, permissions); 317 XXPermissions.startPermissionActivity(AccountActivity.this, permissions);
318 } 318 }
319 }); 319 });
320 } else { 320 } else {
321 getPicFromCamera(); 321 getPicFromCamera();
322 } 322 }
323 } 323 }
324 }); 324 });
325 bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { 325 bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() {
326 @Override 326 @Override
327 public void onClick(View view) { 327 public void onClick(View view) {
328 dialog.dismiss(); 328 dialog.dismiss();
329 getPicFromAlbm(); 329 getPicFromAlbm();
330 } 330 }
331 }); 331 });
332 bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { 332 bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
333 @Override 333 @Override
334 public void onClick(View view) { 334 public void onClick(View view) {
335 dialog.dismiss(); 335 dialog.dismiss();
336 } 336 }
337 }); 337 });
338 dialog.show(); 338 dialog.show();
339 } 339 }
340 340
341 @OnClick(R.id.logout) 341 @OnClick(R.id.logout)
342 public void logout(View view) { 342 public void logout(View view) {
343 AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); 343 AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert);
344 builder.setTitle("温馨提示"); 344 builder.setTitle("温馨提示");
345 builder.setMessage("是否退出登录?"); 345 builder.setMessage("是否退出登录?");
346 builder.setCancelable(false); 346 builder.setCancelable(false);
347 builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { 347 builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
348 @Override 348 @Override
349 public void onClick(DialogInterface dialogInterface, int i) { 349 public void onClick(DialogInterface dialogInterface, int i) {
350 dialogInterface.dismiss(); 350 dialogInterface.dismiss();
351 } 351 }
352 }); 352 });
353 builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { 353 builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
354 @Override 354 @Override
355 public void onClick(DialogInterface dialogInterface, int i) { 355 public void onClick(DialogInterface dialogInterface, int i) {
356 SharedPreferencesUtil.clear(AccountActivity.this); 356 SharedPreferencesUtil.clear(AccountActivity.this);
357 restartApp(); 357 restartApp();
358 } 358 }
359 }); 359 });
360 builder.show(); 360 builder.show();
361 } 361 }
362 362
363 private void restartApp() { 363 private void restartApp() {
364 //重启app,这一步一定要加上,如果不重启app,可能打开新的页面显示的语言会不正确 364 //重启app,这一步一定要加上,如果不重启app,可能打开新的页面显示的语言会不正确
365 Intent intent = new Intent(this, LoginActivity.class); 365 Intent intent = new Intent(this, SmsLoginActivity.class);
366 intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK); 366 intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK);
367 startActivity(intent); 367 startActivity(intent);
368 android.os.Process.killProcess(android.os.Process.myPid()); 368 android.os.Process.killProcess(android.os.Process.myPid());
369 System.exit(0); 369 System.exit(0);
370 } 370 }
371 371
372 } 372 }
app/src/main/java/com/hjx/parent/LoginActivity.java
1 package com.hjx.parent; 1 package com.hjx.parent;
2 2
3 import android.content.Intent; 3 import android.content.Intent;
4 import android.os.Bundle; 4 import android.os.Bundle;
5 import android.telephony.PhoneNumberUtils; 5 import android.telephony.PhoneNumberUtils;
6 import android.text.InputType; 6 import android.text.InputType;
7 import android.text.TextUtils; 7 import android.text.TextUtils;
8 import android.text.method.HideReturnsTransformationMethod; 8 import android.text.method.HideReturnsTransformationMethod;
9 import android.text.method.PasswordTransformationMethod; 9 import android.text.method.PasswordTransformationMethod;
10 import android.widget.Button; 10 import android.widget.Button;
11 import android.widget.CheckBox; 11 import android.widget.CheckBox;
12 import android.widget.EditText; 12 import android.widget.EditText;
13 import android.widget.ImageView; 13 import android.widget.ImageView;
14 import android.widget.TextView; 14 import android.widget.TextView;
15 import android.widget.Toast; 15 import android.widget.Toast;
16 16
17 import androidx.appcompat.app.AppCompatActivity; 17 import androidx.appcompat.app.AppCompatActivity;
18 18
19 import com.prws.common.base.BaseActivity; 19 import com.prws.common.base.BaseActivity;
20 import com.prws.common.base.BasePresenter; 20 import com.prws.common.base.BasePresenter;
21 import com.prws.common.bean.BaseEntity; 21 import com.prws.common.bean.BaseEntity;
22 import com.prws.common.net.NetWorks; 22 import com.prws.common.net.NetWorks;
23 import com.prws.common.utils.LogUtil; 23 import com.prws.common.utils.LogUtil;
24 import com.prws.common.utils.SharedPreferencesUtil; 24 import com.prws.common.utils.SharedPreferencesUtil;
25 import com.prws.common.utils.acmanager.ActivityManager; 25 import com.prws.common.utils.acmanager.ActivityManager;
26 26
27 import org.json.JSONObject; 27 import org.json.JSONObject;
28 28
29 import java.io.IOException; 29 import java.io.IOException;
30 import java.util.HashMap; 30 import java.util.HashMap;
31 import java.util.Map; 31 import java.util.Map;
32 32
33 import io.reactivex.Observer; 33 import io.reactivex.Observer;
34 import io.reactivex.disposables.Disposable; 34 import io.reactivex.disposables.Disposable;
35 import okhttp3.ResponseBody; 35 import okhttp3.ResponseBody;
36 36
37 37
38 public class LoginActivity extends BaseActivity { 38 public class LoginActivity extends BaseActivity {
39 39
40 40
41 EditText et_phone; 41 EditText et_phone;
42 EditText et_pwd; 42 EditText et_pwd;
43 ImageView iv_show; 43 ImageView iv_show;
44 ImageView iv_delete; 44 ImageView iv_delete;
45 Button btn_login; 45 Button btn_login;
46 TextView tv_reg;
47 CheckBox cb_1;
48 TextView tv_user;
49 TextView tv_ys;
50 46
51 47
52 @Override 48 @Override
53 protected int layoutResId() { 49 protected int layoutResId() {
54 return R.layout.activity_login; 50 return R.layout.activity_login;
55 } 51 }
56 52
57 @Override 53 @Override
58 public Object getContract() { 54 public Object getContract() {
59 return null; 55 return null;
60 } 56 }
61 57
62 @Override 58 @Override
63 public BasePresenter getPresenter() { 59 public BasePresenter getPresenter() {
64 return null; 60 return null;
65 } 61 }
66 62
67 63
68 @Override 64 @Override
69 protected void initView() { 65 protected void initView() {
70 et_phone = findViewById(R.id.et_phone); 66 et_phone = findViewById(R.id.et_phone);
71 et_pwd = findViewById(R.id.et_pwd); 67 et_pwd = findViewById(R.id.et_pwd);
72 iv_show = findViewById(R.id.iv_4); 68 iv_show = findViewById(R.id.iv_4);
73 iv_delete = findViewById(R.id.iv_2); 69 iv_delete = findViewById(R.id.iv_2);
74 btn_login = findViewById(R.id.btn_1); 70 btn_login = findViewById(R.id.btn_1);
75 tv_reg = findViewById(R.id.tv_2);
76 cb_1 = findViewById(R.id.cb_1);
77 tv_user = findViewById(R.id.tv_4);
78 tv_ys = findViewById(R.id.tv_6);
79
80 71
81 String student = (String) SharedPreferencesUtil.getData("student", ""); 72 String student = (String) SharedPreferencesUtil.getData("student", "");
82 73
83 if (!TextUtils.isEmpty(student)) { 74 if (!TextUtils.isEmpty(student)) {
84 LogUtil.e(TAG, "role 不是空----"); 75 LogUtil.e(TAG, "role 不是空----");
85 if ((SharedPreferencesUtil.getData("role", "")).equals("parent")) { 76 if ((SharedPreferencesUtil.getData("role", "")).equals("parent")) {
86 Intent intent = new Intent(this, MainActivity.class); 77 Intent intent = new Intent(this, MainActivity.class);
87 startActivity(intent); 78 startActivity(intent);
88 finish(); 79 finish();
89 } else { 80 } else {
90 Intent intent = new Intent(this, TeacherMainActivity.class); 81 Intent intent = new Intent(this, TeacherMainActivity.class);
91 startActivity(intent); 82 startActivity(intent);
92 finish(); 83 finish();
93 } 84 }
94 return; 85 return;
95 } else { 86 } else {
96 LogUtil.e(TAG, "role 是空----"); 87 LogUtil.e(TAG, "role 是空----");
97 } 88 }
98 89
90 findViewById(R.id.tvBack).setOnClickListener(v -> {
91 startActivity(new Intent(this, SmsLoginActivity.class));
92 finish();
93 });
99 94
100 } 95 }
101 96
102 @Override 97 @Override
103 protected void initListener() { 98 protected void initListener() {
104 iv_delete.setOnClickListener(view -> { 99 iv_delete.setOnClickListener(view -> {
105 et_phone.setText(""); 100 et_phone.setText("");
106 }); 101 });
107 iv_show.setOnClickListener(view -> { 102 iv_show.setOnClickListener(view -> {
108 if (iv_show.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) { 103 if (iv_show.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) {
109 iv_show.setBackgroundResource(R.mipmap.yc); 104 iv_show.setBackgroundResource(R.mipmap.yc);
110 et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); 105 et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
111 et_pwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); 106 et_pwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
112 } else { 107 } else {
113 iv_show.setBackgroundResource(R.mipmap.xs); 108 iv_show.setBackgroundResource(R.mipmap.xs);
114 et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); 109 et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
115 et_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); 110 et_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
116 } 111 }
117 }); 112 });
118 113
119 114
120 btn_login.setOnClickListener(view -> { 115 btn_login.setOnClickListener(view -> {
121 116
122 String phone = et_phone.getText().toString().trim(); 117 String phone = et_phone.getText().toString().trim();
123 String pwd = et_pwd.getText().toString().trim(); 118 String pwd = et_pwd.getText().toString().trim();
124 if (phone.isEmpty() || pwd.isEmpty() || phone.length() == 0 || pwd.length() == 0) { 119 if (phone.isEmpty() || pwd.isEmpty() || phone.length() == 0 || pwd.length() == 0) {
125 Toast.makeText(this, "手机号以及密码不能为空", Toast.LENGTH_SHORT).show(); 120 Toast.makeText(this, "手机号以及密码不能为空", Toast.LENGTH_SHORT).show();
126 return; 121 return;
127 } 122 }
128 123
129 if (!PhoneNumberUtils.isGlobalPhoneNumber(et_phone.getText().toString())) { 124 if (!PhoneNumberUtils.isGlobalPhoneNumber(et_phone.getText().toString())) {
130 Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_SHORT).show(); 125 Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_SHORT).show();
131 return; 126 return;
132 } 127 }
133 128
134 if (!cb_1.isChecked()) { 129 // if (!cb_1.isChecked()) {
135 Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show(); 130 // Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show();
136 return; 131 // return;
137 } 132 // }
138 133
139 login(phone, pwd); 134 login(phone, pwd);
140 135
141 }); 136 });
142 137
143 tv_reg.setOnClickListener(view -> { 138 // tv_ys.setOnClickListener(view -> {
144 startActivity(RegisterActivity.class); 139 // startActivity(YinsiActivity.class);
145 finish(); 140 // });
146 }); 141 // tv_user.setOnClickListener(view -> {
147 142 // startActivity(UserAgreementActivity.class);
148 tv_ys.setOnClickListener(view -> { 143 // });
149 startActivity(YinsiActivity.class);
150 });
151 tv_user.setOnClickListener(view -> {
152 startActivity(UserAgreementActivity.class);
153 });
154 } 144 }
155 145
156 public void login(final String phone, String pwd) { 146 public void login(final String phone, String pwd) {
157 147
158 Map map = new HashMap(); 148 Map map = new HashMap();
159 map.put("username", phone); 149 map.put("username", phone);
160 map.put("password", pwd); 150 map.put("password", pwd);
161 151
162 152
163 NetWorks.login(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { 153 NetWorks.login(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() {
164 @Override 154 @Override
165 public void onSubscribe(Disposable d) { 155 public void onSubscribe(Disposable d) {
166 156
167 } 157 }
168 158
169 @Override 159 @Override
170 public void onNext(ResponseBody responseBody) { 160 public void onNext(ResponseBody responseBody) {
171 try { 161 try {
172 String str = responseBody.string().toString(); 162 String str = responseBody.string().toString();
173 LogUtil.e(TAG, "----" + str); 163 LogUtil.e(TAG, "----" + str);
174 JSONObject jo = new JSONObject(str); 164 JSONObject jo = new JSONObject(str);
175 boolean isSucceed = jo.getBoolean("success"); 165 boolean isSucceed = jo.getBoolean("success");
176 if (isSucceed) { 166 if (isSucceed) {
177 JSONObject jo2 = jo.getJSONObject("data"); 167 JSONObject jo2 = jo.getJSONObject("data");
178 String role = jo2.getString("role"); 168 String role = jo2.getString("role");
179 if ("parent".equals(role)) { 169 if ("member_advisor".equals(role) || "teaching_supervision".equals(role)) {
180 SharedPreferencesUtil.putData("phone", phone);
181 SharedPreferencesUtil.putData("role", role);
182 SharedPreferencesUtil.putData("userId", jo2.getString("id"));
183 SharedPreferencesUtil.putData("token", jo2.getString("token"));
184 if (jo2.has("photo") && !jo2.getString("photo").equals("null")) {
185 SharedPreferencesUtil.putData("photo", jo2.getString("photo"));
186 }
187 SharedPreferencesUtil.putData("name", jo2.getString("username"));
188 startActivity(ChooseActivity.class);
189 finish();
190 } else if ("member_advisor".equals(role) || "teaching_supervision".equals(role)) {
191 SharedPreferencesUtil.putData("phone", phone); 170 SharedPreferencesUtil.putData("phone", phone);
192 SharedPreferencesUtil.putData("role", role); 171 SharedPreferencesUtil.putData("role", role);
193 SharedPreferencesUtil.putData("userId", jo2.getString("id")); 172 SharedPreferencesUtil.putData("userId", jo2.getString("id"));
194 SharedPreferencesUtil.putData("token", jo2.getString("token")); 173 SharedPreferencesUtil.putData("token", jo2.getString("token"));
195 SharedPreferencesUtil.putData("name", jo2.getString("username")); 174 SharedPreferencesUtil.putData("name", jo2.getString("username"));
196 SharedPreferencesUtil.putData("photo", jo2.getString("photo")); 175 SharedPreferencesUtil.putData("photo", jo2.getString("photo"));
197 startActivity(TeacherChooseActivity.class); 176 startActivity(TeacherChooseActivity.class);
198 finish(); 177 finish();
199 } else { 178 } else {
200 showToast("您没有权限"); 179 showToast("您没有权限");
201 } 180 }
202 181
203 } else { 182 } else {
204 Toast.makeText(LoginActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); 183 Toast.makeText(LoginActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show();
205 } 184 }
206 } catch (Exception e) { 185 } catch (Exception e) {
207 e.printStackTrace(); 186 e.printStackTrace();
208 Toast.makeText(LoginActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); 187 Toast.makeText(LoginActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show();
209 } 188 }
210 } 189 }
211 190
212 @Override 191 @Override
213 public void onError(Throwable e) { 192 public void onError(Throwable e) {
214 193
215 } 194 }
216 195
217 @Override 196 @Override
218 public void onComplete() { 197 public void onComplete() {
219 198
220 } 199 }
221 }); 200 });
222 } 201 }
223 202
224 203
225 @Override 204 @Override
226 protected void initData() { 205 protected void initData() {
227 206
228 } 207 }
229 208
230 @Override 209 @Override
app/src/main/java/com/hjx/parent/SmsLoginActivity.java
File was created 1 package com.hjx.parent;
2
3 import android.annotation.SuppressLint;
4 import android.content.Intent;
5 import android.os.Bundle;
6 import android.telephony.PhoneNumberUtils;
7 import android.text.TextUtils;
8 import android.view.View;
9 import android.widget.Toast;
10
11 import com.hjx.parent.databinding.ActivitySmsLoginBinding;
12 import com.hjx.parent.rx.BaseRxActivity;
13 import com.prws.common.net.NetWorks;
14 import com.prws.common.utils.LogUtil;
15 import com.prws.common.utils.SharedPreferencesUtil;
16
17 import java.util.HashMap;
18 import java.util.Map;
19 import java.util.concurrent.TimeUnit;
20
21 import io.reactivex.Observable;
22 import io.reactivex.android.schedulers.AndroidSchedulers;
23 import io.reactivex.disposables.Disposable;
24
25 public class SmsLoginActivity extends BaseRxActivity<ActivitySmsLoginBinding> {
26 private final NetWorks.NetService api = NetWorks.service_url;
27 @Override
28 public void initView(Bundle savedInstanceState) {
29 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
30
31 String student = (String) SharedPreferencesUtil.getData("student", "");
32
33 if (!TextUtils.isEmpty(student)) {
34 if ((SharedPreferencesUtil.getData("role", "")).equals("parent")) {
35 Intent intent = new Intent(this, MainActivity.class);
36 startActivity(intent);
37 finish();
38 } else {
39 Intent intent = new Intent(this, TeacherMainActivity.class);
40 startActivity(intent);
41 finish();
42 }
43 return;
44 }
45
46 binding.tvEntrance.setOnClickListener(v -> {
47 startActivity(new Intent(this, LoginActivity.class));
48 finish();
49 });
50 binding.btnGetCode.setOnClickListener(v -> {
51 String phone = binding.etPhone.getText().toString().trim();
52 if (phone.isEmpty()) {
53 showToast("请输入手机号");
54 return;
55 }
56 sendCode(phone);
57 });
58 binding.btnLogin.setOnClickListener(v -> {
59
60 String phone = binding.etPhone.getText().toString().trim();
61 String code = binding.etCode.getText().toString().trim();
62 if (phone.isEmpty() || code.isEmpty()) {
63 Toast.makeText(this, "手机号以及验证码不能为空", Toast.LENGTH_SHORT).show();
64 return;
65 }
66
67 if (!binding.chkPermission.isChecked()) {
68 Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show();
69 return;
70 }
71 login(phone, code);
72 });
73
74 binding.tv6.setOnClickListener(view -> {
75 startActivity(new Intent(this, YinsiActivity.class));
76 });
77 binding.tv4.setOnClickListener(view -> {
78 startActivity(new Intent(this, UserAgreementActivity.class));
79 });
80 }
81
82 @SuppressLint("CheckResult")
83 private void login(String phone, String code) {
84 binding.btnLogin.setEnabled(false);
85 Map<String, String> body = new HashMap<>();
86 body.put("phone", phone);
87 body.put("code", code);
88 api.smsLogin(body)
89 .compose(transformSingle())
90 .subscribe((response, th) -> {
91 binding.btnLogin.setEnabled(true);
92 if (handleResponseData(response, th)) {
93 SharedPreferencesUtil.putData("phone", phone);
94 SharedPreferencesUtil.putData("role", "parent");
95 SharedPreferencesUtil.putData("userId", response.getData().id);
96 SharedPreferencesUtil.putData("token", response.getData().token);
97 SharedPreferencesUtil.putData("name", response.getData().username);
98 startActivity(new Intent(this, ChooseActivity.class));
99 finish();
100 }
101 });
102 }
103
104 @SuppressLint({"SetTextI18n", "CheckResult"})
105 private void sendCode(String phone) {
106 binding.btnGetCode.setEnabled(false);
107 api.smsCode(phone)
108 .compose(transformSingle())
109 .subscribe((response, th) -> {
110 if (handleResponse(response, th)) {
111 showToast("验证码已发送");
112 timeDown();
113 } else {
114 if (disposable != null) disposable.dispose();
115 binding.btnGetCode.setText("获取验证码");
116 binding.btnGetCode.setEnabled(true);
117 }
118 });
119 }
120
121 private int timeDown = 0;
122 private Disposable disposable;
123 @SuppressLint("SetTextI18n")
124 private void timeDown() {
125 timeDown = 60;
126 disposable = Observable
127 .interval(0, 1, TimeUnit.SECONDS)
128 .observeOn(AndroidSchedulers.mainThread())
129 .subscribe(l -> {
130 if (--timeDown <= 0) {
131 if (disposable != null) disposable.dispose();
132 binding.btnGetCode.setText("获取验证码");
133 binding.btnGetCode.setEnabled(true);
134 } else {
135 binding.btnGetCode.setText("获取验证码(" + timeDown + "s)");
136 binding.btnGetCode.setEnabled(false);
137 }
138 }, Throwable::printStackTrace);
139 }
140
141 @Override
142 protected void onDestroy() {
143 super.onDestroy();
144 if (disposable != null) disposable.dispose();
145 }
146
147 @Override
148 protected ActivitySmsLoginBinding getViewBinding() {
149 return ActivitySmsLoginBinding.inflate(getLayoutInflater());
150 }
151 }
152
app/src/main/java/com/hjx/parent/rx/BaseRxActivity.java
1 package com.hjx.parent.rx; 1 package com.hjx.parent.rx;
2 2
3 import android.os.Bundle; 3 import android.os.Bundle;
4 4
5 import androidx.annotation.Nullable; 5 import androidx.annotation.Nullable;
6 import androidx.viewbinding.ViewBinding; 6 import androidx.viewbinding.ViewBinding;
7 7
8 import com.hjx.parent.BaseActivity; 8 import com.hjx.parent.BaseActivity;
9 import com.prws.common.bean.ResponseResult;
9 import com.trello.rxlifecycle2.android.ActivityEvent; 10 import com.trello.rxlifecycle2.android.ActivityEvent;
10 11
11 import io.reactivex.subjects.BehaviorSubject; 12 import io.reactivex.subjects.BehaviorSubject;
12 13
13 public abstract class BaseRxActivity<VB extends ViewBinding> extends BaseActivity<VB> implements ILifecycleActivity { 14 public abstract class BaseRxActivity<VB extends ViewBinding> extends BaseActivity<VB> implements ILifecycleActivity {
14 private BehaviorSubject<ActivityEvent> rxLifecycle = BehaviorSubject.create(); 15 private BehaviorSubject<ActivityEvent> rxLifecycle = BehaviorSubject.create();
15 16
16 @Override 17 @Override
17 public BehaviorSubject<ActivityEvent> getRxLifecycle() { 18 public BehaviorSubject<ActivityEvent> getRxLifecycle() {
18 return rxLifecycle; 19 return rxLifecycle;
19 } 20 }
20 21
21 @Override 22 @Override
22 protected void onCreate(@Nullable Bundle savedInstanceState) { 23 protected void onCreate(@Nullable Bundle savedInstanceState) {
23 super.onCreate(savedInstanceState); 24 super.onCreate(savedInstanceState);
24 rxLifecycle.onNext(ActivityEvent.CREATE); 25 rxLifecycle.onNext(ActivityEvent.CREATE);
25 } 26 }
26 27
27 @Override 28 @Override
28 protected void onStart() { 29 protected void onStart() {
29 super.onStart(); 30 super.onStart();
30 rxLifecycle.onNext(ActivityEvent.START); 31 rxLifecycle.onNext(ActivityEvent.START);
31 } 32 }
32 33
33 @Override 34 @Override
34 protected void onResume() { 35 protected void onResume() {
35 super.onResume(); 36 super.onResume();
36 rxLifecycle.onNext(ActivityEvent.RESUME); 37 rxLifecycle.onNext(ActivityEvent.RESUME);
37 } 38 }
38 39
39 @Override 40 @Override
40 protected void onPause() { 41 protected void onPause() {
41 super.onPause(); 42 super.onPause();
42 rxLifecycle.onNext(ActivityEvent.PAUSE); 43 rxLifecycle.onNext(ActivityEvent.PAUSE);
43 } 44 }
44 45
45 @Override 46 @Override
46 protected void onStop() { 47 protected void onStop() {
47 super.onStop(); 48 super.onStop();
48 rxLifecycle.onNext(ActivityEvent.STOP); 49 rxLifecycle.onNext(ActivityEvent.STOP);
49 } 50 }
50 51
51 @Override 52 @Override
52 protected void onDestroy() { 53 protected void onDestroy() {
53 super.onDestroy(); 54 super.onDestroy();
54 rxLifecycle.onNext(ActivityEvent.DESTROY); 55 rxLifecycle.onNext(ActivityEvent.DESTROY);
55 } 56 }
56 57
58 public <T> boolean handleResponse(ResponseResult<T> response, Throwable t) {
59 if (t != null) {
60 t.printStackTrace();
61 showToast(t.getMessage());
62 }
63 if (response == null) return false;
64 if (response.getSuccess() != null && response.getSuccess()) {
65 return true;
66 } else {
67 if (response.getMsg() != null && !response.getMsg().isEmpty()) {
68 showToast(response.getMsg());
69 }
70 return false;
71 }
72 }
73
74 public <T> boolean handleResponseData(ResponseResult<T> response, Throwable t) {
75 if (handleResponse(response, t)) {
76 return response.getData() != null;
77 }
78 return false;
79 }
57 } 80 }
58 81
app/src/main/res/layout/activity_login.xml
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:app="http://schemas.android.com/apk/res-auto" 3 xmlns:app="http://schemas.android.com/apk/res-auto"
4 android:layout_width="match_parent" 4 android:layout_width="match_parent"
5 android:layout_height="match_parent" 5 android:layout_height="match_parent"
6 android:background="@mipmap/bg"> 6 android:background="@mipmap/bg">
7 7
8 8
9 <TextView 9 <TextView
10 android:id="@+id/tvBack"
11 android:text="家长登录"
12 android:textSize="13sp"
13 android:textColor="#666"
14 android:layout_width="wrap_content"
15 android:layout_height="wrap_content"
16 android:layout_marginTop="72dp"
17 android:layout_marginEnd="30dp"
18 app:layout_constraintTop_toTopOf="parent"
19 app:layout_constraintEnd_toEndOf="parent"/>
20
21 <TextView
10 android:layout_width="wrap_content" 22 android:layout_width="wrap_content"
11 android:layout_height="wrap_content" 23 android:layout_height="wrap_content"
12 android:layout_marginLeft="30dp" 24 android:layout_marginLeft="30dp"
13 android:layout_marginTop="64dp" 25 android:layout_marginTop="64dp"
14 android:text="登录" 26 android:text="教师登录"
15 android:textColor="#333333" 27 android:textColor="#333333"
16 android:textSize="25dp" 28 android:textSize="25dp"
17 android:textStyle="bold" 29 android:textStyle="bold"
18 app:layout_constraintLeft_toLeftOf="parent" 30 app:layout_constraintLeft_toLeftOf="parent"
19 app:layout_constraintTop_toTopOf="parent" /> 31 app:layout_constraintTop_toTopOf="parent" />
20 32
21 <View 33 <View
22 android:id="@+id/view_1" 34 android:id="@+id/view_1"
23 android:layout_width="315dp" 35 android:layout_width="315dp"
24 android:layout_height="50dp" 36 android:layout_height="50dp"
25 android:layout_marginTop="166dp" 37 android:layout_marginTop="166dp"
26 android:background="@drawable/bg_solid_white" 38 android:background="@drawable/bg_solid_white"
27 app:layout_constraintLeft_toLeftOf="parent" 39 app:layout_constraintLeft_toLeftOf="parent"
28 app:layout_constraintRight_toRightOf="parent" 40 app:layout_constraintRight_toRightOf="parent"
29 app:layout_constraintTop_toTopOf="parent" /> 41 app:layout_constraintTop_toTopOf="parent" />
30 42
31 <ImageView 43 <ImageView
32 android:id="@+id/iv_1" 44 android:id="@+id/iv_1"
33 android:layout_width="16dp" 45 android:layout_width="16dp"
34 android:layout_height="18dp" 46 android:layout_height="18dp"
35 android:layout_marginLeft="20dp" 47 android:layout_marginLeft="20dp"
36 android:background="@mipmap/sjh" 48 android:background="@mipmap/sjh"
37 app:layout_constraintBottom_toBottomOf="@id/view_1" 49 app:layout_constraintBottom_toBottomOf="@id/view_1"
38 app:layout_constraintLeft_toLeftOf="@id/view_1" 50 app:layout_constraintLeft_toLeftOf="@id/view_1"
39 app:layout_constraintTop_toTopOf="@id/view_1" /> 51 app:layout_constraintTop_toTopOf="@id/view_1" />
40 52
41 <ImageView 53 <ImageView
42 android:id="@+id/iv_2" 54 android:id="@+id/iv_2"
43 android:layout_width="13dp" 55 android:layout_width="13dp"
44 android:layout_height="13dp" 56 android:layout_height="13dp"
45 android:layout_marginRight="20dp" 57 android:layout_marginRight="20dp"
46 android:background="@mipmap/sc" 58 android:background="@mipmap/sc"
47 app:layout_constraintBottom_toBottomOf="@id/view_1" 59 app:layout_constraintBottom_toBottomOf="@id/view_1"
48 app:layout_constraintRight_toRightOf="@id/view_1" 60 app:layout_constraintRight_toRightOf="@id/view_1"
49 app:layout_constraintTop_toTopOf="@id/view_1" /> 61 app:layout_constraintTop_toTopOf="@id/view_1" />
50 62
51 <EditText 63 <EditText
52 android:id="@+id/et_phone" 64 android:id="@+id/et_phone"
53 android:layout_width="0dp" 65 android:layout_width="0dp"
54 android:layout_height="0dp" 66 android:layout_height="0dp"
55 android:layout_marginLeft="46dp" 67 android:layout_marginLeft="46dp"
56 android:background="@android:color/transparent" 68 android:background="@android:color/transparent"
57 android:gravity="left|center_vertical" 69 android:gravity="left|center_vertical"
58 android:hint="请输入手机号" 70 android:hint="请输入手机号"
59 android:inputType="number" 71 android:inputType="number"
60 android:maxLength="11" 72 android:maxLength="11"
61 android:textColorHint="#999999" 73 android:textColorHint="#999999"
62 android:textSize="16dp" 74 android:textSize="16dp"
63 app:layout_constraintBottom_toBottomOf="@id/view_1" 75 app:layout_constraintBottom_toBottomOf="@id/view_1"
64 app:layout_constraintLeft_toLeftOf="@id/view_1" 76 app:layout_constraintLeft_toLeftOf="@id/view_1"
65 app:layout_constraintRight_toLeftOf="@id/iv_2" 77 app:layout_constraintRight_toLeftOf="@id/iv_2"
66 app:layout_constraintTop_toTopOf="@id/view_1" /> 78 app:layout_constraintTop_toTopOf="@id/view_1" />
67 79
68 80
69 <View 81 <View
70 android:id="@+id/view_2" 82 android:id="@+id/view_2"
71 android:layout_width="315dp" 83 android:layout_width="315dp"
72 android:layout_height="50dp" 84 android:layout_height="50dp"
73 android:layout_marginTop="241dp" 85 android:layout_marginTop="241dp"
74 android:background="@drawable/bg_solid_white" 86 android:background="@drawable/bg_solid_white"
75 app:layout_constraintLeft_toLeftOf="parent" 87 app:layout_constraintLeft_toLeftOf="parent"
76 app:layout_constraintRight_toRightOf="parent" 88 app:layout_constraintRight_toRightOf="parent"
77 app:layout_constraintTop_toTopOf="parent" /> 89 app:layout_constraintTop_toTopOf="parent" />
78 90
79 <ImageView 91 <ImageView
80 android:id="@+id/iv_3" 92 android:id="@+id/iv_3"
81 android:layout_width="16dp" 93 android:layout_width="16dp"
82 android:layout_height="18dp" 94 android:layout_height="18dp"
83 android:layout_marginLeft="20dp" 95 android:layout_marginLeft="20dp"
84 android:background="@mipmap/mm" 96 android:background="@mipmap/mm"
85 app:layout_constraintBottom_toBottomOf="@id/view_2" 97 app:layout_constraintBottom_toBottomOf="@id/view_2"
86 app:layout_constraintLeft_toLeftOf="@id/view_2" 98 app:layout_constraintLeft_toLeftOf="@id/view_2"
87 app:layout_constraintTop_toTopOf="@id/view_2" /> 99 app:layout_constraintTop_toTopOf="@id/view_2" />
88 100
89 <ImageView 101 <ImageView
90 android:id="@+id/iv_4" 102 android:id="@+id/iv_4"
91 android:layout_width="20dp" 103 android:layout_width="20dp"
92 android:layout_height="16dp" 104 android:layout_height="16dp"
93 android:layout_marginRight="20dp" 105 android:layout_marginRight="20dp"
94 android:background="@mipmap/xs" 106 android:background="@mipmap/xs"
95 app:layout_constraintBottom_toBottomOf="@id/view_2" 107 app:layout_constraintBottom_toBottomOf="@id/view_2"
96 app:layout_constraintRight_toRightOf="@id/view_2" 108 app:layout_constraintRight_toRightOf="@id/view_2"
97 app:layout_constraintTop_toTopOf="@id/view_2" /> 109 app:layout_constraintTop_toTopOf="@id/view_2" />
98 110
99 <EditText 111 <EditText
100 android:id="@+id/et_pwd" 112 android:id="@+id/et_pwd"
101 android:layout_width="0dp" 113 android:layout_width="0dp"
102 android:layout_height="0dp" 114 android:layout_height="0dp"
103 android:layout_marginLeft="46dp" 115 android:layout_marginLeft="46dp"
104 android:layout_marginRight="20dp" 116 android:layout_marginRight="20dp"
105 android:background="@android:color/transparent" 117 android:background="@android:color/transparent"
106 android:gravity="left|center_vertical" 118 android:gravity="left|center_vertical"
107 android:hint="请输入密码" 119 android:hint="请输入密码"
108 android:inputType="textPassword" 120 android:inputType="textPassword"
109 android:textColorHint="#999999" 121 android:textColorHint="#999999"
110 android:textSize="16dp" 122 android:textSize="16dp"
111 app:layout_constraintBottom_toBottomOf="@id/view_2" 123 app:layout_constraintBottom_toBottomOf="@id/view_2"
112 app:layout_constraintLeft_toLeftOf="@id/view_2" 124 app:layout_constraintLeft_toLeftOf="@id/view_2"
113 app:layout_constraintRight_toLeftOf="@id/iv_4" 125 app:layout_constraintRight_toLeftOf="@id/iv_4"
114 app:layout_constraintTop_toTopOf="@id/view_2" /> 126 app:layout_constraintTop_toTopOf="@id/view_2" />
115 127
116 128
117 <Button 129 <Button
118 android:id="@+id/btn_1" 130 android:id="@+id/btn_1"
119 android:layout_width="315dp" 131 android:layout_width="315dp"
120 android:layout_height="50dp" 132 android:layout_height="50dp"
121 android:layout_marginTop="331dp" 133 android:layout_marginTop="331dp"
122 android:background="@drawable/bg_solid_btn" 134 android:background="@drawable/bg_solid_btn"
123 android:text="登录" 135 android:text="登录"
124 android:textColor="@color/white" 136 android:textColor="@color/white"
125 android:textSize="18dp" 137 android:textSize="18dp"
126 app:layout_constraintLeft_toLeftOf="parent" 138 app:layout_constraintLeft_toLeftOf="parent"
127 app:layout_constraintRight_toRightOf="parent" 139 app:layout_constraintRight_toRightOf="parent"
128 app:layout_constraintTop_toTopOf="parent" /> 140 app:layout_constraintTop_toTopOf="parent" />
129 141
130 <TextView
131 android:id="@+id/tv_1"
132 android:layout_width="wrap_content"
133 android:layout_height="wrap_content"
134 android:layout_marginLeft="85dp"
135 android:layout_marginTop="15dp"
136 android:text="没有账号,立即"
137 android:textColor="#666666"
138 android:textSize="17dp"
139 app:layout_constraintLeft_toLeftOf="@id/btn_1"
140 app:layout_constraintTop_toBottomOf="@id/btn_1" />
141
142 <TextView
143 android:id="@+id/tv_2"
144 android:layout_width="wrap_content"
145 android:layout_height="wrap_content"
146 android:layout_marginTop="15dp"
147 android:text="注册"
148 android:textColor="#FE5E09"
149 android:textSize="17dp"
150 app:layout_constraintLeft_toRightOf="@id/tv_1"
151 app:layout_constraintTop_toBottomOf="@id/btn_1" />
152
153
154 <CheckBox
155 android:id="@+id/cb_1"
156 android:layout_width="wrap_content"
157 android:layout_height="wrap_content"
158 android:layout_marginLeft="67dp"
159 android:layout_marginBottom="50dp"
160 android:background="@android:color/transparent"
161 app:layout_constraintBottom_toBottomOf="parent"
162 app:layout_constraintLeft_toLeftOf="parent" />
163
164 <TextView
165 android:id="@+id/tv_3"
166 android:layout_width="wrap_content"
167 android:layout_height="wrap_content"
168 android:layout_marginLeft="5dp"
169 android:text="已阅读并同意《"
170 android:textColor="#999999"
171 android:textSize="12dp"
172 app:layout_constraintBottom_toBottomOf="@id/cb_1"
173 app:layout_constraintLeft_toRightOf="@id/cb_1"
174 app:layout_constraintTop_toTopOf="@id/cb_1" />
175
176 <TextView
177 android:id="@+id/tv_4"
178 android:layout_width="wrap_content"
179 android:layout_height="wrap_content"
180 android:text="用户协议"
181 android:textColor="#FE5E09"
182 android:textSize="12dp"
183 app:layout_constraintBottom_toBottomOf="@id/cb_1"
184 app:layout_constraintLeft_toRightOf="@id/tv_3"
185 app:layout_constraintTop_toTopOf="@id/cb_1" />
186
187 <TextView
188 android:id="@+id/tv_5"
189 android:layout_width="wrap_content"
190 android:layout_height="wrap_content"
191 android:text="》和《"
192 android:textColor="#999999"
193 android:textSize="12dp"
194 app:layout_constraintBottom_toBottomOf="@id/cb_1"
195 app:layout_constraintLeft_toRightOf="@id/tv_4"
196 app:layout_constraintTop_toTopOf="@id/cb_1" />
197
198 <TextView
199 android:id="@+id/tv_6"
200 android:layout_width="wrap_content"
201 android:layout_height="wrap_content"
202 android:text="隐私政策"
203 android:textColor="#FE5E09"
204 android:textSize="12dp"
205 app:layout_constraintBottom_toBottomOf="@id/cb_1"
206 app:layout_constraintLeft_toRightOf="@id/tv_5"
207 app:layout_constraintTop_toTopOf="@id/cb_1" />
208
209 <TextView
app/src/main/res/layout/activity_sms_login.xml
File was created 1 <?xml version="1.0" encoding="utf-8"?>
2 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:app="http://schemas.android.com/apk/res-auto"
4 xmlns:tools="http://schemas.android.com/tools"
5 android:layout_width="match_parent"
6 android:layout_height="match_parent"
7 android:background="@mipmap/bg"
8 tools:ignore="HardcodedText,SpUsage,ContentDescription,Autofill">
9
10
11 <TextView
12 android:layout_width="wrap_content"
13 android:layout_height="wrap_content"
14 android:layout_marginStart="30dp"
15 android:layout_marginTop="64dp"
16 android:text="登录"
17 android:textColor="#333333"
18 android:textSize="25dp"
19 android:textStyle="bold"
20 app:layout_constraintLeft_toLeftOf="parent"
21 app:layout_constraintTop_toTopOf="parent" />
22
23 <TextView
24 android:id="@+id/tvEntrance"
25 android:text="教师入口"
26 android:textSize="13sp"
27 android:textColor="#666"
28 android:layout_width="wrap_content"
29 android:layout_height="wrap_content"
30 android:layout_marginTop="72dp"
31 android:layout_marginEnd="30dp"
32 app:layout_constraintTop_toTopOf="parent"
33 app:layout_constraintEnd_toEndOf="parent"/>
34
35 <View
36 android:id="@+id/view_1"
37 android:layout_width="315dp"
38 android:layout_height="50dp"
39 android:layout_marginTop="166dp"
40 android:background="@drawable/bg_solid_white"
41 app:layout_constraintLeft_toLeftOf="parent"
42 app:layout_constraintRight_toRightOf="parent"
43 app:layout_constraintTop_toTopOf="parent" />
44
45 <ImageView
46 android:id="@+id/iv_1"
47 android:layout_width="16dp"
48 android:layout_height="18dp"
49 android:layout_marginStart="20dp"
50 android:background="@mipmap/sjh"
51 app:layout_constraintBottom_toBottomOf="@id/view_1"
52 app:layout_constraintLeft_toLeftOf="@id/view_1"
53 app:layout_constraintTop_toTopOf="@id/view_1" />
54
55 <ImageView
56 android:id="@+id/iv_2"
57 android:layout_width="13dp"
58 android:layout_height="13dp"
59 android:layout_marginEnd="20dp"
60 android:background="@mipmap/sc"
61 app:layout_constraintBottom_toBottomOf="@id/view_1"
62 app:layout_constraintRight_toRightOf="@id/view_1"
63 app:layout_constraintTop_toTopOf="@id/view_1" />
64
65 <EditText
66 android:id="@+id/etPhone"
67 android:layout_width="0dp"
68 android:layout_height="0dp"
69 android:layout_marginStart="46dp"
70 android:background="@android:color/transparent"
71 android:gravity="start|center_vertical"
72 android:hint="请输入手机号"
73 android:inputType="number"
74 android:maxLength="11"
75 android:textColorHint="#999999"
76 android:textSize="16dp"
77 app:layout_constraintBottom_toBottomOf="@id/view_1"
78 app:layout_constraintLeft_toLeftOf="@id/view_1"
79 app:layout_constraintRight_toLeftOf="@id/iv_2"
80 app:layout_constraintTop_toTopOf="@id/view_1"
81 tools:ignore="TextFields" />
82
83
84 <View
85 android:id="@+id/view_2"
86 android:layout_width="315dp"
87 android:layout_height="50dp"
88 android:layout_marginTop="241dp"
89 android:background="@drawable/bg_solid_white"
90 app:layout_constraintLeft_toLeftOf="parent"
91 app:layout_constraintRight_toRightOf="parent"
92 app:layout_constraintTop_toTopOf="parent" />
93
94 <ImageView
95 android:id="@+id/iv_3"
96 android:layout_width="16dp"
97 android:layout_height="18dp"
98 android:layout_marginStart="20dp"
99 android:background="@mipmap/mm"
100 app:layout_constraintBottom_toBottomOf="@id/view_2"
101 app:layout_constraintLeft_toLeftOf="@id/view_2"
102 app:layout_constraintTop_toTopOf="@id/view_2" />
103
104 <TextView
105 android:id="@+id/btnGetCode"
106 android:text="获取验证码"
107 android:textSize="13dp"
108 android:textColor="#999"
109 android:layout_width="wrap_content"
110 android:layout_height="wrap_content"
111 android:layout_marginEnd="20dp"
112 app:layout_constraintBottom_toBottomOf="@id/view_2"
113 app:layout_constraintRight_toRightOf="@id/view_2"
114 app:layout_constraintTop_toTopOf="@id/view_2" />
115
116 <EditText
117 android:id="@+id/etCode"
118 android:maxLength="6"
119 android:layout_width="0dp"
120 android:layout_height="0dp"
121 android:layout_marginStart="46dp"
122 android:layout_marginEnd="20dp"
123 android:background="@android:color/transparent"
124 android:gravity="start|center_vertical"
125 android:hint="请输入验证码"
126 android:inputType="number"
127 android:textColorHint="#999999"
128 android:textSize="16dp"
129 app:layout_constraintBottom_toBottomOf="@id/view_2"
130 app:layout_constraintLeft_toLeftOf="@id/view_2"
131 app:layout_constraintRight_toLeftOf="@id/btnGetCode"
132 app:layout_constraintTop_toTopOf="@id/view_2" />
133
134
135 <Button
136 android:id="@+id/btnLogin"
137 android:layout_width="315dp"
138 android:layout_height="50dp"
139 android:layout_marginTop="331dp"
140 android:background="@drawable/bg_solid_btn"
141 android:text="登录"
142 android:textColor="@color/white"
143 android:textSize="18dp"
144 app:layout_constraintLeft_toLeftOf="parent"
145 app:layout_constraintRight_toRightOf="parent"
146 app:layout_constraintTop_toTopOf="parent" />
147
148
149 <CheckBox
150 android:id="@+id/chkPermission"
151 android:layout_width="wrap_content"
152 android:layout_height="wrap_content"
153 android:layout_marginStart="67dp"
154 android:layout_marginBottom="50dp"
155 android:background="@android:color/transparent"
156 app:layout_constraintBottom_toBottomOf="parent"
157 app:layout_constraintLeft_toLeftOf="parent" />
158
159 <TextView
160 android:id="@+id/tv_3"
161 android:layout_width="wrap_content"
162 android:layout_height="wrap_content"
163 android:layout_marginStart="5dp"
164 android:text="已阅读并同意《"
165 android:textColor="#999999"
166 android:textSize="12dp"
167 app:layout_constraintBottom_toBottomOf="@id/chkPermission"
168 app:layout_constraintLeft_toRightOf="@id/chkPermission"
169 app:layout_constraintTop_toTopOf="@id/chkPermission" />
170
171 <TextView
172 android:id="@+id/tv_4"
173 android:layout_width="wrap_content"
174 android:layout_height="wrap_content"
175 android:text="用户协议"
176 android:textColor="#FE5E09"
177 android:textSize="12dp"
178 app:layout_constraintBottom_toBottomOf="@id/chkPermission"
179 app:layout_constraintLeft_toRightOf="@id/tv_3"
180 app:layout_constraintTop_toTopOf="@id/chkPermission" />
181
182 <TextView
183 android:id="@+id/tv_5"
184 android:layout_width="wrap_content"
185 android:layout_height="wrap_content"
186 android:text="》和《"
187 android:textColor="#999999"
188 android:textSize="12dp"
189 app:layout_constraintBottom_toBottomOf="@id/chkPermission"
190 app:layout_constraintLeft_toRightOf="@id/tv_4"
191 app:layout_constraintTop_toTopOf="@id/chkPermission" />
192
193 <TextView
194 android:id="@+id/tv_6"
195 android:layout_width="wrap_content"
196 android:layout_height="wrap_content"
197 android:text="隐私政策"
198 android:textColor="#FE5E09"
199 android:textSize="12dp"
200 app:layout_constraintBottom_toBottomOf="@id/chkPermission"
201 app:layout_constraintLeft_toRightOf="@id/tv_5"
202 app:layout_constraintTop_toTopOf="@id/chkPermission" />
203
204 <TextView
205 android:id="@+id/tv_7"
206 android:layout_width="wrap_content"
207 android:layout_height="wrap_content"
208 android:text="》"
209 android:textColor="#999999"
210 android:textSize="12dp"
211 app:layout_constraintBottom_toBottomOf="@id/chkPermission"
212 app:layout_constraintLeft_toRightOf="@id/tv_6"
213 app:layout_constraintTop_toTopOf="@id/chkPermission" />
214
215
216 </androidx.constraintlayout.widget.ConstraintLayout>
libs/common/src/main/java/com/prws/common/bean/User.java
File was created 1 package com.prws.common.bean;
2
3 public class User {
4
5 public String id;
6 public String phone;
7 public String account;
8 public String password;
9 public String username;
10 public String identity; //用户身份(NORMAL,ADMIN,EMPLOYEE)
11 public String identityName; //用户身份(普通用户、管理员、内部员工)
12 public String gender; //性别
13 public String registration; //注册方式(用户创建、员工创建)
14 public String token;
15 }
16
libs/common/src/main/java/com/prws/common/net/NetWorks.java
1 package com.prws.common.net; 1 package com.prws.common.net;
2 2
3 3
4 import com.google.gson.Gson; 4 import com.google.gson.Gson;
5 import com.google.gson.JsonObject; 5 import com.google.gson.JsonObject;
6 import com.prws.common.BuildConfig; 6 import com.prws.common.BuildConfig;
7 import com.prws.common.bean.CutPicBean; 7 import com.prws.common.bean.CutPicBean;
8 import com.prws.common.bean.GradeAndSubject; 8 import com.prws.common.bean.GradeAndSubject;
9 import com.prws.common.bean.PageInfo; 9 import com.prws.common.bean.PageInfo;
10 import com.prws.common.bean.ResponseResult; 10 import com.prws.common.bean.ResponseResult;
11 import com.prws.common.bean.ScheduleBean; 11 import com.prws.common.bean.ScheduleBean;
12 import com.prws.common.bean.Student; 12 import com.prws.common.bean.Student;
13 import com.prws.common.bean.Teacher; 13 import com.prws.common.bean.Teacher;
14 import com.prws.common.bean.TopicBean; 14 import com.prws.common.bean.TopicBean;
15 import com.prws.common.bean.UpdateBean; 15 import com.prws.common.bean.UpdateBean;
16 import com.prws.common.bean.User;
16 import com.prws.common.bean.baidu.BaiduInput; 17 import com.prws.common.bean.baidu.BaiduInput;
17 import com.prws.common.bean.homework.HomeWork; 18 import com.prws.common.bean.homework.HomeWork;
18 import com.prws.common.bean.homework.HomeworkDetail; 19 import com.prws.common.bean.homework.HomeworkDetail;
19 import com.prws.common.bean.homework.HomeworkList; 20 import com.prws.common.bean.homework.HomeworkList;
20 import com.prws.common.bean.homework.StDetail; 21 import com.prws.common.bean.homework.StDetail;
21 import com.prws.common.utils.BitmapUtils; 22 import com.prws.common.utils.BitmapUtils;
22 import com.prws.common.utils.SharedPreferencesUtil; 23 import com.prws.common.utils.SharedPreferencesUtil;
23 24
24 import java.io.File; 25 import java.io.File;
25 import java.util.HashMap; 26 import java.util.HashMap;
26 import java.util.List; 27 import java.util.List;
27 import java.util.Map; 28 import java.util.Map;
28 29
29 import io.reactivex.Observable; 30 import io.reactivex.Observable;
30 import io.reactivex.Observer; 31 import io.reactivex.Observer;
31 import io.reactivex.Single; 32 import io.reactivex.Single;
32 import io.reactivex.android.schedulers.AndroidSchedulers; 33 import io.reactivex.android.schedulers.AndroidSchedulers;
33 import io.reactivex.schedulers.Schedulers; 34 import io.reactivex.schedulers.Schedulers;
34 import okhttp3.MediaType; 35 import okhttp3.MediaType;
35 import okhttp3.MultipartBody; 36 import okhttp3.MultipartBody;
36 import okhttp3.RequestBody; 37 import okhttp3.RequestBody;
37 import okhttp3.ResponseBody; 38 import okhttp3.ResponseBody;
38 import retrofit2.Call; 39 import retrofit2.Call;
39 import retrofit2.Callback; 40 import retrofit2.Callback;
40 import retrofit2.http.Body; 41 import retrofit2.http.Body;
41 import retrofit2.http.GET; 42 import retrofit2.http.GET;
42 import retrofit2.http.Header; 43 import retrofit2.http.Header;
43 import retrofit2.http.Headers; 44 import retrofit2.http.Headers;
44 import retrofit2.http.Multipart; 45 import retrofit2.http.Multipart;
45 import retrofit2.http.POST; 46 import retrofit2.http.POST;
46 import retrofit2.http.PUT; 47 import retrofit2.http.PUT;
47 import retrofit2.http.Part; 48 import retrofit2.http.Part;
48 import retrofit2.http.PartMap; 49 import retrofit2.http.PartMap;
49 import retrofit2.http.Query; 50 import retrofit2.http.Query;
50 import retrofit2.http.Url; 51 import retrofit2.http.Url;
51 52
52 /** 53 /**
53 * 类名称:NetWorks 54 * 类名称:NetWorks
54 * 创建人: 55 * 创建人:
55 * <p> 56 * <p>
56 * 类描述:网络请求的操作类 57 * 类描述:网络请求的操作类
57 */ 58 */
58 public class NetWorks extends RetrofitUtils { 59 public class NetWorks extends RetrofitUtils {
59 //服务器路径 60 //服务器路径
60 public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class); 61 public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class);
61 62
62 //设缓存有效期为1天 63 //设缓存有效期为1天
63 protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; 64 protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1;
64 //查询缓存的Cache-Control设置,使用缓存 65 //查询缓存的Cache-Control设置,使用缓存
65 protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; 66 protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC;
66 //查询网络的Cache-Control设置。不使用缓存 67 //查询网络的Cache-Control设置。不使用缓存
67 protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; 68 protected static final String CACHE_CONTROL_NETWORK = "max-age=0";
68 69
69 70
70 public interface NetService { 71 public interface NetService {
71 72
72 73
73 @GET("/api/v1/user/logout") 74 @GET("/api/v1/user/logout")
74 Observable<ResponseBody> logout(); 75 Observable<ResponseBody> logout();
75 76
76 @Multipart 77 @Multipart
77 @POST("/api/v1/user/upLoadAvatar") 78 @POST("/api/v1/user/upLoadAvatar")
78 Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); 79 Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis);
79 80
80 81
81 @Headers("Content-Type: application/json") 82 @Headers("Content-Type: application/json")
82 @POST("/api/v1/user/editUser") 83 @POST("/api/v1/user/editUser")
83 Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); 84 Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body);
84 85
85 @Headers("Content-Type: application/json") 86 @Headers("Content-Type: application/json")
86 @POST("/api/v1/user/changePassword") 87 @POST("/api/v1/user/changePassword")
87 Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); 88 Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body);
88 89
89 90
90 @GET("/api/v1/user/searchById") 91 @GET("/api/v1/user/searchById")
91 Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); 92 Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId);
92 93
93 94
94 @Headers("Content-Type: application/json") 95 @Headers("Content-Type: application/json")
95 @POST("/api/v1/login/userLogin") 96 @POST("/api/v1/login/userLogin")
96 Observable<ResponseBody> login(@Body RequestBody body); 97 Observable<ResponseBody> login(@Body RequestBody body);
97 98
98 @GET("/api/v1/resource/listGradeAndSubject") 99 @GET("/api/v1/resource/listGradeAndSubject")
99 Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); 100 Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token);
100 101
101 102
102 @GET("/api/v1/manager/generalQrCode") 103 @GET("/api/v1/manager/generalQrCode")
103 Observable<ResponseBody> generalQrCode(); 104 Observable<ResponseBody> generalQrCode();
104 105
105 @GET("/api/v1/parent/scanAndLogin?") 106 @GET("/api/v1/parent/scanAndLogin?")
106 Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId); 107 Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId);
107 108
108 @GET("/api/v1/parent/getChildrenList") 109 @GET("/api/v1/parent/getChildrenList")
109 Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); 110 Observable<ResponseBody> getChildrenList(@Header("Authorization") String token);
110 111
111 112
112 @Headers("Content-Type: application/json") 113 @Headers("Content-Type: application/json")
113 @POST("/api/v1/parent/registerParent") 114 @POST("/api/v1/parent/registerParent")
114 Observable<ResponseBody> registerParent(@Body RequestBody body); 115 Observable<ResponseBody> registerParent(@Body RequestBody body);
115 116
116 117
117 @GET("/api/v1/parent/listChildren") 118 @GET("/api/v1/parent/listChildren")
118 Observable<ResponseBody> listChildren(@Header("Authorization") String token); 119 Observable<ResponseBody> listChildren(@Header("Authorization") String token);
119 120
120 121
121 @Headers("Content-Type: application/json") 122 @Headers("Content-Type: application/json")
122 @POST("/api/v1/parent/registerStudent") 123 @POST("/api/v1/parent/registerStudent")
123 Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); 124 Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body);
124 125
125 @Headers("Content-Type: application/json") 126 @Headers("Content-Type: application/json")
126 @POST("/api/v1/parent/bindTeacher") 127 @POST("/api/v1/parent/bindTeacher")
127 Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); 128 Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body);
128 129
129 @Multipart 130 @Multipart
130 @POST("/api/v1/user/upLoadAvatar") 131 @POST("/api/v1/user/upLoadAvatar")
131 Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); 132 Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file);
132 133
133 134
134 @Multipart 135 @Multipart
135 @POST("/api/v1/student/editStudentAvatar") 136 @POST("/api/v1/student/editStudentAvatar")
136 Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); 137 Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map);
137 138
138 @Headers("Content-Type: application/json") 139 @Headers("Content-Type: application/json")
139 @POST("/api/v1/parent/editChild") 140 @POST("/api/v1/parent/editChild")
140 Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); 141 Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body);
141 142
142 @GET("/api/v1/student/getStudyPlanForThisWeek") 143 @GET("/api/v1/student/getStudyPlanForThisWeek")
143 Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); 144 Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId);
144 145
145 @GET("api/v1/parent/searchTeacher") 146 @GET("api/v1/parent/searchTeacher")
146 Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); 147 Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone);
147 148
148 @POST("api/v1/question/listErrorBook") 149 @POST("api/v1/question/listErrorBook")
149 Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); 150 Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body);
150 151
151 @POST 152 @POST
152 Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); 153 Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body);
153 154
154 @POST 155 @POST
155 Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); 156 Observable<CutPicBean> cut(@Url String url, @Body RequestBody body);
156 157
157 @POST 158 @POST
158 Observable<JsonObject> getBaiduToken(@Url String url); 159 Observable<JsonObject> getBaiduToken(@Url String url);
159 160
160 @Multipart 161 @Multipart
161 @POST("api/v1/pad/addErrorBook") 162 @POST("api/v1/pad/addErrorBook")
162 Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); 163 Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map);
163 164
164 @POST("api/v1/pad/deleteStuErrorBook") 165 @POST("api/v1/pad/deleteStuErrorBook")
165 Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); 166 Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map);
166 167
167 @PUT("api/v1/pad/updateStuErrorBookInfo") 168 @PUT("api/v1/pad/updateStuErrorBookInfo")
168 Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); 169 Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map);
169 170
170 @POST("api/v1/question/editErrorBook") 171 @POST("api/v1/question/editErrorBook")
171 Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); 172 Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map);
172 173
173 @GET("api/v1/resource/checkUpdate") 174 @GET("api/v1/resource/checkUpdate")
174 Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); 175 Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type);
175 176
176 @GET("api/v1/teacher/getStudentList") 177 @GET("api/v1/teacher/getStudentList")
177 Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); 178 Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id);
178 179
179 @GET("api/v1/teacher/getStudentList") 180 @GET("api/v1/teacher/getStudentList")
180 Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id); 181 Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id);
181 182
182 @GET("api/v1/answer/listRecordForTeacher") 183 @GET("api/v1/answer/listRecordForTeacher")
183 Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); 184 Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id);
184 185
185 @GET("api/v1/homework/listHomeworkByStuId") 186 @GET("api/v1/homework/listHomeworkByStuId")
186 Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId); 187 Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId);
187 188
188 @POST 189 @POST
189 Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body); 190 Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body);
190 191
191 @Multipart 192 @Multipart
192 @POST("api/v1/homework/uploadHomework") 193 @POST("api/v1/homework/uploadHomework")
193 Single<ResponseResult> uploadImage(@Header("Authorization") String token, @Part() MultipartBody.Part file, @Query("brief") String id); 194 Single<ResponseResult> uploadImage(@Header("Authorization") String token, @Part() MultipartBody.Part file, @Query("brief") String id);
194 195
195 @POST("api/v1/homework/uploadHomeworkAction") 196 @POST("api/v1/homework/uploadHomeworkAction")
196 Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map); 197 Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map);
197 198
198 @GET("api/v1/homework/removeHomework") 199 @GET("api/v1/homework/removeHomework")
199 Single<ResponseResult<Boolean>> deleteHomework( 200 Single<ResponseResult<Boolean>> deleteHomework(
200 @Header("Authorization") String token, 201 @Header("Authorization") String token,
201 @Query("homeworkId") String homeworkId 202 @Query("homeworkId") String homeworkId
202 ); 203 );
203 204
204 @GET("api/v1/homework/listHomeworkById") 205 @GET("api/v1/homework/listHomeworkById")
205 Single<ResponseResult<List<HomeWork>>> getHomeworkDetail(@Header("Authorization") String token, @Query("homeworkId") String homeworkId); 206 Single<ResponseResult<List<HomeWork>>> getHomeworkDetail(@Header("Authorization") String token, @Query("homeworkId") String homeworkId);
206 207
207 @POST("api/v1/homework/uploadHomeworkFeedback") 208 @POST("api/v1/homework/uploadHomeworkFeedback")
208 Single<ResponseResult> uploadHomeworkFeedback(@Header("Authorization") String token, @Body Map<String, Object> map); 209 Single<ResponseResult> uploadHomeworkFeedback(@Header("Authorization") String token, @Body Map<String, Object> map);
209 210
210 @POST("api/v1/homework/editHomeworkInfo") 211 @POST("api/v1/homework/editHomeworkInfo")
211 Single<ResponseResult<Boolean>> editHomework( 212 Single<ResponseResult<Boolean>> editHomework(
212 @Header("Authorization") String token, 213 @Header("Authorization") String token,
213 @Body Object body 214 @Body Object body
214 ); 215 );
215 216
216 @GET("api/v1/homework/listHomeworkDetailByStuId") 217 @GET("api/v1/homework/listHomeworkDetailByStuId")
217 Single<ResponseResult<HomeworkDetail>> getHomeworkCompleteDetail( 218 Single<ResponseResult<HomeworkDetail>> getHomeworkCompleteDetail(
218 @Header("Authorization") String token, 219 @Header("Authorization") String token,
219 @Query("stuId") String stuId, 220 @Query("stuId") String stuId,
220 @Query("homeworkId") String homeworkId, 221 @Query("homeworkId") String homeworkId,
221 // type 固定传true 222 // type 固定传true
222 @Query("type") boolean type 223 @Query("type") boolean type
223 ); 224 );
224 225
225 @GET("api/v1/homework/listHomeworkStatistics") 226 @GET("api/v1/homework/listHomeworkStatistics")
226 Single<ResponseResult<List<StDetail>>> getHuyouList( 227 Single<ResponseResult<List<StDetail>>> getHuyouList(
227 @Header("Authorization") String token, 228 @Header("Authorization") String token,
228 @Query("stuId") String stuId, 229 @Query("stuId") String stuId,
229 @Query("type") int type //0: 周报, 1:阶段总结 230 @Query("type") int type //0: 周报, 1:阶段总结
230 ); 231 );
231 232
232 @GET("api/v1/homework/listHomeworkStatisticsDetailForStudent") 233 @GET("api/v1/homework/listHomeworkStatisticsDetailForStudent")
233 Single<ResponseResult<StDetail>> getHuyouDetail( 234 Single<ResponseResult<StDetail>> getHuyouDetail(
234 @Header("Authorization") String token, 235 @Header("Authorization") String token,
235 @Query("homeworkStatisticsId") String homeworkId 236 @Query("homeworkStatisticsId") String homeworkId
236 ); 237 );
237 238
238 @GET("api/v1/demo/generalStatisticsHomework") 239 @GET("api/v1/demo/generalStatisticsHomework")
239 Single<ResponseResult<Object>> generalHuyou(); 240 Single<ResponseResult<Object>> generalHuyou();
240 241
241 @POST("api/v1/homework/generalHomeworkStageStatistics") 242 @POST("api/v1/homework/generalHomeworkStageStatistics")
242 Single<ResponseResult<Boolean>> generalStageHuyou( 243 Single<ResponseResult<Boolean>> generalStageHuyou(
243 @Header("Authorization") String token, 244 @Header("Authorization") String token,
244 @Body Object body 245 @Body Object body
245 ); 246 );
246 247
247 @GET("api/v1/homework/removeHomeworkStatistics") 248 @GET("api/v1/homework/removeHomeworkStatistics")
248 Single<ResponseResult<Boolean>> deleteHuyou( 249 Single<ResponseResult<Boolean>> deleteHuyou(
249 @Header("Authorization") String token, 250 @Header("Authorization") String token,
250 @Query("homeworkStatisticsId") String homeworkId 251 @Query("homeworkStatisticsId") String homeworkId
251 ); 252 );
252 253
254 @GET("api/v1/login/smsCode")
255 Single<ResponseResult<String>> smsCode(@Query("mobile") String mobile);
256
257 @POST("api/v1/login/smsLogin")
258 Single<ResponseResult<User>> smsLogin(@Body Object body);
259
253 } 260 }
254 261
255 public static String getUserId() { 262 public static String getUserId() {
256 return (String) SharedPreferencesUtil.getData("userId", ""); 263 return (String) SharedPreferencesUtil.getData("userId", "");
257 } 264 }
258 265
259 public static String getHeader() { 266 public static String getHeader() {
260 return (String) SharedPreferencesUtil.getData("token", ""); 267 return (String) SharedPreferencesUtil.getData("token", "");
261 } 268 }
262 269
263 public static String getBaiduToken() { 270 public static String getBaiduToken() {
264 return (String) SharedPreferencesUtil.getData("baiduToken", ""); 271 return (String) SharedPreferencesUtil.getData("baiduToken", "");
265 } 272 }
266 273
267 public static Single<BaiduInput> inputImage(String filePath, String id) { 274 public static Single<BaiduInput> inputImage(String filePath, String id) {
268 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); 275 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
269 String base64 = BitmapUtils.fileToBase64(filePath); 276 String base64 = BitmapUtils.fileToBase64(filePath);
270 File file = new File(filePath); 277 File file = new File(filePath);
271 RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}"); 278 RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}");
272 return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) 279 return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString())
273 .flatMap(token -> { 280 .flatMap(token -> {
274 return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body); 281 return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body);
275 }); 282 });
276 } 283 }
277 284
278 public static Single<ResponseResult> uploadImage(String path, String id) { 285 public static Single<ResponseResult> uploadImage(String path, String id) {
279 File file = new File(path); 286 File file = new File(path);
280 RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); 287 RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file);
281 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); 288 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
282 return service_url.uploadImage(getHeader(), part, id); 289 return service_url.uploadImage(getHeader(), part, id);
283 } 290 }
284 291
285 292
286 public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { 293 public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) {
287 service_url.checkUpdate(code, packageName, 0).enqueue(callback); 294 service_url.checkUpdate(code, packageName, 0).enqueue(callback);
288 } 295 }
289 296
290 public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { 297 public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) {
291 File file = new File(path); 298 File file = new File(path);
292 RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); 299 RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file);
293 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); 300 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
294 Map<String, Object> map = new HashMap<>(); 301 Map<String, Object> map = new HashMap<>();
295 map.put("condition", param); 302 map.put("condition", param);
296 setSubscribe(service_url.addError(part, map), observer); 303 setSubscribe(service_url.addError(part, map), observer);
297 } 304 }
298 305
299 306
300 public static void cut(String base64, Observer<CutPicBean> observer) { 307 public static void cut(String base64, Observer<CutPicBean> observer) {
301 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); 308 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
302 RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); 309 RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true");
303 setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); 310 setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer);
304 } 311 }
305 312
306 public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { 313 public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) {
307 setSubscribe(service_url.editError(getHeader(), map), observer); 314 setSubscribe(service_url.editError(getHeader(), map), observer);
308 } 315 }
309 316
310 public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { 317 public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) {
311 setSubscribe(service_url.updateError(getHeader(), map), observer); 318 setSubscribe(service_url.updateError(getHeader(), map), observer);
312 } 319 }
313 320
314 public static void deleteError(List<String> map, Observer<ResponseResult> observer) { 321 public static void deleteError(List<String> map, Observer<ResponseResult> observer) {
315 setSubscribe(service_url.deleteError(getHeader(), map), observer); 322 setSubscribe(service_url.deleteError(getHeader(), map), observer);
316 } 323 }
317 324
318 public static void getBaiduToken(Observer<JsonObject> observer) { 325 public static void getBaiduToken(Observer<JsonObject> observer) {
319 setSubscribe(service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey + "&client_secret=" + BuildConfig.SecretKey), observer); 326 setSubscribe(service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey + "&client_secret=" + BuildConfig.SecretKey), observer);
320 } 327 }
321 328
322 public static Single<JsonObject> getBaiduTokenOcr() { 329 public static Single<JsonObject> getBaiduTokenOcr() {
323 return service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey1 + "&client_secret=" + BuildConfig.SecretKey1).firstOrError(); 330 return service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey1 + "&client_secret=" + BuildConfig.SecretKey1).firstOrError();
324 } 331 }
325 332
326 public static void removeWriting(String base64, Observer<JsonObject> observer) { 333 public static void removeWriting(String base64, Observer<JsonObject> observer) {
327 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); 334 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
328 RequestBody body = RequestBody.create(mediaType, "image=" + base64); 335 RequestBody body = RequestBody.create(mediaType, "image=" + base64);
329 setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); 336 setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer);
330 } 337 }
331 338
332 public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { 339 public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) {
333 setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); 340 setSubscribe(service_url.searchTeacher(getHeader(), phone), observer);
334 } 341 }
335 342
336 public static void logout(Observer<ResponseBody> observer) { 343 public static void logout(Observer<ResponseBody> observer) {
337 setSubscribe(service_url.logout(), observer); 344 setSubscribe(service_url.logout(), observer);
338 } 345 }
339 346
340 public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { 347 public static void editStudent(RequestBody body, Observer<ResponseResult> observable) {
341 setSubscribe(service_url.editStudent(getHeader(), body), observable); 348 setSubscribe(service_url.editStudent(getHeader(), body), observable);
342 } 349 }
343 350
344 public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { 351 public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) {
345 setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); 352 setSubscribe(service_url.getWeekPlan(getHeader(), id), observer);
346 } 353 }
347 354
348 public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { 355 public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) {
349 RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); 356 RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
350 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); 357 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
351 Map<String, Object> map = new HashMap<>(); 358 Map<String, Object> map = new HashMap<>();
352 map.put("stuId", stuId); 359 map.put("stuId", stuId);
353 setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); 360 setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer);
354 } 361 }
355 362
356 public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { 363 public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) {
357 RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); 364 RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
358 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); 365 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
359 setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); 366 setSubscribe(service_url.uploadAvatar(getHeader(), part), observer);
360 } 367 }
361 368
362 public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { 369 public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) {
363 setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); 370 setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer);
364 } 371 }
365 372
366 373
367 public static void editUser(RequestBody body, Observer<ResponseBody> observer) { 374 public static void editUser(RequestBody body, Observer<ResponseBody> observer) {
368 setSubscribe(service_url.editUser(getHeader(), body), observer); 375 setSubscribe(service_url.editUser(getHeader(), body), observer);
369 } 376 }
370 377
371 public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { 378 public static void changePassword(RequestBody body, Observer<ResponseBody> observer) {
372 setSubscribe(service_url.changePassword(getHeader(), body), observer); 379 setSubscribe(service_url.changePassword(getHeader(), body), observer);
373 } 380 }
374 381
375 382
376 public static void searchById(String userId, Observer<ResponseBody> observer) { 383 public static void searchById(String userId, Observer<ResponseBody> observer) {
377 setSubscribe(service_url.searchById(getHeader(), userId), observer); 384 setSubscribe(service_url.searchById(getHeader(), userId), observer);
378 } 385 }
379 386
380 387
381 public static void login(RequestBody body, Observer<ResponseBody> observer) { 388 public static void login(RequestBody body, Observer<ResponseBody> observer) {
382 setSubscribe(service_url.login(body), observer); 389 setSubscribe(service_url.login(body), observer);
383 } 390 }
384 391
385 public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { 392 public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) {
386 setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); 393 setSubscribe(service_url.listGradeAndSubject(getHeader()), observer);
387 } 394 }
388 395
389 396
390 public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { 397 public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) {
391 setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); 398 setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer);
392 } 399 }
393 400
394 public static void getChildrenList(Observer<ResponseBody> observer) { 401 public static void getChildrenList(Observer<ResponseBody> observer) {
395 setSubscribe(service_url.getChildrenList(getHeader()), observer); 402 setSubscribe(service_url.getChildrenList(getHeader()), observer);
396 } 403 }
397 404
398 405
399 public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { 406 public static void registerParent(RequestBody body, Observer<ResponseBody> observer) {
400 setSubscribe(service_url.registerParent(body), observer); 407 setSubscribe(service_url.registerParent(body), observer);
401 } 408 }
402 409
403 410
404 public static void listChildren(Observer<ResponseBody> observer) { 411 public static void listChildren(Observer<ResponseBody> observer) {
405 setSubscribe(service_url.listChildren(getHeader()), observer); 412 setSubscribe(service_url.listChildren(getHeader()), observer);
406 } 413 }
407 414
408 public static void listStudent(Observer<ResponseBody> observer) { 415 public static void listStudent(Observer<ResponseBody> observer) {
409 setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); 416 setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer);
410 } 417 }
411 418
412 public static Single<ResponseResult<List<Student>>> listStudent() { 419 public static Single<ResponseResult<List<Student>>> listStudent() {
413 return service_url.getStudentList2(getHeader(), getUserId()); 420 return service_url.getStudentList2(getHeader(), getUserId());
414 } 421 }
415 422
416 public static void listRecord(Observer<ResponseBody> observer) { 423 public static void listRecord(Observer<ResponseBody> observer) {
417 setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); 424 setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer);
418 } 425 }
419 426
420 427
421 public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { 428 public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) {
422 setSubscribe(service_url.registerStudent(getHeader(), body), observer); 429 setSubscribe(service_url.registerStudent(getHeader(), body), observer);
423 } 430 }
424 431
425 public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { 432 public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) {
426 setSubscribe(service_url.bindTeacher(getHeader(), body), observer); 433 setSubscribe(service_url.bindTeacher(getHeader(), body), observer);
427 } 434 }
428 435
429 public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { 436 public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) {
430 setSubscribe(service_url.getError(getHeader(), map), observer); 437 setSubscribe(service_url.getError(getHeader(), map), observer);
431 } 438 }
432 439
433 440
434 public static RequestBody getMapRequestBody(Map map) { 441 public static RequestBody getMapRequestBody(Map map) {
435 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); 442 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map));
436 } 443 }
437 444
438 445
439 public static RequestBody getArrayRequestBody(List list) { 446 public static RequestBody getArrayRequestBody(List list) {
440 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); 447 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list));
441 } 448 }
442 449
443 public static RequestBody getFileRequestBody(File file) { 450 public static RequestBody getFileRequestBody(File file) {
444 return RequestBody.create(MediaType.parse("application/octet-stream"), file); 451 return RequestBody.create(MediaType.parse("application/octet-stream"), file);
445 } 452 }
446 453
447 public static RequestBody getFileRequestBody(byte[] bytes) { 454 public static RequestBody getFileRequestBody(byte[] bytes) {
448 return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); 455 return RequestBody.create(MediaType.parse("multipart/form-data"), bytes);
449 } 456 }
450 457
451 public static RequestBody getObjectRequestBody(Object obj) { 458 public static RequestBody getObjectRequestBody(Object obj) {
452 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); 459 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj));
453 } 460 }
454 461
455 public static RequestBody getStringRequestBody(String str) { 462 public static RequestBody getStringRequestBody(String str) {
456 return RequestBody.create(MediaType.parse("text/plain"), str); 463 return RequestBody.create(MediaType.parse("text/plain"), str);
457 } 464 }
458 465
459 466
460 /** 467 /**
461 * 插入观察者 468 * 插入观察者
462 * 469 *
463 * @param observable 470 * @param observable
464 * @param observer 471 * @param observer
465 * @param <T> 472 * @param <T>
466 */ 473 */
467 public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { 474 public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) {
468 observable.subscribeOn(Schedulers.io())//子线程访问网络 475 observable.subscribeOn(Schedulers.io())//子线程访问网络
469 .observeOn(AndroidSchedulers.mainThread())//回调到主线程 476 .observeOn(AndroidSchedulers.mainThread())//回调到主线程
470 .subscribe(observer); 477 .subscribe(observer);
471 } 478 }
472 479
473 } 480 }
474 481