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