Compare View

switch
from
...
to
 
Commits (4)
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <project version="4"> 2 <project version="4">
3 <component name="GradleMigrationSettings" migrationVersion="1" /> 3 <component name="GradleMigrationSettings" migrationVersion="1" />
4 <component name="GradleSettings"> 4 <component name="GradleSettings">
5 <option name="linkedExternalProjectsSettings"> 5 <option name="linkedExternalProjectsSettings">
6 <GradleProjectSettings> 6 <GradleProjectSettings>
7 <option name="externalProjectPath" value="$PROJECT_DIR$" /> 7 <option name="externalProjectPath" value="$PROJECT_DIR$" />
8 <option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" /> 8 <option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
9 <option name="modules"> 9 <option name="modules">
10 <set> 10 <set>
11 <option value="$PROJECT_DIR$" /> 11 <option value="$PROJECT_DIR$" />
12 <option value="$PROJECT_DIR$/app" /> 12 <option value="$PROJECT_DIR$/app" />
13 <option value="$PROJECT_DIR$/libs" /> 13 <option value="$PROJECT_DIR$/libs" />
14 <option value="$PROJECT_DIR$/libs/common" /> 14 <option value="$PROJECT_DIR$/libs/common" />
15 </set> 15 </set>
16 </option> 16 </option>
17 <option name="resolveExternalAnnotations" value="false" /> 17 <option name="resolveExternalAnnotations" value="false" />
18 </GradleProjectSettings> 18 </GradleProjectSettings>
19 </option> 19 </option>
20 <option name="offlineMode" value="true" />
20 <option name="offlineMode" value="true" /> 21 </component>
21 </component> 22 </project>
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, SmsLoginActivity.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/ChooseActivity.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.text.TextUtils; 4 import android.text.TextUtils;
5 import android.view.View; 5 import android.view.View;
6 import android.widget.ImageView; 6 import android.widget.ImageView;
7 import android.widget.ListView; 7 import android.widget.ListView;
8 8
9 import androidx.annotation.NonNull; 9 import androidx.annotation.NonNull;
10 import androidx.recyclerview.widget.LinearLayoutManager; 10 import androidx.recyclerview.widget.LinearLayoutManager;
11 import androidx.recyclerview.widget.RecyclerView; 11 import androidx.recyclerview.widget.RecyclerView;
12 12
13 import com.bumptech.glide.Glide; 13 import com.bumptech.glide.Glide;
14 import com.bumptech.glide.load.resource.bitmap.RoundedCorners; 14 import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
15 import com.bumptech.glide.request.RequestOptions; 15 import com.bumptech.glide.request.RequestOptions;
16 import com.chad.library.adapter.base.BaseQuickAdapter; 16 import com.chad.library.adapter.base.BaseQuickAdapter;
17 import com.chad.library.adapter.base.BaseViewHolder; 17 import com.chad.library.adapter.base.BaseViewHolder;
18 import com.google.gson.Gson; 18 import com.google.gson.Gson;
19 import com.hjx.parent.bean.StudentBean; 19 import com.hjx.parent.bean.StudentBean;
20 import com.prws.common.base.BaseActivity; 20 import com.prws.common.base.BaseActivity;
21 import com.prws.common.base.BasePresenter; 21 import com.prws.common.base.BasePresenter;
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.ScreenUtils; 24 import com.prws.common.utils.ScreenUtils;
25 import com.prws.common.utils.SharedPreferencesUtil; 25 import com.prws.common.utils.SharedPreferencesUtil;
26 26
27 import org.json.JSONArray; 27 import org.json.JSONArray;
28 import org.json.JSONObject; 28 import org.json.JSONObject;
29 29
30 import java.util.ArrayList; 30 import java.util.ArrayList;
31 31
32 import butterknife.BindView; 32 import butterknife.BindView;
33 import butterknife.OnClick; 33 import butterknife.OnClick;
34 import io.reactivex.Observer; 34 import io.reactivex.Observer;
35 import io.reactivex.disposables.Disposable; 35 import io.reactivex.disposables.Disposable;
36 import okhttp3.ResponseBody; 36 import okhttp3.ResponseBody;
37 37
38 public class ChooseActivity extends BaseActivity { 38 public class ChooseActivity extends BaseActivity {
39 @BindView(R.id.recycle) 39 @BindView(R.id.recycle)
40 RecyclerView recycle; 40 RecyclerView recycle;
41 private int select = 0; 41 private int select = 0;
42 42
43 @Override 43 @Override
44 protected int layoutResId() { 44 protected int layoutResId() {
45 return R.layout.choose_activity; 45 return R.layout.choose_activity;
46 } 46 }
47 47
48 @Override 48 @Override
49 public Object getContract() { 49 public Object getContract() {
50 return null; 50 return null;
51 } 51 }
52 52
53 @Override 53 @Override
54 public BasePresenter getPresenter() { 54 public BasePresenter getPresenter() {
55 return null; 55 return null;
56 } 56 }
57 57
58 @Override 58 @Override
59 protected void initView() { 59 protected void initView() {
60 60
61 } 61 }
62 62
63 @Override 63 @Override
64 protected void initListener() { 64 protected void initListener() {
65 65
66 } 66 }
67 67
68 @Override 68 @Override
69 protected void initData() { 69 protected void initData() {
70 70
71 } 71 }
72 72
73 @Override 73 @Override
74 public void onNetChanged(int netWorkState) { 74 public void onNetChanged(int netWorkState) {
75 75
76 } 76 }
77 77
78 @Override 78 @Override
79 protected void onResume() { 79 protected void onResume() {
80 super.onResume(); 80 super.onResume();
81 loadChildList(); 81 loadChildList();
82 } 82 }
83 83
84 ArrayList<StudentBean> alist = new ArrayList<>(); 84 ArrayList<StudentBean> alist = new ArrayList<>();
85 85
86 public void loadChildList() { 86 public void loadChildList() {
87 NetWorks.listChildren(new Observer<ResponseBody>() { 87 NetWorks.listChildren(new Observer<ResponseBody>() {
88 @Override 88 @Override
89 public void onSubscribe(Disposable d) { 89 public void onSubscribe(Disposable d) {
90 90
91 } 91 }
92 92
93 @Override 93 @Override
94 public void onNext(ResponseBody responseBody) { 94 public void onNext(ResponseBody responseBody) {
95 try { 95 try {
96 String str = responseBody.string().toString(); 96 String str = responseBody.string().toString();
97 LogUtil.e("TAG", "----" + str); 97 LogUtil.e("TAG", "----" + str);
98 JSONObject jo = new JSONObject(str); 98 JSONObject jo = new JSONObject(str);
99 boolean isSucceed = jo.getBoolean("success"); 99 boolean isSucceed = jo.getBoolean("success");
100 if (isSucceed) { 100 if (isSucceed) {
101 JSONArray jarr = jo.getJSONArray("data"); 101 JSONArray jarr = jo.getJSONArray("data");
102 alist.clear(); 102 alist.clear();
103 for (int i = 0; i < jarr.length(); i++) { 103 for (int i = 0; i < jarr.length(); i++) {
104 JSONObject jo2 = jarr.getJSONObject(i); 104 JSONObject jo2 = jarr.getJSONObject(i);
105 Gson gson = new Gson(); 105 Gson gson = new Gson();
106 StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class); 106 StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class);
107 alist.add(sb); 107 alist.add(sb);
108 } 108 }
109 loadList(); 109 loadList();
110 } else { 110 } else {
111 111
112 } 112 }
113 } catch (Exception e) { 113 } catch (Exception e) {
114 e.printStackTrace(); 114 e.printStackTrace();
115 } 115 }
116 } 116 }
117 117
118 @Override 118 @Override
119 public void onError(Throwable e) { 119 public void onError(Throwable e) {
120 120
121 } 121 }
122 122
123 @Override 123 @Override
124 public void onComplete() { 124 public void onComplete() {
125 125
126 } 126 }
127 }); 127 });
128 } 128 }
129 129
130 public void loadList() { 130 public void loadList() {
131 String student = (String) SharedPreferencesUtil.getData("student", "");
132 try {
133 StudentBean studentBean = new Gson().fromJson(student, StudentBean.class);
134 for (int i = 0; i < alist.size(); i++) { 131 String student = (String) SharedPreferencesUtil.getData("student", "");
135 if (studentBean.getStuId().equals(alist.get(i).getStuId())) { 132 try {
136 select = i; 133 StudentBean studentBean = new Gson().fromJson(student, StudentBean.class);
137 break; 134 for (int i = 0; i < alist.size(); i++) {
138 } 135 if (studentBean.getStuId().equals(alist.get(i).getStuId())) {
139 } 136 select = i;
140 } catch (Exception e) { 137 break;
141 138 }
142 } 139 }
143 BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child_choose, alist) { 140 } catch (Exception e) {
144 @Override 141
145 public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { 142 }
146 143 BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child_choose, alist) {
147 } 144 @Override
148 145 public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
149 @Override 146
150 protected void convert(@NonNull BaseViewHolder item, Object o) { 147 }
151 StudentBean studentBean = alist.get(item.getAdapterPosition()); 148
152 item.setText(R.id.tv_name, studentBean.getNickName()); 149 @Override
153 if (TextUtils.isEmpty(studentBean.getStuId())) { 150 protected void convert(@NonNull BaseViewHolder item, Object o) {
154 // do nothing 151 StudentBean studentBean = alist.get(item.getAdapterPosition());
155 } else { 152 item.setText(R.id.tv_name, studentBean.getNickName());
156 item.setBackgroundRes(R.id.rl_child, select == item.getAdapterPosition() ? R.drawable.bg_solid_white_10_or : R.drawable.bg_solid_white_10); 153 if (TextUtils.isEmpty(studentBean.getStuId())) {
157 item.setImageResource(R.id.iv_select, select == item.getAdapterPosition() ? R.mipmap.gx : R.mipmap.wsyq); 154 // do nothing
158 item.setVisible(R.id.rl_add, false);
159 if (TextUtils.isEmpty(studentBean.getPhoto())) {
160 item.setImageResource(R.id.iv_avatar, "男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female);
161 } else {
162 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(ChooseActivity.this, 45));
163 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
164 Glide.with(ChooseActivity.this).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); 155 } else {
165 } 156 item.setBackgroundRes(R.id.rl_child, select == item.getAdapterPosition() ? R.drawable.bg_solid_white_10_or : R.drawable.bg_solid_white_10);
166 item.setVisible(R.id.iv_vip, studentBean.getIsIntention() == 1); 157 item.setImageResource(R.id.iv_select, select == item.getAdapterPosition() ? R.mipmap.gx : R.mipmap.wsyq);
167 item.getConvertView().setOnClickListener(new View.OnClickListener() { 158 item.setVisible(R.id.rl_add, false);
168 @Override 159 if (TextUtils.isEmpty(studentBean.getPhoto())) {
169 public void onClick(View view) { 160 item.setImageResource(R.id.iv_avatar, "男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female);
170 select = item.getAdapterPosition(); 161 } else {
171 notifyDataSetChanged(); 162 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(ChooseActivity.this, 45));
172 } 163 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
173 }); 164 Glide.with(ChooseActivity.this).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar));
174 } 165 }
175 } 166 item.setVisible(R.id.iv_vip, studentBean.getIsIntention() == 1);
176 }; 167 item.getConvertView().setOnClickListener(new View.OnClickListener() {
177 recycle.setLayoutManager(new LinearLayoutManager(ChooseActivity.this, LinearLayoutManager.VERTICAL, false)); 168 @Override
178 recycle.setAdapter(adapter); 169 public void onClick(View view) {
179 } 170 select = item.getAdapterPosition();
180 171 notifyDataSetChanged();
181 @OnClick(R.id.tv_confirm) 172 }
182 public void confirm(View view) { 173 });
183 if (alist.size() > 0 && alist.size() - 1 >= select && alist.get(select) != null) { 174 }
184 StudentBean studentBean = alist.get(select); 175 }
185 if (studentBean.getStuId() != null) { 176 };
186 if (getIntent().getBooleanExtra("needBack", false)) { 177 recycle.setLayoutManager(new LinearLayoutManager(ChooseActivity.this, LinearLayoutManager.VERTICAL, false));
187 SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); 178 recycle.setAdapter(adapter);
188 } else { 179 }
189 Intent intent = new Intent(ChooseActivity.this, MainActivity.class); 180
190 SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); 181 @OnClick(R.id.tv_confirm)
191 startActivity(intent); 182 public void confirm(View view) {
192 } 183 if (alist.size() > 0 && alist.size() - 1 >= select && alist.get(select) != null) {
193 finish(); 184 StudentBean studentBean = alist.get(select);
194 } 185 if (studentBean.getStuId() != null) {
195 } 186 if (getIntent().getBooleanExtra("needBack", false)) {
196 } 187 SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean));
197 } 188 } else {
198 189 Intent intent = new Intent(ChooseActivity.this, MainActivity.class);
app/src/main/java/com/hjx/parent/EditStudentActivity.java
1 package com.hjx.parent; 1 package com.hjx.parent;
2 2
3 import android.annotation.SuppressLint; 3 import android.annotation.SuppressLint;
4 import android.content.DialogInterface; 4 import android.content.DialogInterface;
5 import android.content.Intent; 5 import android.content.Intent;
6 import android.graphics.Bitmap; 6 import android.graphics.Bitmap;
7 import android.graphics.Color; 7 import android.graphics.Color;
8 import android.net.Uri; 8 import android.net.Uri;
9 import android.os.Build; 9 import android.os.Build;
10 import android.os.Bundle; 10 import android.os.Bundle;
11 import android.os.Environment; 11 import android.os.Environment;
12 import android.provider.MediaStore; 12 import android.provider.MediaStore;
13 import android.text.TextUtils; 13 import android.text.TextUtils;
14 import android.util.Log; 14 import android.util.Log;
15 import android.view.LayoutInflater; 15 import android.view.LayoutInflater;
16 import android.view.View; 16 import android.view.View;
17 import android.widget.Button; 17 import android.widget.Button;
18 import android.widget.ImageView; 18 import android.widget.ImageView;
19 import android.widget.LinearLayout; 19 import android.widget.LinearLayout;
20 import android.widget.RelativeLayout; 20 import android.widget.RelativeLayout;
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.google.gson.Gson; 30 import com.google.gson.Gson;
31 import com.hjq.permissions.OnPermissionCallback; 31 import com.hjq.permissions.OnPermissionCallback;
32 import com.hjq.permissions.Permission; 32 import com.hjq.permissions.Permission;
33 import com.hjq.permissions.XXPermissions; 33 import com.hjq.permissions.XXPermissions;
34 import com.hjx.parent.bean.StudentBean; 34 import com.hjx.parent.bean.StudentBean;
35 import com.prws.common.base.BaseActivity; 35 import com.prws.common.base.BaseActivity;
36 import com.prws.common.base.BasePresenter; 36 import com.prws.common.base.BasePresenter;
37 import com.prws.common.bean.ResponseResult; 37 import com.prws.common.bean.ResponseResult;
38 import com.prws.common.bean.Teacher; 38 import com.prws.common.bean.Teacher;
39 import com.prws.common.net.NetWorks; 39 import com.prws.common.net.NetWorks;
40 import com.prws.common.utils.LogUtil; 40 import com.prws.common.utils.LogUtil;
41 import com.prws.common.utils.ScreenUtils; 41 import com.prws.common.utils.ScreenUtils;
42 import com.prws.common.utils.SharedPreferencesUtil; 42 import com.prws.common.utils.SharedPreferencesUtil;
43 43
44 import org.json.JSONObject; 44 import org.json.JSONObject;
45 45
46 import java.io.File; 46 import java.io.File;
47 import java.io.FileOutputStream; 47 import java.io.FileOutputStream;
48 import java.io.IOException; 48 import java.io.IOException;
49 import java.util.HashMap; 49 import java.util.HashMap;
50 import java.util.List; 50 import java.util.List;
51 import java.util.Map; 51 import java.util.Map;
52 52
53 import butterknife.BindView; 53 import butterknife.BindView;
54 import butterknife.OnClick; 54 import butterknife.OnClick;
55 import io.reactivex.Observer; 55 import io.reactivex.Observer;
56 import io.reactivex.disposables.Disposable; 56 import io.reactivex.disposables.Disposable;
57 57
58 public class EditStudentActivity extends BaseActivity { 58 public class EditStudentActivity extends BaseActivity {
59 View view_2; 59 View view_2;
60 View view_3; 60 View view_3;
61 View view_4; 61 View view_4;
62 View view_5; 62 View view_5;
63 Button btn_next; 63 Button btn_next;
64 TextView tv_name, tv_sex, tv_nian, tv_shen; 64 TextView tv_name, tv_sex, tv_nian, tv_shen;
65 @BindView(R.id.iv_avatar) 65 @BindView(R.id.iv_avatar)
66 ImageView iv_avatar; 66 ImageView iv_avatar;
67 @BindView(R.id.tv_teacher) 67 @BindView(R.id.tv_teacher)
68 TextView tv_teacher; 68 TextView tv_teacher;
69 @BindView(R.id.iv_teacher) 69 @BindView(R.id.iv_teacher)
70 ImageView iv_teacher; 70 ImageView iv_teacher;
71 @BindView(R.id.rl_teacher) 71 @BindView(R.id.rl_teacher)
72 RelativeLayout rl_teacher; 72 RelativeLayout rl_teacher;
73 @BindView(R.id.view_6)
74 LinearLayout view_6;
75 private static int CAMERA_REQUEST_CODE = 343; 73 @BindView(R.id.view_6)
76 private static int ALBUM_REQUEST_CODE = 456; 74 LinearLayout view_6;
77 private static int CROP_REQUEST_CODE = 234; 75 private static int CAMERA_REQUEST_CODE = 343;
78 76 private static int ALBUM_REQUEST_CODE = 456;
79 private static int BIND_TEACHER_CODE = 345; 77 private static int CROP_REQUEST_CODE = 234;
80 private File tempFile; 78
81 private String path; 79 private static int BIND_TEACHER_CODE = 345;
82 StudentBean studentBean; 80 private File tempFile;
83 private Teacher teacher; 81 private String path;
84 82 StudentBean studentBean;
85 @Override 83 private Teacher teacher;
86 protected int layoutResId() { 84
87 return R.layout.activity_edit_stu; 85 @Override
88 } 86 protected int layoutResId() {
89 87 return R.layout.activity_edit_stu;
90 @Override 88 }
91 public Object getContract() { 89
92 return null; 90 @Override
93 } 91 public Object getContract() {
94 92 return null;
95 @Override 93 }
96 public BasePresenter getPresenter() { 94
97 return null; 95 @Override
98 } 96 public BasePresenter getPresenter() {
99 97 return null;
100 @Override 98 }
101 protected void initView() { 99
102 view_2 = findViewById(R.id.view_2); 100 @Override
103 view_3 = findViewById(R.id.view_3); 101 protected void initView() {
104 view_4 = findViewById(R.id.view_4); 102 view_2 = findViewById(R.id.view_2);
105 view_5 = findViewById(R.id.view_5); 103 view_3 = findViewById(R.id.view_3);
106 tv_name = findViewById(R.id.tv_name); 104 view_4 = findViewById(R.id.view_4);
107 tv_sex = findViewById(R.id.tv_sex); 105 view_5 = findViewById(R.id.view_5);
108 tv_nian = findViewById(R.id.tv_nian); 106 tv_name = findViewById(R.id.tv_name);
109 tv_shen = findViewById(R.id.tv_shen); 107 tv_sex = findViewById(R.id.tv_sex);
110 btn_next = findViewById(R.id.btn_next); 108 tv_nian = findViewById(R.id.tv_nian);
111 } 109 tv_shen = findViewById(R.id.tv_shen);
112 110 btn_next = findViewById(R.id.btn_next);
113 @SuppressLint({"SetTextI18n", "UseCompatLoadingForDrawables"}) 111 }
114 @Override 112
115 protected void onStart() { 113 @SuppressLint({"SetTextI18n", "UseCompatLoadingForDrawables"})
116 super.onStart(); 114 @Override
117 String name = (String) SharedPreferencesUtil.getData("setName", ""); 115 protected void onStart() {
118 String sex = (String) SharedPreferencesUtil.getData("setSex", ""); 116 super.onStart();
119 String nian = (String) SharedPreferencesUtil.getData("setNian", ""); 117 String name = (String) SharedPreferencesUtil.getData("setName", "");
120 String shen = (String) SharedPreferencesUtil.getData("setShen", ""); 118 String sex = (String) SharedPreferencesUtil.getData("setSex", "");
121 String xueq = (String) SharedPreferencesUtil.getData("setXueq", ""); 119 String nian = (String) SharedPreferencesUtil.getData("setNian", "");
122 btn_next.setTextColor(Color.WHITE); 120 String shen = (String) SharedPreferencesUtil.getData("setShen", "");
123 btn_next.setBackground(getResources().getDrawable(R.drawable.bg_solid_btn)); 121 String xueq = (String) SharedPreferencesUtil.getData("setXueq", "");
124 studentBean = new Gson().fromJson(getIntent().getStringExtra("student"), StudentBean.class); 122 btn_next.setTextColor(Color.WHITE);
125 if (name != null && name.length() > 0) { 123 btn_next.setBackground(getResources().getDrawable(R.drawable.bg_solid_btn));
126 studentBean.setNickName(name); 124 studentBean = new Gson().fromJson(getIntent().getStringExtra("student"), StudentBean.class);
127 } 125 if (name != null && name.length() > 0) {
128 if (sex != null && sex.length() > 0) { 126 studentBean.setNickName(name);
129 studentBean.setGender(sex); 127 }
130 } 128 if (sex != null && sex.length() > 0) {
131 if (nian != null && nian.length() > 0) { 129 studentBean.setGender(sex);
132 studentBean.setGrade(nian); 130 }
133 } 131 if (nian != null && nian.length() > 0) {
134 if (xueq != null && xueq.length() > 0) { 132 studentBean.setGrade(nian);
135 studentBean.setTerm(xueq); 133 }
136 } 134 if (xueq != null && xueq.length() > 0) {
137 if (shen != null && shen.length() > 0) { 135 studentBean.setTerm(xueq);
138 studentBean.setParentIdentity(shen); 136 }
139 } 137 if (shen != null && shen.length() > 0) {
140 tv_name.setText(studentBean.getNickName()); 138 studentBean.setParentIdentity(shen);
141 tv_nian.setText(studentBean.getGrade() + studentBean.getTerm()); 139 }
142 tv_sex.setText(studentBean.getGender()); 140 tv_name.setText(studentBean.getNickName());
143 tv_shen.setText(studentBean.getParentIdentity()); 141 tv_nian.setText(studentBean.getGrade() + studentBean.getTerm());
144 if (!TextUtils.isEmpty(studentBean.getPhoto())) { 142 tv_sex.setText(studentBean.getGender());
145 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 45)); 143 tv_shen.setText(studentBean.getParentIdentity());
146 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); 144 if (!TextUtils.isEmpty(studentBean.getPhoto())) {
147 Glide.with(this).load(studentBean.getPhoto()).apply(options).into(iv_avatar); 145 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 45));
148 } else { 146 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
149 iv_avatar.setImageResource("男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); 147 Glide.with(this).load(studentBean.getPhoto()).apply(options).into(iv_avatar);
150 } 148 } else {
151 if (studentBean.getIsIntention() == 1) { 149 iv_avatar.setImageResource("男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female);
152 rl_teacher.setVisibility(View.VISIBLE); 150 }
153 tv_teacher.setText(studentBean.getTeacherName()); 151 if (studentBean.getIsIntention() == 1) {
154 if (!TextUtils.isEmpty(studentBean.getTeacherAvatar())) { 152 rl_teacher.setVisibility(View.VISIBLE);
155 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 25));
156 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); 153 tv_teacher.setText(studentBean.getTeacherName());
157 Glide.with(this).load(studentBean.getTeacherAvatar()).apply(options).into(iv_teacher); 154 if (!TextUtils.isEmpty(studentBean.getTeacherAvatar())) {
158 } else { 155 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 25));
159 iv_teacher.setImageResource(R.mipmap.ic_teacher_female); 156 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
160 } 157 Glide.with(this).load(studentBean.getTeacherAvatar()).apply(options).into(iv_teacher);
161 } else { 158 } else {
162 rl_teacher.setVisibility(View.GONE); 159 iv_teacher.setImageResource(R.mipmap.ic_teacher_female);
163 if ((studentBean.getState() != null && studentBean.getState() == 0)) { 160 }
164 view_6.setEnabled(false); 161 } else {
165 } 162 rl_teacher.setVisibility(View.GONE);
166 } 163 if ((studentBean.getState() != null && studentBean.getState() == 0)) {
167
168 }
169 164 view_6.setEnabled(false);
170 @Override 165 }
171 protected void initListener() { 166 }
172 view_2.setOnClickListener(view -> startActivity(NickActivity.class)); 167
173 view_3.setOnClickListener(view -> startActivity(SexActivity.class)); 168 }
174 view_4.setOnClickListener(view -> startActivity(NianActivity.class)); 169
175 view_5.setOnClickListener(view -> startActivity(ShenActivity.class)); 170 @Override
176 findViewById(R.id.tv_cancel).setOnClickListener(view -> onBackPressed()); 171 protected void initListener() {
177 btn_next.setOnClickListener(view -> { 172 view_2.setOnClickListener(view -> startActivity(NickActivity.class));
178 editStudent(); 173 view_3.setOnClickListener(view -> startActivity(SexActivity.class));
179 }); 174 view_4.setOnClickListener(view -> startActivity(NianActivity.class));
180 } 175 view_5.setOnClickListener(view -> startActivity(ShenActivity.class));
181 176 findViewById(R.id.tv_cancel).setOnClickListener(view -> onBackPressed());
182 public void editStudent() { 177 btn_next.setOnClickListener(view -> {
183 Map<String, Object> map = new HashMap<>(); 178 editStudent();
184 map.put("nickName", studentBean.getNickName());
185 map.put("gender", studentBean.getGender());
186 map.put("parentIdentity", studentBean.getParentIdentity());
187 map.put("term", studentBean.getTerm());
188 if (teacher != null) {
189 map.put("teacherId", teacher.getId());
190 }
191 map.put("stuId", studentBean.getStuId());
192 NetWorks.editStudent(NetWorks.getMapRequestBody(map), new Observer<ResponseResult>() {
193 @Override
194 public void onSubscribe(Disposable d) {
195
196 }
197
198 @Override
199 public void onNext(ResponseResult responseResult) {
200 try {
201 boolean isSucceed = responseResult.getSuccess();
202 if (isSucceed) {
203 finish();
204 } else {
205 Toast.makeText(EditStudentActivity.this, responseResult.getMsg(), Toast.LENGTH_SHORT).show(); 179 });
206 } 180 }
207 } catch (Exception e) { 181
208
209 }
210 }
211
212 @Override
213 public void onError(Throwable e) {
214 182 public void editStudent() {
215 } 183 Map<String, Object> map = new HashMap<>();
216 184 map.put("nickName", studentBean.getNickName());
217 @Override 185 map.put("gender", studentBean.getGender());
218 public void onComplete() { 186 map.put("parentIdentity", studentBean.getParentIdentity());
219 187 map.put("term", studentBean.getTerm());
220 } 188 if (teacher != null) {
221 }); 189 map.put("teacherId", teacher.getId());
222 } 190 }
223 191 map.put("stuId", studentBean.getStuId());
224 @Override 192 NetWorks.editStudent(NetWorks.getMapRequestBody(map), new Observer<ResponseResult>() {
225 protected void initData() { 193 @Override
226 194 public void onSubscribe(Disposable d) {
227 } 195
228 196 }
229 @Override 197
230 public void onNetChanged(int netWorkState) { 198 @Override
231 199 public void onNext(ResponseResult responseResult) {
232 } 200 try {
233 201 boolean isSucceed = responseResult.getSuccess();
234 private void cropPhoto(Uri uri) { 202 if (isSucceed) {
235 Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg")); 203 finish();
236 Intent intent = new Intent("com.android.camera.action.CROP"); 204 } else {
237 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 205 Toast.makeText(EditStudentActivity.this, responseResult.getMsg(), Toast.LENGTH_SHORT).show();
238 //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片 206 }
239 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 207 } catch (Exception e) {
240 } 208
241 intent.setDataAndType(uri, "image/*"); 209 }
242 intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪 210 }
243 intent.putExtra("scale", true);// 设置缩放 211
244 intent.putExtra("scaleUpIfNeeded", true);// 去黑边 212 @Override
245 intent.putExtra("aspectX", 1); 213 public void onError(Throwable e) {
246 intent.putExtra("aspectY", 1); 214
247 //上述两个属性控制裁剪框的缩放比例。 215 }
248 //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。 216
249 intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。 217 @Override
250 intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存, 218 public void onComplete() {
251 intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式 219
252 intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap 220 }
253 intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径 221 });
254 startActivityForResult(intent, CROP_REQUEST_CODE); 222 }
255 } 223
256 224 @Override
257 @Override 225 protected void initData() {
258 protected void onActivityResult(int requestCode, int resultCode, Intent intent) { 226
259 super.onActivityResult(requestCode, resultCode, intent); 227 }
260 if (requestCode == CAMERA_REQUEST_CODE) { 228
261 if (resultCode == RESULT_OK) { 229 @Override
262 //用相机返回的照片去调用剪裁也需要对Uri进行处理 230 public void onNetChanged(int netWorkState) {
263 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 231
264 Uri contentUri = FileProvider.getUriForFile(this, 232 }
265 this.getPackageName() + ".fileprovider", tempFile); 233
266 cropPhoto(contentUri); 234 private void cropPhoto(Uri uri) {
267 } else { 235 Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"));
268 cropPhoto(Uri.fromFile(tempFile)); 236 Intent intent = new Intent("com.android.camera.action.CROP");
269 } 237 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
270 } 238 //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片
271 } else if (requestCode == ALBUM_REQUEST_CODE) { 239 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
272 if (resultCode == RESULT_OK) { 240 }
273 Uri uri = intent.getData(); 241 intent.setDataAndType(uri, "image/*");
274 cropPhoto(uri); 242 intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪
275 } 243 intent.putExtra("scale", true);// 设置缩放
276 } else if (requestCode == CROP_REQUEST_CODE) { 244 intent.putExtra("scaleUpIfNeeded", true);// 去黑边
277 if (intent == null) { 245 intent.putExtra("aspectX", 1);
278 return; 246 intent.putExtra("aspectY", 1);
279 } 247 //上述两个属性控制裁剪框的缩放比例。
280 Bundle bundle = intent.getExtras(); 248 //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。
281 if (bundle != null) { 249 intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。
282 //在这里获得了剪裁后的Bitmap对象,可以用于上传 250 intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存,
283 Bitmap image = bundle.getParcelable("data"); 251 intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式
284 //设置到ImageView上 252 intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap
285 //也可以进行一些保存、压缩等操作后上传 253 intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径
286 File file = saveImage("head_output", image); 254 startActivityForResult(intent, CROP_REQUEST_CODE);
287 uploadAvatar(file); 255 }
288 // Log.d("dsadsadsa",path); 256
289 } 257 @Override
290 } else if (requestCode == BIND_TEACHER_CODE && resultCode == 1000) { 258 protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
291 String t = intent.getStringExtra("teacher"); 259 super.onActivityResult(requestCode, resultCode, intent);
292 teacher = new Gson().fromJson(t, Teacher.class); 260 if (requestCode == CAMERA_REQUEST_CODE) {
293 rl_teacher.setVisibility(View.VISIBLE); 261 if (resultCode == RESULT_OK) {
294 tv_teacher.setText(teacher.getUserName()); 262 //用相机返回的照片去调用剪裁也需要对Uri进行处理
295 if (!TextUtils.isEmpty(teacher.getPhoto())) { 263 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
296 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(EditStudentActivity.this, 20)); 264 Uri contentUri = FileProvider.getUriForFile(this,
297 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); 265 this.getPackageName() + ".fileprovider", tempFile);
298 Glide.with(EditStudentActivity.this).load(teacher.getPhoto()).apply(options).into(iv_teacher); 266 cropPhoto(contentUri);
299 } 267 } else {
300 } 268 cropPhoto(Uri.fromFile(tempFile));
301 } 269 }
302 270 }
303 private void uploadAvatar(File file) { 271 } else if (requestCode == ALBUM_REQUEST_CODE) {
304 NetWorks.uploadStudentAvatar(file, studentBean.getStuId(), new Observer<ResponseResult<Map<String, String>>>() { 272 if (resultCode == RESULT_OK) {
305 @Override 273 Uri uri = intent.getData();
306 public void onSubscribe(Disposable d) { 274 cropPhoto(uri);
307 275 }
308 } 276 } else if (requestCode == CROP_REQUEST_CODE) {
309 277 if (intent == null) {
310 @Override 278 return;
311 public void onNext(ResponseResult<Map<String, String>> responseBody) { 279 }
312 if (responseBody.getData() != null && responseBody.getCode() == 200) { 280 Bundle bundle = intent.getExtras();
313 String filePath = responseBody.getData().get("imageUrl"); 281 if (bundle != null) {
314 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(EditStudentActivity.this, 45)); 282 //在这里获得了剪裁后的Bitmap对象,可以用于上传
315 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); 283 Bitmap image = bundle.getParcelable("data");
316 Glide.with(EditStudentActivity.this).load(filePath).apply(options).into(iv_avatar); 284 //设置到ImageView上
317 } 285 //也可以进行一些保存、压缩等操作后上传
318 } 286 File file = saveImage("head_output", image);
319 287 uploadAvatar(file);
320 @Override 288 // Log.d("dsadsadsa",path);
321 public void onError(Throwable e) { 289 }
322 e.toString(); 290 } else if (requestCode == BIND_TEACHER_CODE && resultCode == 1000) {
323 } 291 String t = intent.getStringExtra("teacher");
324 292 teacher = new Gson().fromJson(t, Teacher.class);
325 @Override 293 rl_teacher.setVisibility(View.VISIBLE);
326 public void onComplete() {
327 294 tv_teacher.setText(teacher.getUserName());
328 } 295 if (!TextUtils.isEmpty(teacher.getPhoto())) {
329 }); 296 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(EditStudentActivity.this, 20));
330 } 297 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
331 298 Glide.with(EditStudentActivity.this).load(teacher.getPhoto()).apply(options).into(iv_teacher);
332 public File saveImage(String name, Bitmap bmp) { 299 }
333 File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath()); 300 }
334 if (!appDir.exists()) { 301 }
335 appDir.mkdir(); 302
336 } 303 private void uploadAvatar(File file) {
337 String fileName = name + ".jpg"; 304 NetWorks.uploadStudentAvatar(file, studentBean.getStuId(), new Observer<ResponseResult<Map<String, String>>>() {
338 File file = new File(appDir, fileName); 305 @Override
339 try { 306 public void onSubscribe(Disposable d) {
340 FileOutputStream fos = new FileOutputStream(file); 307
341 bmp.compress(Bitmap.CompressFormat.PNG, 100, fos); 308 }
342 fos.flush(); 309
343 fos.close(); 310 @Override
344 return file; 311 public void onNext(ResponseResult<Map<String, String>> responseBody) {
345 } catch (IOException e) { 312 if (responseBody.getData() != null && responseBody.getCode() == 200) {
346 Log.d("dsadsadsa", e.getLocalizedMessage()); 313 String filePath = responseBody.getData().get("imageUrl");
347 e.printStackTrace(); 314 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(EditStudentActivity.this, 45));
348 } 315 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
349 return null; 316 Glide.with(EditStudentActivity.this).load(filePath).apply(options).into(iv_avatar);
350 } 317 }
351 318 }
352 private void getPicFromCamera() { 319
353 //用于保存调用相机拍照后所生成的文件 320 @Override
354 tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"); 321 public void onError(Throwable e) {
355 //跳转到调用系统相机 322 e.toString();
356 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 323 }
357 //判断版本 324
358 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri 325 @Override
359 intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); 326 public void onComplete() {
360 Uri contentUri = FileProvider.getUriForFile(this, 327
361 this.getPackageName() + ".fileprovider", tempFile); 328 }
362 intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri); 329 });
363 } else { //否则使用Uri.fromFile(file)方法获取Uri 330 }
364 intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); 331
365 } 332 public File saveImage(String name, Bitmap bmp) {
366 startActivityForResult(intent, CAMERA_REQUEST_CODE); 333 File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath());
367 } 334 if (!appDir.exists()) {
368 335 appDir.mkdir();
369 /** 336 }
370 * 从相册获取图片 337 String fileName = name + ".jpg";
371 */ 338 File file = new File(appDir, fileName);
372 private void getPicFromAlbm() { 339 try {
373 Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); 340 FileOutputStream fos = new FileOutputStream(file);
374 photoPickerIntent.setType("image/*"); 341 bmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
375 startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE); 342 fos.flush();
376 } 343 fos.close();
377 344 return file;
378 @Override 345 } catch (IOException e) {
379 protected void onDestroy() { 346 Log.d("dsadsadsa", e.getLocalizedMessage());
380 super.onDestroy(); 347 e.printStackTrace();
381 SharedPreferencesUtil.putData("setName", ""); 348 }
382 SharedPreferencesUtil.putData("setSex", ""); 349 return null;
383 SharedPreferencesUtil.putData("setNian", ""); 350 }
384 SharedPreferencesUtil.putData("setShen", ""); 351
385 SharedPreferencesUtil.putData("setXueq", ""); 352 private void getPicFromCamera() {
386 SharedPreferencesUtil.putData("grade", 0); 353 //用于保存调用相机拍照后所生成的文件
387 } 354 tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg");
388 355 //跳转到调用系统相机
389 @OnClick(R.id.iv_avatar) 356 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
390 public void showButtonDialog(View view) { 357 //判断版本
391 BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); 358 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri
392 View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null); 359 intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
393 dialog.setContentView(bottomView); 360 Uri contentUri = FileProvider.getUriForFile(this,
394 bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { 361 this.getPackageName() + ".fileprovider", tempFile);
395 @Override 362 intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);
396 public void onClick(View view) { 363 } else { //否则使用Uri.fromFile(file)方法获取Uri
397 dialog.dismiss(); 364 intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));
398 if (!XXPermissions.isGranted(EditStudentActivity.this, Permission.CAMERA)) { 365 }
399 XXPermissions.with(EditStudentActivity.this) 366 startActivityForResult(intent, CAMERA_REQUEST_CODE);
400 // 申请多个权限 367 }
401 .permission(Permission.CAMERA) 368
402 .request(new OnPermissionCallback() { 369 /**
403 @Override 370 * 从相册获取图片
404 public void onGranted(List<String> permissions, boolean all) { 371 */
405 if (all) { 372 private void getPicFromAlbm() {
406 //开启扫码界面 373 Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
407 getPicFromCamera(); 374 photoPickerIntent.setType("image/*");
408 } else { 375 startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE);
409 Toast.makeText(EditStudentActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show(); 376 }
410 } 377
411 } 378 @Override
412 379 protected void onDestroy() {
413 @Override 380 super.onDestroy();
414 public void onDenied(List<String> permissions, boolean never) { 381 SharedPreferencesUtil.putData("setName", "");
415 XXPermissions.startPermissionActivity(EditStudentActivity.this, permissions); 382 SharedPreferencesUtil.putData("setSex", "");
416 } 383 SharedPreferencesUtil.putData("setNian", "");
417 }); 384 SharedPreferencesUtil.putData("setShen", "");
418 } else { 385 SharedPreferencesUtil.putData("setXueq", "");
419 getPicFromCamera(); 386 SharedPreferencesUtil.putData("grade", 0);
420 } 387 }
421 388
422 } 389 @OnClick(R.id.iv_avatar)
423 }); 390 public void showButtonDialog(View view) {
424 bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { 391 BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog);
425 @Override 392 View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null);
426 public void onClick(View view) { 393 dialog.setContentView(bottomView);
427 dialog.dismiss(); 394 bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() {
428 getPicFromAlbm(); 395 @Override
429 } 396 public void onClick(View view) {
430 }); 397 dialog.dismiss();
431 bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { 398 if (!XXPermissions.isGranted(EditStudentActivity.this, Permission.CAMERA)) {
432 @Override 399 XXPermissions.with(EditStudentActivity.this)
433 public void onClick(View view) { 400 // 申请多个权限
434 dialog.dismiss(); 401 .permission(Permission.CAMERA)
435 } 402 .request(new OnPermissionCallback() {
436 }); 403 @Override
437 dialog.show(); 404 public void onGranted(List<String> permissions, boolean all) {
438 } 405 if (all) {
439 406 //开启扫码界面
440 407 getPicFromCamera();
441 } 408 } else {
442 409 Toast.makeText(EditStudentActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show();
app/src/main/java/com/hjx/parent/SmsLoginActivity.java
1 package com.hjx.parent; 1 package com.hjx.parent;
2 2
3 import android.annotation.SuppressLint; 3 import android.annotation.SuppressLint;
4 import android.content.Intent; 4 import android.content.Intent;
5 import android.os.Bundle; 5 import android.os.Bundle;
6 import android.telephony.PhoneNumberUtils; 6 import android.telephony.PhoneNumberUtils;
7 import android.text.TextUtils; 7 import android.text.TextUtils;
8 import android.view.View; 8 import android.view.View;
9 import android.widget.Toast; 9 import android.widget.Toast;
10 10
11 import com.hjx.parent.databinding.ActivitySmsLoginBinding; 11 import com.hjx.parent.databinding.ActivitySmsLoginBinding;
12 import com.hjx.parent.rx.BaseRxActivity; 12 import com.hjx.parent.rx.BaseRxActivity;
13 import com.prws.common.bean.Student;
13 import com.prws.common.bean.Student; 14 import com.prws.common.net.NetWorks;
14 import com.prws.common.net.NetWorks; 15 import com.prws.common.utils.LogUtil;
15 import com.prws.common.utils.LogUtil; 16 import com.prws.common.utils.SharedPreferencesUtil;
16 import com.prws.common.utils.SharedPreferencesUtil; 17
17 18 import java.util.HashMap;
19 import java.util.List;
18 import java.util.HashMap; 20 import java.util.Map;
19 import java.util.List; 21 import java.util.concurrent.TimeUnit;
20 import java.util.Map; 22
21 import java.util.concurrent.TimeUnit; 23 import io.reactivex.Observable;
22 24 import io.reactivex.android.schedulers.AndroidSchedulers;
23 import io.reactivex.Observable; 25 import io.reactivex.disposables.Disposable;
24 import io.reactivex.android.schedulers.AndroidSchedulers; 26
25 import io.reactivex.disposables.Disposable; 27 public class SmsLoginActivity extends BaseRxActivity<ActivitySmsLoginBinding> {
26 28 private final NetWorks.NetService api = NetWorks.service_url;
27 public class SmsLoginActivity extends BaseRxActivity<ActivitySmsLoginBinding> { 29 @Override
28 private final NetWorks.NetService api = NetWorks.service_url; 30 public void initView(Bundle savedInstanceState) {
29 @Override 31 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
30 public void initView(Bundle savedInstanceState) { 32
31 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); 33 String student = (String) SharedPreferencesUtil.getData("student", "");
32 34
33 String student = (String) SharedPreferencesUtil.getData("student", ""); 35 if (!TextUtils.isEmpty(student)) {
34 36 if ((SharedPreferencesUtil.getData("role", "")).equals("parent")) {
35 if (!TextUtils.isEmpty(student)) { 37 Intent intent = new Intent(this, MainActivity.class);
36 if ((SharedPreferencesUtil.getData("role", "")).equals("parent")) { 38 startActivity(intent);
37 Intent intent = new Intent(this, MainActivity.class); 39 finish();
38 startActivity(intent); 40 } else {
39 finish(); 41 Intent intent = new Intent(this, TeacherMainActivity.class);
40 } else { 42 startActivity(intent);
41 Intent intent = new Intent(this, TeacherMainActivity.class); 43 finish();
42 startActivity(intent); 44 }
43 finish(); 45 return;
44 } 46 }
45 return; 47
46 } 48 binding.tvEntrance.setOnClickListener(v -> {
47 49 startActivity(new Intent(this, LoginActivity.class));
48 binding.tvEntrance.setOnClickListener(v -> { 50 finish();
49 startActivity(new Intent(this, LoginActivity.class)); 51 });
50 finish(); 52 binding.btnGetCode.setOnClickListener(v -> {
51 }); 53 String phone = binding.etPhone.getText().toString().trim();
52 binding.btnGetCode.setOnClickListener(v -> { 54 if (phone.isEmpty()) {
53 String phone = binding.etPhone.getText().toString().trim(); 55 showToast("请输入手机号");
54 if (phone.isEmpty()) { 56 return;
55 showToast("请输入手机号"); 57 }
56 return; 58 sendCode(phone);
57 } 59 });
58 sendCode(phone); 60 binding.btnLogin.setOnClickListener(v -> {
59 }); 61
60 binding.btnLogin.setOnClickListener(v -> { 62 String phone = binding.etPhone.getText().toString().trim();
61 63 String code = binding.etCode.getText().toString().trim();
62 String phone = binding.etPhone.getText().toString().trim(); 64 if (phone.isEmpty() || code.isEmpty()) {
63 String code = binding.etCode.getText().toString().trim(); 65 Toast.makeText(this, "手机号以及验证码不能为空", Toast.LENGTH_SHORT).show();
64 if (phone.isEmpty() || code.isEmpty()) { 66 return;
65 Toast.makeText(this, "手机号以及验证码不能为空", Toast.LENGTH_SHORT).show(); 67 }
66 return; 68
67 } 69 if (!binding.chkPermission.isChecked()) {
68 70 Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show();
69 if (!binding.chkPermission.isChecked()) { 71 return;
70 Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show(); 72 }
71 return; 73 login(phone, code);
72 } 74 });
73 login(phone, code); 75
74 }); 76 binding.tv6.setOnClickListener(view -> {
75 77 startActivity(new Intent(this, YinsiActivity.class));
76 binding.tv6.setOnClickListener(view -> { 78 });
77 startActivity(new Intent(this, YinsiActivity.class)); 79 binding.tv4.setOnClickListener(view -> {
78 }); 80 startActivity(new Intent(this, UserAgreementActivity.class));
79 binding.tv4.setOnClickListener(view -> { 81 });
80 startActivity(new Intent(this, UserAgreementActivity.class)); 82 }
81 }); 83
82 } 84 @SuppressLint("CheckResult")
83 85 private void login(String phone, String code) {
84 @SuppressLint("CheckResult") 86 binding.btnLogin.setEnabled(false);
85 private void login(String phone, String code) { 87 Map<String, String> body = new HashMap<>();
86 binding.btnLogin.setEnabled(false); 88 body.put("phone", phone);
87 Map<String, String> body = new HashMap<>(); 89 body.put("code", code);
88 body.put("phone", phone); 90 api.smsLogin(body)
89 body.put("code", code); 91 .compose(transformSingle())
90 api.smsLogin(body) 92 .subscribe((response, th) -> {
91 .compose(transformSingle()) 93 binding.btnLogin.setEnabled(true);
92 .subscribe((response, th) -> { 94 if (handleResponseData(response, th)) {
95 List<Student> list = response.getData().parentInfoList;
96 if (list == null || list.isEmpty()) {
97 showToast("未注册学生, 无法登录");
98 return;
99 }
93 binding.btnLogin.setEnabled(true); 100 SharedPreferencesUtil.putData("phone", phone);
94 if (handleResponseData(response, th)) { 101 SharedPreferencesUtil.putData("role", "parent");
95 List<Student> list = response.getData().parentInfoList; 102 SharedPreferencesUtil.putData("userId", response.getData().id);
96 if (list == null || list.isEmpty()) { 103 SharedPreferencesUtil.putData("token", response.getData().token);
97 showToast("未注册学生, 无法登录"); 104 SharedPreferencesUtil.putData("name", response.getData().username);
98 return; 105 startActivity(new Intent(this, ChooseActivity.class));
99 } 106 finish();
100 SharedPreferencesUtil.putData("phone", phone); 107 }
101 SharedPreferencesUtil.putData("role", "parent"); 108 });
102 SharedPreferencesUtil.putData("userId", response.getData().id); 109 }
103 SharedPreferencesUtil.putData("token", response.getData().token); 110
104 SharedPreferencesUtil.putData("name", response.getData().username); 111 @SuppressLint({"SetTextI18n", "CheckResult"})
105 startActivity(new Intent(this, ChooseActivity.class)); 112 private void sendCode(String phone) {
106 finish(); 113 binding.btnGetCode.setEnabled(false);
107 } 114 api.smsCode(phone)
108 }); 115 .compose(transformSingle())
109 } 116 .subscribe((response, th) -> {
110 117 if (handleResponse(response, th)) {
111 @SuppressLint({"SetTextI18n", "CheckResult"}) 118 showToast("验证码已发送");
112 private void sendCode(String phone) { 119 timeDown();
113 binding.btnGetCode.setEnabled(false); 120 } else {
114 api.smsCode(phone) 121 if (disposable != null) disposable.dispose();
115 .compose(transformSingle()) 122 binding.btnGetCode.setText("获取验证码");
116 .subscribe((response, th) -> { 123 binding.btnGetCode.setEnabled(true);
117 if (handleResponse(response, th)) { 124 }
118 showToast("验证码已发送"); 125 });
119 timeDown(); 126 }
120 } else { 127
121 if (disposable != null) disposable.dispose(); 128 private int timeDown = 0;
122 binding.btnGetCode.setText("获取验证码"); 129 private Disposable disposable;
123 binding.btnGetCode.setEnabled(true); 130 @SuppressLint("SetTextI18n")
124 } 131 private void timeDown() {
125 }); 132 timeDown = 60;
126 } 133 disposable = Observable
127 134 .interval(0, 1, TimeUnit.SECONDS)
128 private int timeDown = 0; 135 .observeOn(AndroidSchedulers.mainThread())
129 private Disposable disposable; 136 .subscribe(l -> {
130 @SuppressLint("SetTextI18n") 137 if (--timeDown <= 0) {
131 private void timeDown() { 138 if (disposable != null) disposable.dispose();
132 timeDown = 60; 139 binding.btnGetCode.setText("获取验证码");
133 disposable = Observable 140 binding.btnGetCode.setEnabled(true);
134 .interval(0, 1, TimeUnit.SECONDS) 141 } else {
135 .observeOn(AndroidSchedulers.mainThread()) 142 binding.btnGetCode.setText("获取验证码(" + timeDown + "s)");
136 .subscribe(l -> { 143 binding.btnGetCode.setEnabled(false);
137 if (--timeDown <= 0) { 144 }
138 if (disposable != null) disposable.dispose(); 145 }, Throwable::printStackTrace);
139 binding.btnGetCode.setText("获取验证码"); 146 }
140 binding.btnGetCode.setEnabled(true); 147
141 } else { 148 @Override
142 binding.btnGetCode.setText("获取验证码(" + timeDown + "s)"); 149 protected void onDestroy() {
143 binding.btnGetCode.setEnabled(false); 150 super.onDestroy();
144 } 151 if (disposable != null) disposable.dispose();
145 }, Throwable::printStackTrace); 152 }
146 } 153
147 154 @Override
148 @Override 155 protected ActivitySmsLoginBinding getViewBinding() {
149 protected void onDestroy() { 156 return ActivitySmsLoginBinding.inflate(getLayoutInflater());
150 super.onDestroy(); 157 }
151 if (disposable != null) disposable.dispose(); 158 }
152 } 159
app/src/main/java/com/hjx/parent/fragment/MeFragment.java
1 package com.hjx.parent.fragment; 1 package com.hjx.parent.fragment;
2 2
3 import android.content.Intent; 3 import android.content.Intent;
4 import android.text.TextUtils; 4 import android.text.TextUtils;
5 import android.view.View; 5 import android.view.View;
6 import android.widget.ImageView; 6 import android.widget.ImageView;
7 import android.widget.TextView; 7 import android.widget.TextView;
8 8
9 import androidx.annotation.NonNull; 9 import androidx.annotation.NonNull;
10 import androidx.constraintlayout.widget.Group; 10 import androidx.constraintlayout.widget.Group;
11 import androidx.recyclerview.widget.LinearLayoutManager; 11 import androidx.recyclerview.widget.LinearLayoutManager;
12 import androidx.recyclerview.widget.RecyclerView; 12 import androidx.recyclerview.widget.RecyclerView;
13 13
14 import com.bumptech.glide.Glide; 14 import com.bumptech.glide.Glide;
15 import com.bumptech.glide.load.resource.bitmap.RoundedCorners; 15 import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
16 import com.bumptech.glide.request.RequestOptions; 16 import com.bumptech.glide.request.RequestOptions;
17 import com.chad.library.adapter.base.BaseQuickAdapter; 17 import com.chad.library.adapter.base.BaseQuickAdapter;
18 import com.chad.library.adapter.base.BaseViewHolder; 18 import com.chad.library.adapter.base.BaseViewHolder;
19 import com.google.gson.Gson; 19 import com.google.gson.Gson;
20 import com.hjx.parent.AccountActivity; 20 import com.hjx.parent.AccountActivity;
21 import com.hjx.parent.AddStudentActivity; 21 import com.hjx.parent.AddStudentActivity;
22 import com.hjx.parent.EditStudentActivity; 22 import com.hjx.parent.EditStudentActivity;
23 import com.hjx.parent.R; 23 import com.hjx.parent.R;
24 import com.hjx.parent.UserActivity; 24 import com.hjx.parent.UserActivity;
25 import com.hjx.parent.YinsiActivity; 25 import com.hjx.parent.YinsiActivity;
26 import com.hjx.parent.bean.StudentBean; 26 import com.hjx.parent.bean.StudentBean;
27 import com.prws.common.base.BaseFragment; 27 import com.prws.common.base.BaseFragment;
28 import com.prws.common.net.NetWorks; 28 import com.prws.common.net.NetWorks;
29 import com.prws.common.utils.LogUtil; 29 import com.prws.common.utils.LogUtil;
30 import com.prws.common.utils.ScreenUtils; 30 import com.prws.common.utils.ScreenUtils;
31 import com.prws.common.utils.SharedPreferencesUtil; 31 import com.prws.common.utils.SharedPreferencesUtil;
32 32
33 import org.json.JSONArray; 33 import org.json.JSONArray;
34 import org.json.JSONObject; 34 import org.json.JSONObject;
35 35
36 import java.util.ArrayList; 36 import java.util.ArrayList;
37 37
38 import io.reactivex.Observer; 38 import io.reactivex.Observer;
39 import io.reactivex.disposables.Disposable; 39 import io.reactivex.disposables.Disposable;
40 import okhttp3.ResponseBody; 40 import okhttp3.ResponseBody;
41 41
42 public class MeFragment extends BaseFragment { 42 public class MeFragment extends BaseFragment {
43 @Override 43 @Override
44 protected int getLayoutRes() { 44 protected int getLayoutRes() {
45 return R.layout.fragment_me; 45 return R.layout.fragment_me;
46 } 46 }
47 47
48 Group group_1; 48 Group group_1;
49 TextView tv_name; 49 TextView tv_name;
50 TextView tv_phone; 50 TextView tv_phone;
51 ImageView iv_toux; 51 ImageView iv_toux;
52 RecyclerView recycle; 52 RecyclerView recycle;
53 53
54 @Override 54 @Override
55 protected void initDatas() { 55 protected void initDatas() {
56 super.initDatas(); 56 super.initDatas();
57 recycle = mRootView.findViewById(R.id.recycle); 57 recycle = mRootView.findViewById(R.id.recycle);
58 group_1 = mRootView.findViewById(R.id.group_1); 58 group_1 = mRootView.findViewById(R.id.group_1);
59 String role = (String) SharedPreferencesUtil.getData("role", ""); 59 String role = (String) SharedPreferencesUtil.getData("role", "");
60 String userId = (String) SharedPreferencesUtil.getData("userId", ""); 60 String userId = (String) SharedPreferencesUtil.getData("userId", "");
61 String token = (String) SharedPreferencesUtil.getData("token", ""); 61 String token = (String) SharedPreferencesUtil.getData("token", "");
62 String phone = (String) SharedPreferencesUtil.getData("phone", ""); 62 String phone = (String) SharedPreferencesUtil.getData("phone", "");
63 group_1.setVisibility(View.VISIBLE); 63 group_1.setVisibility(View.VISIBLE);
64 iv_toux = mRootView.findViewById(R.id.iv_toux); 64 iv_toux = mRootView.findViewById(R.id.iv_toux);
65 tv_name = mRootView.findViewById(R.id.tv_name); 65 tv_name = mRootView.findViewById(R.id.tv_name);
66 tv_phone = mRootView.findViewById(R.id.tv_phone); 66 tv_phone = mRootView.findViewById(R.id.tv_phone);
67 tv_phone.setVisibility(View.GONE); 67 tv_phone.setVisibility(View.GONE);
68 // tv_phone.setText(phone); 68 // tv_phone.setText(phone);
69 tv_name.setText(phone); 69 tv_name.setText(phone);
70 } 70 }
71 71
72 @Override 72 @Override
73 public void onResume() { 73 public void onResume() {
74 super.onResume(); 74 super.onResume();
75 String photo = (String) SharedPreferencesUtil.getData("photo", ""); 75 String photo = (String) SharedPreferencesUtil.getData("photo", "");
76 if (!TextUtils.isEmpty(photo)) { 76 if (!TextUtils.isEmpty(photo)) {
77 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); 77 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45));
78 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); 78 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
79 Glide.with(getContext()).load(photo).error(R.mipmap.ic_parent_avatar).apply(options).into(iv_toux); 79 Glide.with(getContext()).load(photo).error(R.mipmap.ic_parent_avatar).apply(options).into(iv_toux);
80 } 80 }
81 loadChildList(); 81 loadChildList();
82 } 82 }
83 83
84 ArrayList<StudentBean> alist = new ArrayList<>(); 84 ArrayList<StudentBean> alist = new ArrayList<>();
85 85
86 public void loadChildList() { 86 public void loadChildList() {
87 NetWorks.listChildren(new Observer<ResponseBody>() { 87 NetWorks.listChildren(new Observer<ResponseBody>() {
88 @Override 88 @Override
89 public void onSubscribe(Disposable d) { 89 public void onSubscribe(Disposable d) {
90 90
91 } 91 }
92 92
93 @Override 93 @Override
94 public void onNext(ResponseBody responseBody) { 94 public void onNext(ResponseBody responseBody) {
95 try { 95 try {
96 96
97 String str = responseBody.string().toString(); 97 String str = responseBody.string().toString();
98 98
99 99
100 LogUtil.e("TAG", "----" + str); 100 LogUtil.e("TAG", "----" + str);
101 JSONObject jo = new JSONObject(str); 101 JSONObject jo = new JSONObject(str);
102 boolean isSucceed = jo.getBoolean("success"); 102 boolean isSucceed = jo.getBoolean("success");
103 if (isSucceed) { 103 if (isSucceed) {
104 JSONArray jarr = jo.getJSONArray("data"); 104 JSONArray jarr = jo.getJSONArray("data");
105 alist.clear(); 105 alist.clear();
106 for (int i = 0; i < jarr.length(); i++) { 106 for (int i = 0; i < jarr.length(); i++) {
107 JSONObject jo2 = jarr.getJSONObject(i); 107 JSONObject jo2 = jarr.getJSONObject(i);
108 Gson gson = new Gson(); 108 Gson gson = new Gson();
109 StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class); 109 StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class);
110 alist.add(sb); 110 alist.add(sb);
111 } 111 }
112 if (alist.size() > 0) { 112 if (alist.size() > 0) {
113 loadList(); 113 loadList();
114 } 114 }
115 115
116 } else { 116 } else {
117 117
118 } 118 }
119 } catch (Exception e) { 119 } catch (Exception e) {
120 e.printStackTrace(); 120 e.printStackTrace();
121 } 121 }
122 } 122 }
123 123
124 @Override 124 @Override
125 public void onError(Throwable e) { 125 public void onError(Throwable e) {
126 e.toString(); 126 e.toString();
127 } 127 }
128 128
129 @Override 129 @Override
130 public void onComplete() { 130 public void onComplete() {
131 131
132 } 132 }
133 }); 133 });
134 mRootView.findViewById(R.id.view_4).setOnClickListener(view -> startActivity(new Intent(getActivity(), YinsiActivity.class))); 134 mRootView.findViewById(R.id.view_4).setOnClickListener(view -> startActivity(new Intent(getActivity(), YinsiActivity.class)));
135 mRootView.findViewById(R.id.view_5).setOnClickListener(view -> startActivity(new Intent(getActivity(), UserActivity.class))); 135 mRootView.findViewById(R.id.view_5).setOnClickListener(view -> startActivity(new Intent(getActivity(), UserActivity.class)));
136 mRootView.findViewById(R.id.view_3).setOnClickListener(view -> startActivityForResult(new Intent(getActivity(), AccountActivity.class), 1003)); 136 mRootView.findViewById(R.id.view_3).setOnClickListener(view -> startActivityForResult(new Intent(getActivity(), AccountActivity.class), 1003));
137 } 137 }
138 138
139 // @Override 139 // @Override
140 // public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { 140 // public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
141 // super.onActivityResult(requestCode, resultCode, data); 141 // super.onActivityResult(requestCode, resultCode, data);
142 // Intent intent = new Intent(getActivity(), LoginActivity.class); 142 // Intent intent = new Intent(getActivity(), LoginActivity.class);
143 // startActivity(intent); 143 // startActivity(intent);
144 // getActivity().finish(); 144 // getActivity().finish();
145 // } 145 // }
146 146
147 public void loadList() { 147 public void loadList() {
148 BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child, alist) {
149 @Override
150 public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
151 148 BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child, alist) {
152 } 149 @Override
153 150 public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
154 @Override 151
155 protected void convert(@NonNull BaseViewHolder item, Object o) { 152 }
156 StudentBean studentBean = alist.get(item.getAdapterPosition()); 153
157 item.setText(R.id.tv_name, studentBean.getNickName()); 154 @Override
158 if (TextUtils.isEmpty(studentBean.getStuId())) { 155 protected void convert(@NonNull BaseViewHolder item, Object o) {
159 // do nothing 156 StudentBean studentBean = alist.get(item.getAdapterPosition());
160 } else { 157 item.setText(R.id.tv_name, studentBean.getNickName());
161 if (TextUtils.isEmpty(studentBean.getPhoto())) { 158 if (TextUtils.isEmpty(studentBean.getStuId())) {
162 item.setImageResource(R.id.iv_avatar, "男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); 159 // do nothing
163 } else {
164 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45));
165 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
166 Glide.with(getActivity()).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar));
167 }
168 item.setVisible(R.id.iv_vip, studentBean.getIsIntention() == 1);
169 item.getConvertView().setOnClickListener(new View.OnClickListener() {
170 @Override 160 } else {
171 public void onClick(View view) { 161 if (TextUtils.isEmpty(studentBean.getPhoto())) {
172 startActivity(new Intent(getActivity(), EditStudentActivity.class).putExtra("student", new Gson().toJson(studentBean))); 162 item.setImageResource(R.id.iv_avatar, "男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female);
173 } 163 } else {
174 }); 164 RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45));
175 } 165 RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
176 } 166 Glide.with(getActivity()).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar));
177 }; 167 }
178 recycle.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); 168 item.setVisible(R.id.iv_vip, studentBean.getIsIntention() == 1);
179 recycle.setAdapter(adapter); 169 item.getConvertView().setOnClickListener(new View.OnClickListener() {
180 } 170 @Override
181 171 public void onClick(View view) {
182 } 172 startActivity(new Intent(getActivity(), EditStudentActivity.class).putExtra("student", new Gson().toJson(studentBean)));
183 173 }
app/src/main/res/layout/activity_edit_stu.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="#F4F6F8"> 6 android:background="#F4F6F8">
7 7
8 <View 8 <View
9 android:id="@+id/view_1" 9 android:id="@+id/view_1"
10 android:layout_width="match_parent" 10 android:layout_width="match_parent"
11 android:layout_height="44dp" 11 android:layout_height="44dp"
12 android:background="@android:color/white" 12 android:background="@android:color/white"
13 app:layout_constraintTop_toTopOf="parent" /> 13 app:layout_constraintTop_toTopOf="parent" />
14 14
15 <TextView 15 <TextView
16 android:layout_width="wrap_content" 16 android:layout_width="wrap_content"
17 android:layout_height="wrap_content" 17 android:layout_height="wrap_content"
18 android:text="编辑学生" 18 android:text="编辑学生"
19 android:textColor="#333333" 19 android:textColor="#333333"
20 android:textSize="18dp" 20 android:textSize="18dp"
21 app:layout_constraintBottom_toBottomOf="@id/view_1" 21 app:layout_constraintBottom_toBottomOf="@id/view_1"
22 app:layout_constraintLeft_toLeftOf="@id/view_1" 22 app:layout_constraintLeft_toLeftOf="@id/view_1"
23 app:layout_constraintRight_toRightOf="@id/view_1" 23 app:layout_constraintRight_toRightOf="@id/view_1"
24 app:layout_constraintTop_toTopOf="@id/view_1" /> 24 app:layout_constraintTop_toTopOf="@id/view_1" />
25 25
26 <TextView 26 <TextView
27 android:id="@+id/tv_cancel" 27 android:id="@+id/tv_cancel"
28 android:layout_width="wrap_content" 28 android:layout_width="wrap_content"
29 android:layout_height="wrap_content" 29 android:layout_height="wrap_content"
30 android:layout_marginLeft="15dp" 30 android:layout_marginLeft="15dp"
31 android:text="取消" 31 android:text="取消"
32 android:textColor="#666666" 32 android:textColor="#666666"
33 android:textSize="16dp" 33 android:textSize="16dp"
34 app:layout_constraintBottom_toBottomOf="@id/view_1" 34 app:layout_constraintBottom_toBottomOf="@id/view_1"
35 app:layout_constraintLeft_toLeftOf="@id/view_1" 35 app:layout_constraintLeft_toLeftOf="@id/view_1"
36 app:layout_constraintTop_toTopOf="@id/view_1" /> 36 app:layout_constraintTop_toTopOf="@id/view_1" />
37 37
38 <RelativeLayout 38 <RelativeLayout
39 android:id="@+id/rl_avatar" 39 android:id="@+id/rl_avatar"
40 android:layout_width="75dp" 40 android:layout_width="75dp"
41 android:layout_height="75dp" 41 android:layout_height="75dp"
42 android:layout_marginTop="32dp" 42 android:layout_marginTop="32dp"
43 app:layout_constraintLeft_toLeftOf="parent" 43 app:layout_constraintLeft_toLeftOf="parent"
44 app:layout_constraintRight_toRightOf="parent" 44 app:layout_constraintRight_toRightOf="parent"
45 app:layout_constraintTop_toBottomOf="@id/view_1"> 45 app:layout_constraintTop_toBottomOf="@id/view_1">
46 46
47 <ImageView 47 <ImageView
48 android:id="@+id/iv_avatar" 48 android:id="@+id/iv_avatar"
49 android:layout_width="match_parent" 49 android:layout_width="match_parent"
50 android:layout_height="match_parent" 50 android:layout_height="match_parent"
51 android:background="@mipmap/txz" /> 51 android:background="@mipmap/txz" />
52 52
53 <ImageView 53 <ImageView
54 android:layout_width="20dp" 54 android:layout_width="20dp"
55 android:layout_height="20dp" 55 android:layout_height="20dp"
56 android:layout_alignParentRight="true" 56 android:layout_alignParentRight="true"
57 android:layout_alignParentBottom="true" 57 android:layout_alignParentBottom="true"
58 android:layout_marginBottom="5dp" 58 android:layout_marginBottom="5dp"
59 android:src="@mipmap/ic_edit" /> 59 android:src="@mipmap/ic_edit" />
60 </RelativeLayout> 60 </RelativeLayout>
61 61
62 62
63 <View 63 <View
64 android:id="@+id/view_2" 64 android:id="@+id/view_2"
65 android:layout_width="match_parent" 65 android:layout_width="match_parent"
66 android:layout_marginLeft="15dp" 66 android:layout_marginLeft="15dp"
67 android:layout_marginRight="15dp" 67 android:layout_marginRight="15dp"
68 android:layout_height="50dp" 68 android:layout_height="50dp"
69 android:layout_marginTop="195dp" 69 android:layout_marginTop="195dp"
70 android:background="@drawable/bg_solid_white_10" 70 android:background="@drawable/bg_solid_white_10"
71 app:layout_constraintLeft_toLeftOf="parent" 71 app:layout_constraintLeft_toLeftOf="parent"
72 app:layout_constraintRight_toRightOf="parent" 72 app:layout_constraintRight_toRightOf="parent"
73 app:layout_constraintTop_toTopOf="parent" /> 73 app:layout_constraintTop_toTopOf="parent" />
74 74
75 <TextView 75 <TextView
76 android:layout_width="wrap_content" 76 android:layout_width="wrap_content"
77 android:layout_height="wrap_content" 77 android:layout_height="wrap_content"
78 android:layout_marginLeft="15dp" 78 android:layout_marginLeft="15dp"
79 android:text="昵称" 79 android:text="昵称"
80 android:textColor="#666666" 80 android:textColor="#666666"
81 android:textSize="16dp" 81 android:textSize="16dp"
82 app:layout_constraintBottom_toBottomOf="@id/view_2" 82 app:layout_constraintBottom_toBottomOf="@id/view_2"
83 app:layout_constraintLeft_toLeftOf="@id/view_2" 83 app:layout_constraintLeft_toLeftOf="@id/view_2"
84 app:layout_constraintTop_toTopOf="@id/view_2" /> 84 app:layout_constraintTop_toTopOf="@id/view_2" />
85 85
86 <ImageView 86 <ImageView
87 android:layout_width="5.5dp" 87 android:layout_width="5.5dp"
88 android:layout_height="9.5dp" 88 android:layout_height="9.5dp"
89 android:layout_marginRight="15dp" 89 android:layout_marginRight="15dp"
90 android:background="@mipmap/ycaj" 90 android:background="@mipmap/ycaj"
91 app:layout_constraintBottom_toBottomOf="@id/view_2" 91 app:layout_constraintBottom_toBottomOf="@id/view_2"
92 app:layout_constraintRight_toRightOf="@id/view_2" 92 app:layout_constraintRight_toRightOf="@id/view_2"
93 app:layout_constraintTop_toTopOf="@id/view_2" /> 93 app:layout_constraintTop_toTopOf="@id/view_2" />
94 94
95 <TextView 95 <TextView
96 android:id="@+id/tv_name" 96 android:id="@+id/tv_name"
97 android:layout_width="wrap_content" 97 android:layout_width="wrap_content"
98 android:layout_height="wrap_content" 98 android:layout_height="wrap_content"
99 android:layout_marginRight="26dp" 99 android:layout_marginRight="26dp"
100 android:text="请输入" 100 android:text="请输入"
101 android:textColor="#333333" 101 android:textColor="#333333"
102 android:textSize="16dp" 102 android:textSize="16dp"
103 app:layout_constraintBottom_toBottomOf="@id/view_2" 103 app:layout_constraintBottom_toBottomOf="@id/view_2"
104 app:layout_constraintRight_toRightOf="@id/view_2" 104 app:layout_constraintRight_toRightOf="@id/view_2"
105 app:layout_constraintTop_toTopOf="@id/view_2" /> 105 app:layout_constraintTop_toTopOf="@id/view_2" />
106 106
107 <View 107 <View
108 android:id="@+id/view_3" 108 android:id="@+id/view_3"
109 android:layout_width="match_parent" 109 android:layout_width="match_parent"
110 android:layout_marginLeft="15dp" 110 android:layout_marginLeft="15dp"
111 android:layout_marginRight="15dp" 111 android:layout_marginRight="15dp"
112 android:layout_height="50dp" 112 android:layout_height="50dp"
113 android:layout_marginTop="260dp" 113 android:layout_marginTop="260dp"
114 android:background="@drawable/bg_solid_white_10" 114 android:background="@drawable/bg_solid_white_10"
115 app:layout_constraintLeft_toLeftOf="parent" 115 app:layout_constraintLeft_toLeftOf="parent"
116 app:layout_constraintRight_toRightOf="parent" 116 app:layout_constraintRight_toRightOf="parent"
117 app:layout_constraintTop_toTopOf="parent" /> 117 app:layout_constraintTop_toTopOf="parent" />
118 118
119 <TextView 119 <TextView
120 android:layout_width="wrap_content" 120 android:layout_width="wrap_content"
121 android:layout_height="wrap_content" 121 android:layout_height="wrap_content"
122 android:layout_marginLeft="15dp" 122 android:layout_marginLeft="15dp"
123 android:text="性别" 123 android:text="性别"
124 android:textColor="#666666" 124 android:textColor="#666666"
125 android:textSize="16dp" 125 android:textSize="16dp"
126 app:layout_constraintBottom_toBottomOf="@id/view_3" 126 app:layout_constraintBottom_toBottomOf="@id/view_3"
127 app:layout_constraintLeft_toLeftOf="@id/view_3" 127 app:layout_constraintLeft_toLeftOf="@id/view_3"
128 app:layout_constraintTop_toTopOf="@id/view_3" /> 128 app:layout_constraintTop_toTopOf="@id/view_3" />
129 129
130 <ImageView 130 <ImageView
131 android:layout_width="5.5dp" 131 android:layout_width="5.5dp"
132 android:layout_height="9.5dp" 132 android:layout_height="9.5dp"
133 android:layout_marginRight="15dp" 133 android:layout_marginRight="15dp"
134 android:background="@mipmap/ycaj" 134 android:background="@mipmap/ycaj"
135 app:layout_constraintBottom_toBottomOf="@id/view_3" 135 app:layout_constraintBottom_toBottomOf="@id/view_3"
136 app:layout_constraintRight_toRightOf="@id/view_3" 136 app:layout_constraintRight_toRightOf="@id/view_3"
137 app:layout_constraintTop_toTopOf="@id/view_3" /> 137 app:layout_constraintTop_toTopOf="@id/view_3" />
138 138
139 <TextView 139 <TextView
140 android:id="@+id/tv_sex" 140 android:id="@+id/tv_sex"
141 android:layout_width="wrap_content" 141 android:layout_width="wrap_content"
142 android:layout_height="wrap_content" 142 android:layout_height="wrap_content"
143 android:layout_marginRight="26dp" 143 android:layout_marginRight="26dp"
144 android:text="请选择" 144 android:text="请选择"
145 android:textColor="#333333" 145 android:textColor="#333333"
146 android:textSize="16dp" 146 android:textSize="16dp"
147 app:layout_constraintBottom_toBottomOf="@id/view_3" 147 app:layout_constraintBottom_toBottomOf="@id/view_3"
148 app:layout_constraintRight_toRightOf="@id/view_3" 148 app:layout_constraintRight_toRightOf="@id/view_3"
149 app:layout_constraintTop_toTopOf="@id/view_3" /> 149 app:layout_constraintTop_toTopOf="@id/view_3" />
150 150
151 <View 151 <View
152 android:id="@+id/view_4" 152 android:id="@+id/view_4"
153 android:layout_width="match_parent" 153 android:layout_width="match_parent"
154 android:layout_marginLeft="15dp" 154 android:layout_marginLeft="15dp"
155 android:layout_marginRight="15dp" 155 android:layout_marginRight="15dp"
156 android:layout_height="50dp" 156 android:layout_height="50dp"
157 android:layout_marginTop="325dp" 157 android:layout_marginTop="325dp"
158 android:background="@drawable/bg_solid_white_10" 158 android:background="@drawable/bg_solid_white_10"
159 app:layout_constraintLeft_toLeftOf="parent" 159 app:layout_constraintLeft_toLeftOf="parent"
160 app:layout_constraintRight_toRightOf="parent" 160 app:layout_constraintRight_toRightOf="parent"
161 app:layout_constraintTop_toTopOf="parent" 161 app:layout_constraintTop_toTopOf="parent"
162 162
163 /> 163 />
164 164
165 <TextView 165 <TextView
166 android:layout_width="wrap_content" 166 android:layout_width="wrap_content"
167 android:layout_height="wrap_content" 167 android:layout_height="wrap_content"
168 android:layout_marginLeft="15dp" 168 android:layout_marginLeft="15dp"
169 android:text="年级" 169 android:text="年级"
170 android:textColor="#666666" 170 android:textColor="#666666"
171 android:textSize="16dp" 171 android:textSize="16dp"
172 app:layout_constraintBottom_toBottomOf="@id/view_4" 172 app:layout_constraintBottom_toBottomOf="@id/view_4"
173 app:layout_constraintLeft_toLeftOf="@id/view_4" 173 app:layout_constraintLeft_toLeftOf="@id/view_4"
174 app:layout_constraintTop_toTopOf="@id/view_4" /> 174 app:layout_constraintTop_toTopOf="@id/view_4" />
175 175
176 <ImageView 176 <ImageView
177 android:layout_width="5.5dp" 177 android:layout_width="5.5dp"
178 android:layout_height="9.5dp" 178 android:layout_height="9.5dp"
179 android:layout_marginRight="15dp" 179 android:layout_marginRight="15dp"
180 android:background="@mipmap/ycaj" 180 android:background="@mipmap/ycaj"
181 app:layout_constraintBottom_toBottomOf="@id/view_4" 181 app:layout_constraintBottom_toBottomOf="@id/view_4"
182 app:layout_constraintRight_toRightOf="@id/view_4" 182 app:layout_constraintRight_toRightOf="@id/view_4"
183 app:layout_constraintTop_toTopOf="@id/view_4" /> 183 app:layout_constraintTop_toTopOf="@id/view_4" />
184 184
185 <TextView 185 <TextView
186 android:id="@+id/tv_nian" 186 android:id="@+id/tv_nian"
187 android:layout_width="wrap_content" 187 android:layout_width="wrap_content"
188 android:layout_height="wrap_content" 188 android:layout_height="wrap_content"
189 android:layout_marginRight="26dp" 189 android:layout_marginRight="26dp"
190 android:text="请选择" 190 android:text="请选择"
191 android:textColor="#333333" 191 android:textColor="#333333"
192 android:textSize="16dp" 192 android:textSize="16dp"
193 app:layout_constraintBottom_toBottomOf="@id/view_4" 193 app:layout_constraintBottom_toBottomOf="@id/view_4"
194 app:layout_constraintRight_toRightOf="@id/view_4" 194 app:layout_constraintRight_toRightOf="@id/view_4"
195 app:layout_constraintTop_toTopOf="@id/view_4" /> 195 app:layout_constraintTop_toTopOf="@id/view_4" />
196 196
197 <View 197 <View
198 android:id="@+id/view_5" 198 android:id="@+id/view_5"
199 android:layout_width="match_parent" 199 android:layout_width="match_parent"
200 android:layout_marginLeft="15dp" 200 android:layout_marginLeft="15dp"
201 android:layout_marginRight="15dp" 201 android:layout_marginRight="15dp"
202 android:layout_height="50dp" 202 android:layout_height="50dp"
203 android:layout_marginTop="390dp" 203 android:layout_marginTop="390dp"
204 android:background="@drawable/bg_solid_white_10" 204 android:background="@drawable/bg_solid_white_10"
205 app:layout_constraintLeft_toLeftOf="parent" 205 app:layout_constraintLeft_toLeftOf="parent"
206 app:layout_constraintRight_toRightOf="parent" 206 app:layout_constraintRight_toRightOf="parent"
207 app:layout_constraintTop_toTopOf="parent" 207 app:layout_constraintTop_toTopOf="parent"
208 208
209 /> 209 />
210 210
211 <TextView 211 <TextView
212 212
213 android:layout_width="wrap_content" 213 android:layout_width="wrap_content"
214 android:layout_height="wrap_content" 214 android:layout_height="wrap_content"
215 android:layout_marginLeft="15dp" 215 android:layout_marginLeft="15dp"
216 android:text="家长身份" 216 android:text="家长身份"
217 android:textColor="#666666" 217 android:textColor="#666666"
218 android:textSize="16dp" 218 android:textSize="16dp"
219 app:layout_constraintBottom_toBottomOf="@id/view_5" 219 app:layout_constraintBottom_toBottomOf="@id/view_5"
220 app:layout_constraintLeft_toLeftOf="@id/view_5" 220 app:layout_constraintLeft_toLeftOf="@id/view_5"
221 app:layout_constraintTop_toTopOf="@id/view_5" /> 221 app:layout_constraintTop_toTopOf="@id/view_5" />
222 222
223 <TextView 223 <TextView
224 android:id="@+id/tv_shen" 224 android:id="@+id/tv_shen"
225 android:layout_width="wrap_content" 225 android:layout_width="wrap_content"
226 android:layout_height="wrap_content" 226 android:layout_height="wrap_content"
227 android:layout_marginRight="26dp" 227 android:layout_marginRight="26dp"
228 android:text="请选择" 228 android:text="请选择"
229 android:textColor="#333333" 229 android:textColor="#333333"
230 android:textSize="16dp" 230 android:textSize="16dp"
231 app:layout_constraintBottom_toBottomOf="@id/view_5" 231 app:layout_constraintBottom_toBottomOf="@id/view_5"
232 app:layout_constraintRight_toRightOf="@id/view_5" 232 app:layout_constraintRight_toRightOf="@id/view_5"
233 app:layout_constraintTop_toTopOf="@id/view_5" /> 233 app:layout_constraintTop_toTopOf="@id/view_5" />
234 234
235 <ImageView 235 <ImageView
236 android:layout_width="5.5dp" 236 android:layout_width="5.5dp"
237 android:layout_height="9.5dp" 237 android:layout_height="9.5dp"
238 android:layout_marginRight="15dp" 238 android:layout_marginRight="15dp"
239 android:background="@mipmap/ycaj" 239 android:background="@mipmap/ycaj"
240 app:layout_constraintBottom_toBottomOf="@id/view_5" 240 app:layout_constraintBottom_toBottomOf="@id/view_5"
241 app:layout_constraintRight_toRightOf="@id/view_5" 241 app:layout_constraintRight_toRightOf="@id/view_5"
242 app:layout_constraintTop_toTopOf="@id/view_5" /> 242 app:layout_constraintTop_toTopOf="@id/view_5" />
243 243
244 <LinearLayout 244 <LinearLayout
245 android:id="@+id/view_6" 245 android:id="@+id/view_6"
246 android:layout_width="match_parent" 246 android:layout_width="match_parent"
247 android:layout_height="wrap_content" 247 android:layout_height="wrap_content"
248 android:layout_marginLeft="15dp" 248 android:layout_marginLeft="15dp"
249 android:layout_marginTop="460dp" 249 android:layout_marginTop="460dp"
250 android:layout_marginRight="15dp" 250 android:layout_marginRight="15dp"
251 android:background="@drawable/bg_solid_white_10" 251 android:background="@drawable/bg_solid_white_10"
252 android:orientation="vertical" 252 android:orientation="vertical"
253 app:layout_constraintLeft_toLeftOf="parent" 253 app:layout_constraintLeft_toLeftOf="parent"
254 app:layout_constraintRight_toRightOf="parent" 254 app:layout_constraintRight_toRightOf="parent"
255 app:layout_constraintTop_toTopOf="parent"> 255 app:layout_constraintTop_toTopOf="parent">
256 256
257 <RelativeLayout 257 <RelativeLayout
258 android:layout_width="match_parent" 258 android:layout_width="match_parent"
259 android:layout_height="50dp"> 259 android:layout_height="50dp">
260 260
261 <TextView
262 android:layout_width="wrap_content"
263 android:layout_height="wrap_content"
264 android:layout_centerVertical="true"
265 android:layout_marginLeft="15dp"
266 android:text="我的老师"
267 android:textColor="#666666"
268 android:textSize="16dp" />
269 </RelativeLayout>
270
271 <RelativeLayout
272 android:id="@+id/rl_teacher"
273 android:layout_width="match_parent"
274 android:layout_height="35dp"
275 android:layout_marginBottom="15dp"
276 android:visibility="gone">
277
278 <ImageView
279 android:id="@+id/iv_teacher"
280 android:layout_width="35dp" 261 <TextView
281 android:layout_height="35dp" 262 android:layout_width="wrap_content"
282 android:layout_marginLeft="15dp" 263 android:layout_height="wrap_content"
283 android:src="@mipmap/ic_teacher_male" /> 264 android:layout_centerVertical="true"
284 265 android:layout_marginLeft="15dp"
285 <TextView 266 android:text="我的老师"
286 android:id="@+id/tv_teacher" 267 android:textColor="#666666"
287 android:layout_width="wrap_content" 268 android:textSize="16dp" />
288 android:layout_height="wrap_content" 269 </RelativeLayout>
289 android:layout_alignParentRight="true" 270
290 android:layout_centerVertical="true" 271 <RelativeLayout
291 android:layout_marginRight="15dp" 272 android:id="@+id/rl_teacher"
292 android:textColor="#999999" 273 android:layout_width="match_parent"
293 android:textSize="16dp" /> 274 android:layout_height="35dp"
294 </RelativeLayout> 275 android:layout_marginBottom="15dp"
295 </LinearLayout> 276 android:visibility="gone">
296 277
297 278 <ImageView
298 <Button 279 android:id="@+id/iv_teacher"
299 android:id="@+id/btn_next" 280 android:layout_width="35dp"
300 android:layout_width="180dp" 281 android:layout_height="35dp"
301 android:layout_height="40dp" 282 android:layout_marginLeft="15dp"
302 android:layout_marginTop="570dp" 283 android:src="@mipmap/ic_teacher_male" />
303 android:background="@drawable/bg_solid_btn_grad" 284
304 android:text="确认" 285 <TextView
305 android:textColor="#999999" 286 android:id="@+id/tv_teacher"
306 android:textSize="16dp" 287 android:layout_width="wrap_content"
307 app:layout_constraintLeft_toLeftOf="parent" 288 android:layout_height="wrap_content"
308 app:layout_constraintRight_toRightOf="parent" 289 android:layout_alignParentRight="true"
309 app:layout_constraintTop_toTopOf="parent" /> 290 android:layout_centerVertical="true"
310 291 android:layout_marginRight="15dp"
311 292 android:textColor="#999999"
312 </androidx.constraintlayout.widget.ConstraintLayout> 293 android:textSize="16dp" />
app/src/main/res/layout/activity_setac.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="#F4F6F8"> 6 android:background="#F4F6F8">
7 7
8 <View 8 <View
9 android:id="@+id/view_1" 9 android:id="@+id/view_1"
10 android:layout_width="match_parent" 10 android:layout_width="match_parent"
11 android:layout_height="44dp" 11 android:layout_height="44dp"
12 android:background="@android:color/white" 12 android:background="@android:color/white"
13 app:layout_constraintTop_toTopOf="parent" /> 13 app:layout_constraintTop_toTopOf="parent" />
14 14
15 <TextView 15 <TextView
16 android:layout_width="wrap_content" 16 android:layout_width="wrap_content"
17 android:layout_height="wrap_content" 17 android:layout_height="wrap_content"
18 android:text="账号设置" 18 android:text="账号设置"
19 android:textColor="#333333" 19 android:textColor="#333333"
20 android:textSize="18dp" 20 android:textSize="18dp"
21 app:layout_constraintBottom_toBottomOf="@id/view_1" 21 app:layout_constraintBottom_toBottomOf="@id/view_1"
22 app:layout_constraintLeft_toLeftOf="@id/view_1" 22 app:layout_constraintLeft_toLeftOf="@id/view_1"
23 app:layout_constraintRight_toRightOf="@id/view_1" 23 app:layout_constraintRight_toRightOf="@id/view_1"
24 app:layout_constraintTop_toTopOf="@id/view_1" /> 24 app:layout_constraintTop_toTopOf="@id/view_1" />
25 25
26 <ImageView 26 <ImageView
27 android:id="@+id/iv_back" 27 android:id="@+id/iv_back"
28 android:layout_width="10dp" 28 android:layout_width="10dp"
29 android:layout_height="16dp" 29 android:layout_height="16dp"
30 android:layout_marginLeft="15dp" 30 android:layout_marginLeft="15dp"
31 android:background="@mipmap/icon_back" 31 android:background="@mipmap/icon_back"
32 app:layout_constraintBottom_toBottomOf="@id/view_1" 32 app:layout_constraintBottom_toBottomOf="@id/view_1"
33 app:layout_constraintLeft_toLeftOf="parent" 33 app:layout_constraintLeft_toLeftOf="parent"
34 app:layout_constraintTop_toTopOf="@id/view_1" /> 34 app:layout_constraintTop_toTopOf="@id/view_1" />
35 35
36 <View 36 <View
37 android:layout_width="match_parent" 37 android:layout_width="match_parent"
38 android:layout_height="1dp" 38 android:layout_height="1dp"
39 android:background="#EEEEEE" 39 android:background="#EEEEEE"
40 app:layout_constraintTop_toBottomOf="@id/view_1" /> 40 app:layout_constraintTop_toBottomOf="@id/view_1" />
41 41
42 <View 42 <View
43 android:id="@+id/view_3" 43 android:id="@+id/view_3"
44 android:layout_width="match_parent" 44 android:layout_width="match_parent"
45 android:layout_height="80dp" 45 android:layout_height="80dp"
46 android:layout_marginLeft="15dp" 46 android:layout_marginLeft="15dp"
47 android:layout_marginTop="90dp" 47 android:layout_marginTop="90dp"
48 android:layout_marginRight="15dp" 48 android:layout_marginRight="15dp"
49 android:background="@drawable/bg_solid_white_10" 49 android:background="@drawable/bg_solid_white_10"
50 app:layout_constraintLeft_toLeftOf="parent" 50 app:layout_constraintLeft_toLeftOf="parent"
51 app:layout_constraintRight_toRightOf="parent" 51 app:layout_constraintRight_toRightOf="parent"
52 app:layout_constraintTop_toTopOf="parent" /> 52 app:layout_constraintTop_toTopOf="parent" />
53 53
54 <ImageView 54 <ImageView
55 android:id="@+id/iv_3" 55 android:id="@+id/iv_3"
56 android:layout_width="57dp" 56 android:layout_width="57dp"
57 android:layout_height="57dp" 57 android:layout_height="57dp"
58 android:layout_marginRight="31dp" 58 android:layout_marginRight="31dp"
59 android:background="@mipmap/ic_parent_avatar" 59 android:background="@mipmap/ic_parent_avatar"
60 app:layout_constraintBottom_toBottomOf="@id/view_3" 60 app:layout_constraintBottom_toBottomOf="@id/view_3"
61 app:layout_constraintRight_toRightOf="@id/view_3" 61 app:layout_constraintRight_toRightOf="@id/view_3"
62 app:layout_constraintTop_toTopOf="@id/view_3" /> 62 app:layout_constraintTop_toTopOf="@id/view_3" />
63 63
64 <TextView 64 <TextView
65 android:id="@+id/tv_3" 65 android:id="@+id/tv_3"
66 android:layout_width="wrap_content" 66 android:layout_width="wrap_content"
67 android:layout_height="wrap_content" 67 android:layout_height="wrap_content"
68 android:layout_marginLeft="15dp" 68 android:layout_marginLeft="15dp"
69 android:text="头像" 69 android:text="头像"
70 android:textColor="#333333" 70 android:textColor="#333333"
71 android:textSize="15dp" 71 android:textSize="15dp"
72 app:layout_constraintBottom_toBottomOf="@id/view_3" 72 app:layout_constraintBottom_toBottomOf="@id/view_3"
73 app:layout_constraintLeft_toLeftOf="@id/view_3" 73 app:layout_constraintLeft_toLeftOf="@id/view_3"
74 app:layout_constraintTop_toTopOf="@id/view_3" /> 74 app:layout_constraintTop_toTopOf="@id/view_3" />
75 75
76 <ImageView 76 <ImageView
77 android:layout_width="5.5dp" 77 android:layout_width="5.5dp"
78 android:layout_height="9.5dp" 78 android:layout_height="9.5dp"
79 android:layout_marginRight="15dp" 79 android:layout_marginRight="15dp"
80 android:background="@mipmap/ycaj" 80 android:background="@mipmap/ycaj"
81 app:layout_constraintBottom_toBottomOf="@id/view_3" 81 app:layout_constraintBottom_toBottomOf="@id/view_3"
82 app:layout_constraintRight_toRightOf="@id/view_3" 82 app:layout_constraintRight_toRightOf="@id/view_3"
83 app:layout_constraintTop_toTopOf="@id/view_3" /> 83 app:layout_constraintTop_toTopOf="@id/view_3" />
84 84
85 <View 85 <View
86 android:id="@+id/view_4" 86 android:id="@+id/view_4"
87 android:layout_width="match_parent" 87 android:layout_width="match_parent"
88 android:layout_height="90dp" 88 android:layout_height="52dp"
89 android:layout_marginLeft="15dp" 89 android:layout_marginLeft="15dp"
90 android:layout_marginTop="185dp" 90 android:layout_marginTop="185dp"
91 android:layout_marginRight="15dp" 91 android:layout_marginRight="15dp"
92 android:background="@drawable/bg_solid_white_10" 92 android:background="@drawable/bg_solid_white_10"
93 app:layout_constraintLeft_toLeftOf="parent" 93 app:layout_constraintLeft_toLeftOf="parent"
94 app:layout_constraintRight_toRightOf="parent" 94 app:layout_constraintRight_toRightOf="parent"
95 app:layout_constraintTop_toTopOf="parent" /> 95 app:layout_constraintTop_toTopOf="parent" />
96 96
97 <TextView 97 <TextView
98 android:id="@+id/tv_4" 98 android:id="@+id/tv_4"
99 android:layout_width="wrap_content" 99 android:layout_width="wrap_content"
100 android:layout_height="wrap_content" 100 android:layout_height="wrap_content"
101 android:layout_marginLeft="15dp" 101 android:layout_marginLeft="15dp"
102 android:layout_marginTop="15dp" 102 android:layout_marginTop="15dp"
103 android:text="账户" 103 android:text="账户"
104 android:textColor="#333333" 104 android:textColor="#333333"
105 android:textSize="15dp" 105 android:textSize="15dp"
106 app:layout_constraintLeft_toLeftOf="@id/view_4" 106 app:layout_constraintLeft_toLeftOf="@id/view_4"
107 app:layout_constraintTop_toTopOf="@id/view_4" /> 107 app:layout_constraintTop_toTopOf="@id/view_4" />
108 108
109 <TextView 109 <TextView
110 android:visibility="invisible"
110 android:id="@+id/tv_5" 111 android:id="@+id/tv_5"
111 android:layout_width="wrap_content" 112 android:layout_width="wrap_content"
112 android:layout_height="wrap_content" 113 android:layout_height="wrap_content"
113 android:layout_marginLeft="15dp" 114 android:layout_marginLeft="15dp"
114 android:layout_marginTop="60dp" 115 android:layout_marginTop="60dp"
115 android:text="密码" 116 android:text="密码"
116 android:textColor="#333333" 117 android:textColor="#333333"
117 android:textSize="15dp" 118 android:textSize="15dp"
118 app:layout_constraintLeft_toLeftOf="@id/view_4" 119 app:layout_constraintLeft_toLeftOf="@id/view_4"
119 app:layout_constraintTop_toTopOf="@id/view_4" /> 120 app:layout_constraintTop_toTopOf="@id/view_4" />
120 121
121 <TextView 122 <TextView
122 android:id="@+id/tv_6" 123 android:id="@+id/tv_6"
123 android:layout_width="wrap_content" 124 android:layout_width="wrap_content"
124 android:layout_height="wrap_content" 125 android:layout_height="wrap_content"
125 android:layout_marginTop="15dp" 126 android:layout_marginTop="15dp"
126 android:layout_marginRight="15dp" 127 android:layout_marginRight="15dp"
127 android:text="123" 128 android:text="123"
128 android:textColor="#666666" 129 android:textColor="#666666"
129 android:textSize="15dp" 130 android:textSize="15dp"
130 app:layout_constraintRight_toRightOf="@id/view_4" 131 app:layout_constraintRight_toRightOf="@id/view_4"
131 app:layout_constraintTop_toTopOf="@id/view_4" /> 132 app:layout_constraintTop_toTopOf="@id/view_4" />
132 133
133 <ImageView 134 <ImageView
135 android:visibility="invisible"
134 android:layout_width="5.5dp" 136 android:layout_width="5.5dp"
135 android:layout_height="9.5dp" 137 android:layout_height="9.5dp"
136 android:layout_marginRight="15dp" 138 android:layout_marginRight="15dp"
137 android:background="@mipmap/ycaj" 139 android:background="@mipmap/ycaj"
138 app:layout_constraintBottom_toBottomOf="@id/tv_7" 140 app:layout_constraintBottom_toBottomOf="@id/tv_7"
139 app:layout_constraintRight_toRightOf="@id/view_4" 141 app:layout_constraintRight_toRightOf="@id/view_4"
140 app:layout_constraintTop_toTopOf="@id/tv_7" /> 142 app:layout_constraintTop_toTopOf="@id/tv_7" />
141 143
142 <TextView 144 <TextView
145 android:visibility="invisible"
143 android:id="@+id/tv_7" 146 android:id="@+id/tv_7"
144 android:layout_width="wrap_content" 147 android:layout_width="wrap_content"
145 android:layout_height="wrap_content" 148 android:layout_height="wrap_content"
146 android:layout_marginTop="60dp" 149 android:layout_marginTop="60dp"
147 android:layout_marginRight="31dp" 150 android:layout_marginRight="31dp"
148 android:text="已设置" 151 android:text="已设置"
149 android:textColor="#666666" 152 android:textColor="#666666"
150 android:textSize="15dp" 153 android:textSize="15dp"
151 app:layout_constraintRight_toRightOf="@id/view_4" 154 app:layout_constraintRight_toRightOf="@id/view_4"
152 app:layout_constraintTop_toTopOf="@id/view_4" /> 155 app:layout_constraintTop_toTopOf="@id/view_4" />
153 156
154 <Button 157 <Button
155 android:id="@+id/logout" 158 android:id="@+id/logout"
156 android:layout_width="315dp" 159 android:layout_width="315dp"
157 android:layout_height="50dp" 160 android:layout_height="50dp"
158 android:layout_marginBottom="120dp" 161 android:layout_marginBottom="120dp"
159 android:background="@drawable/bg_solid_btn" 162 android:background="@drawable/bg_solid_btn"
160 android:text="退出登录" 163 android:text="退出登录"
161 android:textColor="@color/white" 164 android:textColor="@color/white"
162 android:textSize="18dp" 165 android:textSize="18dp"
163 app:layout_constraintBottom_toBottomOf="parent" 166 app:layout_constraintBottom_toBottomOf="parent"
164 app:layout_constraintLeft_toLeftOf="parent" 167 app:layout_constraintLeft_toLeftOf="parent"
165 app:layout_constraintRight_toRightOf="parent" /> 168 app:layout_constraintRight_toRightOf="parent" />
166 </androidx.constraintlayout.widget.ConstraintLayout> 169 </androidx.constraintlayout.widget.ConstraintLayout>
libs/common/src/main/java/com/prws/common/bean/User.java
1 package com.prws.common.bean; 1 package com.prws.common.bean;
2 2
3 import java.util.ArrayList;
4
3 import java.util.ArrayList; 5 public class User {
4 6
5 public class User { 7 public String id;
6 8 public String phone;
7 public String id; 9 public String account;
8 public String phone; 10 public String password;
9 public String account; 11 public String username;
10 public String password; 12 public String identity; //用户身份(NORMAL,ADMIN,EMPLOYEE)
11 public String username; 13 public String identityName; //用户身份(普通用户、管理员、内部员工)
12 public String identity; //用户身份(NORMAL,ADMIN,EMPLOYEE) 14 public String gender; //性别
13 public String identityName; //用户身份(普通用户、管理员、内部员工) 15 public String registration; //注册方式(用户创建、员工创建)
16 public ArrayList<Student> parentInfoList;
14 public String gender; //性别 17 public String token;
15 public String registration; //注册方式(用户创建、员工创建) 18 }
16 public ArrayList<Student> parentInfoList; 19
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.User;
17 import com.prws.common.bean.baidu.BaiduInput; 17 import com.prws.common.bean.baidu.BaiduInput;
18 import com.prws.common.bean.homework.HomeWork; 18 import com.prws.common.bean.homework.HomeWork;
19 import com.prws.common.bean.homework.HomeworkDetail; 19 import com.prws.common.bean.homework.HomeworkDetail;
20 import com.prws.common.bean.homework.HomeworkList; 20 import com.prws.common.bean.homework.HomeworkList;
21 import com.prws.common.bean.homework.StDetail; 21 import com.prws.common.bean.homework.StDetail;
22 import com.prws.common.utils.BitmapUtils; 22 import com.prws.common.utils.BitmapUtils;
23 import com.prws.common.utils.SharedPreferencesUtil; 23 import com.prws.common.utils.SharedPreferencesUtil;
24 24
25 import java.io.File; 25 import java.io.File;
26 import java.util.HashMap; 26 import java.util.HashMap;
27 import java.util.List; 27 import java.util.List;
28 import java.util.Map; 28 import java.util.Map;
29 29
30 import io.reactivex.Observable; 30 import io.reactivex.Observable;
31 import io.reactivex.Observer; 31 import io.reactivex.Observer;
32 import io.reactivex.Single; 32 import io.reactivex.Single;
33 import io.reactivex.android.schedulers.AndroidSchedulers; 33 import io.reactivex.android.schedulers.AndroidSchedulers;
34 import io.reactivex.schedulers.Schedulers; 34 import io.reactivex.schedulers.Schedulers;
35 import okhttp3.MediaType; 35 import okhttp3.MediaType;
36 import okhttp3.MultipartBody; 36 import okhttp3.MultipartBody;
37 import okhttp3.RequestBody; 37 import okhttp3.RequestBody;
38 import okhttp3.ResponseBody; 38 import okhttp3.ResponseBody;
39 import retrofit2.Call; 39 import retrofit2.Call;
40 import retrofit2.Callback; 40 import retrofit2.Callback;
41 import retrofit2.http.Body; 41 import retrofit2.http.Body;
42 import retrofit2.http.GET; 42 import retrofit2.http.GET;
43 import retrofit2.http.Header; 43 import retrofit2.http.Header;
44 import retrofit2.http.Headers; 44 import retrofit2.http.Headers;
45 import retrofit2.http.Multipart; 45 import retrofit2.http.Multipart;
46 import retrofit2.http.POST; 46 import retrofit2.http.POST;
47 import retrofit2.http.PUT; 47 import retrofit2.http.PUT;
48 import retrofit2.http.Part; 48 import retrofit2.http.Part;
49 import retrofit2.http.PartMap; 49 import retrofit2.http.PartMap;
50 import retrofit2.http.Query; 50 import retrofit2.http.Query;
51 import retrofit2.http.Url; 51 import retrofit2.http.Url;
52 52
53 /** 53 /**
54 * 类名称:NetWorks 54 * 类名称:NetWorks
55 * 创建人: 55 * 创建人:
56 * <p> 56 * <p>
57 * 类描述:网络请求的操作类 57 * 类描述:网络请求的操作类
58 */ 58 */
59 public class NetWorks extends RetrofitUtils { 59 public class NetWorks extends RetrofitUtils {
60 //服务器路径 60 //服务器路径
61 public static final NetService service_url = getMachineRetrofit("https://mgr.hjx.com").create(NetService.class); 61 public static final NetService service_url = getMachineRetrofit("https://mgr.hjx.com").create(NetService.class);
62 62
63 //设缓存有效期为1天 63 //设缓存有效期为1天
64 protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; 64 protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1;
65 //查询缓存的Cache-Control设置,使用缓存 65 //查询缓存的Cache-Control设置,使用缓存
66 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;
67 //查询网络的Cache-Control设置。不使用缓存 67 //查询网络的Cache-Control设置。不使用缓存
68 protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; 68 protected static final String CACHE_CONTROL_NETWORK = "max-age=0";
69 69
70 70
71 public interface NetService { 71 public interface NetService {
72 72
73 73
74 @GET("/api/v1/user/logout") 74 @GET("/api/v1/user/logout")
75 Observable<ResponseBody> logout(); 75 Observable<ResponseBody> logout();
76 76
77 @Multipart 77 @Multipart
78 @POST("/api/v1/user/upLoadAvatar") 78 @POST("/api/v1/user/upLoadAvatar")
79 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);
80 80
81 81
82 @Headers("Content-Type: application/json") 82 @Headers("Content-Type: application/json")
83 @POST("/api/v1/user/editUser") 83 @POST("/api/v1/user/editUser")
84 Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); 84 Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body);
85 85
86 @Headers("Content-Type: application/json") 86 @Headers("Content-Type: application/json")
87 @POST("/api/v1/user/changePassword") 87 @POST("/api/v1/user/changePassword")
88 Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); 88 Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body);
89 89
90 90
91 @GET("/api/v1/user/searchById") 91 @GET("/api/v1/user/searchById")
92 Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); 92 Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId);
93 93
94 94
95 @Headers("Content-Type: application/json") 95 @Headers("Content-Type: application/json")
96 @POST("/api/v1/login/userLogin") 96 @POST("/api/v1/login/userLogin")
97 Observable<ResponseBody> login(@Body RequestBody body); 97 Observable<ResponseBody> login(@Body RequestBody body);
98 98
99 @GET("/api/v1/resource/listGradeAndSubject") 99 @GET("/api/v1/resource/listGradeAndSubject")
100 Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); 100 Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token);
101 101
102 102
103 @GET("/api/v1/manager/generalQrCode") 103 @GET("/api/v1/manager/generalQrCode")
104 Observable<ResponseBody> generalQrCode(); 104 Observable<ResponseBody> generalQrCode();
105 105
106 @GET("/api/v1/parent/scanAndLogin") 106 @GET("/api/v1/parent/scanAndLogin")
107 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);
108 108
109 @GET("/api/v1/parent/getChildrenList") 109 @GET("/api/v1/parent/getChildrenList")
110 Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); 110 Observable<ResponseBody> getChildrenList(@Header("Authorization") String token);
111 111
112 112
113 @Headers("Content-Type: application/json") 113 @Headers("Content-Type: application/json")
114 @POST("/api/v1/parent/registerParent") 114 @POST("/api/v1/parent/registerParent")
115 Observable<ResponseBody> registerParent(@Body RequestBody body); 115 Observable<ResponseBody> registerParent(@Body RequestBody body);
116 116
117 117
118 @GET("/api/v1/parent/listChildren") 118 @GET("/api/v1/parent/listChildren")
119 Observable<ResponseBody> listChildren(@Header("Authorization") String token); 119 Observable<ResponseBody> listChildren(@Header("Authorization") String token);
120 120
121 121
122 @Headers("Content-Type: application/json") 122 @Headers("Content-Type: application/json")
123 @POST("/api/v1/parent/registerStudent") 123 @POST("/api/v1/parent/registerStudent")
124 Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); 124 Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body);
125 125
126 @Headers("Content-Type: application/json") 126 @Headers("Content-Type: application/json")
127 @POST("/api/v1/parent/bindTeacher") 127 @POST("/api/v1/parent/bindTeacher")
128 Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); 128 Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body);
129 129
130 @Multipart 130 @Multipart
131 @POST("/api/v1/user/upLoadAvatar") 131 @POST("/api/v1/user/upLoadAvatar")
132 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);
133 133
134 134
135 @Multipart 135 @Multipart
136 @POST("/api/v1/student/editStudentAvatar") 136 @POST("/api/v1/student/editStudentAvatar")
137 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);
138 138
139 @Headers("Content-Type: application/json") 139 @Headers("Content-Type: application/json")
140 @POST("/api/v1/parent/editChild") 140 @POST("/api/v1/parent/editChild")
141 Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); 141 Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body);
142 142
143 @GET("/api/v1/student/getStudyPlanForThisWeek") 143 @GET("/api/v1/student/getStudyPlanForThisWeek")
144 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);
145 145
146 @GET("api/v1/parent/searchTeacher") 146 @GET("api/v1/parent/searchTeacher")
147 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);
148 148
149 @POST("api/v1/question/listErrorBook") 149 @POST("api/v1/question/listErrorBook")
150 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);
151 151
152 @POST 152 @POST
153 Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); 153 Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body);
154 154
155 @POST 155 @POST
156 Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); 156 Observable<CutPicBean> cut(@Url String url, @Body RequestBody body);
157 157
158 @POST 158 @POST
159 Observable<JsonObject> getBaiduToken(@Url String url); 159 Observable<JsonObject> getBaiduToken(@Url String url);
160 160
161 @Multipart 161 @Multipart
162 @POST("api/v1/pad/addErrorBook") 162 @POST("api/v1/pad/addErrorBook")
163 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);
164 164
165 @POST("api/v1/pad/deleteStuErrorBook") 165 @POST("api/v1/pad/deleteStuErrorBook")
166 Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); 166 Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map);
167 167
168 @PUT("api/v1/pad/updateStuErrorBookInfo") 168 @PUT("api/v1/pad/updateStuErrorBookInfo")
169 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);
170 170
171 @POST("api/v1/question/editErrorBook") 171 @POST("api/v1/question/editErrorBook")
172 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);
173 173
174 @GET("api/v1/resource/checkUpdate") 174 @GET("api/v1/resource/checkUpdate")
175 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);
176 176
177 @GET("api/v1/teacher/getStudentList") 177 @GET("api/v1/teacher/getStudentList")
178 Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); 178 Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id);
179 179
180 @GET("api/v1/teacher/getStudentList") 180 @GET("api/v1/teacher/getStudentList")
181 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);
182 182
183 @GET("api/v1/answer/listRecordForTeacher") 183 @GET("api/v1/answer/listRecordForTeacher")
184 Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); 184 Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id);
185 185
186 @GET("api/v1/homework/listHomeworkByStuId") 186 @GET("api/v1/homework/listHomeworkByStuId")
187 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);
188 188
189 @POST 189 @POST
190 Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body); 190 Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body);
191 191
192 @Multipart 192 @Multipart
193 @POST("api/v1/homework/uploadHomework") 193 @POST("api/v1/homework/uploadHomework")
194 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);
195 195
196 @POST("api/v1/homework/uploadHomeworkAction") 196 @POST("api/v1/homework/uploadHomeworkAction")
197 Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map); 197 Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map);
198 198
199 @GET("api/v1/homework/removeHomework") 199 @GET("api/v1/homework/removeHomework")
200 Single<ResponseResult<Boolean>> deleteHomework( 200 Single<ResponseResult<Boolean>> deleteHomework(
201 @Header("Authorization") String token, 201 @Header("Authorization") String token,
202 @Query("homeworkId") String homeworkId 202 @Query("homeworkId") String homeworkId
203 ); 203 );
204 204
205 @GET("api/v1/homework/listHomeworkById") 205 @GET("api/v1/homework/listHomeworkById")
206 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);
207 207
208 @POST("api/v1/homework/uploadHomeworkFeedback") 208 @POST("api/v1/homework/uploadHomeworkFeedback")
209 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);
210 210
211 @POST("api/v1/homework/editHomeworkInfo") 211 @POST("api/v1/homework/editHomeworkInfo")
212 Single<ResponseResult<Boolean>> editHomework( 212 Single<ResponseResult<Boolean>> editHomework(
213 @Header("Authorization") String token, 213 @Header("Authorization") String token,
214 @Body Object body 214 @Body Object body
215 ); 215 );
216 216
217 @GET("api/v1/homework/listHomeworkDetailByStuId") 217 @GET("api/v1/homework/listHomeworkDetailByStuId")
218 Single<ResponseResult<HomeworkDetail>> getHomeworkCompleteDetail( 218 Single<ResponseResult<HomeworkDetail>> getHomeworkCompleteDetail(
219 @Header("Authorization") String token, 219 @Header("Authorization") String token,
220 @Query("stuId") String stuId, 220 @Query("stuId") String stuId,
221 @Query("homeworkId") String homeworkId, 221 @Query("homeworkId") String homeworkId,
222 // type 固定传true 222 // type 固定传true
223 @Query("type") boolean type 223 @Query("type") boolean type
224 ); 224 );
225 225
226 @GET("api/v1/homework/listHomeworkStatistics") 226 @GET("api/v1/homework/listHomeworkStatistics")
227 Single<ResponseResult<List<StDetail>>> getHuyouList( 227 Single<ResponseResult<List<StDetail>>> getHuyouList(
228 @Header("Authorization") String token, 228 @Header("Authorization") String token,
229 @Query("stuId") String stuId, 229 @Query("stuId") String stuId,
230 @Query("type") int type //0: 周报, 1:阶段总结 230 @Query("type") int type //0: 周报, 1:阶段总结
231 ); 231 );
232 232
233 @GET("api/v1/homework/listHomeworkStatisticsDetailForStudent") 233 @GET("api/v1/homework/listHomeworkStatisticsDetailForStudent")
234 Single<ResponseResult<StDetail>> getHuyouDetail( 234 Single<ResponseResult<StDetail>> getHuyouDetail(
235 @Header("Authorization") String token, 235 @Header("Authorization") String token,
236 @Query("homeworkStatisticsId") String homeworkId 236 @Query("homeworkStatisticsId") String homeworkId
237 ); 237 );
238 238
239 @GET("api/v1/demo/generalStatisticsHomework") 239 @GET("api/v1/demo/generalStatisticsHomework")
240 Single<ResponseResult<Object>> generalHuyou(); 240 Single<ResponseResult<Object>> generalHuyou();
241 241
242 @POST("api/v1/homework/generalHomeworkStageStatistics") 242 @POST("api/v1/homework/generalHomeworkStageStatistics")
243 Single<ResponseResult<Boolean>> generalStageHuyou( 243 Single<ResponseResult<Boolean>> generalStageHuyou(
244 @Header("Authorization") String token, 244 @Header("Authorization") String token,
245 @Body Object body 245 @Body Object body
246 ); 246 );
247 247
248 @GET("api/v1/homework/removeHomeworkStatistics") 248 @GET("api/v1/homework/removeHomeworkStatistics")
249 Single<ResponseResult<Boolean>> deleteHuyou( 249 Single<ResponseResult<Boolean>> deleteHuyou(
250 @Header("Authorization") String token, 250 @Header("Authorization") String token,
251 @Query("homeworkStatisticsId") String homeworkId 251 @Query("homeworkStatisticsId") String homeworkId
252 ); 252 );
253 253
254 @GET("api/v1/login/smsCode") 254 @GET("api/v1/login/smsCode")
255 Single<ResponseResult<String>> smsCode(@Query("mobile") String mobile); 255 Single<ResponseResult<String>> smsCode(@Query("mobile") String mobile);
256 256
257 @POST("api/v1/login/smsLogin") 257 @POST("api/v1/login/smsLogin")
258 Single<ResponseResult<User>> smsLogin(@Body Object body); 258 Single<ResponseResult<User>> smsLogin(@Body Object body);
259 259
260 } 260 }
261 261
262 public static String getUserId() { 262 public static String getUserId() {
263 return (String) SharedPreferencesUtil.getData("userId", ""); 263 return (String) SharedPreferencesUtil.getData("userId", "");
264 } 264 }
265 265
266 public static String getHeader() { 266 public static String getHeader() {
267 return (String) SharedPreferencesUtil.getData("token", ""); 267 return (String) SharedPreferencesUtil.getData("token", "");
268 } 268 }
269 269
270 public static String getBaiduToken() { 270 public static String getBaiduToken() {
271 return (String) SharedPreferencesUtil.getData("baiduToken", ""); 271 return (String) SharedPreferencesUtil.getData("baiduToken", "");
272 } 272 }
273 273
274 public static Single<BaiduInput> inputImage(String filePath, String id) { 274 public static Single<BaiduInput> inputImage(String filePath, String id) {
275 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); 275 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
276 String base64 = BitmapUtils.fileToBase64(filePath); 276 String base64 = BitmapUtils.fileToBase64(filePath);
277 File file = new File(filePath); 277 File file = new File(filePath);
278 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 + "\"}");
279 return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) 279 return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString())
280 .flatMap(token -> { 280 .flatMap(token -> {
281 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);
282 }); 282 });
283 } 283 }
284 284
285 public static Single<ResponseResult> uploadImage(String path, String id) { 285 public static Single<ResponseResult> uploadImage(String path, String id) {
286 File file = new File(path); 286 File file = new File(path);
287 RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); 287 RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file);
288 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); 288 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
289 return service_url.uploadImage(getHeader(), part, id); 289 return service_url.uploadImage(getHeader(), part, id);
290 } 290 }
291 291
292 292
293 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) {
294 service_url.checkUpdate(code, packageName, 0).enqueue(callback); 294 service_url.checkUpdate(code, packageName, 0).enqueue(callback);
295 } 295 }
296 296
297 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) {
298 File file = new File(path); 298 File file = new File(path);
299 RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); 299 RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file);
300 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); 300 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
301 Map<String, Object> map = new HashMap<>(); 301 Map<String, Object> map = new HashMap<>();
302 map.put("condition", param); 302 map.put("condition", param);
303 setSubscribe(service_url.addError(part, map), observer); 303 setSubscribe(service_url.addError(part, map), observer);
304 } 304 }
305 305
306 306
307 public static void cut(String base64, Observer<CutPicBean> observer) { 307 public static void cut(String base64, Observer<CutPicBean> observer) {
308 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); 308 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
309 RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); 309 RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true");
310 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);
311 } 311 }
312 312
313 public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { 313 public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) {
314 setSubscribe(service_url.editError(getHeader(), map), observer); 314 setSubscribe(service_url.editError(getHeader(), map), observer);
315 } 315 }
316 316
317 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) {
318 setSubscribe(service_url.updateError(getHeader(), map), observer); 318 setSubscribe(service_url.updateError(getHeader(), map), observer);
319 } 319 }
320 320
321 public static void deleteError(List<String> map, Observer<ResponseResult> observer) { 321 public static void deleteError(List<String> map, Observer<ResponseResult> observer) {
322 setSubscribe(service_url.deleteError(getHeader(), map), observer); 322 setSubscribe(service_url.deleteError(getHeader(), map), observer);
323 } 323 }
324 324
325 public static void getBaiduToken(Observer<JsonObject> observer) { 325 public static void getBaiduToken(Observer<JsonObject> 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); 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);
327 } 327 }
328 328
329 public static Single<JsonObject> getBaiduTokenOcr() { 329 public static Single<JsonObject> getBaiduTokenOcr() {
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(); 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();
331 } 331 }
332 332
333 public static void removeWriting(String base64, Observer<JsonObject> observer) { 333 public static void removeWriting(String base64, Observer<JsonObject> observer) {
334 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); 334 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
335 RequestBody body = RequestBody.create(mediaType, "image=" + base64); 335 RequestBody body = RequestBody.create(mediaType, "image=" + base64);
336 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);
337 } 337 }
338 338
339 public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { 339 public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) {
340 setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); 340 setSubscribe(service_url.searchTeacher(getHeader(), phone), observer);
341 } 341 }
342 342
343 public static void logout(Observer<ResponseBody> observer) { 343 public static void logout(Observer<ResponseBody> observer) {
344 setSubscribe(service_url.logout(), observer); 344 setSubscribe(service_url.logout(), observer);
345 } 345 }
346 346
347 public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { 347 public static void editStudent(RequestBody body, Observer<ResponseResult> observable) {
348 setSubscribe(service_url.editStudent(getHeader(), body), observable); 348 setSubscribe(service_url.editStudent(getHeader(), body), observable);
349 } 349 }
350 350
351 public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { 351 public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) {
352 setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); 352 setSubscribe(service_url.getWeekPlan(getHeader(), id), observer);
353 } 353 }
354 354
355 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) {
356 RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); 356 RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
357 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); 357 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
358 Map<String, Object> map = new HashMap<>(); 358 Map<String, Object> map = new HashMap<>();
359 map.put("stuId", stuId); 359 map.put("stuId", stuId);
360 setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); 360 setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer);
361 } 361 }
362 362
363 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) {
364 RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); 364 RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
365 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); 365 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
366 setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); 366 setSubscribe(service_url.uploadAvatar(getHeader(), part), observer);
367 } 367 }
368 368
369 public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { 369 public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) {
370 setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); 370 setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer);
371 } 371 }
372 372
373 373
374 public static void editUser(RequestBody body, Observer<ResponseBody> observer) { 374 public static void editUser(RequestBody body, Observer<ResponseBody> observer) {
375 setSubscribe(service_url.editUser(getHeader(), body), observer); 375 setSubscribe(service_url.editUser(getHeader(), body), observer);
376 } 376 }
377 377
378 public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { 378 public static void changePassword(RequestBody body, Observer<ResponseBody> observer) {
379 setSubscribe(service_url.changePassword(getHeader(), body), observer); 379 setSubscribe(service_url.changePassword(getHeader(), body), observer);
380 } 380 }
381 381
382 382
383 public static void searchById(String userId, Observer<ResponseBody> observer) { 383 public static void searchById(String userId, Observer<ResponseBody> observer) {
384 setSubscribe(service_url.searchById(getHeader(), userId), observer); 384 setSubscribe(service_url.searchById(getHeader(), userId), observer);
385 } 385 }
386 386
387 387
388 public static void login(RequestBody body, Observer<ResponseBody> observer) { 388 public static void login(RequestBody body, Observer<ResponseBody> observer) {
389 setSubscribe(service_url.login(body), observer); 389 setSubscribe(service_url.login(body), observer);
390 } 390 }
391 391
392 public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { 392 public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) {
393 setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); 393 setSubscribe(service_url.listGradeAndSubject(getHeader()), observer);
394 } 394 }
395 395
396 396
397 public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { 397 public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) {
398 setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); 398 setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer);
399 } 399 }
400 400
401 public static void getChildrenList(Observer<ResponseBody> observer) { 401 public static void getChildrenList(Observer<ResponseBody> observer) {
402 setSubscribe(service_url.getChildrenList(getHeader()), observer); 402 setSubscribe(service_url.getChildrenList(getHeader()), observer);
403 } 403 }
404 404
405 405
406 public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { 406 public static void registerParent(RequestBody body, Observer<ResponseBody> observer) {
407 setSubscribe(service_url.registerParent(body), observer); 407 setSubscribe(service_url.registerParent(body), observer);
408 } 408 }
409 409
410 410
411 public static void listChildren(Observer<ResponseBody> observer) { 411 public static void listChildren(Observer<ResponseBody> observer) {
412 setSubscribe(service_url.listChildren(getHeader()), observer); 412 setSubscribe(service_url.listChildren(getHeader()), observer);
413 } 413 }
414 414
415 public static void listStudent(Observer<ResponseBody> observer) { 415 public static void listStudent(Observer<ResponseBody> observer) {
416 setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); 416 setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer);
417 } 417 }
418 418
419 public static Single<ResponseResult<List<Student>>> listStudent() { 419 public static Single<ResponseResult<List<Student>>> listStudent() {
420 return service_url.getStudentList2(getHeader(), getUserId()); 420 return service_url.getStudentList2(getHeader(), getUserId());
421 } 421 }
422 422
423 public static void listRecord(Observer<ResponseBody> observer) { 423 public static void listRecord(Observer<ResponseBody> observer) {
424 setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); 424 setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer);
425 } 425 }
426 426
427 427
428 public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { 428 public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) {
429 setSubscribe(service_url.registerStudent(getHeader(), body), observer); 429 setSubscribe(service_url.registerStudent(getHeader(), body), observer);
430 } 430 }
431 431
432 public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { 432 public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) {
433 setSubscribe(service_url.bindTeacher(getHeader(), body), observer); 433 setSubscribe(service_url.bindTeacher(getHeader(), body), observer);
434 } 434 }
435 435
436 public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { 436 public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) {
437 setSubscribe(service_url.getError(getHeader(), map), observer); 437 setSubscribe(service_url.getError(getHeader(), map), observer);
438 } 438 }
439 439
440 440
441 public static RequestBody getMapRequestBody(Map map) { 441 public static RequestBody getMapRequestBody(Map map) {
442 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); 442 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map));
443 } 443 }
444 444
445 445
446 public static RequestBody getArrayRequestBody(List list) { 446 public static RequestBody getArrayRequestBody(List list) {
447 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); 447 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list));
448 } 448 }
449 449
450 public static RequestBody getFileRequestBody(File file) { 450 public static RequestBody getFileRequestBody(File file) {
451 return RequestBody.create(MediaType.parse("application/octet-stream"), file); 451 return RequestBody.create(MediaType.parse("application/octet-stream"), file);
452 } 452 }
453 453
454 public static RequestBody getFileRequestBody(byte[] bytes) { 454 public static RequestBody getFileRequestBody(byte[] bytes) {
455 return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); 455 return RequestBody.create(MediaType.parse("multipart/form-data"), bytes);
456 } 456 }
457 457
458 public static RequestBody getObjectRequestBody(Object obj) { 458 public static RequestBody getObjectRequestBody(Object obj) {
459 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); 459 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj));
460 } 460 }
461 461
462 public static RequestBody getStringRequestBody(String str) { 462 public static RequestBody getStringRequestBody(String str) {
463 return RequestBody.create(MediaType.parse("text/plain"), str); 463 return RequestBody.create(MediaType.parse("text/plain"), str);
464 } 464 }
465 465
466 466
467 /** 467 /**
468 * 插入观察者 468 * 插入观察者
469 * 469 *
470 * @param observable 470 * @param observable
471 * @param observer 471 * @param observer
472 * @param <T> 472 * @param <T>
473 */ 473 */
474 public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { 474 public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) {
475 observable.subscribeOn(Schedulers.io())//子线程访问网络 475 observable.subscribeOn(Schedulers.io())//子线程访问网络
476 .observeOn(AndroidSchedulers.mainThread())//回调到主线程 476 .observeOn(AndroidSchedulers.mainThread())//回调到主线程
477 .subscribe(observer); 477 .subscribe(observer);
478 } 478 }
479 479
480 } 480 }
481 481