Commit 06daaf123b5d0629ed8c83516721632eb2b5bf8d

Authored by shixianjie
1 parent 8d5120ae75
Exists in master

编辑作业

app/src/main/java/com/hjx/parent/HomeworkDetailActivity.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.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 10
11 import com.bumptech.glide.Glide; 11 import com.bumptech.glide.Glide;
12 import com.chad.library.adapter.base.BaseQuickAdapter; 12 import com.chad.library.adapter.base.BaseQuickAdapter;
13 import com.chad.library.adapter.base.BaseViewHolder; 13 import com.chad.library.adapter.base.BaseViewHolder;
14 import com.hjx.parent.databinding.ActivityHomeworkDetailBinding; 14 import com.hjx.parent.databinding.ActivityHomeworkDetailBinding;
15 import com.hjx.parent.dialog.EditHomeworkDialog;
15 import com.hjx.parent.rx.BaseRxActivity; 16 import com.hjx.parent.rx.BaseRxActivity;
16 import com.prws.common.bean.ResponseResult; 17 import com.prws.common.bean.ResponseResult;
17 import com.prws.common.bean.Student; 18 import com.prws.common.bean.Student;
18 import com.prws.common.bean.homework.HomeWork; 19 import com.prws.common.bean.homework.HomeWork;
19 import com.prws.common.bean.homework.HomeworkList; 20 import com.prws.common.bean.homework.HomeworkList;
20 import com.prws.common.net.NetWorks; 21 import com.prws.common.net.NetWorks;
21 22
22 import java.util.ArrayList; 23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.Map;
23 26
24 public class HomeworkDetailActivity extends BaseRxActivity<ActivityHomeworkDetailBinding> { 27 public class HomeworkDetailActivity extends BaseRxActivity<ActivityHomeworkDetailBinding> {
25 28
26 private HomeworkList mData; 29 private HomeworkList mData;
27 private Student student; 30 private Student student;
28 31
29 private Adapter mAdapter = new Adapter(); 32 private Adapter mAdapter = new Adapter();
33 private EditHomeworkDialog mDialog;
30 34
31 @Override 35 @Override
32 public void initView(Bundle savedInstanceState) { 36 public void initView(Bundle savedInstanceState) {
33 binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); 37 binding.toolbar.setNavigationOnClickListener(v -> onBackPressed());
34 mData = (HomeworkList) getIntent().getSerializableExtra("data"); 38 mData = (HomeworkList) getIntent().getSerializableExtra("data");
35 student = (Student) getIntent().getSerializableExtra("student"); 39 student = (Student) getIntent().getSerializableExtra("student");
40 mDialog = new EditHomeworkDialog(this, mData);
36 binding.tvTitle.setText(mData.getName()); 41 binding.tvTitle.setText(mData.getName());
37 42
38 binding.recyclerView.setAdapter(mAdapter); 43 binding.recyclerView.setAdapter(mAdapter);
39 getDetail(); 44 getDetail();
40 45
41 binding.btnFeedback.setOnClickListener(v -> { 46 binding.btnFeedback.setOnClickListener(v -> {
42 if (mAdapter.getData().size() == 0) return; 47 if (mAdapter.getData().size() == 0) return;
43 Intent intent = new Intent(this, HomeworkSelectActivity.class); 48 Intent intent = new Intent(this, HomeworkSelectActivity.class);
44 intent.putExtra("data", mData); 49 intent.putExtra("data", mData);
45 intent.putExtra("student", student); 50 intent.putExtra("student", student);
46 intent.putExtra("list", new ArrayList<>(mAdapter.getData())); 51 intent.putExtra("list", new ArrayList<>(mAdapter.getData()));
47 startActivity(intent); 52 startActivity(intent);
48 }); 53 });
54 binding.btnEdit.setOnClickListener(v -> mDialog.show(data -> {
55 edit(data);
56 }));
49 } 57 }
50 58
51 @SuppressLint("CheckResult") 59 @SuppressLint("CheckResult")
52 private void getDetail() { 60 private void getDetail() {
53 NetWorks.service_url.getHomeworkDetail(NetWorks.getHeader(), mData.getId()) 61 NetWorks.service_url.getHomeworkDetail(NetWorks.getHeader(), mData.getId())
54 .compose(transformSingle()) 62 .compose(transformSingle())
55 .map(ResponseResult::getData) 63 .map(ResponseResult::getData)
56 .subscribe((list, th) -> { 64 .subscribe((list, th) -> {
57 if (th != null) th.printStackTrace(); 65 if (th != null) th.printStackTrace();
58 mAdapter.setNewData(list); 66 mAdapter.setNewData(list);
59 }); 67 });
60 } 68 }
61 69
70 @SuppressLint("CheckResult")
71 private void edit(HomeworkList data) {
72 Map<String, Object> body = new HashMap<>();
73 body.put("homeworkId", data.getId());
74 body.put("name", data.getName());
75 body.put("grade", data.getGrade());
76 body.put("subject", data.getSubject());
77 body.put("term", data.getTerm());
78 body.put("uploadTime", data.uploadTime);
79 showLoadingDialog("请稍等···");
80 NetWorks.service_url.editHomework(NetWorks.getHeader(), body)
81 .compose(transformSingle())
82 .subscribe((response, th) -> {
83 if (th != null) th.printStackTrace();
84 if (response != null && response.getSuccess()) {
85 cancelLoadingDialog();
86 binding.tvTitle.setText(data.getName());
87 } else {
88 loadFail(response == null ? "" : response.getMsg());
89 }
90 });
91 }
92
62 @Override 93 @Override
63 protected ActivityHomeworkDetailBinding getViewBinding() { 94 protected ActivityHomeworkDetailBinding getViewBinding() {
64 return ActivityHomeworkDetailBinding.inflate(getLayoutInflater()); 95 return ActivityHomeworkDetailBinding.inflate(getLayoutInflater());
65 } 96 }
66 97
67 static class Adapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { 98 static class Adapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> {
68 99
69 public Adapter() { 100 public Adapter() {
70 super(R.layout.item_homework_detail); 101 super(R.layout.item_homework_detail);
71 } 102 }
72 103
73 @SuppressLint("SetTextI18n") 104 @SuppressLint("SetTextI18n")
74 @Override 105 @Override
75 protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { 106 protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) {
76 TextView tvNumber = holder.getView(R.id.tvNumber); 107 TextView tvNumber = holder.getView(R.id.tvNumber);
77 ImageView imageView = holder.getView(R.id.ivTopic); 108 ImageView imageView = holder.getView(R.id.ivTopic);
78 int number = getData().indexOf(homeWork) + 1; 109 int number = getData().indexOf(homeWork) + 1;
79 tvNumber.setText("第" + number + "题"); 110 tvNumber.setText("第" + number + "题");
80 Glide.with(mContext).load(homeWork.url).into(imageView); 111 Glide.with(mContext).load(homeWork.url).into(imageView);
81 } 112 }
82 } 113 }
83 } 114 }
84 115
app/src/main/java/com/hjx/parent/dialog/EditHomeworkDialog.java
File was created 1 package com.hjx.parent.dialog;
2
3 import android.annotation.SuppressLint;
4 import android.content.Context;
5 import android.util.Pair;
6 import android.view.View;
7 import android.widget.AdapterView;
8 import android.widget.ArrayAdapter;
9 import android.widget.Toast;
10
11 import androidx.annotation.NonNull;
12
13 import com.bigkoo.pickerview.builder.TimePickerBuilder;
14 import com.google.gson.Gson;
15 import com.hjx.parent.R;
16 import com.hjx.parent.bean.StudentBean;
17 import com.hjx.parent.databinding.DialogAddHomeworkBinding;
18 import com.hjx.parent.function.Function1;
19 import com.hjx.parent.rx.BaseRxActivity;
20 import com.prws.common.bean.GradeAndSubject;
21 import com.prws.common.bean.ResponseResult;
22 import com.prws.common.bean.Student;
23 import com.prws.common.bean.Subject;
24 import com.prws.common.bean.baidu.BaiduInput;
25 import com.prws.common.bean.homework.HomeworkList;
26 import com.prws.common.net.NetWorks;
27 import com.prws.common.utils.SharedPreferencesUtil;
28 import com.trello.rxlifecycle2.android.RxLifecycleAndroid;
29
30 import java.io.File;
31 import java.text.SimpleDateFormat;
32 import java.util.ArrayList;
33 import java.util.Calendar;
34 import java.util.Date;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Locale;
38 import java.util.Map;
39
40 import io.reactivex.Observable;
41 import io.reactivex.android.schedulers.AndroidSchedulers;
42 import io.reactivex.schedulers.Schedulers;
43
44 public class EditHomeworkDialog extends BaseDialog<DialogAddHomeworkBinding>{
45 private final BaseRxActivity<?> activity;
46
47 private Function1<HomeworkList> callback;
48
49 HomeworkList mData;
50
51 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.CHINA);
52 List<GradeAndSubject> gradeAndSubjectList;
53
54 String grade;
55 String term;
56 String subject;
57 Date uploadTime;
58
59 public EditHomeworkDialog(BaseRxActivity<?> context, HomeworkList data) {
60 super((Context) context);
61 activity = context;
62 mData = data;
63 uploadTime = data.uploadTime;
64 }
65
66 public void show(Function1<HomeworkList> callback) {
67 this.callback = callback;
68 super.show();
69 }
70
71 @SuppressLint("SetTextI18n")
72 @Override
73 public void initView() {
74 binding.tvTitle.setText("编辑作业");
75 binding.btnClose.setOnClickListener(v -> dismiss());
76 binding.tvStu.setVisibility(View.GONE);
77 binding.spStudent.setVisibility(View.GONE);
78 binding.spTerm.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
79 @Override
80 public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
81 term = getContext().getResources().getStringArray(R.array.grade_array)[position];
82 }
83 @Override
84 public void onNothingSelected(AdapterView<?> parent) {
85 }
86 });
87 binding.spGrade.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
88 @Override
89 public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
90 grade = gradeAndSubjectList.get(position).getGrade().getGrade();
91 refreshSubjects(position);
92 }
93
94 @Override
95 public void onNothingSelected(AdapterView<?> parent) {
96 }
97 });
98
99 binding.tvDate.setText(dateFormat.format(uploadTime));
100 binding.tvDate.setOnClickListener(v -> {
101 Calendar calendar = Calendar.getInstance();
102 calendar.setTime(uploadTime);
103 new TimePickerBuilder(getContext(), (date, v1) -> {
104 uploadTime = date;
105 binding.tvDate.setText(dateFormat.format(uploadTime));
106 binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业");
107 }).setType(new boolean[]{true, true, true, false, false, false}).setDate(calendar)
108 .isDialog(true).build().show();
109 });
110
111 binding.btnConfirm.setOnClickListener(v -> {
112 String name = binding.etName.getText().toString().trim();
113 if (name.isEmpty()) {
114 Toast.makeText(getContext(), "请输入作业名称", Toast.LENGTH_SHORT).show();
115 return;
116 }
117 dismiss();
118 if (callback != null) {
119 mData.setGrade(grade);
120 mData.setTerm(term);
121 mData.setSubject(subject);
122 mData.uploadTime = uploadTime;
123 mData.setName(name);
124 callback.invoke(mData);
125 }
126 });
127
128 getGrade();
129 }
130
131 @SuppressLint("CheckResult")
132 private void getGrade() {
133 NetWorks.service_url.listGradeAndSubject(NetWorks.getHeader())
134 .subscribeOn(Schedulers.io())
135 .observeOn(AndroidSchedulers.mainThread())
136 .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle()))
137 .map(ResponseResult::getData)
138 .firstOrError()
139 .subscribe((data, th) -> {
140 if (th != null) th.printStackTrace();
141 if (data != null && data.size() > 0) {
142 gradeAndSubjectList = data;
143 List<String> grades = new ArrayList<>();
144 for (GradeAndSubject it: data) {
145 grades.add(it.getGrade().getGrade());
146 }
147 binding.spGrade.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, grades));
148
149 int p = 0;
150 for (GradeAndSubject it: gradeAndSubjectList) {
151 if (it.getGrade().getGrade().equals(mData.getGrade())) {
152 p = gradeAndSubjectList.indexOf(it);
153 break;
154 }
155 }
156 binding.spGrade.setSelection(p);
157 }
158 });
159 }
160
161 private void refreshSubjects(int gradePosition) {
162 if (gradeAndSubjectList == null) return;
163 List<Subject> subjectList = gradeAndSubjectList.get(gradePosition).getSubjects();
164 List<String> subjects = new ArrayList<>();
165 for (Subject s: subjectList) {
166 subjects.add(s.getSubject());
167 }
168 int position = Math.max(subjects.indexOf(mData.getSubject()), 0);
169 binding.spSubject.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
170 @SuppressLint("SetTextI18n")
171 @Override
172 public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
173 subject = subjects.get(position);
174 binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业");
175 }
176 @Override
177 public void onNothingSelected(AdapterView<?> parent) {
178 }
179 });
180 binding.spSubject.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, subjects));
181 binding.spSubject.setSelection(position);
182 }
183
184 @NonNull
185 @Override
186 public DialogAddHomeworkBinding getBinding() {
187 return DialogAddHomeworkBinding.inflate(getLayoutInflater());
188 }
189 }
190
app/src/main/res/layout/activity_homework_detail.xml
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout 2 <LinearLayout
3 xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:android="http://schemas.android.com/apk/res/android"
4 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:app="http://schemas.android.com/apk/res-auto"
5 xmlns:tools="http://schemas.android.com/tools" 5 xmlns:tools="http://schemas.android.com/tools"
6 android:orientation="vertical" 6 android:orientation="vertical"
7 android:layout_width="match_parent" 7 android:layout_width="match_parent"
8 android:layout_height="match_parent" 8 android:layout_height="match_parent"
9 tools:ignore="HardcodedText"> 9 tools:ignore="HardcodedText">
10 10
11 <androidx.appcompat.widget.Toolbar 11 <androidx.appcompat.widget.Toolbar
12 android:id="@+id/toolbar" 12 android:id="@+id/toolbar"
13 app:navigationIcon="@drawable/svg_back" 13 app:navigationIcon="@drawable/svg_back"
14 app:contentInsetStartWithNavigation="14dp" 14 app:contentInsetStartWithNavigation="14dp"
15 android:paddingStart="-8dp" 15 android:paddingStart="-8dp"
16 android:paddingEnd="-8dp" 16 android:paddingEnd="-8dp"
17 android:background="@color/white" 17 android:background="@color/white"
18 android:layout_width="match_parent" 18 android:layout_width="match_parent"
19 android:layout_height="40dp"> 19 android:layout_height="40dp">
20 <TextView 20 <TextView
21 android:id="@+id/tvTitle" 21 android:id="@+id/tvTitle"
22 tools:text="作业名称" 22 tools:text="作业名称"
23 android:textSize="18sp" 23 android:textSize="18sp"
24 android:textColor="#333" 24 android:textColor="#333"
25 android:textStyle="bold" 25 android:textStyle="bold"
26 android:layout_width="wrap_content" 26 android:layout_width="wrap_content"
27 android:layout_height="wrap_content"/> 27 android:layout_height="wrap_content"/>
28 <androidx.appcompat.widget.AppCompatImageView
29 android:id="@+id/btnEdit"
30 android:src="@drawable/svg_homework_edit"
31 android:layout_marginStart="5dp"
32 android:layout_width="18dp"
33 android:layout_height="18dp"/>
28 <TextView 34 <TextView
29 android:id="@+id/btnFeedback" 35 android:id="@+id/btnFeedback"
30 android:text="反馈作业" 36 android:text="反馈作业"
31 android:textSize="13sp" 37 android:textSize="13sp"
32 android:textColor="#1C90F3" 38 android:textColor="#1C90F3"
33 android:textStyle="bold" 39 android:textStyle="bold"
34 android:layout_gravity="end|center_vertical" 40 android:layout_gravity="end|center_vertical"
35 android:layout_marginEnd="24dp" 41 android:layout_marginEnd="24dp"
36 android:layout_width="wrap_content" 42 android:layout_width="wrap_content"
37 android:layout_height="wrap_content"/> 43 android:layout_height="wrap_content"/>
38 </androidx.appcompat.widget.Toolbar> 44 </androidx.appcompat.widget.Toolbar>
39 45
40 <androidx.recyclerview.widget.RecyclerView 46 <androidx.recyclerview.widget.RecyclerView
41 android:id="@+id/recyclerView" 47 android:id="@+id/recyclerView"
42 android:orientation="vertical" 48 android:orientation="vertical"
43 app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" 49 app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
44 android:layout_width="match_parent" 50 android:layout_width="match_parent"
45 android:layout_height="match_parent"/> 51 android:layout_height="match_parent"/>
46 52
47 </LinearLayout> 53 </LinearLayout>
app/src/main/res/layout/dialog_add_homework.xml
1 <FrameLayout 1 <FrameLayout
2 xmlns:android="http://schemas.android.com/apk/res/android" 2 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 xmlns:tools="http://schemas.android.com/tools" 4 xmlns:tools="http://schemas.android.com/tools"
5 android:layout_width="match_parent" 5 android:layout_width="match_parent"
6 android:layout_height="match_parent" 6 android:layout_height="match_parent"
7 tools:ignore="HardcodedText,ContentDescription,UselessParent" > 7 tools:ignore="HardcodedText,ContentDescription,UselessParent" >
8 8
9 <LinearLayout 9 <LinearLayout
10 android:orientation="vertical" 10 android:orientation="vertical"
11 android:background="@drawable/shape_radius_top_10" 11 android:background="@drawable/shape_radius_top_10"
12 android:layout_marginTop="80dp" 12 android:layout_marginTop="80dp"
13 android:layout_width="match_parent" 13 android:layout_width="match_parent"
14 android:layout_height="match_parent"> 14 android:layout_height="match_parent">
15 15
16 <FrameLayout 16 <FrameLayout
17 android:layout_marginVertical="8dp" 17 android:layout_marginTop="8dp"
18 android:layout_marginBottom="-12dp"
18 android:layout_width="match_parent" 19 android:layout_width="match_parent"
19 android:layout_height="wrap_content"> 20 android:layout_height="wrap_content">
20 21
21 <TextView 22 <TextView
23 android:id="@+id/tvTitle"
22 android:text="录入作业" 24 android:text="录入作业"
23 android:textSize="17sp" 25 android:textSize="17sp"
24 android:textStyle="bold" 26 android:textStyle="bold"
25 android:layout_gravity="center" 27 android:layout_gravity="center"
26 android:textColor="@color/text_title" 28 android:textColor="@color/text_title"
27 android:layout_width="wrap_content" 29 android:layout_width="wrap_content"
28 android:layout_height="wrap_content" /> 30 android:layout_height="wrap_content" />
29 31
30 <ImageView 32 <ImageView
31 android:id="@+id/btnClose" 33 android:id="@+id/btnClose"
32 android:padding="12dp" 34 android:padding="12dp"
33 android:src="@mipmap/ic_close" 35 android:src="@mipmap/ic_close"
34 android:layout_gravity="end|center_vertical" 36 android:layout_gravity="end|center_vertical"
35 android:layout_width="35dp" 37 android:layout_width="35dp"
36 android:layout_height="35dp" /> 38 android:layout_height="35dp" />
37 </FrameLayout> 39 </FrameLayout>
38 40
39 <TextView 41 <TextView
42 android:id="@+id/tvStu"
43 android:layout_marginTop="20dp"
40 android:layout_width="wrap_content" 44 android:layout_width="wrap_content"
41 android:layout_height="wrap_content" 45 android:layout_height="wrap_content"
42 android:layout_marginHorizontal="15dp" 46 android:layout_marginHorizontal="15dp"
43 android:text="学生" 47 android:text="学生"
44 android:textColor="@color/text_title" 48 android:textColor="@color/text_title"
45 android:textSize="14sp" 49 android:textSize="14sp"
46 android:textStyle="bold" /> 50 android:textStyle="bold" />
47 51
48 <androidx.appcompat.widget.AppCompatSpinner 52 <androidx.appcompat.widget.AppCompatSpinner
49 android:id="@+id/spStudent" 53 android:id="@+id/spStudent"
50 style="@style/customSpinnerStyle" 54 style="@style/customSpinnerStyle"
51 android:layout_width="match_parent" 55 android:layout_width="match_parent"
52 android:layout_height="40dp" 56 android:layout_height="40dp"
53 android:layout_marginTop="10dp" 57 android:layout_marginTop="10dp"
54 android:layout_marginHorizontal="15dp" 58 android:layout_marginHorizontal="15dp"
55 android:background="@drawable/selector_for_input_spinner" 59 android:background="@drawable/selector_for_input_spinner"
56 android:popupBackground="@drawable/shape_for_input_spinner" 60 android:popupBackground="@drawable/shape_for_input_spinner"
57 android:scrollbars="none" /> 61 android:scrollbars="none" />
58 62
59 <TextView 63 <TextView
60 android:layout_width="wrap_content" 64 android:layout_width="wrap_content"
61 android:layout_height="wrap_content" 65 android:layout_height="wrap_content"
62 android:layout_marginHorizontal="15dp" 66 android:layout_marginHorizontal="15dp"
63 android:layout_marginTop="20dp" 67 android:layout_marginTop="20dp"
64 android:text="年级" 68 android:text="年级"
65 android:textColor="@color/text_title" 69 android:textColor="@color/text_title"
66 android:textSize="14sp" 70 android:textSize="14sp"
67 android:textStyle="bold" /> 71 android:textStyle="bold" />
68 72
69 <androidx.appcompat.widget.AppCompatSpinner 73 <androidx.appcompat.widget.AppCompatSpinner
70 android:id="@+id/spGrade" 74 android:id="@+id/spGrade"
71 style="@style/customSpinnerStyle" 75 style="@style/customSpinnerStyle"
72 android:layout_width="match_parent" 76 android:layout_width="match_parent"
73 android:layout_height="40dp" 77 android:layout_height="40dp"
74 android:layout_marginTop="10dp" 78 android:layout_marginTop="10dp"
75 android:layout_marginHorizontal="15dp" 79 android:layout_marginHorizontal="15dp"
76 android:background="@drawable/selector_for_input_spinner" 80 android:background="@drawable/selector_for_input_spinner"
77 android:popupBackground="@drawable/shape_for_input_spinner" 81 android:popupBackground="@drawable/shape_for_input_spinner"
78 android:scrollbars="none" /> 82 android:scrollbars="none" />
79 83
80 <TextView 84 <TextView
81 android:layout_width="wrap_content" 85 android:layout_width="wrap_content"
82 android:layout_height="wrap_content" 86 android:layout_height="wrap_content"
83 android:layout_marginHorizontal="15dp" 87 android:layout_marginHorizontal="15dp"
84 android:layout_marginTop="20dp" 88 android:layout_marginTop="20dp"
85 android:text="学期" 89 android:text="学期"
86 android:textColor="@color/text_title" 90 android:textColor="@color/text_title"
87 android:textSize="14sp" 91 android:textSize="14sp"
88 android:textStyle="bold" /> 92 android:textStyle="bold" />
89 93
90 <androidx.appcompat.widget.AppCompatSpinner 94 <androidx.appcompat.widget.AppCompatSpinner
91 android:id="@+id/spTerm" 95 android:id="@+id/spTerm"
92 style="@style/customSpinnerStyle" 96 style="@style/customSpinnerStyle"
93 android:layout_width="match_parent" 97 android:layout_width="match_parent"
94 android:layout_height="40dp" 98 android:layout_height="40dp"
95 android:layout_marginTop="10dp" 99 android:layout_marginTop="10dp"
96 android:layout_marginHorizontal="15dp" 100 android:layout_marginHorizontal="15dp"
97 android:background="@drawable/selector_for_input_spinner" 101 android:background="@drawable/selector_for_input_spinner"
98 android:entries="@array/grade_array" 102 android:entries="@array/grade_array"
99 android:popupBackground="@drawable/shape_for_input_spinner" 103 android:popupBackground="@drawable/shape_for_input_spinner"
100 android:scrollbars="none" /> 104 android:scrollbars="none" />
101 105
102 <TextView 106 <TextView
103 android:layout_width="wrap_content" 107 android:layout_width="wrap_content"
104 android:layout_height="wrap_content" 108 android:layout_height="wrap_content"
105 android:layout_marginHorizontal="15dp" 109 android:layout_marginHorizontal="15dp"
106 android:layout_marginTop="20dp" 110 android:layout_marginTop="20dp"
107 android:text="科目" 111 android:text="科目"
108 android:textColor="@color/text_title" 112 android:textColor="@color/text_title"
109 android:textSize="14sp" 113 android:textSize="14sp"
110 android:textStyle="bold" /> 114 android:textStyle="bold" />
111 115
112 <androidx.appcompat.widget.AppCompatSpinner 116 <androidx.appcompat.widget.AppCompatSpinner
113 android:id="@+id/spSubject" 117 android:id="@+id/spSubject"
114 style="@style/customSpinnerStyle" 118 style="@style/customSpinnerStyle"
115 android:layout_width="match_parent" 119 android:layout_width="match_parent"
116 android:layout_height="40dp" 120 android:layout_height="40dp"
117 android:layout_marginTop="10dp" 121 android:layout_marginTop="10dp"
118 android:layout_marginHorizontal="15dp" 122 android:layout_marginHorizontal="15dp"
119 android:background="@drawable/selector_for_input_spinner" 123 android:background="@drawable/selector_for_input_spinner"
120 android:popupBackground="@drawable/shape_for_input_spinner" 124 android:popupBackground="@drawable/shape_for_input_spinner"
121 android:scrollbars="none" /> 125 android:scrollbars="none" />
122 126
123 <TextView 127 <TextView
124 android:layout_width="wrap_content" 128 android:layout_width="wrap_content"
125 android:layout_height="wrap_content" 129 android:layout_height="wrap_content"
126 android:layout_marginHorizontal="15dp" 130 android:layout_marginHorizontal="15dp"
127 android:layout_marginTop="20dp" 131 android:layout_marginTop="20dp"
128 android:text="日期" 132 android:text="日期"
129 android:textColor="@color/text_title" 133 android:textColor="@color/text_title"
130 android:textSize="14sp" 134 android:textSize="14sp"
131 android:textStyle="bold" /> 135 android:textStyle="bold" />
132 136
133 <TextView 137 <TextView
134 android:id="@+id/tvDate" 138 android:id="@+id/tvDate"
135 tools:text="2024-09-18" 139 tools:text="2024-09-18"
136 android:textSize="16sp" 140 android:textSize="16sp"
137 android:textColor="#333" 141 android:textColor="#333"
138 android:gravity="center_vertical" 142 android:gravity="center_vertical"
139 android:paddingHorizontal="16dp" 143 android:paddingHorizontal="16dp"
140 android:layout_width="match_parent" 144 android:layout_width="match_parent"
141 android:layout_height="40dp" 145 android:layout_height="40dp"
142 android:layout_marginTop="10dp" 146 android:layout_marginTop="10dp"
143 android:layout_marginHorizontal="15dp" 147 android:layout_marginHorizontal="15dp"
144 android:background="@drawable/selector_for_input_spinner" /> 148 android:background="@drawable/selector_for_input_spinner" />
145 149
146 <TextView 150 <TextView
147 android:layout_width="wrap_content" 151 android:layout_width="wrap_content"
148 android:layout_height="wrap_content" 152 android:layout_height="wrap_content"
149 android:layout_marginHorizontal="15dp" 153 android:layout_marginHorizontal="15dp"
150 android:layout_marginTop="20dp" 154 android:layout_marginTop="20dp"
151 android:text="作业名称" 155 android:text="作业名称"
152 android:textColor="@color/text_title" 156 android:textColor="@color/text_title"
153 android:textSize="14sp" 157 android:textSize="14sp"
154 android:textStyle="bold" /> 158 android:textStyle="bold" />
155 159
156 <EditText 160 <EditText
157 android:id="@+id/etName" 161 android:id="@+id/etName"
158 android:layout_width="match_parent" 162 android:layout_width="match_parent"
159 android:layout_height="40dp" 163 android:layout_height="40dp"
160 android:layout_marginTop="10dp" 164 android:layout_marginTop="10dp"
161 android:layout_marginHorizontal="15dp" 165 android:layout_marginHorizontal="15dp"
162 android:background="@drawable/shape_for_input_spinner" 166 android:background="@drawable/shape_for_input_spinner"
163 android:fillViewport="true" 167 android:fillViewport="true"
164 android:gravity="center_vertical" 168 android:gravity="center_vertical"
165 android:maxLength="50" 169 android:maxLength="50"
166 android:paddingHorizontal="16dp" 170 android:paddingHorizontal="16dp"
167 android:textColor="@color/text_title" 171 android:textColor="@color/text_title"
168 android:textSize="13sp" 172 android:textSize="13sp"
169 android:inputType="text" 173 android:inputType="text"
170 tools:ignore="Autofill,LabelFor" /> 174 tools:ignore="Autofill,LabelFor" />
171 175
172 <Space style="@style/empty_space"/> 176 <Space style="@style/empty_space"/>
173 <TextView 177 <TextView
174 android:id="@+id/btnConfirm" 178 android:id="@+id/btnConfirm"
175 android:text="确认录入" 179 android:text="确认录入"
176 android:gravity="center" 180 android:gravity="center"
177 android:textSize="16sp" 181 android:textSize="16sp"
178 android:textColor="@color/white" 182 android:textColor="@color/white"
179 android:background="@drawable/shape_radius_5" 183 android:background="@drawable/shape_radius_5"
180 android:backgroundTint="#1C90F3" 184 android:backgroundTint="#1C90F3"
181 android:layout_gravity="center_horizontal" 185 android:layout_gravity="center_horizontal"
182 android:layout_marginBottom="16dp" 186 android:layout_marginBottom="16dp"
183 android:layout_width="224dp" 187 android:layout_width="224dp"
184 android:layout_height="36dp"/> 188 android:layout_height="36dp"/>
185 </LinearLayout> 189 </LinearLayout>
186 </FrameLayout> 190 </FrameLayout>
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.baidu.BaiduInput; 16 import com.prws.common.bean.baidu.BaiduInput;
17 import com.prws.common.bean.homework.HomeWork; 17 import com.prws.common.bean.homework.HomeWork;
18 import com.prws.common.bean.homework.HomeworkList; 18 import com.prws.common.bean.homework.HomeworkList;
19 import com.prws.common.utils.BitmapUtils; 19 import com.prws.common.utils.BitmapUtils;
20 import com.prws.common.utils.SharedPreferencesUtil; 20 import com.prws.common.utils.SharedPreferencesUtil;
21 21
22 import java.io.File; 22 import java.io.File;
23 import java.util.HashMap; 23 import java.util.HashMap;
24 import java.util.List; 24 import java.util.List;
25 import java.util.Map; 25 import java.util.Map;
26 26
27 import io.reactivex.Observable; 27 import io.reactivex.Observable;
28 import io.reactivex.Observer; 28 import io.reactivex.Observer;
29 import io.reactivex.Single; 29 import io.reactivex.Single;
30 import io.reactivex.android.schedulers.AndroidSchedulers; 30 import io.reactivex.android.schedulers.AndroidSchedulers;
31 import io.reactivex.schedulers.Schedulers; 31 import io.reactivex.schedulers.Schedulers;
32 import okhttp3.MediaType; 32 import okhttp3.MediaType;
33 import okhttp3.MultipartBody; 33 import okhttp3.MultipartBody;
34 import okhttp3.RequestBody; 34 import okhttp3.RequestBody;
35 import okhttp3.ResponseBody; 35 import okhttp3.ResponseBody;
36 import retrofit2.Call; 36 import retrofit2.Call;
37 import retrofit2.Callback; 37 import retrofit2.Callback;
38 import retrofit2.http.Body; 38 import retrofit2.http.Body;
39 import retrofit2.http.GET; 39 import retrofit2.http.GET;
40 import retrofit2.http.Header; 40 import retrofit2.http.Header;
41 import retrofit2.http.Headers; 41 import retrofit2.http.Headers;
42 import retrofit2.http.Multipart; 42 import retrofit2.http.Multipart;
43 import retrofit2.http.POST; 43 import retrofit2.http.POST;
44 import retrofit2.http.PUT; 44 import retrofit2.http.PUT;
45 import retrofit2.http.Part; 45 import retrofit2.http.Part;
46 import retrofit2.http.PartMap; 46 import retrofit2.http.PartMap;
47 import retrofit2.http.Query; 47 import retrofit2.http.Query;
48 import retrofit2.http.Url; 48 import retrofit2.http.Url;
49 49
50 /** 50 /**
51 * 类名称:NetWorks 51 * 类名称:NetWorks
52 * 创建人: 52 * 创建人:
53 * <p> 53 * <p>
54 * 类描述:网络请求的操作类 54 * 类描述:网络请求的操作类
55 */ 55 */
56 public class NetWorks extends RetrofitUtils { 56 public class NetWorks extends RetrofitUtils {
57 //服务器路径 57 //服务器路径
58 public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class); 58 public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class);
59 59
60 //设缓存有效期为1天 60 //设缓存有效期为1天
61 protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; 61 protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1;
62 //查询缓存的Cache-Control设置,使用缓存 62 //查询缓存的Cache-Control设置,使用缓存
63 protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; 63 protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC;
64 //查询网络的Cache-Control设置。不使用缓存 64 //查询网络的Cache-Control设置。不使用缓存
65 protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; 65 protected static final String CACHE_CONTROL_NETWORK = "max-age=0";
66 66
67 67
68 public interface NetService { 68 public interface NetService {
69 69
70 70
71 @GET("/api/v1/user/logout") 71 @GET("/api/v1/user/logout")
72 Observable<ResponseBody> logout(); 72 Observable<ResponseBody> logout();
73 73
74 @Multipart 74 @Multipart
75 @POST("/api/v1/user/upLoadAvatar") 75 @POST("/api/v1/user/upLoadAvatar")
76 Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); 76 Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis);
77 77
78 78
79 @Headers("Content-Type: application/json") 79 @Headers("Content-Type: application/json")
80 @POST("/api/v1/user/editUser") 80 @POST("/api/v1/user/editUser")
81 Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); 81 Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body);
82 82
83 @Headers("Content-Type: application/json") 83 @Headers("Content-Type: application/json")
84 @POST("/api/v1/user/changePassword") 84 @POST("/api/v1/user/changePassword")
85 Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); 85 Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body);
86 86
87 87
88 @GET("/api/v1/user/searchById") 88 @GET("/api/v1/user/searchById")
89 Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); 89 Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId);
90 90
91 91
92 @Headers("Content-Type: application/json") 92 @Headers("Content-Type: application/json")
93 @POST("/api/v1/auth/login") 93 @POST("/api/v1/auth/login")
94 Observable<ResponseBody> login(@Body RequestBody body); 94 Observable<ResponseBody> login(@Body RequestBody body);
95 95
96 @GET("/api/v1/resource/listGradeAndSubject") 96 @GET("/api/v1/resource/listGradeAndSubject")
97 Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); 97 Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token);
98 98
99 99
100 @GET("/api/v1/manager/generalQrCode") 100 @GET("/api/v1/manager/generalQrCode")
101 Observable<ResponseBody> generalQrCode(); 101 Observable<ResponseBody> generalQrCode();
102 102
103 @GET("/api/v1/parent/scanAndLogin?") 103 @GET("/api/v1/parent/scanAndLogin?")
104 Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId); 104 Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId);
105 105
106 @GET("/api/v1/parent/getChildrenList") 106 @GET("/api/v1/parent/getChildrenList")
107 Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); 107 Observable<ResponseBody> getChildrenList(@Header("Authorization") String token);
108 108
109 109
110 @Headers("Content-Type: application/json") 110 @Headers("Content-Type: application/json")
111 @POST("/api/v1/parent/registerParent") 111 @POST("/api/v1/parent/registerParent")
112 Observable<ResponseBody> registerParent(@Body RequestBody body); 112 Observable<ResponseBody> registerParent(@Body RequestBody body);
113 113
114 114
115 @GET("/api/v1/parent/listChildren") 115 @GET("/api/v1/parent/listChildren")
116 Observable<ResponseBody> listChildren(@Header("Authorization") String token); 116 Observable<ResponseBody> listChildren(@Header("Authorization") String token);
117 117
118 118
119 @Headers("Content-Type: application/json") 119 @Headers("Content-Type: application/json")
120 @POST("/api/v1/parent/registerStudent") 120 @POST("/api/v1/parent/registerStudent")
121 Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); 121 Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body);
122 122
123 @Headers("Content-Type: application/json") 123 @Headers("Content-Type: application/json")
124 @POST("/api/v1/parent/bindTeacher") 124 @POST("/api/v1/parent/bindTeacher")
125 Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); 125 Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body);
126 126
127 @Multipart 127 @Multipart
128 @POST("/api/v1/user/upLoadAvatar") 128 @POST("/api/v1/user/upLoadAvatar")
129 Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); 129 Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file);
130 130
131 131
132 @Multipart 132 @Multipart
133 @POST("/api/v1/student/editStudentAvatar") 133 @POST("/api/v1/student/editStudentAvatar")
134 Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); 134 Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map);
135 135
136 @Headers("Content-Type: application/json") 136 @Headers("Content-Type: application/json")
137 @POST("/api/v1/parent/editChild") 137 @POST("/api/v1/parent/editChild")
138 Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); 138 Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body);
139 139
140 @GET("/api/v1/student/getStudyPlanForThisWeek") 140 @GET("/api/v1/student/getStudyPlanForThisWeek")
141 Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); 141 Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId);
142 142
143 @GET("api/v1/parent/searchTeacher") 143 @GET("api/v1/parent/searchTeacher")
144 Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); 144 Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone);
145 145
146 @POST("api/v1/question/listErrorBook") 146 @POST("api/v1/question/listErrorBook")
147 Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); 147 Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body);
148 148
149 @POST 149 @POST
150 Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); 150 Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body);
151 151
152 @POST 152 @POST
153 Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); 153 Observable<CutPicBean> cut(@Url String url, @Body RequestBody body);
154 154
155 @POST 155 @POST
156 Observable<JsonObject> getBaiduToken(@Url String url); 156 Observable<JsonObject> getBaiduToken(@Url String url);
157 157
158 @Multipart 158 @Multipart
159 @POST("api/v1/pad/addErrorBook") 159 @POST("api/v1/pad/addErrorBook")
160 Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); 160 Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map);
161 161
162 @POST("api/v1/pad/deleteStuErrorBook") 162 @POST("api/v1/pad/deleteStuErrorBook")
163 Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); 163 Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map);
164 164
165 @PUT("api/v1/pad/updateStuErrorBookInfo") 165 @PUT("api/v1/pad/updateStuErrorBookInfo")
166 Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); 166 Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map);
167 167
168 @POST("api/v1/question/editErrorBook") 168 @POST("api/v1/question/editErrorBook")
169 Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); 169 Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map);
170 170
171 @GET("api/v1/resource/checkUpdate") 171 @GET("api/v1/resource/checkUpdate")
172 Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); 172 Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type);
173 173
174 @GET("api/v1/teacher/getStudentList") 174 @GET("api/v1/teacher/getStudentList")
175 Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); 175 Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id);
176 176
177 @GET("api/v1/teacher/getStudentList") 177 @GET("api/v1/teacher/getStudentList")
178 Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id); 178 Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id);
179 179
180 @GET("api/v1/answer/listRecordForTeacher") 180 @GET("api/v1/answer/listRecordForTeacher")
181 Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); 181 Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id);
182 182
183 @GET("api/v1/homework/listHomeworkByStuId") 183 @GET("api/v1/homework/listHomeworkByStuId")
184 Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId); 184 Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId);
185 185
186 @POST 186 @POST
187 Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body); 187 Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body);
188 188
189 @Multipart 189 @Multipart
190 @POST("api/v1/homework/uploadHomework") 190 @POST("api/v1/homework/uploadHomework")
191 Single<ResponseResult> uploadImage(@Header("Authorization") String token, @Part() MultipartBody.Part file, @Query("brief") String id); 191 Single<ResponseResult> uploadImage(@Header("Authorization") String token, @Part() MultipartBody.Part file, @Query("brief") String id);
192 192
193 @POST("api/v1/homework/uploadHomeworkAction") 193 @POST("api/v1/homework/uploadHomeworkAction")
194 Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map); 194 Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map);
195 195
196 @GET("api/v1/homework/removeHomework") 196 @GET("api/v1/homework/removeHomework")
197 Single<ResponseResult<Boolean>> deleteHomework( 197 Single<ResponseResult<Boolean>> deleteHomework(
198 @Header("Authorization") String token, 198 @Header("Authorization") String token,
199 @Query("homeworkId") String homeworkId 199 @Query("homeworkId") String homeworkId
200 ); 200 );
201 201
202 @GET("api/v1/homework/listHomeworkById") 202 @GET("api/v1/homework/listHomeworkById")
203 Single<ResponseResult<List<HomeWork>>> getHomeworkDetail(@Header("Authorization") String token, @Query("homeworkId") String homeworkId); 203 Single<ResponseResult<List<HomeWork>>> getHomeworkDetail(@Header("Authorization") String token, @Query("homeworkId") String homeworkId);
204 204
205 @POST("api/v1/homework/uploadHomeworkFeedback") 205 @POST("api/v1/homework/uploadHomeworkFeedback")
206 Single<ResponseResult> uploadHomeworkFeedback(@Header("Authorization") String token, @Body Map<String, Object> map); 206 Single<ResponseResult> uploadHomeworkFeedback(@Header("Authorization") String token, @Body Map<String, Object> map);
207 207
208 @POST("api/v1/homework/editHomeworkInfo")
209 Single<ResponseResult<Boolean>> editHomework(
210 @Header("Authorization") String token,
211 @Body Object body
212 );
213
208 } 214 }
209 215
210 public static String getUserId() { 216 public static String getUserId() {
211 return (String) SharedPreferencesUtil.getData("userId", ""); 217 return (String) SharedPreferencesUtil.getData("userId", "");
212 } 218 }
213 219
214 public static String getHeader() { 220 public static String getHeader() {
215 return (String) SharedPreferencesUtil.getData("token", ""); 221 return (String) SharedPreferencesUtil.getData("token", "");
216 } 222 }
217 223
218 public static String getBaiduToken() { 224 public static String getBaiduToken() {
219 return (String) SharedPreferencesUtil.getData("baiduToken", ""); 225 return (String) SharedPreferencesUtil.getData("baiduToken", "");
220 } 226 }
221 227
222 public static Single<BaiduInput> inputImage(String filePath, String id) { 228 public static Single<BaiduInput> inputImage(String filePath, String id) {
223 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); 229 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
224 String base64 = BitmapUtils.fileToBase64(filePath); 230 String base64 = BitmapUtils.fileToBase64(filePath);
225 File file = new File(filePath); 231 File file = new File(filePath);
226 RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}"); 232 RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}");
227 return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) 233 return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString())
228 .flatMap(token -> { 234 .flatMap(token -> {
229 return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body); 235 return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body);
230 }); 236 });
231 } 237 }
232 238
233 public static Single<ResponseResult> uploadImage(String path, String id) { 239 public static Single<ResponseResult> uploadImage(String path, String id) {
234 File file = new File(path); 240 File file = new File(path);
235 RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); 241 RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file);
236 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); 242 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
237 return service_url.uploadImage(getHeader(), part, id); 243 return service_url.uploadImage(getHeader(), part, id);
238 } 244 }
239 245
240 246
241 public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { 247 public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) {
242 service_url.checkUpdate(code, packageName, 0).enqueue(callback); 248 service_url.checkUpdate(code, packageName, 0).enqueue(callback);
243 } 249 }
244 250
245 public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { 251 public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) {
246 File file = new File(path); 252 File file = new File(path);
247 RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); 253 RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file);
248 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); 254 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
249 Map<String, Object> map = new HashMap<>(); 255 Map<String, Object> map = new HashMap<>();
250 map.put("condition", param); 256 map.put("condition", param);
251 setSubscribe(service_url.addError(part, map), observer); 257 setSubscribe(service_url.addError(part, map), observer);
252 } 258 }
253 259
254 260
255 public static void cut(String base64, Observer<CutPicBean> observer) { 261 public static void cut(String base64, Observer<CutPicBean> observer) {
256 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); 262 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
257 RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); 263 RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true");
258 setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); 264 setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer);
259 } 265 }
260 266
261 public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { 267 public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) {
262 setSubscribe(service_url.editError(getHeader(), map), observer); 268 setSubscribe(service_url.editError(getHeader(), map), observer);
263 } 269 }
264 270
265 public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { 271 public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) {
266 setSubscribe(service_url.updateError(getHeader(), map), observer); 272 setSubscribe(service_url.updateError(getHeader(), map), observer);
267 } 273 }
268 274
269 public static void deleteError(List<String> map, Observer<ResponseResult> observer) { 275 public static void deleteError(List<String> map, Observer<ResponseResult> observer) {
270 setSubscribe(service_url.deleteError(getHeader(), map), observer); 276 setSubscribe(service_url.deleteError(getHeader(), map), observer);
271 } 277 }
272 278
273 public static void getBaiduToken(Observer<JsonObject> observer) { 279 public static void getBaiduToken(Observer<JsonObject> observer) {
274 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); 280 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);
275 } 281 }
276 282
277 public static Single<JsonObject> getBaiduTokenOcr() { 283 public static Single<JsonObject> getBaiduTokenOcr() {
278 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(); 284 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();
279 } 285 }
280 286
281 public static void removeWriting(String base64, Observer<JsonObject> observer) { 287 public static void removeWriting(String base64, Observer<JsonObject> observer) {
282 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); 288 MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
283 RequestBody body = RequestBody.create(mediaType, "image=" + base64); 289 RequestBody body = RequestBody.create(mediaType, "image=" + base64);
284 setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); 290 setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer);
285 } 291 }
286 292
287 public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { 293 public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) {
288 setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); 294 setSubscribe(service_url.searchTeacher(getHeader(), phone), observer);
289 } 295 }
290 296
291 public static void logout(Observer<ResponseBody> observer) { 297 public static void logout(Observer<ResponseBody> observer) {
292 setSubscribe(service_url.logout(), observer); 298 setSubscribe(service_url.logout(), observer);
293 } 299 }
294 300
295 public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { 301 public static void editStudent(RequestBody body, Observer<ResponseResult> observable) {
296 setSubscribe(service_url.editStudent(getHeader(), body), observable); 302 setSubscribe(service_url.editStudent(getHeader(), body), observable);
297 } 303 }
298 304
299 public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { 305 public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) {
300 setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); 306 setSubscribe(service_url.getWeekPlan(getHeader(), id), observer);
301 } 307 }
302 308
303 public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { 309 public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) {
304 RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); 310 RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
305 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); 311 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
306 Map<String, Object> map = new HashMap<>(); 312 Map<String, Object> map = new HashMap<>();
307 map.put("stuId", stuId); 313 map.put("stuId", stuId);
308 setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); 314 setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer);
309 } 315 }
310 316
311 public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { 317 public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) {
312 RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); 318 RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
313 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); 319 MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
314 setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); 320 setSubscribe(service_url.uploadAvatar(getHeader(), part), observer);
315 } 321 }
316 322
317 public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { 323 public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) {
318 setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); 324 setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer);
319 } 325 }
320 326
321 327
322 public static void editUser(RequestBody body, Observer<ResponseBody> observer) { 328 public static void editUser(RequestBody body, Observer<ResponseBody> observer) {
323 setSubscribe(service_url.editUser(getHeader(), body), observer); 329 setSubscribe(service_url.editUser(getHeader(), body), observer);
324 } 330 }
325 331
326 public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { 332 public static void changePassword(RequestBody body, Observer<ResponseBody> observer) {
327 setSubscribe(service_url.changePassword(getHeader(), body), observer); 333 setSubscribe(service_url.changePassword(getHeader(), body), observer);
328 } 334 }
329 335
330 336
331 public static void searchById(String userId, Observer<ResponseBody> observer) { 337 public static void searchById(String userId, Observer<ResponseBody> observer) {
332 setSubscribe(service_url.searchById(getHeader(), userId), observer); 338 setSubscribe(service_url.searchById(getHeader(), userId), observer);
333 } 339 }
334 340
335 341
336 public static void login(RequestBody body, Observer<ResponseBody> observer) { 342 public static void login(RequestBody body, Observer<ResponseBody> observer) {
337 setSubscribe(service_url.login(body), observer); 343 setSubscribe(service_url.login(body), observer);
338 } 344 }
339 345
340 public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { 346 public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) {
341 setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); 347 setSubscribe(service_url.listGradeAndSubject(getHeader()), observer);
342 } 348 }
343 349
344 350
345 public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { 351 public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) {
346 setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); 352 setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer);
347 } 353 }
348 354
349 public static void getChildrenList(Observer<ResponseBody> observer) { 355 public static void getChildrenList(Observer<ResponseBody> observer) {
350 setSubscribe(service_url.getChildrenList(getHeader()), observer); 356 setSubscribe(service_url.getChildrenList(getHeader()), observer);
351 } 357 }
352 358
353 359
354 public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { 360 public static void registerParent(RequestBody body, Observer<ResponseBody> observer) {
355 setSubscribe(service_url.registerParent(body), observer); 361 setSubscribe(service_url.registerParent(body), observer);
356 } 362 }
357 363
358 364
359 public static void listChildren(Observer<ResponseBody> observer) { 365 public static void listChildren(Observer<ResponseBody> observer) {
360 setSubscribe(service_url.listChildren(getHeader()), observer); 366 setSubscribe(service_url.listChildren(getHeader()), observer);
361 } 367 }
362 368
363 public static void listStudent(Observer<ResponseBody> observer) { 369 public static void listStudent(Observer<ResponseBody> observer) {
364 setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); 370 setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer);
365 } 371 }
366 372
367 public static Single<ResponseResult<List<Student>>> listStudent() { 373 public static Single<ResponseResult<List<Student>>> listStudent() {
368 return service_url.getStudentList2(getHeader(), getUserId()); 374 return service_url.getStudentList2(getHeader(), getUserId());
369 } 375 }
370 376
371 public static void listRecord(Observer<ResponseBody> observer) { 377 public static void listRecord(Observer<ResponseBody> observer) {
372 setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); 378 setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer);
373 } 379 }
374 380
375 381
376 public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { 382 public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) {
377 setSubscribe(service_url.registerStudent(getHeader(), body), observer); 383 setSubscribe(service_url.registerStudent(getHeader(), body), observer);
378 } 384 }
379 385
380 public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { 386 public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) {
381 setSubscribe(service_url.bindTeacher(getHeader(), body), observer); 387 setSubscribe(service_url.bindTeacher(getHeader(), body), observer);
382 } 388 }
383 389
384 public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { 390 public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) {
385 setSubscribe(service_url.getError(getHeader(), map), observer); 391 setSubscribe(service_url.getError(getHeader(), map), observer);
386 } 392 }
387 393
388 394
389 public static RequestBody getMapRequestBody(Map map) { 395 public static RequestBody getMapRequestBody(Map map) {
390 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); 396 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map));
391 } 397 }
392 398
393 399
394 public static RequestBody getArrayRequestBody(List list) { 400 public static RequestBody getArrayRequestBody(List list) {
395 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); 401 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list));
396 } 402 }
397 403
398 public static RequestBody getFileRequestBody(File file) { 404 public static RequestBody getFileRequestBody(File file) {
399 return RequestBody.create(MediaType.parse("application/octet-stream"), file); 405 return RequestBody.create(MediaType.parse("application/octet-stream"), file);
400 } 406 }
401 407
402 public static RequestBody getFileRequestBody(byte[] bytes) { 408 public static RequestBody getFileRequestBody(byte[] bytes) {
403 return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); 409 return RequestBody.create(MediaType.parse("multipart/form-data"), bytes);
404 } 410 }
405 411
406 public static RequestBody getObjectRequestBody(Object obj) { 412 public static RequestBody getObjectRequestBody(Object obj) {
407 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); 413 return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj));
408 } 414 }
409 415
410 public static RequestBody getStringRequestBody(String str) { 416 public static RequestBody getStringRequestBody(String str) {
411 return RequestBody.create(MediaType.parse("text/plain"), str); 417 return RequestBody.create(MediaType.parse("text/plain"), str);
412 } 418 }
413 419
414 420
415 /** 421 /**
416 * 插入观察者 422 * 插入观察者
417 * 423 *
418 * @param observable 424 * @param observable
419 * @param observer 425 * @param observer
420 * @param <T> 426 * @param <T>
421 */ 427 */
422 public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { 428 public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) {
423 observable.subscribeOn(Schedulers.io())//子线程访问网络 429 observable.subscribeOn(Schedulers.io())//子线程访问网络
424 .observeOn(AndroidSchedulers.mainThread())//回调到主线程 430 .observeOn(AndroidSchedulers.mainThread())//回调到主线程
425 .subscribe(observer); 431 .subscribe(observer);
426 } 432 }
427 433
428 } 434 }
429 435