Commit 92afa3a05c3aba9422275ccfe7a27c5fff9dfc1a
1 parent
7eb90a5ec1
Exists in
master
作业反馈
Showing
6 changed files
with
204 additions
and
2 deletions
Show diff stats
app/src/main/java/com/hjx/parent/HomeworkFeedbackActivity.java
| 1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
| 2 | 2 | ||
| 3 | import android.annotation.SuppressLint; | ||
| 3 | import android.os.Bundle; | 4 | import android.os.Bundle; |
| 4 | import android.view.View; | 5 | import android.view.View; |
| 5 | import android.widget.ImageView; | 6 | import android.widget.ImageView; |
| 6 | import android.widget.RadioButton; | 7 | import android.widget.RadioButton; |
| 8 | import android.widget.Toast; | ||
| 7 | 9 | ||
| 8 | import androidx.annotation.NonNull; | 10 | import androidx.annotation.NonNull; |
| 9 | import androidx.annotation.Nullable; | 11 | import androidx.annotation.Nullable; |
| 10 | 12 | ||
| 11 | import com.bumptech.glide.Glide; | 13 | import com.bumptech.glide.Glide; |
| 12 | import com.chad.library.adapter.base.BaseQuickAdapter; | 14 | import com.chad.library.adapter.base.BaseQuickAdapter; |
| 13 | import com.chad.library.adapter.base.BaseViewHolder; | 15 | import com.chad.library.adapter.base.BaseViewHolder; |
| 14 | import com.google.android.flexbox.FlexboxLayoutManager; | 16 | import com.google.android.flexbox.FlexboxLayoutManager; |
| 17 | import com.google.gson.Gson; | ||
| 15 | import com.hjx.parent.databinding.ActivityHomeworkFeedbackBinding; | 18 | import com.hjx.parent.databinding.ActivityHomeworkFeedbackBinding; |
| 16 | import com.hjx.parent.rx.BaseRxActivity; | 19 | import com.hjx.parent.rx.BaseRxActivity; |
| 17 | import com.prws.common.bean.Student; | 20 | import com.prws.common.bean.Student; |
| 21 | import com.prws.common.bean.homework.Correction; | ||
| 22 | import com.prws.common.bean.homework.CorrectionPoint; | ||
| 18 | import com.prws.common.bean.homework.HomeWork; | 23 | import com.prws.common.bean.homework.HomeWork; |
| 19 | import com.prws.common.bean.homework.HomeworkList; | 24 | import com.prws.common.bean.homework.HomeworkList; |
| 25 | import com.prws.common.bean.homework.KeyValue; | ||
| 26 | import com.prws.common.net.NetWorks; | ||
| 20 | 27 | ||
| 21 | import java.text.DecimalFormat; | 28 | import java.text.DecimalFormat; |
| 22 | import java.util.ArrayList; | 29 | import java.util.ArrayList; |
| 30 | import java.util.HashMap; | ||
| 31 | import java.util.HashSet; | ||
| 23 | import java.util.List; | 32 | import java.util.List; |
| 33 | import java.util.Map; | ||
| 34 | import java.util.Set; | ||
| 24 | 35 | ||
| 25 | public class HomeworkFeedbackActivity extends BaseRxActivity<ActivityHomeworkFeedbackBinding> { | 36 | public class HomeworkFeedbackActivity extends BaseRxActivity<ActivityHomeworkFeedbackBinding> { |
| 26 | private Student student; | 37 | private Student student; |
| 27 | private HomeworkList mData; | 38 | private HomeworkList mData; |
| 28 | private ArrayList<HomeWork> mList; | 39 | private ArrayList<HomeWork> mList; |
| 40 | private List<Correction> corrections = new ArrayList<>(); | ||
| 29 | 41 | ||
| 30 | @SuppressWarnings("unchecked") | 42 | @SuppressWarnings("unchecked") |
| 31 | @Override | 43 | @Override |
| 32 | public void initView(Bundle savedInstanceState) { | 44 | public void initView(Bundle savedInstanceState) { |
| 33 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); | 45 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); |
| 34 | student = (Student) getIntent().getSerializableExtra("student"); | 46 | student = (Student) getIntent().getSerializableExtra("student"); |
| 35 | mData = (HomeworkList) getIntent().getSerializableExtra("data"); | 47 | mData = (HomeworkList) getIntent().getSerializableExtra("data"); |
| 36 | mList = (ArrayList<HomeWork>) getIntent().getSerializableExtra("list"); | 48 | mList = (ArrayList<HomeWork>) getIntent().getSerializableExtra("list"); |
| 37 | 49 | ||
| 38 | binding.tvStuName.setText(student.stuName); | 50 | binding.tvStuName.setText(student.stuName); |
| 39 | binding.tvGrade.setText(student.grade); | 51 | binding.tvGrade.setText(student.grade); |
| 40 | 52 | ||
| 41 | List<HomeWork> errorList = new ArrayList<>(); | 53 | List<HomeWork> errorList = new ArrayList<>(); |
| 42 | int correctNo = 0; | 54 | int correctNo = 0; |
| 43 | for (HomeWork homeWork: mList) { | 55 | for (HomeWork homeWork: mList) { |
| 44 | homeWork.homeworkId = mData.getId(); | 56 | homeWork.state = 1; |
| 57 | homeWork.index = mList.indexOf(homeWork); | ||
| 58 | corrections.add(new Correction(homeWork.brief, homeWork.check ? 1 : 0)); | ||
| 45 | if (!homeWork.check) correctNo ++; | 59 | if (!homeWork.check) correctNo ++; |
| 46 | else errorList.add(homeWork); | 60 | else errorList.add(homeWork); |
| 47 | } | 61 | } |
| 48 | binding.tvPercent.setText(new DecimalFormat("0%").format(1f * correctNo / mList.size())); | 62 | binding.tvPercent.setText(new DecimalFormat("0%").format(1f * correctNo / mList.size())); |
| 49 | 63 | ||
| 50 | binding.rvCorrect.setLayoutManager(new FlexboxLayoutManager(this)); | 64 | binding.rvCorrect.setLayoutManager(new FlexboxLayoutManager(this)); |
| 51 | binding.rvCorrect.setAdapter(new NumberAdapter(mList)); | 65 | binding.rvCorrect.setAdapter(new NumberAdapter(mList)); |
| 52 | binding.rvError.setVisibility(errorList.isEmpty() ? View.GONE : View.VISIBLE); | 66 | binding.rvError.setVisibility(errorList.isEmpty() ? View.GONE : View.VISIBLE); |
| 53 | binding.rvError.setAdapter(new EvalAdapter(errorList)); | 67 | binding.rvError.setAdapter(new EvalAdapter(errorList)); |
| 68 | |||
| 69 | binding.btnPublish.setOnClickListener(v -> submit()); | ||
| 70 | } | ||
| 71 | |||
| 72 | @SuppressLint("CheckResult") | ||
| 73 | private void submit() { | ||
| 74 | Map<String, Object> body = new HashMap<>(); | ||
| 75 | body.put("homeworkId", mData.getId()); | ||
| 76 | body.put("comment", binding.etComment.getText().toString()); | ||
| 77 | body.put("stuId", student.stuId); | ||
| 78 | body.put("points", countPoint()); | ||
| 79 | body.put("correctionList", corrections); | ||
| 80 | NetWorks.service_url.uploadHomeworkFeedback(NetWorks.getHeader(), body) | ||
| 81 | .compose(transformSingle()) | ||
| 82 | .subscribe((response, th) -> { | ||
| 83 | if (th != null) th.printStackTrace(); | ||
| 84 | if (response != null && response.getSuccess()) { | ||
| 85 | // TODO | ||
| 86 | Toast.makeText(this, "反馈成功", Toast.LENGTH_SHORT).show(); | ||
| 87 | } | ||
| 88 | }); | ||
| 54 | } | 89 | } |
| 55 | 90 | ||
| 91 | @SuppressLint("CheckResult") | ||
| 92 | private List<CorrectionPoint> countPoint() { | ||
| 93 | Set<KeyValue> set = new HashSet<>(); | ||
| 94 | Map<String, Integer> totalTimes = new HashMap<>(); | ||
| 95 | Map<String, Integer> correctTimes = new HashMap<>(); | ||
| 96 | Map<String, Integer> underTimes = new HashMap<>(); | ||
| 97 | Map<String, Integer> baseTimes = new HashMap<>(); | ||
| 98 | Map<String, Integer> normalTimes = new HashMap<>(); | ||
| 99 | Gson gson = new Gson(); | ||
| 100 | for (HomeWork homeWork: mList) { | ||
| 101 | homeWork.formatPoints(gson); | ||
| 102 | |||
| 103 | set.addAll(homeWork.pointsObj); | ||
| 104 | for (KeyValue keyValue: homeWork.pointsObj) { | ||
| 105 | String key = keyValue.Key; | ||
| 106 | if (totalTimes.containsKey(key)) { | ||
| 107 | totalTimes.put(key, totalTimes.get(key) + 1); | ||
| 108 | } else { | ||
| 109 | totalTimes.put(key, 1); | ||
| 110 | } | ||
| 111 | if (!homeWork.check) { | ||
| 112 | if (correctTimes.containsKey(key)) { | ||
| 113 | correctTimes.put(key, correctTimes.get(key) + 1); | ||
| 114 | } else { | ||
| 115 | correctTimes.put(key, 1); | ||
| 116 | } | ||
| 117 | } else if (homeWork.state == 1) { | ||
| 118 | if (underTimes.containsKey(key)) { | ||
| 119 | underTimes.put(key, underTimes.get(key) + 1); | ||
| 120 | } else { | ||
| 121 | underTimes.put(key, 1); | ||
| 122 | } | ||
| 123 | } else if (homeWork.state == 2) { | ||
| 124 | if (baseTimes.containsKey(key)) { | ||
| 125 | baseTimes.put(key, baseTimes.get(key) + 1); | ||
| 126 | } else { | ||
| 127 | baseTimes.put(key, 1); | ||
| 128 | } | ||
| 129 | } else if (homeWork.state == 3) { | ||
| 130 | if (normalTimes.containsKey(key)) { | ||
| 131 | normalTimes.put(key, normalTimes.get(key) + 1); | ||
| 132 | } else { | ||
| 133 | normalTimes.put(key, 1); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | } | ||
| 137 | } | ||
| 138 | List<CorrectionPoint> points = new ArrayList<>(); | ||
| 139 | for (KeyValue obj: set) { | ||
| 140 | CorrectionPoint point = new CorrectionPoint(); | ||
| 141 | point.pointId = obj.Key; | ||
| 142 | point.pointName = obj.Value; | ||
| 143 | point.totalCount = ifNull(totalTimes.get(obj.Key), 1); | ||
| 144 | point.correctCount = ifNull(correctTimes.get(obj.Key), 0); | ||
| 145 | point.understandCount = ifNull(underTimes.get(obj.Key), 0); | ||
| 146 | point.basicCount = ifNull(baseTimes.get(obj.Key), 0); | ||
| 147 | point.normalCount = ifNull(normalTimes.get(obj.Key), 0); | ||
| 148 | |||
| 149 | points.add(point); | ||
| 150 | } | ||
| 151 | |||
| 152 | return points; | ||
| 153 | } | ||
| 154 | |||
| 155 | private int ifNull(Integer src, int defaultVal) { | ||
| 156 | if (src == null) return defaultVal; | ||
| 157 | else return src; | ||
| 158 | } | ||
| 159 | |||
| 160 | |||
| 56 | @Override | 161 | @Override |
| 57 | protected ActivityHomeworkFeedbackBinding getViewBinding() { | 162 | protected ActivityHomeworkFeedbackBinding getViewBinding() { |
| 58 | return ActivityHomeworkFeedbackBinding.inflate(getLayoutInflater()); | 163 | return ActivityHomeworkFeedbackBinding.inflate(getLayoutInflater()); |
| 59 | } | 164 | } |
| 60 | 165 | ||
| 61 | static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { | 166 | static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { |
| 62 | 167 | ||
| 63 | public NumberAdapter(List<HomeWork> list) { | 168 | public NumberAdapter(List<HomeWork> list) { |
| 64 | super(R.layout.item_feedback_num, list); | 169 | super(R.layout.item_feedback_num, list); |
| 65 | } | 170 | } |
| 66 | 171 | ||
| 67 | @Override | 172 | @Override |
| 68 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { | 173 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { |
| 69 | int position = getData().indexOf(homeWork); | 174 | int position = getData().indexOf(homeWork); |
| 70 | holder.setText(R.id.tvNum, String.valueOf(position + 1)); | 175 | holder.setText(R.id.tvNum, String.valueOf(position + 1)); |
| 71 | if (homeWork.check) { | 176 | if (homeWork.check) { |
| 72 | holder.setImageResource(R.id.ivType, R.drawable.ic_wrong_small); | 177 | holder.setImageResource(R.id.ivType, R.drawable.ic_wrong_small); |
| 73 | } else { | 178 | } else { |
| 74 | holder.setImageResource(R.id.ivType, R.drawable.ic_correct_small); | 179 | holder.setImageResource(R.id.ivType, R.drawable.ic_correct_small); |
| 75 | } | 180 | } |
| 76 | } | 181 | } |
| 77 | } | 182 | } |
| 78 | 183 | ||
| 79 | static class EvalAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { | 184 | static class EvalAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { |
| 80 | 185 | ||
| 81 | public EvalAdapter(@Nullable List<HomeWork> data) { | 186 | public EvalAdapter(@Nullable List<HomeWork> data) { |
| 82 | super(R.layout.item_homework_eval, data); | 187 | super(R.layout.item_homework_eval, data); |
| 83 | } | 188 | } |
| 84 | 189 | ||
| 85 | @Override | 190 | @Override |
| 86 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { | 191 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { |
| 87 | holder.itemView.setClipToOutline(true); | 192 | holder.itemView.setClipToOutline(true); |
| 88 | holder.setText(R.id.tvNo, "题目" + (homeWork.index + 1)); | 193 | holder.setText(R.id.tvNo, "题目" + (homeWork.index + 1)); |
| 89 | ImageView iv = holder.getView(R.id.ivTopic); | 194 | ImageView iv = holder.getView(R.id.ivTopic); |
| 90 | Glide.with(mContext).load(homeWork.url).into(iv); | 195 | Glide.with(mContext).load(homeWork.url).into(iv); |
| 91 | 196 | ||
| 92 | RadioButton chk1 = holder.getView(R.id.chk1); | 197 | RadioButton chk1 = holder.getView(R.id.chk1); |
| 93 | RadioButton chk2 = holder.getView(R.id.chk2); | 198 | RadioButton chk2 = holder.getView(R.id.chk2); |
| 94 | RadioButton chk3 = holder.getView(R.id.chk3); | 199 | RadioButton chk3 = holder.getView(R.id.chk3); |
| 95 | chk1.setOnCheckedChangeListener((v, b) -> { | 200 | chk1.setOnCheckedChangeListener((v, b) -> { |
| 96 | if (b) { | 201 | if (b) { |
| 97 | homeWork.state = 1; | 202 | homeWork.state = 1; |
| 98 | } | 203 | } |
| 99 | }); | 204 | }); |
| 100 | chk2.setOnCheckedChangeListener((v, b) -> { | 205 | chk2.setOnCheckedChangeListener((v, b) -> { |
| 101 | if (b) { | 206 | if (b) { |
| 102 | homeWork.state = 2; | 207 | homeWork.state = 2; |
| 103 | } | 208 | } |
| 104 | }); | 209 | }); |
| 105 | chk3.setOnCheckedChangeListener((v, b) -> { | 210 | chk3.setOnCheckedChangeListener((v, b) -> { |
| 106 | if (b) { | 211 | if (b) { |
| 107 | homeWork.state = 3; | 212 | homeWork.state = 3; |
| 108 | } | 213 | } |
| 109 | }); | 214 | }); |
| 110 | chk1.setChecked(homeWork.state == 1); | 215 | chk1.setChecked(homeWork.state == 1); |
| 111 | chk2.setChecked(homeWork.state == 2); | 216 | chk2.setChecked(homeWork.state == 2); |
| 112 | chk3.setChecked(homeWork.state == 3); | 217 | chk3.setChecked(homeWork.state == 3); |
| 113 | } | 218 | } |
| 114 | } | 219 | } |
| 115 | } | 220 | } |
| 116 | 221 |
libs/common/src/main/java/com/prws/common/bean/homework/Correction.java
| File was created | 1 | package com.prws.common.bean.homework; | |
| 2 | |||
| 3 | public class Correction { | ||
| 4 | |||
| 5 | public String brief; | ||
| 6 | |||
| 7 | public int correction; // 0 对, 1 错 | ||
| 8 | |||
| 9 | public Correction() { | ||
| 10 | } | ||
| 11 | |||
| 12 | public Correction(String brief, int correction) { | ||
| 13 | this.brief = brief; | ||
| 14 | this.correction = correction; | ||
| 15 | } | ||
| 16 | } | ||
| 17 |
libs/common/src/main/java/com/prws/common/bean/homework/CorrectionPoint.java
| File was created | 1 | package com.prws.common.bean.homework; | |
| 2 | |||
| 3 | public class CorrectionPoint { | ||
| 4 | /** | ||
| 5 | * 知识点id | ||
| 6 | */ | ||
| 7 | public String pointId; | ||
| 8 | |||
| 9 | /** | ||
| 10 | * 知识点名称 | ||
| 11 | */ | ||
| 12 | public String pointName; | ||
| 13 | |||
| 14 | /** | ||
| 15 | * 知识点出现次数 | ||
| 16 | */ | ||
| 17 | public Integer totalCount; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * 知识点正确次数 | ||
| 21 | */ | ||
| 22 | public Integer correctCount; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * 知识点听懂次数 | ||
| 26 | */ | ||
| 27 | public Integer understandCount; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * 知识点基本听懂次数 | ||
| 31 | */ | ||
| 32 | public Integer basicCount; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * 知识点一般听懂次数 | ||
| 36 | */ | ||
| 37 | public Integer normalCount; | ||
| 38 | } | ||
| 39 |
libs/common/src/main/java/com/prws/common/bean/homework/HomeWork.java
| 1 | package com.prws.common.bean.homework; | 1 | package com.prws.common.bean.homework; |
| 2 | 2 | ||
| 3 | import com.google.gson.Gson; | ||
| 3 | import com.google.gson.annotations.SerializedName; | 4 | import com.google.gson.annotations.SerializedName; |
| 5 | import com.google.gson.reflect.TypeToken; | ||
| 4 | 6 | ||
| 5 | import java.io.Serializable; | 7 | import java.io.Serializable; |
| 8 | import java.util.ArrayList; | ||
| 9 | import java.util.List; | ||
| 6 | 10 | ||
| 7 | public class HomeWork implements Serializable { | 11 | public class HomeWork implements Serializable { |
| 8 | 12 | ||
| 9 | @SerializedName(value = "homeworkId", alternate = "id") | 13 | @SerializedName(value = "homeworkId", alternate = "id") |
| 10 | public String homeworkId; | 14 | public String homeworkId; |
| 11 | public String brief; | 15 | public String brief; |
| 12 | public String url; | 16 | public String url; |
| 13 | public String analyseUrl; | 17 | public String analyseUrl; |
| 14 | public String analyseVideoUrl; | 18 | public String analyseVideoUrl; |
| 15 | public Integer correction; | 19 | public Integer correction; |
| 16 | public String answer; | 20 | public String answer; |
| 17 | public String points; | 21 | public String points; |
| 18 | 22 | ||
| 19 | public boolean check = false; | 23 | public boolean check = false; //选中为错题 |
| 20 | public transient int index = 0; | 24 | public transient int index = 0; |
| 21 | public transient int state = 1; | 25 | public transient int state = 1; |
| 22 | 26 | ||
| 27 | public transient List<KeyValue> pointsObj; | ||
| 28 | public void formatPoints(Gson gson) { | ||
| 29 | if (points == null) { | ||
| 30 | pointsObj = new ArrayList<>(); | ||
| 31 | return; | ||
| 32 | } | ||
| 33 | try { | ||
| 34 | pointsObj = gson.fromJson(points, new TypeToken<List<KeyValue>>(){}.getType()); | ||
| 35 | } catch (Exception e) { | ||
| 36 | e.printStackTrace(); | ||
| 37 | pointsObj = new ArrayList<>(); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 23 | } | 41 | } |
| 24 | 42 |
libs/common/src/main/java/com/prws/common/bean/homework/KeyValue.java
| File was created | 1 | package com.prws.common.bean.homework; | |
| 2 | |||
| 3 | import java.util.Objects; | ||
| 4 | |||
| 5 | public class KeyValue { | ||
| 6 | public String Key; | ||
| 7 | public String Value; | ||
| 8 | |||
| 9 | @Override | ||
| 10 | public boolean equals(Object o) { | ||
| 11 | if (this == o) return true; | ||
| 12 | if (o == null || getClass() != o.getClass()) return false; | ||
| 13 | KeyValue keyValue = (KeyValue) o; | ||
| 14 | return Objects.equals(Key.toUpperCase(), keyValue.Key.toUpperCase()); | ||
| 15 | } | ||
| 16 | |||
| 17 | @Override | ||
| 18 | public int hashCode() { | ||
| 19 | return Objects.hash(Key.toUpperCase()); | ||
| 20 | } | ||
| 21 | |||
| 22 | } | ||
| 23 |
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") | ||
| 206 | Single<ResponseResult> uploadHomeworkFeedback(@Header("Authorization") String token, @Body Map<String, Object> map); | ||
| 207 | |||
| 205 | } | 208 | } |
| 206 | 209 | ||
| 207 | public static String getUserId() { | 210 | public static String getUserId() { |
| 208 | return (String) SharedPreferencesUtil.getData("userId", ""); | 211 | return (String) SharedPreferencesUtil.getData("userId", ""); |
| 209 | } | 212 | } |
| 210 | 213 | ||
| 211 | public static String getHeader() { | 214 | public static String getHeader() { |
| 212 | return (String) SharedPreferencesUtil.getData("token", ""); | 215 | return (String) SharedPreferencesUtil.getData("token", ""); |
| 213 | } | 216 | } |
| 214 | 217 | ||
| 215 | public static String getBaiduToken() { | 218 | public static String getBaiduToken() { |
| 216 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); | 219 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); |
| 217 | } | 220 | } |
| 218 | 221 | ||
| 219 | public static Single<BaiduInput> inputImage(String filePath, String id) { | 222 | public static Single<BaiduInput> inputImage(String filePath, String id) { |
| 220 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 223 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 221 | String base64 = BitmapUtils.fileToBase64(filePath); | 224 | String base64 = BitmapUtils.fileToBase64(filePath); |
| 222 | File file = new File(filePath); | 225 | File file = new File(filePath); |
| 223 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}"); | 226 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}"); |
| 224 | return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) | 227 | return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) |
| 225 | .flatMap(token -> { | 228 | .flatMap(token -> { |
| 226 | return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body); | 229 | return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body); |
| 227 | }); | 230 | }); |
| 228 | } | 231 | } |
| 229 | 232 | ||
| 230 | public static Single<ResponseResult> uploadImage(String path, String id) { | 233 | public static Single<ResponseResult> uploadImage(String path, String id) { |
| 231 | File file = new File(path); | 234 | File file = new File(path); |
| 232 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | 235 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); |
| 233 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 236 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 234 | return service_url.uploadImage(getHeader(), part, id); | 237 | return service_url.uploadImage(getHeader(), part, id); |
| 235 | } | 238 | } |
| 236 | 239 | ||
| 237 | 240 | ||
| 238 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { | 241 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { |
| 239 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); | 242 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); |
| 240 | } | 243 | } |
| 241 | 244 | ||
| 242 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { | 245 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { |
| 243 | File file = new File(path); | 246 | File file = new File(path); |
| 244 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | 247 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); |
| 245 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 248 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 246 | Map<String, Object> map = new HashMap<>(); | 249 | Map<String, Object> map = new HashMap<>(); |
| 247 | map.put("condition", param); | 250 | map.put("condition", param); |
| 248 | setSubscribe(service_url.addError(part, map), observer); | 251 | setSubscribe(service_url.addError(part, map), observer); |
| 249 | } | 252 | } |
| 250 | 253 | ||
| 251 | 254 | ||
| 252 | public static void cut(String base64, Observer<CutPicBean> observer) { | 255 | public static void cut(String base64, Observer<CutPicBean> observer) { |
| 253 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 256 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 254 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); | 257 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); |
| 255 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); | 258 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); |
| 256 | } | 259 | } |
| 257 | 260 | ||
| 258 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { | 261 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { |
| 259 | setSubscribe(service_url.editError(getHeader(), map), observer); | 262 | setSubscribe(service_url.editError(getHeader(), map), observer); |
| 260 | } | 263 | } |
| 261 | 264 | ||
| 262 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { | 265 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { |
| 263 | setSubscribe(service_url.updateError(getHeader(), map), observer); | 266 | setSubscribe(service_url.updateError(getHeader(), map), observer); |
| 264 | } | 267 | } |
| 265 | 268 | ||
| 266 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { | 269 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { |
| 267 | setSubscribe(service_url.deleteError(getHeader(), map), observer); | 270 | setSubscribe(service_url.deleteError(getHeader(), map), observer); |
| 268 | } | 271 | } |
| 269 | 272 | ||
| 270 | public static void getBaiduToken(Observer<JsonObject> observer) { | 273 | public static void getBaiduToken(Observer<JsonObject> observer) { |
| 271 | 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); | 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); |
| 272 | } | 275 | } |
| 273 | 276 | ||
| 274 | public static Single<JsonObject> getBaiduTokenOcr() { | 277 | public static Single<JsonObject> getBaiduTokenOcr() { |
| 275 | 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(); | 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(); |
| 276 | } | 279 | } |
| 277 | 280 | ||
| 278 | public static void removeWriting(String base64, Observer<JsonObject> observer) { | 281 | public static void removeWriting(String base64, Observer<JsonObject> observer) { |
| 279 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 282 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 280 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); | 283 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); |
| 281 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); | 284 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); |
| 282 | } | 285 | } |
| 283 | 286 | ||
| 284 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { | 287 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { |
| 285 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); | 288 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); |
| 286 | } | 289 | } |
| 287 | 290 | ||
| 288 | public static void logout(Observer<ResponseBody> observer) { | 291 | public static void logout(Observer<ResponseBody> observer) { |
| 289 | setSubscribe(service_url.logout(), observer); | 292 | setSubscribe(service_url.logout(), observer); |
| 290 | } | 293 | } |
| 291 | 294 | ||
| 292 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { | 295 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { |
| 293 | setSubscribe(service_url.editStudent(getHeader(), body), observable); | 296 | setSubscribe(service_url.editStudent(getHeader(), body), observable); |
| 294 | } | 297 | } |
| 295 | 298 | ||
| 296 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { | 299 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { |
| 297 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); | 300 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); |
| 298 | } | 301 | } |
| 299 | 302 | ||
| 300 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { | 303 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { |
| 301 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 304 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
| 302 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 305 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 303 | Map<String, Object> map = new HashMap<>(); | 306 | Map<String, Object> map = new HashMap<>(); |
| 304 | map.put("stuId", stuId); | 307 | map.put("stuId", stuId); |
| 305 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); | 308 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); |
| 306 | } | 309 | } |
| 307 | 310 | ||
| 308 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { | 311 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { |
| 309 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 312 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
| 310 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 313 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 311 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); | 314 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); |
| 312 | } | 315 | } |
| 313 | 316 | ||
| 314 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { | 317 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { |
| 315 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); | 318 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); |
| 316 | } | 319 | } |
| 317 | 320 | ||
| 318 | 321 | ||
| 319 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { | 322 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { |
| 320 | setSubscribe(service_url.editUser(getHeader(), body), observer); | 323 | setSubscribe(service_url.editUser(getHeader(), body), observer); |
| 321 | } | 324 | } |
| 322 | 325 | ||
| 323 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { | 326 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { |
| 324 | setSubscribe(service_url.changePassword(getHeader(), body), observer); | 327 | setSubscribe(service_url.changePassword(getHeader(), body), observer); |
| 325 | } | 328 | } |
| 326 | 329 | ||
| 327 | 330 | ||
| 328 | public static void searchById(String userId, Observer<ResponseBody> observer) { | 331 | public static void searchById(String userId, Observer<ResponseBody> observer) { |
| 329 | setSubscribe(service_url.searchById(getHeader(), userId), observer); | 332 | setSubscribe(service_url.searchById(getHeader(), userId), observer); |
| 330 | } | 333 | } |
| 331 | 334 | ||
| 332 | 335 | ||
| 333 | public static void login(RequestBody body, Observer<ResponseBody> observer) { | 336 | public static void login(RequestBody body, Observer<ResponseBody> observer) { |
| 334 | setSubscribe(service_url.login(body), observer); | 337 | setSubscribe(service_url.login(body), observer); |
| 335 | } | 338 | } |
| 336 | 339 | ||
| 337 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { | 340 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { |
| 338 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); | 341 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); |
| 339 | } | 342 | } |
| 340 | 343 | ||
| 341 | 344 | ||
| 342 | public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { | 345 | public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { |
| 343 | setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); | 346 | setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); |
| 344 | } | 347 | } |
| 345 | 348 | ||
| 346 | public static void getChildrenList(Observer<ResponseBody> observer) { | 349 | public static void getChildrenList(Observer<ResponseBody> observer) { |
| 347 | setSubscribe(service_url.getChildrenList(getHeader()), observer); | 350 | setSubscribe(service_url.getChildrenList(getHeader()), observer); |
| 348 | } | 351 | } |
| 349 | 352 | ||
| 350 | 353 | ||
| 351 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { | 354 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { |
| 352 | setSubscribe(service_url.registerParent(body), observer); | 355 | setSubscribe(service_url.registerParent(body), observer); |
| 353 | } | 356 | } |
| 354 | 357 | ||
| 355 | 358 | ||
| 356 | public static void listChildren(Observer<ResponseBody> observer) { | 359 | public static void listChildren(Observer<ResponseBody> observer) { |
| 357 | setSubscribe(service_url.listChildren(getHeader()), observer); | 360 | setSubscribe(service_url.listChildren(getHeader()), observer); |
| 358 | } | 361 | } |
| 359 | 362 | ||
| 360 | public static void listStudent(Observer<ResponseBody> observer) { | 363 | public static void listStudent(Observer<ResponseBody> observer) { |
| 361 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 364 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
| 362 | } | 365 | } |
| 363 | 366 | ||
| 364 | public static Single<ResponseResult<List<Student>>> listStudent() { | 367 | public static Single<ResponseResult<List<Student>>> listStudent() { |
| 365 | return service_url.getStudentList2(getHeader(), getUserId()); | 368 | return service_url.getStudentList2(getHeader(), getUserId()); |
| 366 | } | 369 | } |
| 367 | 370 | ||
| 368 | public static void listRecord(Observer<ResponseBody> observer) { | 371 | public static void listRecord(Observer<ResponseBody> observer) { |
| 369 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 372 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
| 370 | } | 373 | } |
| 371 | 374 | ||
| 372 | 375 | ||
| 373 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { | 376 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { |
| 374 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); | 377 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); |
| 375 | } | 378 | } |
| 376 | 379 | ||
| 377 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { | 380 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { |
| 378 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); | 381 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); |
| 379 | } | 382 | } |
| 380 | 383 | ||
| 381 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { | 384 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { |
| 382 | setSubscribe(service_url.getError(getHeader(), map), observer); | 385 | setSubscribe(service_url.getError(getHeader(), map), observer); |
| 383 | } | 386 | } |
| 384 | 387 | ||
| 385 | 388 | ||
| 386 | public static RequestBody getMapRequestBody(Map map) { | 389 | public static RequestBody getMapRequestBody(Map map) { |
| 387 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); | 390 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); |
| 388 | } | 391 | } |
| 389 | 392 | ||
| 390 | 393 | ||
| 391 | public static RequestBody getArrayRequestBody(List list) { | 394 | public static RequestBody getArrayRequestBody(List list) { |
| 392 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); | 395 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); |
| 393 | } | 396 | } |
| 394 | 397 | ||
| 395 | public static RequestBody getFileRequestBody(File file) { | 398 | public static RequestBody getFileRequestBody(File file) { |
| 396 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); | 399 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); |
| 397 | } | 400 | } |
| 398 | 401 | ||
| 399 | public static RequestBody getFileRequestBody(byte[] bytes) { | 402 | public static RequestBody getFileRequestBody(byte[] bytes) { |
| 400 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); | 403 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); |
| 401 | } | 404 | } |
| 402 | 405 | ||
| 403 | public static RequestBody getObjectRequestBody(Object obj) { | 406 | public static RequestBody getObjectRequestBody(Object obj) { |
| 404 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); | 407 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); |
| 405 | } | 408 | } |
| 406 | 409 | ||
| 407 | public static RequestBody getStringRequestBody(String str) { | 410 | public static RequestBody getStringRequestBody(String str) { |
| 408 | return RequestBody.create(MediaType.parse("text/plain"), str); | 411 | return RequestBody.create(MediaType.parse("text/plain"), str); |
| 409 | } | 412 | } |
| 410 | 413 | ||
| 411 | 414 | ||
| 412 | /** | 415 | /** |
| 413 | * 插入观察者 | 416 | * 插入观察者 |
| 414 | * | 417 | * |
| 415 | * @param observable | 418 | * @param observable |
| 416 | * @param observer | 419 | * @param observer |
| 417 | * @param <T> | 420 | * @param <T> |
| 418 | */ | 421 | */ |
| 419 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { | 422 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { |
| 420 | observable.subscribeOn(Schedulers.io())//子线程访问网络 | 423 | observable.subscribeOn(Schedulers.io())//子线程访问网络 |
| 421 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 | 424 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 |
| 422 | .subscribe(observer); | 425 | .subscribe(observer); |
| 423 | } | 426 | } |
| 424 | 427 | ||
| 425 | } | 428 | } |
| 426 | 429 |