Commit a516c951d2a39f6977fcaa3a78d0167f417e92e9
1 parent
028132f43d
Exists in
master
作业删除
Showing
4 changed files
with
39 additions
and
5 deletions
Show diff stats
.idea/deploymentTargetDropDown.xml
| 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="deploymentTargetDropDown"> | 3 | <component name="deploymentTargetDropDown"> |
| 4 | <value> | 4 | <value> |
| 5 | <entry key="app"> | 5 | <entry key="app"> |
| 6 | <State /> | 6 | <State> |
| 7 | <runningDeviceTargetSelectedWithDropDown> | ||
| 8 | <Target> | ||
| 9 | <type value="RUNNING_DEVICE_TARGET" /> | ||
| 10 | <deviceKey> | ||
| 11 | <Key> | ||
| 12 | <type value="SERIAL_NUMBER" /> | ||
| 13 | <value value="192.168.3.176:39671" /> | ||
| 14 | </Key> | ||
| 15 | </deviceKey> | ||
| 16 | </Target> | ||
| 17 | </runningDeviceTargetSelectedWithDropDown> | ||
| 18 | <timeTargetWasSelectedWithDropDown value="2024-09-29T02:03:12.057655600Z" /> | ||
| 19 | </State> | ||
| 7 | </entry> | 20 | </entry> |
| 8 | </value> | 21 | </value> |
| 9 | </component> | 22 | </component> |
| 10 | </project> | 23 | </project> |
app/src/main/java/com/hjx/parent/StuHomeworkActivity.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.os.Bundle; | 4 | import android.os.Bundle; |
| 5 | import android.widget.LinearLayout; | 5 | import android.widget.LinearLayout; |
| 6 | import android.widget.PopupWindow; | 6 | import android.widget.PopupWindow; |
| 7 | 7 | ||
| 8 | import androidx.lifecycle.MutableLiveData; | 8 | import androidx.lifecycle.MutableLiveData; |
| 9 | 9 | ||
| 10 | import com.google.gson.Gson; | 10 | import com.google.gson.Gson; |
| 11 | import com.hjx.parent.adapter.HomeworkListAdapter; | 11 | import com.hjx.parent.adapter.HomeworkListAdapter; |
| 12 | import com.hjx.parent.databinding.ActivityStudentHomeworkBinding; | 12 | import com.hjx.parent.databinding.ActivityStudentHomeworkBinding; |
| 13 | import com.hjx.parent.databinding.PopupFilterFeedbackBinding; | 13 | import com.hjx.parent.databinding.PopupFilterFeedbackBinding; |
| 14 | import com.hjx.parent.databinding.PopupFilterGradeBinding; | 14 | import com.hjx.parent.databinding.PopupFilterGradeBinding; |
| 15 | import com.hjx.parent.databinding.PopupFilterSubjectBinding; | 15 | import com.hjx.parent.databinding.PopupFilterSubjectBinding; |
| 16 | import com.hjx.parent.databinding.PopupFilterTermBinding; | 16 | import com.hjx.parent.databinding.PopupFilterTermBinding; |
| 17 | import com.hjx.parent.dialog.MsgConfirmDialog; | 17 | import com.hjx.parent.dialog.MsgConfirmDialog; |
| 18 | import com.hjx.parent.rx.BaseRxActivity; | 18 | import com.hjx.parent.rx.BaseRxActivity; |
| 19 | import com.prws.common.bean.Student; | 19 | import com.prws.common.bean.Student; |
| 20 | import com.prws.common.bean.homework.HomeworkList; | ||
| 20 | import com.prws.common.net.NetWorks; | 21 | import com.prws.common.net.NetWorks; |
| 21 | import com.prws.common.utils.SharedPreferencesUtil; | 22 | import com.prws.common.utils.SharedPreferencesUtil; |
| 22 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; | 23 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; |
| 23 | 24 | ||
| 24 | import java.util.Collections; | 25 | import java.util.Collections; |
| 25 | 26 | ||
| 26 | import io.reactivex.Observable; | 27 | import io.reactivex.Observable; |
| 27 | import io.reactivex.android.schedulers.AndroidSchedulers; | 28 | import io.reactivex.android.schedulers.AndroidSchedulers; |
| 28 | import io.reactivex.schedulers.Schedulers; | 29 | import io.reactivex.schedulers.Schedulers; |
| 29 | 30 | ||
| 30 | public class StuHomeworkActivity extends BaseRxActivity<ActivityStudentHomeworkBinding> { | 31 | public class StuHomeworkActivity extends BaseRxActivity<ActivityStudentHomeworkBinding> { |
| 31 | 32 | ||
| 32 | private final HomeworkListAdapter homeworkAdapter = new HomeworkListAdapter(); | 33 | private final HomeworkListAdapter homeworkAdapter = new HomeworkListAdapter(); |
| 33 | 34 | ||
| 34 | PopupWindow subjectFilter, gradeFilter, termFilter, feedbackFilter; | 35 | PopupWindow subjectFilter, gradeFilter, termFilter, feedbackFilter; |
| 35 | MsgConfirmDialog deleteDialog; | 36 | MsgConfirmDialog deleteDialog; |
| 36 | State state = new State(); | 37 | State state = new State(); |
| 37 | 38 | ||
| 38 | private void handlerIntent() { | 39 | private void handlerIntent() { |
| 39 | String json = getIntent().getStringExtra("studentJson"); | 40 | String json = getIntent().getStringExtra("studentJson"); |
| 40 | if (json == null) json = (String) SharedPreferencesUtil.getData("student", ""); | 41 | if (json == null) json = (String) SharedPreferencesUtil.getData("student", ""); |
| 41 | try { state.student = new Gson().fromJson(json, Student.class); } | 42 | try { state.student = new Gson().fromJson(json, Student.class); } |
| 42 | catch (Throwable t) { t.printStackTrace(); } | 43 | catch (Throwable t) { t.printStackTrace(); } |
| 43 | } | 44 | } |
| 44 | 45 | ||
| 45 | @SuppressLint("SetTextI18n") | 46 | @SuppressLint("SetTextI18n") |
| 46 | @Override | 47 | @Override |
| 47 | public void initView(Bundle savedInstanceState) { | 48 | public void initView(Bundle savedInstanceState) { |
| 48 | handlerIntent(); | 49 | handlerIntent(); |
| 49 | if (state.student == null) { | 50 | if (state.student == null) { |
| 50 | finish(); | 51 | finish(); |
| 51 | return; | 52 | return; |
| 52 | } | 53 | } |
| 53 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); | 54 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); |
| 54 | binding.tvTitle.setText(state.student.stuName + "的全部作业"); | 55 | binding.tvTitle.setText(state.student.stuName + "的全部作业"); |
| 55 | 56 | ||
| 56 | binding.recyclerView.setAdapter(homeworkAdapter); | 57 | binding.recyclerView.setAdapter(homeworkAdapter); |
| 57 | getHomework(); | 58 | getHomework(); |
| 58 | 59 | ||
| 59 | binding.ftSubject.setOnClickListener(v -> showSubjectFilter()); | 60 | binding.ftSubject.setOnClickListener(v -> showSubjectFilter()); |
| 60 | binding.ftGrade.setOnClickListener(v -> showGradeFilter()); | 61 | binding.ftGrade.setOnClickListener(v -> showGradeFilter()); |
| 61 | binding.ftTerm.setOnClickListener(v -> showTermFilter()); | 62 | binding.ftTerm.setOnClickListener(v -> showTermFilter()); |
| 62 | binding.ftFeedback.setOnClickListener(v -> showFeedbackFilter()); | 63 | binding.ftFeedback.setOnClickListener(v -> showFeedbackFilter()); |
| 63 | homeworkAdapter.deleteCall = data -> { | 64 | homeworkAdapter.deleteCall = data -> { |
| 64 | if (deleteDialog == null) { | 65 | if (deleteDialog == null) { |
| 65 | deleteDialog = new MsgConfirmDialog.Builder(this) | 66 | deleteDialog = new MsgConfirmDialog.Builder(this) |
| 66 | .setMessage("确认要删除吗?一旦删除不可恢复") | 67 | .setMessage("确认要删除吗?一旦删除不可恢复") |
| 67 | .setPositive("暂不删除") | 68 | .setPositive("暂不删除") |
| 68 | .setNegative("确定删除") | 69 | .setNegative("确定删除") |
| 69 | .build(); | 70 | .build(); |
| 70 | } | 71 | } |
| 71 | deleteDialog.show(() -> { | 72 | deleteDialog.show(() -> { |
| 72 | // TODO Delete | 73 | deleteHomework(data); |
| 73 | return true; | 74 | return true; |
| 74 | }, null); | 75 | }, null); |
| 75 | }; | 76 | }; |
| 76 | } | 77 | } |
| 77 | 78 | ||
| 79 | @SuppressLint("CheckResult") | ||
| 80 | protected void deleteHomework(HomeworkList data) { | ||
| 81 | NetWorks.service_url.deleteHomework(NetWorks.getHeader(), data.getId()) | ||
| 82 | .subscribeOn(Schedulers.io()) | ||
| 83 | .observeOn(AndroidSchedulers.mainThread()) | ||
| 84 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) | ||
| 85 | .subscribe((response, th) -> { | ||
| 86 | if (th != null) th.printStackTrace(); | ||
| 87 | if (response != null && response.getSuccess()) { | ||
| 88 | getHomework(); | ||
| 89 | } | ||
| 90 | }); | ||
| 91 | |||
| 92 | } | ||
| 78 | 93 | ||
| 79 | @SuppressLint("CheckResult") | 94 | @SuppressLint("CheckResult") |
| 80 | protected void getHomework() { | 95 | protected void getHomework() { |
| 81 | NetWorks.service_url.getStudentHomework(NetWorks.getHeader(), state.student.stuId) | 96 | NetWorks.service_url.getStudentHomework(NetWorks.getHeader(), state.student.stuId) |
| 82 | .subscribeOn(Schedulers.io()) | 97 | .subscribeOn(Schedulers.io()) |
| 83 | .observeOn(AndroidSchedulers.mainThread()) | 98 | .observeOn(AndroidSchedulers.mainThread()) |
| 84 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) | 99 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) |
| 85 | .toObservable() | 100 | .toObservable() |
| 86 | .flatMap(response -> Observable.fromIterable(response.getData())) | 101 | .flatMap(response -> Observable.fromIterable(response.getData())) |
| 87 | // 过滤 | 102 | // 过滤 |
| 88 | .filter(data -> { // 学科 | 103 | .filter(data -> { // 学科 |
| 89 | String subject = state.subject.getValue(); | 104 | String subject = state.subject.getValue(); |
| 90 | if (subject == null || subject.isEmpty()) return true; | 105 | if (subject == null || subject.isEmpty()) return true; |
| 91 | else return subject.equals(data.getSubject()); | 106 | else return subject.equals(data.getSubject()); |
| 92 | }) | 107 | }) |
| 93 | .filter(data -> { // 年级 | 108 | .filter(data -> { // 年级 |
| 94 | String grade = state.grade.getValue(); | 109 | String grade = state.grade.getValue(); |
| 95 | if (grade == null || grade.isEmpty()) return true; | 110 | if (grade == null || grade.isEmpty()) return true; |
| 96 | else return grade.equals(data.getGrade()); | 111 | else return grade.equals(data.getGrade()); |
| 97 | }) | 112 | }) |
| 98 | .filter(data -> { // 学期 | 113 | .filter(data -> { // 学期 |
| 99 | String term = state.term.getValue(); | 114 | String term = state.term.getValue(); |
| 100 | if (term == null || term.isEmpty()) return true; | 115 | if (term == null || term.isEmpty()) return true; |
| 101 | else return term.equals(data.getTerm()); | 116 | else return term.equals(data.getTerm()); |
| 102 | }) | 117 | }) |
| 103 | .filter(data -> { // 反馈 | 118 | .filter(data -> { // 反馈 |
| 104 | Integer feedback = state.feedback.getValue(); | 119 | Integer feedback = state.feedback.getValue(); |
| 105 | if (feedback == null || feedback == 0) return true; | 120 | if (feedback == null || feedback == 0) return true; |
| 106 | else return (feedback == 1 && data.getRight() != null) || (feedback == 2 && data.getRight() == null); | 121 | else return (feedback == 1 && data.getRight() != null) || (feedback == 2 && data.getRight() == null); |
| 107 | }) | 122 | }) |
| 108 | // 过滤完成, 收集 | 123 | // 过滤完成, 收集 |
| 109 | .toList() | 124 | .toList() |
| 110 | .subscribe((data, th) -> { | 125 | .subscribe((data, th) -> { |
| 111 | if (th != null) th.printStackTrace(); | 126 | if (th != null) th.printStackTrace(); |
| 112 | if (data != null) { | 127 | if (data != null) { |
| 113 | Collections.sort(data); | 128 | Collections.sort(data); |
| 114 | } | 129 | } |
| 115 | homeworkAdapter.setNewData(data); | 130 | homeworkAdapter.setNewData(data); |
| 116 | }); | 131 | }); |
| 117 | } | 132 | } |
| 118 | 133 | ||
| 119 | private void showSubjectFilter() { | 134 | private void showSubjectFilter() { |
| 120 | if (subjectFilter == null) { | 135 | if (subjectFilter == null) { |
| 121 | PopupFilterSubjectBinding db = PopupFilterSubjectBinding.inflate(getLayoutInflater()); | 136 | PopupFilterSubjectBinding db = PopupFilterSubjectBinding.inflate(getLayoutInflater()); |
| 122 | db.setLifecycleOwner(this); | 137 | db.setLifecycleOwner(this); |
| 123 | db.setState(state); | 138 | db.setState(state); |
| 124 | db.bg.setOnClickListener(v -> subjectFilter.dismiss()); | 139 | db.bg.setOnClickListener(v -> subjectFilter.dismiss()); |
| 125 | subjectFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 140 | subjectFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
| 126 | subjectFilter.setOutsideTouchable(true); | 141 | subjectFilter.setOutsideTouchable(true); |
| 127 | subjectFilter.setOnDismissListener(this::getHomework); | 142 | subjectFilter.setOnDismissListener(this::getHomework); |
| 128 | } | 143 | } |
| 129 | subjectFilter.showAsDropDown(binding.anchorView); | 144 | subjectFilter.showAsDropDown(binding.anchorView); |
| 130 | } | 145 | } |
| 131 | 146 | ||
| 132 | private void showGradeFilter() { | 147 | private void showGradeFilter() { |
| 133 | if (gradeFilter == null) { | 148 | if (gradeFilter == null) { |
| 134 | PopupFilterGradeBinding db = PopupFilterGradeBinding.inflate(getLayoutInflater()); | 149 | PopupFilterGradeBinding db = PopupFilterGradeBinding.inflate(getLayoutInflater()); |
| 135 | db.setLifecycleOwner(this); | 150 | db.setLifecycleOwner(this); |
| 136 | db.setState(state); | 151 | db.setState(state); |
| 137 | db.bg.setOnClickListener(v -> gradeFilter.dismiss()); | 152 | db.bg.setOnClickListener(v -> gradeFilter.dismiss()); |
| 138 | gradeFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 153 | gradeFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
| 139 | gradeFilter.setOutsideTouchable(true); | 154 | gradeFilter.setOutsideTouchable(true); |
| 140 | gradeFilter.setOnDismissListener(this::getHomework); | 155 | gradeFilter.setOnDismissListener(this::getHomework); |
| 141 | } | 156 | } |
| 142 | gradeFilter.showAsDropDown(binding.anchorView); | 157 | gradeFilter.showAsDropDown(binding.anchorView); |
| 143 | } | 158 | } |
| 144 | 159 | ||
| 145 | private void showTermFilter() { | 160 | private void showTermFilter() { |
| 146 | if (termFilter == null) { | 161 | if (termFilter == null) { |
| 147 | PopupFilterTermBinding db = PopupFilterTermBinding.inflate(getLayoutInflater()); | 162 | PopupFilterTermBinding db = PopupFilterTermBinding.inflate(getLayoutInflater()); |
| 148 | db.setLifecycleOwner(this); | 163 | db.setLifecycleOwner(this); |
| 149 | db.setState(state); | 164 | db.setState(state); |
| 150 | db.bg.setOnClickListener(v -> termFilter.dismiss()); | 165 | db.bg.setOnClickListener(v -> termFilter.dismiss()); |
| 151 | termFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 166 | termFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
| 152 | termFilter.setOutsideTouchable(true); | 167 | termFilter.setOutsideTouchable(true); |
| 153 | termFilter.setOnDismissListener(this::getHomework); | 168 | termFilter.setOnDismissListener(this::getHomework); |
| 154 | } | 169 | } |
| 155 | termFilter.showAsDropDown(binding.anchorView); | 170 | termFilter.showAsDropDown(binding.anchorView); |
| 156 | } | 171 | } |
| 157 | 172 | ||
| 158 | private void showFeedbackFilter() { | 173 | private void showFeedbackFilter() { |
| 159 | if (feedbackFilter == null) { | 174 | if (feedbackFilter == null) { |
| 160 | PopupFilterFeedbackBinding db = PopupFilterFeedbackBinding.inflate(getLayoutInflater()); | 175 | PopupFilterFeedbackBinding db = PopupFilterFeedbackBinding.inflate(getLayoutInflater()); |
| 161 | db.setLifecycleOwner(this); | 176 | db.setLifecycleOwner(this); |
| 162 | db.setState(state); | 177 | db.setState(state); |
| 163 | db.bg.setOnClickListener(v -> feedbackFilter.dismiss()); | 178 | db.bg.setOnClickListener(v -> feedbackFilter.dismiss()); |
| 164 | feedbackFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 179 | feedbackFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
| 165 | feedbackFilter.setOutsideTouchable(true); | 180 | feedbackFilter.setOutsideTouchable(true); |
| 166 | feedbackFilter.setOnDismissListener(this::getHomework); | 181 | feedbackFilter.setOnDismissListener(this::getHomework); |
| 167 | } | 182 | } |
| 168 | feedbackFilter.showAsDropDown(binding.anchorView); | 183 | feedbackFilter.showAsDropDown(binding.anchorView); |
| 169 | } | 184 | } |
| 170 | 185 | ||
| 171 | @Override | 186 | @Override |
| 172 | protected ActivityStudentHomeworkBinding getViewBinding() { | 187 | protected ActivityStudentHomeworkBinding getViewBinding() { |
| 173 | return ActivityStudentHomeworkBinding.inflate(getLayoutInflater()); | 188 | return ActivityStudentHomeworkBinding.inflate(getLayoutInflater()); |
| 174 | } | 189 | } |
| 175 | 190 | ||
| 176 | public static class State { | 191 | public static class State { |
| 177 | public Student student; | 192 | public Student student; |
| 178 | 193 | ||
| 179 | public MutableLiveData<String> subject = new MutableLiveData<>(""); | 194 | public MutableLiveData<String> subject = new MutableLiveData<>(""); |
| 180 | public void setSubject(String value) { | 195 | public void setSubject(String value) { |
| 181 | subject.setValue(value); | 196 | subject.setValue(value); |
| 182 | } | 197 | } |
| 183 | 198 | ||
| 184 | public MutableLiveData<String> grade = new MutableLiveData<>(""); | 199 | public MutableLiveData<String> grade = new MutableLiveData<>(""); |
| 185 | public void setGrade(String value) { | 200 | public void setGrade(String value) { |
| 186 | grade.setValue(value); | 201 | grade.setValue(value); |
| 187 | } | 202 | } |
| 188 | 203 | ||
| 189 | public MutableLiveData<String> term = new MutableLiveData<>(""); | 204 | public MutableLiveData<String> term = new MutableLiveData<>(""); |
| 190 | public void setTerm(String value) { | 205 | public void setTerm(String value) { |
| 191 | term.setValue(value); | 206 | term.setValue(value); |
| 192 | } | 207 | } |
| 193 | 208 | ||
| 194 | //0:全部, 1: 已反馈, 2:未反馈 | 209 | //0:全部, 1: 已反馈, 2:未反馈 |
| 195 | public MutableLiveData<Integer> feedback = new MutableLiveData<>(0); | 210 | public MutableLiveData<Integer> feedback = new MutableLiveData<>(0); |
| 196 | public void setFeedback(int value) { | 211 | public void setFeedback(int value) { |
| 197 | feedback.setValue(value); | 212 | feedback.setValue(value); |
| 198 | } | 213 | } |
| 199 | } | 214 | } |
| 200 | } | 215 | } |
| 201 | 216 |
libs/common/src/main/java/com/prws/common/bean/homework/HomeworkList.java
| 1 | package com.prws.common.bean.homework; | 1 | package com.prws.common.bean.homework; |
| 2 | 2 | ||
| 3 | import com.google.gson.annotations.SerializedName; | 3 | import com.google.gson.annotations.SerializedName; |
| 4 | 4 | ||
| 5 | import java.text.SimpleDateFormat; | 5 | import java.text.SimpleDateFormat; |
| 6 | import java.util.Date; | 6 | import java.util.Date; |
| 7 | import java.util.Locale; | 7 | import java.util.Locale; |
| 8 | 8 | ||
| 9 | public class HomeworkList implements Comparable<HomeworkList> { | 9 | public class HomeworkList implements Comparable<HomeworkList> { |
| 10 | 10 | ||
| 11 | @SerializedName(value = "homeworkId", alternate = "id") | 11 | @SerializedName(value = "homeworkId", alternate = "id") |
| 12 | private Integer homeworkId; | 12 | private String homeworkId; |
| 13 | @SerializedName(value = "name", alternate = "homeworkName") | 13 | @SerializedName(value = "name", alternate = "homeworkName") |
| 14 | private String name; | 14 | private String name; |
| 15 | @SerializedName("grade") | 15 | @SerializedName("grade") |
| 16 | private String grade; | 16 | private String grade; |
| 17 | @SerializedName("term") | 17 | @SerializedName("term") |
| 18 | private String term; | 18 | private String term; |
| 19 | @SerializedName("subject") | 19 | @SerializedName("subject") |
| 20 | private String subject; | 20 | private String subject; |
| 21 | private int completeFlag; | 21 | private int completeFlag; |
| 22 | 22 | ||
| 23 | private Integer total; | 23 | private Integer total; |
| 24 | private Integer right; | 24 | private Integer right; |
| 25 | 25 | ||
| 26 | public Date uploadTime; | 26 | public Date uploadTime; |
| 27 | 27 | ||
| 28 | public Integer getTotal() { | 28 | public Integer getTotal() { |
| 29 | return total; | 29 | return total; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | public Integer getRight() { | 32 | public Integer getRight() { |
| 33 | return right; | 33 | return right; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | public void setRight(Integer right) { | 36 | public void setRight(Integer right) { |
| 37 | this.right = right; | 37 | this.right = right; |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | public void setTotal(Integer total) { | 40 | public void setTotal(Integer total) { |
| 41 | this.total = total; | 41 | this.total = total; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | public void setId(Integer id) { | 44 | public void setId(String id) { |
| 45 | this.homeworkId = id; | 45 | this.homeworkId = id; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | public void setName(String name) { | 48 | public void setName(String name) { |
| 49 | this.name = name; | 49 | this.name = name; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | public void setGrade(String grade) { | 52 | public void setGrade(String grade) { |
| 53 | this.grade = grade; | 53 | this.grade = grade; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | public void setTerm(String term) { | 56 | public void setTerm(String term) { |
| 57 | this.term = term; | 57 | this.term = term; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | public void setSubject(String subject) { | 60 | public void setSubject(String subject) { |
| 61 | this.subject = subject; | 61 | this.subject = subject; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | public void setCompleteFlag(int completeFlag) { | 64 | public void setCompleteFlag(int completeFlag) { |
| 65 | this.completeFlag = completeFlag; | 65 | this.completeFlag = completeFlag; |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | public Integer getId() { | 68 | public String getId() { |
| 69 | return homeworkId; | 69 | return homeworkId; |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | public String getName() { | 72 | public String getName() { |
| 73 | return name; | 73 | return name; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | public String getGrade() { | 76 | public String getGrade() { |
| 77 | return grade; | 77 | return grade; |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | public String getTerm() { | 80 | public String getTerm() { |
| 81 | return term; | 81 | return term; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | public String getSubject() { | 84 | public String getSubject() { |
| 85 | return subject; | 85 | return subject; |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | public int getCompleteFlag() { | 88 | public int getCompleteFlag() { |
| 89 | return completeFlag; | 89 | return completeFlag; |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | @Override | 92 | @Override |
| 93 | public int compareTo(HomeworkList other) { | 93 | public int compareTo(HomeworkList other) { |
| 94 | long time1 = this.uploadTime == null ? 0 : this.uploadTime.getTime(); | 94 | long time1 = this.uploadTime == null ? 0 : this.uploadTime.getTime(); |
| 95 | long time2 = other.uploadTime == null ? 0 : other.uploadTime.getTime(); | 95 | long time2 = other.uploadTime == null ? 0 : other.uploadTime.getTime(); |
| 96 | return (int) (time2 - time1); | 96 | return (int) (time2 - time1); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | private String time; | 99 | private String time; |
| 100 | private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA); | 100 | private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA); |
| 101 | public String getFormatTime() { | 101 | public String getFormatTime() { |
| 102 | if (uploadTime == null) return ""; | 102 | if (uploadTime == null) return ""; |
| 103 | if (time != null) return time; | 103 | if (time != null) return time; |
| 104 | time = format.format(uploadTime); | 104 | time = format.format(uploadTime); |
| 105 | return time; | 105 | return time; |
| 106 | } | 106 | } |
| 107 | } | 107 | } |
| 108 | 108 |
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.HomeworkList; | 17 | import com.prws.common.bean.homework.HomeworkList; |
| 18 | import com.prws.common.utils.BitmapUtils; | 18 | import com.prws.common.utils.BitmapUtils; |
| 19 | import com.prws.common.utils.SharedPreferencesUtil; | 19 | import com.prws.common.utils.SharedPreferencesUtil; |
| 20 | 20 | ||
| 21 | import java.io.File; | 21 | import java.io.File; |
| 22 | import java.util.HashMap; | 22 | import java.util.HashMap; |
| 23 | import java.util.List; | 23 | import java.util.List; |
| 24 | import java.util.Map; | 24 | import java.util.Map; |
| 25 | 25 | ||
| 26 | import io.reactivex.Observable; | 26 | import io.reactivex.Observable; |
| 27 | import io.reactivex.Observer; | 27 | import io.reactivex.Observer; |
| 28 | import io.reactivex.Single; | 28 | import io.reactivex.Single; |
| 29 | import io.reactivex.android.schedulers.AndroidSchedulers; | 29 | import io.reactivex.android.schedulers.AndroidSchedulers; |
| 30 | import io.reactivex.schedulers.Schedulers; | 30 | import io.reactivex.schedulers.Schedulers; |
| 31 | import okhttp3.MediaType; | 31 | import okhttp3.MediaType; |
| 32 | import okhttp3.MultipartBody; | 32 | import okhttp3.MultipartBody; |
| 33 | import okhttp3.RequestBody; | 33 | import okhttp3.RequestBody; |
| 34 | import okhttp3.ResponseBody; | 34 | import okhttp3.ResponseBody; |
| 35 | import retrofit2.Call; | 35 | import retrofit2.Call; |
| 36 | import retrofit2.Callback; | 36 | import retrofit2.Callback; |
| 37 | import retrofit2.http.Body; | 37 | import retrofit2.http.Body; |
| 38 | import retrofit2.http.GET; | 38 | import retrofit2.http.GET; |
| 39 | import retrofit2.http.Header; | 39 | import retrofit2.http.Header; |
| 40 | import retrofit2.http.Headers; | 40 | import retrofit2.http.Headers; |
| 41 | import retrofit2.http.Multipart; | 41 | import retrofit2.http.Multipart; |
| 42 | import retrofit2.http.POST; | 42 | import retrofit2.http.POST; |
| 43 | import retrofit2.http.PUT; | 43 | import retrofit2.http.PUT; |
| 44 | import retrofit2.http.Part; | 44 | import retrofit2.http.Part; |
| 45 | import retrofit2.http.PartMap; | 45 | import retrofit2.http.PartMap; |
| 46 | import retrofit2.http.Query; | 46 | import retrofit2.http.Query; |
| 47 | import retrofit2.http.Url; | 47 | import retrofit2.http.Url; |
| 48 | 48 | ||
| 49 | /** | 49 | /** |
| 50 | * 类名称:NetWorks | 50 | * 类名称:NetWorks |
| 51 | * 创建人: | 51 | * 创建人: |
| 52 | * <p> | 52 | * <p> |
| 53 | * 类描述:网络请求的操作类 | 53 | * 类描述:网络请求的操作类 |
| 54 | */ | 54 | */ |
| 55 | public class NetWorks extends RetrofitUtils { | 55 | public class NetWorks extends RetrofitUtils { |
| 56 | //服务器路径 | 56 | //服务器路径 |
| 57 | public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class); | 57 | public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class); |
| 58 | 58 | ||
| 59 | //设缓存有效期为1天 | 59 | //设缓存有效期为1天 |
| 60 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; | 60 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; |
| 61 | //查询缓存的Cache-Control设置,使用缓存 | 61 | //查询缓存的Cache-Control设置,使用缓存 |
| 62 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; | 62 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; |
| 63 | //查询网络的Cache-Control设置。不使用缓存 | 63 | //查询网络的Cache-Control设置。不使用缓存 |
| 64 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; | 64 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; |
| 65 | 65 | ||
| 66 | 66 | ||
| 67 | public interface NetService { | 67 | public interface NetService { |
| 68 | 68 | ||
| 69 | 69 | ||
| 70 | @GET("/api/v1/user/logout") | 70 | @GET("/api/v1/user/logout") |
| 71 | Observable<ResponseBody> logout(); | 71 | Observable<ResponseBody> logout(); |
| 72 | 72 | ||
| 73 | @Multipart | 73 | @Multipart |
| 74 | @POST("/api/v1/user/upLoadAvatar") | 74 | @POST("/api/v1/user/upLoadAvatar") |
| 75 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); | 75 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); |
| 76 | 76 | ||
| 77 | 77 | ||
| 78 | @Headers("Content-Type: application/json") | 78 | @Headers("Content-Type: application/json") |
| 79 | @POST("/api/v1/user/editUser") | 79 | @POST("/api/v1/user/editUser") |
| 80 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); | 80 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); |
| 81 | 81 | ||
| 82 | @Headers("Content-Type: application/json") | 82 | @Headers("Content-Type: application/json") |
| 83 | @POST("/api/v1/user/changePassword") | 83 | @POST("/api/v1/user/changePassword") |
| 84 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); | 84 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); |
| 85 | 85 | ||
| 86 | 86 | ||
| 87 | @GET("/api/v1/user/searchById") | 87 | @GET("/api/v1/user/searchById") |
| 88 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); | 88 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); |
| 89 | 89 | ||
| 90 | 90 | ||
| 91 | @Headers("Content-Type: application/json") | 91 | @Headers("Content-Type: application/json") |
| 92 | @POST("/api/v1/auth/login") | 92 | @POST("/api/v1/auth/login") |
| 93 | Observable<ResponseBody> login(@Body RequestBody body); | 93 | Observable<ResponseBody> login(@Body RequestBody body); |
| 94 | 94 | ||
| 95 | @GET("/api/v1/resource/listGradeAndSubject") | 95 | @GET("/api/v1/resource/listGradeAndSubject") |
| 96 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); | 96 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); |
| 97 | 97 | ||
| 98 | 98 | ||
| 99 | @GET("/api/v1/manager/generalQrCode") | 99 | @GET("/api/v1/manager/generalQrCode") |
| 100 | Observable<ResponseBody> generalQrCode(); | 100 | Observable<ResponseBody> generalQrCode(); |
| 101 | 101 | ||
| 102 | @GET("/api/v1/parent/scanAndLogin?") | 102 | @GET("/api/v1/parent/scanAndLogin?") |
| 103 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId); | 103 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId); |
| 104 | 104 | ||
| 105 | @GET("/api/v1/parent/getChildrenList") | 105 | @GET("/api/v1/parent/getChildrenList") |
| 106 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); | 106 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); |
| 107 | 107 | ||
| 108 | 108 | ||
| 109 | @Headers("Content-Type: application/json") | 109 | @Headers("Content-Type: application/json") |
| 110 | @POST("/api/v1/parent/registerParent") | 110 | @POST("/api/v1/parent/registerParent") |
| 111 | Observable<ResponseBody> registerParent(@Body RequestBody body); | 111 | Observable<ResponseBody> registerParent(@Body RequestBody body); |
| 112 | 112 | ||
| 113 | 113 | ||
| 114 | @GET("/api/v1/parent/listChildren") | 114 | @GET("/api/v1/parent/listChildren") |
| 115 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); | 115 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); |
| 116 | 116 | ||
| 117 | 117 | ||
| 118 | @Headers("Content-Type: application/json") | 118 | @Headers("Content-Type: application/json") |
| 119 | @POST("/api/v1/parent/registerStudent") | 119 | @POST("/api/v1/parent/registerStudent") |
| 120 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); | 120 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); |
| 121 | 121 | ||
| 122 | @Headers("Content-Type: application/json") | 122 | @Headers("Content-Type: application/json") |
| 123 | @POST("/api/v1/parent/bindTeacher") | 123 | @POST("/api/v1/parent/bindTeacher") |
| 124 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); | 124 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); |
| 125 | 125 | ||
| 126 | @Multipart | 126 | @Multipart |
| 127 | @POST("/api/v1/user/upLoadAvatar") | 127 | @POST("/api/v1/user/upLoadAvatar") |
| 128 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); | 128 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); |
| 129 | 129 | ||
| 130 | 130 | ||
| 131 | @Multipart | 131 | @Multipart |
| 132 | @POST("/api/v1/student/editStudentAvatar") | 132 | @POST("/api/v1/student/editStudentAvatar") |
| 133 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 133 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
| 134 | 134 | ||
| 135 | @Headers("Content-Type: application/json") | 135 | @Headers("Content-Type: application/json") |
| 136 | @POST("/api/v1/parent/editChild") | 136 | @POST("/api/v1/parent/editChild") |
| 137 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); | 137 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); |
| 138 | 138 | ||
| 139 | @GET("/api/v1/student/getStudyPlanForThisWeek") | 139 | @GET("/api/v1/student/getStudyPlanForThisWeek") |
| 140 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); | 140 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); |
| 141 | 141 | ||
| 142 | @GET("api/v1/parent/searchTeacher") | 142 | @GET("api/v1/parent/searchTeacher") |
| 143 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); | 143 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); |
| 144 | 144 | ||
| 145 | @POST("api/v1/question/listErrorBook") | 145 | @POST("api/v1/question/listErrorBook") |
| 146 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); | 146 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); |
| 147 | 147 | ||
| 148 | @POST | 148 | @POST |
| 149 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); | 149 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); |
| 150 | 150 | ||
| 151 | @POST | 151 | @POST |
| 152 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); | 152 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); |
| 153 | 153 | ||
| 154 | @POST | 154 | @POST |
| 155 | Observable<JsonObject> getBaiduToken(@Url String url); | 155 | Observable<JsonObject> getBaiduToken(@Url String url); |
| 156 | 156 | ||
| 157 | @Multipart | 157 | @Multipart |
| 158 | @POST("api/v1/pad/addErrorBook") | 158 | @POST("api/v1/pad/addErrorBook") |
| 159 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 159 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
| 160 | 160 | ||
| 161 | @POST("api/v1/pad/deleteStuErrorBook") | 161 | @POST("api/v1/pad/deleteStuErrorBook") |
| 162 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); | 162 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); |
| 163 | 163 | ||
| 164 | @PUT("api/v1/pad/updateStuErrorBookInfo") | 164 | @PUT("api/v1/pad/updateStuErrorBookInfo") |
| 165 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); | 165 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); |
| 166 | 166 | ||
| 167 | @POST("api/v1/question/editErrorBook") | 167 | @POST("api/v1/question/editErrorBook") |
| 168 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); | 168 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); |
| 169 | 169 | ||
| 170 | @GET("api/v1/resource/checkUpdate") | 170 | @GET("api/v1/resource/checkUpdate") |
| 171 | Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); | 171 | Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); |
| 172 | 172 | ||
| 173 | @GET("api/v1/teacher/getStudentList") | 173 | @GET("api/v1/teacher/getStudentList") |
| 174 | Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); | 174 | Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); |
| 175 | 175 | ||
| 176 | @GET("api/v1/teacher/getStudentList") | 176 | @GET("api/v1/teacher/getStudentList") |
| 177 | Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id); | 177 | Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id); |
| 178 | 178 | ||
| 179 | @GET("api/v1/answer/listRecordForTeacher") | 179 | @GET("api/v1/answer/listRecordForTeacher") |
| 180 | Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); | 180 | Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); |
| 181 | 181 | ||
| 182 | @GET("api/v1/homework/listHomeworkByStuId") | 182 | @GET("api/v1/homework/listHomeworkByStuId") |
| 183 | Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId); | 183 | Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId); |
| 184 | 184 | ||
| 185 | @POST | 185 | @POST |
| 186 | Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body); | 186 | Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body); |
| 187 | 187 | ||
| 188 | @Multipart | 188 | @Multipart |
| 189 | @POST("api/v1/homework/uploadHomework") | 189 | @POST("api/v1/homework/uploadHomework") |
| 190 | Single<ResponseResult> uploadImage(@Header("Authorization") String token, @Part() MultipartBody.Part file, @Query("brief") String id); | 190 | Single<ResponseResult> uploadImage(@Header("Authorization") String token, @Part() MultipartBody.Part file, @Query("brief") String id); |
| 191 | 191 | ||
| 192 | @POST("api/v1/homework/uploadHomeworkAction") | 192 | @POST("api/v1/homework/uploadHomeworkAction") |
| 193 | Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map); | 193 | Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map); |
| 194 | 194 | ||
| 195 | @GET("api/v1/homework/removeHomework") | ||
| 196 | Single<ResponseResult<Boolean>> deleteHomework( | ||
| 197 | @Header("Authorization") String token, | ||
| 198 | @Query("homeworkId") String homeworkId | ||
| 199 | ); | ||
| 200 | |||
| 195 | } | 201 | } |
| 196 | 202 | ||
| 197 | public static String getUserId() { | 203 | public static String getUserId() { |
| 198 | return (String) SharedPreferencesUtil.getData("userId", ""); | 204 | return (String) SharedPreferencesUtil.getData("userId", ""); |
| 199 | } | 205 | } |
| 200 | 206 | ||
| 201 | public static String getHeader() { | 207 | public static String getHeader() { |
| 202 | return (String) SharedPreferencesUtil.getData("token", ""); | 208 | return (String) SharedPreferencesUtil.getData("token", ""); |
| 203 | } | 209 | } |
| 204 | 210 | ||
| 205 | public static String getBaiduToken() { | 211 | public static String getBaiduToken() { |
| 206 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); | 212 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); |
| 207 | } | 213 | } |
| 208 | 214 | ||
| 209 | public static Single<BaiduInput> inputImage(String filePath, String id) { | 215 | public static Single<BaiduInput> inputImage(String filePath, String id) { |
| 210 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 216 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 211 | String base64 = BitmapUtils.fileToBase64(filePath); | 217 | String base64 = BitmapUtils.fileToBase64(filePath); |
| 212 | File file = new File(filePath); | 218 | File file = new File(filePath); |
| 213 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}"); | 219 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}"); |
| 214 | return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) | 220 | return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) |
| 215 | .flatMap(token -> { | 221 | .flatMap(token -> { |
| 216 | return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body); | 222 | return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body); |
| 217 | }); | 223 | }); |
| 218 | } | 224 | } |
| 219 | 225 | ||
| 220 | public static Single<ResponseResult> uploadImage(String path, String id) { | 226 | public static Single<ResponseResult> uploadImage(String path, String id) { |
| 221 | File file = new File(path); | 227 | File file = new File(path); |
| 222 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | 228 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); |
| 223 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 229 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 224 | return service_url.uploadImage(getHeader(), part, id); | 230 | return service_url.uploadImage(getHeader(), part, id); |
| 225 | } | 231 | } |
| 226 | 232 | ||
| 227 | 233 | ||
| 228 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { | 234 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { |
| 229 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); | 235 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); |
| 230 | } | 236 | } |
| 231 | 237 | ||
| 232 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { | 238 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { |
| 233 | File file = new File(path); | 239 | File file = new File(path); |
| 234 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | 240 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); |
| 235 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 241 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 236 | Map<String, Object> map = new HashMap<>(); | 242 | Map<String, Object> map = new HashMap<>(); |
| 237 | map.put("condition", param); | 243 | map.put("condition", param); |
| 238 | setSubscribe(service_url.addError(part, map), observer); | 244 | setSubscribe(service_url.addError(part, map), observer); |
| 239 | } | 245 | } |
| 240 | 246 | ||
| 241 | 247 | ||
| 242 | public static void cut(String base64, Observer<CutPicBean> observer) { | 248 | public static void cut(String base64, Observer<CutPicBean> observer) { |
| 243 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 249 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 244 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); | 250 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); |
| 245 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); | 251 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); |
| 246 | } | 252 | } |
| 247 | 253 | ||
| 248 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { | 254 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { |
| 249 | setSubscribe(service_url.editError(getHeader(), map), observer); | 255 | setSubscribe(service_url.editError(getHeader(), map), observer); |
| 250 | } | 256 | } |
| 251 | 257 | ||
| 252 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { | 258 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { |
| 253 | setSubscribe(service_url.updateError(getHeader(), map), observer); | 259 | setSubscribe(service_url.updateError(getHeader(), map), observer); |
| 254 | } | 260 | } |
| 255 | 261 | ||
| 256 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { | 262 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { |
| 257 | setSubscribe(service_url.deleteError(getHeader(), map), observer); | 263 | setSubscribe(service_url.deleteError(getHeader(), map), observer); |
| 258 | } | 264 | } |
| 259 | 265 | ||
| 260 | public static void getBaiduToken(Observer<JsonObject> observer) { | 266 | public static void getBaiduToken(Observer<JsonObject> observer) { |
| 261 | 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); | 267 | 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); |
| 262 | } | 268 | } |
| 263 | 269 | ||
| 264 | public static Single<JsonObject> getBaiduTokenOcr() { | 270 | public static Single<JsonObject> getBaiduTokenOcr() { |
| 265 | 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(); | 271 | 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(); |
| 266 | } | 272 | } |
| 267 | 273 | ||
| 268 | public static void removeWriting(String base64, Observer<JsonObject> observer) { | 274 | public static void removeWriting(String base64, Observer<JsonObject> observer) { |
| 269 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 275 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 270 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); | 276 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); |
| 271 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); | 277 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); |
| 272 | } | 278 | } |
| 273 | 279 | ||
| 274 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { | 280 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { |
| 275 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); | 281 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); |
| 276 | } | 282 | } |
| 277 | 283 | ||
| 278 | public static void logout(Observer<ResponseBody> observer) { | 284 | public static void logout(Observer<ResponseBody> observer) { |
| 279 | setSubscribe(service_url.logout(), observer); | 285 | setSubscribe(service_url.logout(), observer); |
| 280 | } | 286 | } |
| 281 | 287 | ||
| 282 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { | 288 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { |
| 283 | setSubscribe(service_url.editStudent(getHeader(), body), observable); | 289 | setSubscribe(service_url.editStudent(getHeader(), body), observable); |
| 284 | } | 290 | } |
| 285 | 291 | ||
| 286 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { | 292 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { |
| 287 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); | 293 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); |
| 288 | } | 294 | } |
| 289 | 295 | ||
| 290 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { | 296 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { |
| 291 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 297 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
| 292 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 298 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 293 | Map<String, Object> map = new HashMap<>(); | 299 | Map<String, Object> map = new HashMap<>(); |
| 294 | map.put("stuId", stuId); | 300 | map.put("stuId", stuId); |
| 295 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); | 301 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); |
| 296 | } | 302 | } |
| 297 | 303 | ||
| 298 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { | 304 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { |
| 299 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 305 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
| 300 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 306 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 301 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); | 307 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); |
| 302 | } | 308 | } |
| 303 | 309 | ||
| 304 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { | 310 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { |
| 305 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); | 311 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); |
| 306 | } | 312 | } |
| 307 | 313 | ||
| 308 | 314 | ||
| 309 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { | 315 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { |
| 310 | setSubscribe(service_url.editUser(getHeader(), body), observer); | 316 | setSubscribe(service_url.editUser(getHeader(), body), observer); |
| 311 | } | 317 | } |
| 312 | 318 | ||
| 313 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { | 319 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { |
| 314 | setSubscribe(service_url.changePassword(getHeader(), body), observer); | 320 | setSubscribe(service_url.changePassword(getHeader(), body), observer); |
| 315 | } | 321 | } |
| 316 | 322 | ||
| 317 | 323 | ||
| 318 | public static void searchById(String userId, Observer<ResponseBody> observer) { | 324 | public static void searchById(String userId, Observer<ResponseBody> observer) { |
| 319 | setSubscribe(service_url.searchById(getHeader(), userId), observer); | 325 | setSubscribe(service_url.searchById(getHeader(), userId), observer); |
| 320 | } | 326 | } |
| 321 | 327 | ||
| 322 | 328 | ||
| 323 | public static void login(RequestBody body, Observer<ResponseBody> observer) { | 329 | public static void login(RequestBody body, Observer<ResponseBody> observer) { |
| 324 | setSubscribe(service_url.login(body), observer); | 330 | setSubscribe(service_url.login(body), observer); |
| 325 | } | 331 | } |
| 326 | 332 | ||
| 327 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { | 333 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { |
| 328 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); | 334 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); |
| 329 | } | 335 | } |
| 330 | 336 | ||
| 331 | 337 | ||
| 332 | public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { | 338 | public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { |
| 333 | setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); | 339 | setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); |
| 334 | } | 340 | } |
| 335 | 341 | ||
| 336 | public static void getChildrenList(Observer<ResponseBody> observer) { | 342 | public static void getChildrenList(Observer<ResponseBody> observer) { |
| 337 | setSubscribe(service_url.getChildrenList(getHeader()), observer); | 343 | setSubscribe(service_url.getChildrenList(getHeader()), observer); |
| 338 | } | 344 | } |
| 339 | 345 | ||
| 340 | 346 | ||
| 341 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { | 347 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { |
| 342 | setSubscribe(service_url.registerParent(body), observer); | 348 | setSubscribe(service_url.registerParent(body), observer); |
| 343 | } | 349 | } |
| 344 | 350 | ||
| 345 | 351 | ||
| 346 | public static void listChildren(Observer<ResponseBody> observer) { | 352 | public static void listChildren(Observer<ResponseBody> observer) { |
| 347 | setSubscribe(service_url.listChildren(getHeader()), observer); | 353 | setSubscribe(service_url.listChildren(getHeader()), observer); |
| 348 | } | 354 | } |
| 349 | 355 | ||
| 350 | public static void listStudent(Observer<ResponseBody> observer) { | 356 | public static void listStudent(Observer<ResponseBody> observer) { |
| 351 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 357 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
| 352 | } | 358 | } |
| 353 | 359 | ||
| 354 | public static Single<ResponseResult<List<Student>>> listStudent() { | 360 | public static Single<ResponseResult<List<Student>>> listStudent() { |
| 355 | return service_url.getStudentList2(getHeader(), getUserId()); | 361 | return service_url.getStudentList2(getHeader(), getUserId()); |
| 356 | } | 362 | } |
| 357 | 363 | ||
| 358 | public static void listRecord(Observer<ResponseBody> observer) { | 364 | public static void listRecord(Observer<ResponseBody> observer) { |
| 359 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 365 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
| 360 | } | 366 | } |
| 361 | 367 | ||
| 362 | 368 | ||
| 363 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { | 369 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { |
| 364 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); | 370 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); |
| 365 | } | 371 | } |
| 366 | 372 | ||
| 367 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { | 373 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { |
| 368 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); | 374 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); |
| 369 | } | 375 | } |
| 370 | 376 | ||
| 371 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { | 377 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { |
| 372 | setSubscribe(service_url.getError(getHeader(), map), observer); | 378 | setSubscribe(service_url.getError(getHeader(), map), observer); |
| 373 | } | 379 | } |
| 374 | 380 | ||
| 375 | 381 | ||
| 376 | public static RequestBody getMapRequestBody(Map map) { | 382 | public static RequestBody getMapRequestBody(Map map) { |
| 377 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); | 383 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); |
| 378 | } | 384 | } |
| 379 | 385 | ||
| 380 | 386 | ||
| 381 | public static RequestBody getArrayRequestBody(List list) { | 387 | public static RequestBody getArrayRequestBody(List list) { |
| 382 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); | 388 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); |
| 383 | } | 389 | } |
| 384 | 390 | ||
| 385 | public static RequestBody getFileRequestBody(File file) { | 391 | public static RequestBody getFileRequestBody(File file) { |
| 386 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); | 392 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); |
| 387 | } | 393 | } |
| 388 | 394 | ||
| 389 | public static RequestBody getFileRequestBody(byte[] bytes) { | 395 | public static RequestBody getFileRequestBody(byte[] bytes) { |
| 390 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); | 396 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); |
| 391 | } | 397 | } |
| 392 | 398 | ||
| 393 | public static RequestBody getObjectRequestBody(Object obj) { | 399 | public static RequestBody getObjectRequestBody(Object obj) { |
| 394 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); | 400 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); |
| 395 | } | 401 | } |
| 396 | 402 | ||
| 397 | public static RequestBody getStringRequestBody(String str) { | 403 | public static RequestBody getStringRequestBody(String str) { |
| 398 | return RequestBody.create(MediaType.parse("text/plain"), str); | 404 | return RequestBody.create(MediaType.parse("text/plain"), str); |
| 399 | } | 405 | } |
| 400 | 406 | ||
| 401 | 407 | ||
| 402 | /** | 408 | /** |
| 403 | * 插入观察者 | 409 | * 插入观察者 |
| 404 | * | 410 | * |
| 405 | * @param observable | 411 | * @param observable |
| 406 | * @param observer | 412 | * @param observer |
| 407 | * @param <T> | 413 | * @param <T> |
| 408 | */ | 414 | */ |
| 409 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { | 415 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { |
| 410 | observable.subscribeOn(Schedulers.io())//子线程访问网络 | 416 | observable.subscribeOn(Schedulers.io())//子线程访问网络 |
| 411 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 | 417 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 |
| 412 | .subscribe(observer); | 418 | .subscribe(observer); |
| 413 | } | 419 | } |
| 414 | 420 | ||
| 415 | } | 421 | } |
| 416 | 422 |