Commit f23a9e8ddd565a59826a7abf190f1bd0abe6c528
1 parent
b5769c213d
Exists in
master
日报传参补充
Showing
1 changed file
with
4 additions
and
0 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.annotation.SuppressLint; |
| 4 | import android.content.Intent; | 4 | import android.content.Intent; |
| 5 | import android.os.Bundle; | 5 | import android.os.Bundle; |
| 6 | import android.view.View; | 6 | import android.view.View; |
| 7 | import android.widget.ImageView; | 7 | import android.widget.ImageView; |
| 8 | import android.widget.RadioButton; | 8 | import android.widget.RadioButton; |
| 9 | import android.widget.Toast; | 9 | import android.widget.Toast; |
| 10 | 10 | ||
| 11 | import androidx.annotation.NonNull; | 11 | import androidx.annotation.NonNull; |
| 12 | import androidx.annotation.Nullable; | 12 | import androidx.annotation.Nullable; |
| 13 | 13 | ||
| 14 | import com.bumptech.glide.Glide; | 14 | import com.bumptech.glide.Glide; |
| 15 | import com.chad.library.adapter.base.BaseQuickAdapter; | 15 | import com.chad.library.adapter.base.BaseQuickAdapter; |
| 16 | import com.chad.library.adapter.base.BaseViewHolder; | 16 | import com.chad.library.adapter.base.BaseViewHolder; |
| 17 | import com.google.android.flexbox.FlexboxLayoutManager; | 17 | import com.google.android.flexbox.FlexboxLayoutManager; |
| 18 | import com.google.gson.Gson; | 18 | import com.google.gson.Gson; |
| 19 | import com.hjx.parent.databinding.ActivityHomeworkFeedbackBinding; | 19 | import com.hjx.parent.databinding.ActivityHomeworkFeedbackBinding; |
| 20 | import com.hjx.parent.rx.BaseRxActivity; | 20 | import com.hjx.parent.rx.BaseRxActivity; |
| 21 | import com.prws.common.bean.Student; | 21 | import com.prws.common.bean.Student; |
| 22 | import com.prws.common.bean.homework.Correction; | 22 | import com.prws.common.bean.homework.Correction; |
| 23 | import com.prws.common.bean.homework.CorrectionPoint; | 23 | import com.prws.common.bean.homework.CorrectionPoint; |
| 24 | import com.prws.common.bean.homework.HomeWork; | 24 | import com.prws.common.bean.homework.HomeWork; |
| 25 | import com.prws.common.bean.homework.HomeworkList; | 25 | import com.prws.common.bean.homework.HomeworkList; |
| 26 | import com.prws.common.bean.homework.KeyValue; | 26 | import com.prws.common.bean.homework.KeyValue; |
| 27 | import com.prws.common.net.NetWorks; | 27 | import com.prws.common.net.NetWorks; |
| 28 | 28 | ||
| 29 | import java.text.DecimalFormat; | 29 | import java.text.DecimalFormat; |
| 30 | import java.text.SimpleDateFormat; | ||
| 30 | import java.util.ArrayList; | 31 | import java.util.ArrayList; |
| 31 | import java.util.HashMap; | 32 | import java.util.HashMap; |
| 32 | import java.util.HashSet; | 33 | import java.util.HashSet; |
| 33 | import java.util.List; | 34 | import java.util.List; |
| 35 | import java.util.Locale; | ||
| 34 | import java.util.Map; | 36 | import java.util.Map; |
| 35 | import java.util.Set; | 37 | import java.util.Set; |
| 36 | 38 | ||
| 37 | public class HomeworkFeedbackActivity extends BaseRxActivity<ActivityHomeworkFeedbackBinding> { | 39 | public class HomeworkFeedbackActivity extends BaseRxActivity<ActivityHomeworkFeedbackBinding> { |
| 38 | private Student student; | 40 | private Student student; |
| 39 | private HomeworkList mData; | 41 | private HomeworkList mData; |
| 40 | private ArrayList<HomeWork> mList; | 42 | private ArrayList<HomeWork> mList; |
| 41 | private List<Correction> corrections = new ArrayList<>(); | 43 | private List<Correction> corrections = new ArrayList<>(); |
| 42 | 44 | ||
| 43 | @SuppressWarnings("unchecked") | 45 | @SuppressWarnings("unchecked") |
| 44 | @Override | 46 | @Override |
| 45 | public void initView(Bundle savedInstanceState) { | 47 | public void initView(Bundle savedInstanceState) { |
| 46 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); | 48 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); |
| 47 | student = (Student) getIntent().getSerializableExtra("student"); | 49 | student = (Student) getIntent().getSerializableExtra("student"); |
| 48 | mData = (HomeworkList) getIntent().getSerializableExtra("data"); | 50 | mData = (HomeworkList) getIntent().getSerializableExtra("data"); |
| 49 | mList = (ArrayList<HomeWork>) getIntent().getSerializableExtra("list"); | 51 | mList = (ArrayList<HomeWork>) getIntent().getSerializableExtra("list"); |
| 50 | 52 | ||
| 51 | binding.tvStuName.setText(student.stuName); | 53 | binding.tvStuName.setText(student.stuName); |
| 52 | binding.tvGrade.setText(student.grade); | 54 | binding.tvGrade.setText(student.grade); |
| 53 | 55 | ||
| 54 | List<HomeWork> errorList = new ArrayList<>(); | 56 | List<HomeWork> errorList = new ArrayList<>(); |
| 55 | int correctNo = 0; | 57 | int correctNo = 0; |
| 56 | for (HomeWork homeWork: mList) { | 58 | for (HomeWork homeWork: mList) { |
| 57 | homeWork.state = 1; | 59 | homeWork.state = 1; |
| 58 | homeWork.index = mList.indexOf(homeWork); | 60 | homeWork.index = mList.indexOf(homeWork); |
| 59 | corrections.add(new Correction(homeWork.brief, homeWork.check ? 1 : 0)); | 61 | corrections.add(new Correction(homeWork.brief, homeWork.check ? 1 : 0)); |
| 60 | if (!homeWork.check) correctNo ++; | 62 | if (!homeWork.check) correctNo ++; |
| 61 | else errorList.add(homeWork); | 63 | else errorList.add(homeWork); |
| 62 | } | 64 | } |
| 63 | binding.tvPercent.setText(new DecimalFormat("0%").format(1f * correctNo / mList.size())); | 65 | binding.tvPercent.setText(new DecimalFormat("0%").format(1f * correctNo / mList.size())); |
| 64 | 66 | ||
| 65 | binding.rvCorrect.setLayoutManager(new FlexboxLayoutManager(this)); | 67 | binding.rvCorrect.setLayoutManager(new FlexboxLayoutManager(this)); |
| 66 | NumberAdapter numberAdapter = new NumberAdapter(mList); | 68 | NumberAdapter numberAdapter = new NumberAdapter(mList); |
| 67 | binding.rvCorrect.setAdapter(numberAdapter); | 69 | binding.rvCorrect.setAdapter(numberAdapter); |
| 68 | binding.rvError.setVisibility(errorList.isEmpty() ? View.GONE : View.VISIBLE); | 70 | binding.rvError.setVisibility(errorList.isEmpty() ? View.GONE : View.VISIBLE); |
| 69 | binding.rvError.setAdapter(new EvalAdapter(errorList)); | 71 | binding.rvError.setAdapter(new EvalAdapter(errorList)); |
| 70 | if (errorList.isEmpty()) { | 72 | if (errorList.isEmpty()) { |
| 71 | binding.flEval.setVisibility(View.GONE); | 73 | binding.flEval.setVisibility(View.GONE); |
| 72 | } | 74 | } |
| 73 | 75 | ||
| 74 | binding.btnDetail.setOnClickListener(v -> { | 76 | binding.btnDetail.setOnClickListener(v -> { |
| 75 | viewTopicDetail(0); | 77 | viewTopicDetail(0); |
| 76 | }); | 78 | }); |
| 77 | numberAdapter.setOnItemClickListener((baseQuickAdapter, view, i) -> { | 79 | numberAdapter.setOnItemClickListener((baseQuickAdapter, view, i) -> { |
| 78 | viewTopicDetail(i); | 80 | viewTopicDetail(i); |
| 79 | }); | 81 | }); |
| 80 | binding.btnPublish.setOnClickListener(v -> submit()); | 82 | binding.btnPublish.setOnClickListener(v -> submit()); |
| 81 | } | 83 | } |
| 82 | 84 | ||
| 83 | private void viewTopicDetail(int position) { | 85 | private void viewTopicDetail(int position) { |
| 84 | Intent intent = new Intent(this, HomeworkTopicActivity.class); | 86 | Intent intent = new Intent(this, HomeworkTopicActivity.class); |
| 85 | intent.putExtra("list", mList); | 87 | intent.putExtra("list", mList); |
| 86 | intent.putExtra("position", position); | 88 | intent.putExtra("position", position); |
| 87 | startActivity(intent); | 89 | startActivity(intent); |
| 88 | } | 90 | } |
| 89 | 91 | ||
| 90 | @SuppressLint("CheckResult") | 92 | @SuppressLint("CheckResult") |
| 91 | private void submit() { | 93 | private void submit() { |
| 92 | Map<String, Object> body = new HashMap<>(); | 94 | Map<String, Object> body = new HashMap<>(); |
| 93 | body.put("homeworkId", mData.getId()); | 95 | body.put("homeworkId", mData.getId()); |
| 94 | body.put("comment", binding.etComment.getText().toString()); | 96 | body.put("comment", binding.etComment.getText().toString()); |
| 95 | body.put("stuId", student.stuId); | 97 | body.put("stuId", student.stuId); |
| 96 | body.put("points", countPoint()); | 98 | body.put("points", countPoint()); |
| 97 | body.put("correctionList", corrections); | 99 | body.put("correctionList", corrections); |
| 98 | NetWorks.service_url.uploadHomeworkFeedback(NetWorks.getHeader(), body) | 100 | NetWorks.service_url.uploadHomeworkFeedback(NetWorks.getHeader(), body) |
| 99 | .compose(transformSingle()) | 101 | .compose(transformSingle()) |
| 100 | .subscribe((response, th) -> { | 102 | .subscribe((response, th) -> { |
| 101 | if (th != null) th.printStackTrace(); | 103 | if (th != null) th.printStackTrace(); |
| 102 | if (response != null && response.getSuccess()) { | 104 | if (response != null && response.getSuccess()) { |
| 103 | Toast.makeText(this, "反馈成功", Toast.LENGTH_SHORT).show(); | 105 | Toast.makeText(this, "反馈成功", Toast.LENGTH_SHORT).show(); |
| 104 | 106 | ||
| 105 | Intent intent = new Intent(this, HomeworkShareActivity.class); | 107 | Intent intent = new Intent(this, HomeworkShareActivity.class); |
| 106 | intent.putExtra("student", student); | 108 | intent.putExtra("student", student); |
| 107 | intent.putExtra("id", mData.getId()); | 109 | intent.putExtra("id", mData.getId()); |
| 108 | intent.putExtra("grade", mData.getGrade()); | 110 | intent.putExtra("grade", mData.getGrade()); |
| 109 | intent.putExtra("subject", mData.getSubject()); | 111 | intent.putExtra("subject", mData.getSubject()); |
| 112 | String name = new SimpleDateFormat("yyyy年M月d日作业", Locale.CHINA).format(mData.uploadTime); | ||
| 113 | intent.putExtra("name", name); | ||
| 110 | startActivity(intent); | 114 | startActivity(intent); |
| 111 | 115 | ||
| 112 | setResult(RESULT_OK); | 116 | setResult(RESULT_OK); |
| 113 | finish(); | 117 | finish(); |
| 114 | } else { | 118 | } else { |
| 115 | Toast.makeText(this, "反馈失败", Toast.LENGTH_SHORT).show(); | 119 | Toast.makeText(this, "反馈失败", Toast.LENGTH_SHORT).show(); |
| 116 | } | 120 | } |
| 117 | }); | 121 | }); |
| 118 | } | 122 | } |
| 119 | 123 | ||
| 120 | @SuppressLint("CheckResult") | 124 | @SuppressLint("CheckResult") |
| 121 | private List<CorrectionPoint> countPoint() { | 125 | private List<CorrectionPoint> countPoint() { |
| 122 | Set<KeyValue> set = new HashSet<>(); | 126 | Set<KeyValue> set = new HashSet<>(); |
| 123 | Map<String, Integer> totalTimes = new HashMap<>(); | 127 | Map<String, Integer> totalTimes = new HashMap<>(); |
| 124 | Map<String, Integer> correctTimes = new HashMap<>(); | 128 | Map<String, Integer> correctTimes = new HashMap<>(); |
| 125 | Map<String, Integer> underTimes = new HashMap<>(); | 129 | Map<String, Integer> underTimes = new HashMap<>(); |
| 126 | Map<String, Integer> baseTimes = new HashMap<>(); | 130 | Map<String, Integer> baseTimes = new HashMap<>(); |
| 127 | Map<String, Integer> normalTimes = new HashMap<>(); | 131 | Map<String, Integer> normalTimes = new HashMap<>(); |
| 128 | Gson gson = new Gson(); | 132 | Gson gson = new Gson(); |
| 129 | for (HomeWork homeWork: mList) { | 133 | for (HomeWork homeWork: mList) { |
| 130 | homeWork.formatPoints(gson); | 134 | homeWork.formatPoints(gson); |
| 131 | 135 | ||
| 132 | set.addAll(homeWork.pointsObj); | 136 | set.addAll(homeWork.pointsObj); |
| 133 | for (KeyValue keyValue: homeWork.pointsObj) { | 137 | for (KeyValue keyValue: homeWork.pointsObj) { |
| 134 | String key = keyValue.Key; | 138 | String key = keyValue.Key; |
| 135 | if (totalTimes.containsKey(key)) { | 139 | if (totalTimes.containsKey(key)) { |
| 136 | totalTimes.put(key, totalTimes.get(key) + 1); | 140 | totalTimes.put(key, totalTimes.get(key) + 1); |
| 137 | } else { | 141 | } else { |
| 138 | totalTimes.put(key, 1); | 142 | totalTimes.put(key, 1); |
| 139 | } | 143 | } |
| 140 | if (!homeWork.check) { | 144 | if (!homeWork.check) { |
| 141 | if (correctTimes.containsKey(key)) { | 145 | if (correctTimes.containsKey(key)) { |
| 142 | correctTimes.put(key, correctTimes.get(key) + 1); | 146 | correctTimes.put(key, correctTimes.get(key) + 1); |
| 143 | } else { | 147 | } else { |
| 144 | correctTimes.put(key, 1); | 148 | correctTimes.put(key, 1); |
| 145 | } | 149 | } |
| 146 | } else if (homeWork.state == 1) { | 150 | } else if (homeWork.state == 1) { |
| 147 | if (underTimes.containsKey(key)) { | 151 | if (underTimes.containsKey(key)) { |
| 148 | underTimes.put(key, underTimes.get(key) + 1); | 152 | underTimes.put(key, underTimes.get(key) + 1); |
| 149 | } else { | 153 | } else { |
| 150 | underTimes.put(key, 1); | 154 | underTimes.put(key, 1); |
| 151 | } | 155 | } |
| 152 | } else if (homeWork.state == 2) { | 156 | } else if (homeWork.state == 2) { |
| 153 | if (baseTimes.containsKey(key)) { | 157 | if (baseTimes.containsKey(key)) { |
| 154 | baseTimes.put(key, baseTimes.get(key) + 1); | 158 | baseTimes.put(key, baseTimes.get(key) + 1); |
| 155 | } else { | 159 | } else { |
| 156 | baseTimes.put(key, 1); | 160 | baseTimes.put(key, 1); |
| 157 | } | 161 | } |
| 158 | } else if (homeWork.state == 3) { | 162 | } else if (homeWork.state == 3) { |
| 159 | if (normalTimes.containsKey(key)) { | 163 | if (normalTimes.containsKey(key)) { |
| 160 | normalTimes.put(key, normalTimes.get(key) + 1); | 164 | normalTimes.put(key, normalTimes.get(key) + 1); |
| 161 | } else { | 165 | } else { |
| 162 | normalTimes.put(key, 1); | 166 | normalTimes.put(key, 1); |
| 163 | } | 167 | } |
| 164 | } | 168 | } |
| 165 | } | 169 | } |
| 166 | } | 170 | } |
| 167 | List<CorrectionPoint> points = new ArrayList<>(); | 171 | List<CorrectionPoint> points = new ArrayList<>(); |
| 168 | for (KeyValue obj: set) { | 172 | for (KeyValue obj: set) { |
| 169 | CorrectionPoint point = new CorrectionPoint(); | 173 | CorrectionPoint point = new CorrectionPoint(); |
| 170 | point.pointId = obj.Key; | 174 | point.pointId = obj.Key; |
| 171 | point.pointName = obj.Value; | 175 | point.pointName = obj.Value; |
| 172 | point.totalCount = ifNull(totalTimes.get(obj.Key), 1); | 176 | point.totalCount = ifNull(totalTimes.get(obj.Key), 1); |
| 173 | point.correctCount = ifNull(correctTimes.get(obj.Key), 0); | 177 | point.correctCount = ifNull(correctTimes.get(obj.Key), 0); |
| 174 | point.understandCount = ifNull(underTimes.get(obj.Key), 0); | 178 | point.understandCount = ifNull(underTimes.get(obj.Key), 0); |
| 175 | point.basicCount = ifNull(baseTimes.get(obj.Key), 0); | 179 | point.basicCount = ifNull(baseTimes.get(obj.Key), 0); |
| 176 | point.normalCount = ifNull(normalTimes.get(obj.Key), 0); | 180 | point.normalCount = ifNull(normalTimes.get(obj.Key), 0); |
| 177 | 181 | ||
| 178 | points.add(point); | 182 | points.add(point); |
| 179 | } | 183 | } |
| 180 | 184 | ||
| 181 | return points; | 185 | return points; |
| 182 | } | 186 | } |
| 183 | 187 | ||
| 184 | private int ifNull(Integer src, int defaultVal) { | 188 | private int ifNull(Integer src, int defaultVal) { |
| 185 | if (src == null) return defaultVal; | 189 | if (src == null) return defaultVal; |
| 186 | else return src; | 190 | else return src; |
| 187 | } | 191 | } |
| 188 | 192 | ||
| 189 | 193 | ||
| 190 | @Override | 194 | @Override |
| 191 | protected ActivityHomeworkFeedbackBinding getViewBinding() { | 195 | protected ActivityHomeworkFeedbackBinding getViewBinding() { |
| 192 | return ActivityHomeworkFeedbackBinding.inflate(getLayoutInflater()); | 196 | return ActivityHomeworkFeedbackBinding.inflate(getLayoutInflater()); |
| 193 | } | 197 | } |
| 194 | 198 | ||
| 195 | static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { | 199 | static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { |
| 196 | 200 | ||
| 197 | public NumberAdapter(List<HomeWork> list) { | 201 | public NumberAdapter(List<HomeWork> list) { |
| 198 | super(R.layout.item_feedback_num, list); | 202 | super(R.layout.item_feedback_num, list); |
| 199 | } | 203 | } |
| 200 | 204 | ||
| 201 | @Override | 205 | @Override |
| 202 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { | 206 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { |
| 203 | int position = getData().indexOf(homeWork); | 207 | int position = getData().indexOf(homeWork); |
| 204 | holder.setText(R.id.tvNum, String.valueOf(position + 1)); | 208 | holder.setText(R.id.tvNum, String.valueOf(position + 1)); |
| 205 | if (homeWork.check) { | 209 | if (homeWork.check) { |
| 206 | holder.setImageResource(R.id.ivType, R.drawable.ic_wrong_small); | 210 | holder.setImageResource(R.id.ivType, R.drawable.ic_wrong_small); |
| 207 | } else { | 211 | } else { |
| 208 | holder.setImageResource(R.id.ivType, R.drawable.ic_correct_small); | 212 | holder.setImageResource(R.id.ivType, R.drawable.ic_correct_small); |
| 209 | } | 213 | } |
| 210 | } | 214 | } |
| 211 | } | 215 | } |
| 212 | 216 | ||
| 213 | static class EvalAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { | 217 | static class EvalAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { |
| 214 | 218 | ||
| 215 | public EvalAdapter(@Nullable List<HomeWork> data) { | 219 | public EvalAdapter(@Nullable List<HomeWork> data) { |
| 216 | super(R.layout.item_homework_eval, data); | 220 | super(R.layout.item_homework_eval, data); |
| 217 | } | 221 | } |
| 218 | 222 | ||
| 219 | @Override | 223 | @Override |
| 220 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { | 224 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { |
| 221 | holder.itemView.setClipToOutline(true); | 225 | holder.itemView.setClipToOutline(true); |
| 222 | holder.setText(R.id.tvNo, "题目" + (homeWork.index + 1)); | 226 | holder.setText(R.id.tvNo, "题目" + (homeWork.index + 1)); |
| 223 | ImageView iv = holder.getView(R.id.ivTopic); | 227 | ImageView iv = holder.getView(R.id.ivTopic); |
| 224 | Glide.with(mContext).load(homeWork.url).into(iv); | 228 | Glide.with(mContext).load(homeWork.url).into(iv); |
| 225 | 229 | ||
| 226 | RadioButton chk1 = holder.getView(R.id.chk1); | 230 | RadioButton chk1 = holder.getView(R.id.chk1); |
| 227 | RadioButton chk2 = holder.getView(R.id.chk2); | 231 | RadioButton chk2 = holder.getView(R.id.chk2); |
| 228 | RadioButton chk3 = holder.getView(R.id.chk3); | 232 | RadioButton chk3 = holder.getView(R.id.chk3); |
| 229 | chk1.setOnCheckedChangeListener((v, b) -> { | 233 | chk1.setOnCheckedChangeListener((v, b) -> { |
| 230 | if (b) { | 234 | if (b) { |
| 231 | homeWork.state = 1; | 235 | homeWork.state = 1; |
| 232 | } | 236 | } |
| 233 | }); | 237 | }); |
| 234 | chk2.setOnCheckedChangeListener((v, b) -> { | 238 | chk2.setOnCheckedChangeListener((v, b) -> { |
| 235 | if (b) { | 239 | if (b) { |
| 236 | homeWork.state = 2; | 240 | homeWork.state = 2; |
| 237 | } | 241 | } |
| 238 | }); | 242 | }); |
| 239 | chk3.setOnCheckedChangeListener((v, b) -> { | 243 | chk3.setOnCheckedChangeListener((v, b) -> { |
| 240 | if (b) { | 244 | if (b) { |
| 241 | homeWork.state = 3; | 245 | homeWork.state = 3; |
| 242 | } | 246 | } |
| 243 | }); | 247 | }); |
| 244 | chk1.setChecked(homeWork.state == 1); | 248 | chk1.setChecked(homeWork.state == 1); |
| 245 | chk2.setChecked(homeWork.state == 2); | 249 | chk2.setChecked(homeWork.state == 2); |
| 246 | chk3.setChecked(homeWork.state == 3); | 250 | chk3.setChecked(homeWork.state == 3); |
| 247 | } | 251 | } |
| 248 | } | 252 | } |
| 249 | } | 253 | } |
| 250 | 254 |