Commit 4e0766ff7389dcb31de43b4a00cf88e16b1663fe
1 parent
a0aac741c4
Exists in
master
反馈完成后回到列表
Showing
4 changed files
with
31 additions
and
6 deletions
Show diff stats
app/src/main/java/com/hjx/parent/HomeworkDetailActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import android.annotation.SuppressLint; | 3 | import android.annotation.SuppressLint; |
4 | import android.content.Intent; | 4 | import android.content.Intent; |
5 | import android.os.Bundle; | 5 | import android.os.Bundle; |
6 | import android.widget.ImageView; | 6 | import android.widget.ImageView; |
7 | import android.widget.TextView; | 7 | import android.widget.TextView; |
8 | 8 | ||
9 | import androidx.annotation.NonNull; | 9 | import androidx.annotation.NonNull; |
10 | import androidx.annotation.Nullable; | ||
10 | 11 | ||
11 | import com.bumptech.glide.Glide; | 12 | import com.bumptech.glide.Glide; |
12 | import com.chad.library.adapter.base.BaseQuickAdapter; | 13 | import com.chad.library.adapter.base.BaseQuickAdapter; |
13 | import com.chad.library.adapter.base.BaseViewHolder; | 14 | import com.chad.library.adapter.base.BaseViewHolder; |
14 | import com.hjx.parent.databinding.ActivityHomeworkDetailBinding; | 15 | import com.hjx.parent.databinding.ActivityHomeworkDetailBinding; |
15 | import com.hjx.parent.dialog.EditHomeworkDialog; | 16 | import com.hjx.parent.dialog.EditHomeworkDialog; |
16 | import com.hjx.parent.rx.BaseRxActivity; | 17 | import com.hjx.parent.rx.BaseRxActivity; |
17 | import com.prws.common.bean.ResponseResult; | 18 | import com.prws.common.bean.ResponseResult; |
18 | import com.prws.common.bean.Student; | 19 | import com.prws.common.bean.Student; |
19 | import com.prws.common.bean.homework.HomeWork; | 20 | import com.prws.common.bean.homework.HomeWork; |
20 | import com.prws.common.bean.homework.HomeworkList; | 21 | import com.prws.common.bean.homework.HomeworkList; |
21 | import com.prws.common.net.NetWorks; | 22 | import com.prws.common.net.NetWorks; |
22 | 23 | ||
23 | import java.util.ArrayList; | 24 | import java.util.ArrayList; |
24 | import java.util.HashMap; | 25 | import java.util.HashMap; |
25 | import java.util.Map; | 26 | import java.util.Map; |
26 | 27 | ||
27 | public class HomeworkDetailActivity extends BaseRxActivity<ActivityHomeworkDetailBinding> { | 28 | public class HomeworkDetailActivity extends BaseRxActivity<ActivityHomeworkDetailBinding> { |
28 | 29 | ||
29 | private HomeworkList mData; | 30 | private HomeworkList mData; |
30 | private Student student; | 31 | private Student student; |
31 | 32 | ||
32 | private Adapter mAdapter = new Adapter(); | 33 | private Adapter mAdapter = new Adapter(); |
33 | private EditHomeworkDialog mDialog; | 34 | private EditHomeworkDialog mDialog; |
34 | 35 | ||
35 | @Override | 36 | @Override |
36 | public void initView(Bundle savedInstanceState) { | 37 | public void initView(Bundle savedInstanceState) { |
37 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); | 38 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); |
38 | mData = (HomeworkList) getIntent().getSerializableExtra("data"); | 39 | mData = (HomeworkList) getIntent().getSerializableExtra("data"); |
39 | student = (Student) getIntent().getSerializableExtra("student"); | 40 | student = (Student) getIntent().getSerializableExtra("student"); |
40 | mDialog = new EditHomeworkDialog(this, mData); | 41 | mDialog = new EditHomeworkDialog(this, mData); |
41 | binding.tvTitle.setText(mData.getName()); | 42 | binding.tvTitle.setText(mData.getName()); |
42 | 43 | ||
43 | binding.recyclerView.setAdapter(mAdapter); | 44 | binding.recyclerView.setAdapter(mAdapter); |
44 | getDetail(); | 45 | getDetail(); |
45 | 46 | ||
46 | binding.btnFeedback.setOnClickListener(v -> { | 47 | binding.btnFeedback.setOnClickListener(v -> { |
47 | if (mAdapter.getData().size() == 0) return; | 48 | if (mAdapter.getData().size() == 0) return; |
48 | Intent intent = new Intent(this, HomeworkSelectActivity.class); | 49 | Intent intent = new Intent(this, HomeworkSelectActivity.class); |
49 | intent.putExtra("data", mData); | 50 | intent.putExtra("data", mData); |
50 | intent.putExtra("student", student); | 51 | intent.putExtra("student", student); |
51 | intent.putExtra("list", new ArrayList<>(mAdapter.getData())); | 52 | intent.putExtra("list", new ArrayList<>(mAdapter.getData())); |
52 | startActivity(intent); | 53 | startActivityForResult(intent, 0xA01); |
53 | }); | 54 | }); |
54 | binding.btnEdit.setOnClickListener(v -> mDialog.show(data -> { | 55 | binding.btnEdit.setOnClickListener(v -> mDialog.show(data -> { |
55 | edit(data); | 56 | edit(data); |
56 | })); | 57 | })); |
57 | } | 58 | } |
58 | 59 | ||
60 | @Override | ||
61 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | ||
62 | super.onActivityResult(requestCode, resultCode, data); | ||
63 | if (requestCode == 0xA01 && resultCode == RESULT_OK) { | ||
64 | finish(); | ||
65 | } | ||
66 | } | ||
67 | |||
59 | @SuppressLint("CheckResult") | 68 | @SuppressLint("CheckResult") |
60 | private void getDetail() { | 69 | private void getDetail() { |
61 | NetWorks.service_url.getHomeworkDetail(NetWorks.getHeader(), mData.getId()) | 70 | NetWorks.service_url.getHomeworkDetail(NetWorks.getHeader(), mData.getId()) |
62 | .compose(transformSingle()) | 71 | .compose(transformSingle()) |
63 | .map(ResponseResult::getData) | 72 | .map(ResponseResult::getData) |
64 | .subscribe((list, th) -> { | 73 | .subscribe((list, th) -> { |
65 | if (th != null) th.printStackTrace(); | 74 | if (th != null) th.printStackTrace(); |
66 | mAdapter.setNewData(list); | 75 | mAdapter.setNewData(list); |
67 | }); | 76 | }); |
68 | } | 77 | } |
69 | 78 | ||
70 | @SuppressLint("CheckResult") | 79 | @SuppressLint("CheckResult") |
71 | private void edit(HomeworkList data) { | 80 | private void edit(HomeworkList data) { |
72 | Map<String, Object> body = new HashMap<>(); | 81 | Map<String, Object> body = new HashMap<>(); |
73 | body.put("homeworkId", data.getId()); | 82 | body.put("homeworkId", data.getId()); |
74 | body.put("name", data.getName()); | 83 | body.put("name", data.getName()); |
75 | body.put("grade", data.getGrade()); | 84 | body.put("grade", data.getGrade()); |
76 | body.put("subject", data.getSubject()); | 85 | body.put("subject", data.getSubject()); |
77 | body.put("term", data.getTerm()); | 86 | body.put("term", data.getTerm()); |
78 | body.put("uploadTime", data.uploadTime); | 87 | body.put("uploadTime", data.uploadTime); |
79 | showLoadingDialog("请稍等···"); | 88 | showLoadingDialog("请稍等···"); |
80 | NetWorks.service_url.editHomework(NetWorks.getHeader(), body) | 89 | NetWorks.service_url.editHomework(NetWorks.getHeader(), body) |
81 | .compose(transformSingle()) | 90 | .compose(transformSingle()) |
82 | .subscribe((response, th) -> { | 91 | .subscribe((response, th) -> { |
83 | if (th != null) th.printStackTrace(); | 92 | if (th != null) th.printStackTrace(); |
84 | if (response != null && response.getSuccess()) { | 93 | if (response != null && response.getSuccess()) { |
85 | cancelLoadingDialog(); | 94 | cancelLoadingDialog(); |
86 | binding.tvTitle.setText(data.getName()); | 95 | binding.tvTitle.setText(data.getName()); |
87 | } else { | 96 | } else { |
88 | loadFail(response == null ? "" : response.getMsg()); | 97 | loadFail(response == null ? "" : response.getMsg()); |
89 | } | 98 | } |
90 | }); | 99 | }); |
91 | } | 100 | } |
92 | 101 | ||
93 | @Override | 102 | @Override |
94 | protected ActivityHomeworkDetailBinding getViewBinding() { | 103 | protected ActivityHomeworkDetailBinding getViewBinding() { |
95 | return ActivityHomeworkDetailBinding.inflate(getLayoutInflater()); | 104 | return ActivityHomeworkDetailBinding.inflate(getLayoutInflater()); |
96 | } | 105 | } |
97 | 106 | ||
98 | static class Adapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { | 107 | static class Adapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { |
99 | 108 | ||
100 | public Adapter() { | 109 | public Adapter() { |
101 | super(R.layout.item_homework_detail); | 110 | super(R.layout.item_homework_detail); |
102 | } | 111 | } |
103 | 112 | ||
104 | @SuppressLint("SetTextI18n") | 113 | @SuppressLint("SetTextI18n") |
105 | @Override | 114 | @Override |
106 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { | 115 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { |
107 | TextView tvNumber = holder.getView(R.id.tvNumber); | 116 | TextView tvNumber = holder.getView(R.id.tvNumber); |
108 | ImageView imageView = holder.getView(R.id.ivTopic); | 117 | ImageView imageView = holder.getView(R.id.ivTopic); |
109 | int number = getData().indexOf(homeWork) + 1; | 118 | int number = getData().indexOf(homeWork) + 1; |
110 | tvNumber.setText("第" + number + "题"); | 119 | tvNumber.setText("第" + number + "题"); |
111 | Glide.with(mContext).load(homeWork.url).into(imageView); | 120 | Glide.with(mContext).load(homeWork.url).into(imageView); |
112 | } | 121 | } |
113 | } | 122 | } |
114 | } | 123 | } |
115 | 124 |
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 | 70 | ||
71 | binding.btnDetail.setOnClickListener(v -> { | 71 | binding.btnDetail.setOnClickListener(v -> { |
72 | viewTopicDetail(0); | 72 | viewTopicDetail(0); |
73 | }); | 73 | }); |
74 | numberAdapter.setOnItemClickListener((baseQuickAdapter, view, i) -> { | 74 | numberAdapter.setOnItemClickListener((baseQuickAdapter, view, i) -> { |
75 | viewTopicDetail(i); | 75 | viewTopicDetail(i); |
76 | }); | 76 | }); |
77 | binding.btnPublish.setOnClickListener(v -> submit()); | 77 | binding.btnPublish.setOnClickListener(v -> submit()); |
78 | } | 78 | } |
79 | 79 | ||
80 | private void viewTopicDetail(int position) { | 80 | private void viewTopicDetail(int position) { |
81 | Intent intent = new Intent(this, HomeworkTopicActivity.class); | 81 | Intent intent = new Intent(this, HomeworkTopicActivity.class); |
82 | intent.putExtra("list", mList); | 82 | intent.putExtra("list", mList); |
83 | intent.putExtra("position", position); | 83 | intent.putExtra("position", position); |
84 | startActivity(intent); | 84 | startActivity(intent); |
85 | } | 85 | } |
86 | 86 | ||
87 | @SuppressLint("CheckResult") | 87 | @SuppressLint("CheckResult") |
88 | private void submit() { | 88 | private void submit() { |
89 | Map<String, Object> body = new HashMap<>(); | 89 | Map<String, Object> body = new HashMap<>(); |
90 | body.put("homeworkId", mData.getId()); | 90 | body.put("homeworkId", mData.getId()); |
91 | body.put("comment", binding.etComment.getText().toString()); | 91 | body.put("comment", binding.etComment.getText().toString()); |
92 | body.put("stuId", student.stuId); | 92 | body.put("stuId", student.stuId); |
93 | body.put("points", countPoint()); | 93 | body.put("points", countPoint()); |
94 | body.put("correctionList", corrections); | 94 | body.put("correctionList", corrections); |
95 | NetWorks.service_url.uploadHomeworkFeedback(NetWorks.getHeader(), body) | 95 | NetWorks.service_url.uploadHomeworkFeedback(NetWorks.getHeader(), body) |
96 | .compose(transformSingle()) | 96 | .compose(transformSingle()) |
97 | .subscribe((response, th) -> { | 97 | .subscribe((response, th) -> { |
98 | if (th != null) th.printStackTrace(); | 98 | if (th != null) th.printStackTrace(); |
99 | if (response != null && response.getSuccess()) { | 99 | if (response != null && response.getSuccess()) { |
100 | // TODO | 100 | // TODO |
101 | Toast.makeText(this, "反馈成功", Toast.LENGTH_SHORT).show(); | 101 | Toast.makeText(this, "反馈成功", Toast.LENGTH_SHORT).show(); |
102 | setResult(RESULT_OK); | ||
103 | finish(); | ||
102 | } | 104 | } |
103 | }); | 105 | }); |
104 | } | 106 | } |
105 | 107 | ||
106 | @SuppressLint("CheckResult") | 108 | @SuppressLint("CheckResult") |
107 | private List<CorrectionPoint> countPoint() { | 109 | private List<CorrectionPoint> countPoint() { |
108 | Set<KeyValue> set = new HashSet<>(); | 110 | Set<KeyValue> set = new HashSet<>(); |
109 | Map<String, Integer> totalTimes = new HashMap<>(); | 111 | Map<String, Integer> totalTimes = new HashMap<>(); |
110 | Map<String, Integer> correctTimes = new HashMap<>(); | 112 | Map<String, Integer> correctTimes = new HashMap<>(); |
111 | Map<String, Integer> underTimes = new HashMap<>(); | 113 | Map<String, Integer> underTimes = new HashMap<>(); |
112 | Map<String, Integer> baseTimes = new HashMap<>(); | 114 | Map<String, Integer> baseTimes = new HashMap<>(); |
113 | Map<String, Integer> normalTimes = new HashMap<>(); | 115 | Map<String, Integer> normalTimes = new HashMap<>(); |
114 | Gson gson = new Gson(); | 116 | Gson gson = new Gson(); |
115 | for (HomeWork homeWork: mList) { | 117 | for (HomeWork homeWork: mList) { |
116 | homeWork.formatPoints(gson); | 118 | homeWork.formatPoints(gson); |
117 | 119 | ||
118 | set.addAll(homeWork.pointsObj); | 120 | set.addAll(homeWork.pointsObj); |
119 | for (KeyValue keyValue: homeWork.pointsObj) { | 121 | for (KeyValue keyValue: homeWork.pointsObj) { |
120 | String key = keyValue.Key; | 122 | String key = keyValue.Key; |
121 | if (totalTimes.containsKey(key)) { | 123 | if (totalTimes.containsKey(key)) { |
122 | totalTimes.put(key, totalTimes.get(key) + 1); | 124 | totalTimes.put(key, totalTimes.get(key) + 1); |
123 | } else { | 125 | } else { |
124 | totalTimes.put(key, 1); | 126 | totalTimes.put(key, 1); |
125 | } | 127 | } |
126 | if (!homeWork.check) { | 128 | if (!homeWork.check) { |
127 | if (correctTimes.containsKey(key)) { | 129 | if (correctTimes.containsKey(key)) { |
128 | correctTimes.put(key, correctTimes.get(key) + 1); | 130 | correctTimes.put(key, correctTimes.get(key) + 1); |
129 | } else { | 131 | } else { |
130 | correctTimes.put(key, 1); | 132 | correctTimes.put(key, 1); |
131 | } | 133 | } |
132 | } else if (homeWork.state == 1) { | 134 | } else if (homeWork.state == 1) { |
133 | if (underTimes.containsKey(key)) { | 135 | if (underTimes.containsKey(key)) { |
134 | underTimes.put(key, underTimes.get(key) + 1); | 136 | underTimes.put(key, underTimes.get(key) + 1); |
135 | } else { | 137 | } else { |
136 | underTimes.put(key, 1); | 138 | underTimes.put(key, 1); |
137 | } | 139 | } |
138 | } else if (homeWork.state == 2) { | 140 | } else if (homeWork.state == 2) { |
139 | if (baseTimes.containsKey(key)) { | 141 | if (baseTimes.containsKey(key)) { |
140 | baseTimes.put(key, baseTimes.get(key) + 1); | 142 | baseTimes.put(key, baseTimes.get(key) + 1); |
141 | } else { | 143 | } else { |
142 | baseTimes.put(key, 1); | 144 | baseTimes.put(key, 1); |
143 | } | 145 | } |
144 | } else if (homeWork.state == 3) { | 146 | } else if (homeWork.state == 3) { |
145 | if (normalTimes.containsKey(key)) { | 147 | if (normalTimes.containsKey(key)) { |
146 | normalTimes.put(key, normalTimes.get(key) + 1); | 148 | normalTimes.put(key, normalTimes.get(key) + 1); |
147 | } else { | 149 | } else { |
148 | normalTimes.put(key, 1); | 150 | normalTimes.put(key, 1); |
149 | } | 151 | } |
150 | } | 152 | } |
151 | } | 153 | } |
152 | } | 154 | } |
153 | List<CorrectionPoint> points = new ArrayList<>(); | 155 | List<CorrectionPoint> points = new ArrayList<>(); |
154 | for (KeyValue obj: set) { | 156 | for (KeyValue obj: set) { |
155 | CorrectionPoint point = new CorrectionPoint(); | 157 | CorrectionPoint point = new CorrectionPoint(); |
156 | point.pointId = obj.Key; | 158 | point.pointId = obj.Key; |
157 | point.pointName = obj.Value; | 159 | point.pointName = obj.Value; |
158 | point.totalCount = ifNull(totalTimes.get(obj.Key), 1); | 160 | point.totalCount = ifNull(totalTimes.get(obj.Key), 1); |
159 | point.correctCount = ifNull(correctTimes.get(obj.Key), 0); | 161 | point.correctCount = ifNull(correctTimes.get(obj.Key), 0); |
160 | point.understandCount = ifNull(underTimes.get(obj.Key), 0); | 162 | point.understandCount = ifNull(underTimes.get(obj.Key), 0); |
161 | point.basicCount = ifNull(baseTimes.get(obj.Key), 0); | 163 | point.basicCount = ifNull(baseTimes.get(obj.Key), 0); |
162 | point.normalCount = ifNull(normalTimes.get(obj.Key), 0); | 164 | point.normalCount = ifNull(normalTimes.get(obj.Key), 0); |
163 | 165 | ||
164 | points.add(point); | 166 | points.add(point); |
165 | } | 167 | } |
166 | 168 | ||
167 | return points; | 169 | return points; |
168 | } | 170 | } |
169 | 171 | ||
170 | private int ifNull(Integer src, int defaultVal) { | 172 | private int ifNull(Integer src, int defaultVal) { |
171 | if (src == null) return defaultVal; | 173 | if (src == null) return defaultVal; |
172 | else return src; | 174 | else return src; |
173 | } | 175 | } |
174 | 176 | ||
175 | 177 | ||
176 | @Override | 178 | @Override |
177 | protected ActivityHomeworkFeedbackBinding getViewBinding() { | 179 | protected ActivityHomeworkFeedbackBinding getViewBinding() { |
178 | return ActivityHomeworkFeedbackBinding.inflate(getLayoutInflater()); | 180 | return ActivityHomeworkFeedbackBinding.inflate(getLayoutInflater()); |
179 | } | 181 | } |
180 | 182 | ||
181 | static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { | 183 | static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { |
182 | 184 | ||
183 | public NumberAdapter(List<HomeWork> list) { | 185 | public NumberAdapter(List<HomeWork> list) { |
184 | super(R.layout.item_feedback_num, list); | 186 | super(R.layout.item_feedback_num, list); |
185 | } | 187 | } |
186 | 188 | ||
187 | @Override | 189 | @Override |
188 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { | 190 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { |
189 | int position = getData().indexOf(homeWork); | 191 | int position = getData().indexOf(homeWork); |
190 | holder.setText(R.id.tvNum, String.valueOf(position + 1)); | 192 | holder.setText(R.id.tvNum, String.valueOf(position + 1)); |
191 | if (homeWork.check) { | 193 | if (homeWork.check) { |
192 | holder.setImageResource(R.id.ivType, R.drawable.ic_wrong_small); | 194 | holder.setImageResource(R.id.ivType, R.drawable.ic_wrong_small); |
193 | } else { | 195 | } else { |
194 | holder.setImageResource(R.id.ivType, R.drawable.ic_correct_small); | 196 | holder.setImageResource(R.id.ivType, R.drawable.ic_correct_small); |
195 | } | 197 | } |
196 | } | 198 | } |
197 | } | 199 | } |
198 | 200 | ||
199 | static class EvalAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { | 201 | static class EvalAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { |
200 | 202 | ||
201 | public EvalAdapter(@Nullable List<HomeWork> data) { | 203 | public EvalAdapter(@Nullable List<HomeWork> data) { |
202 | super(R.layout.item_homework_eval, data); | 204 | super(R.layout.item_homework_eval, data); |
203 | } | 205 | } |
204 | 206 | ||
205 | @Override | 207 | @Override |
206 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { | 208 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { |
207 | holder.itemView.setClipToOutline(true); | 209 | holder.itemView.setClipToOutline(true); |
208 | holder.setText(R.id.tvNo, "题目" + (homeWork.index + 1)); | 210 | holder.setText(R.id.tvNo, "题目" + (homeWork.index + 1)); |
209 | ImageView iv = holder.getView(R.id.ivTopic); | 211 | ImageView iv = holder.getView(R.id.ivTopic); |
210 | Glide.with(mContext).load(homeWork.url).into(iv); | 212 | Glide.with(mContext).load(homeWork.url).into(iv); |
211 | 213 | ||
212 | RadioButton chk1 = holder.getView(R.id.chk1); | 214 | RadioButton chk1 = holder.getView(R.id.chk1); |
213 | RadioButton chk2 = holder.getView(R.id.chk2); | 215 | RadioButton chk2 = holder.getView(R.id.chk2); |
214 | RadioButton chk3 = holder.getView(R.id.chk3); | 216 | RadioButton chk3 = holder.getView(R.id.chk3); |
215 | chk1.setOnCheckedChangeListener((v, b) -> { | 217 | chk1.setOnCheckedChangeListener((v, b) -> { |
216 | if (b) { | 218 | if (b) { |
217 | homeWork.state = 1; | 219 | homeWork.state = 1; |
218 | } | 220 | } |
219 | }); | 221 | }); |
220 | chk2.setOnCheckedChangeListener((v, b) -> { | 222 | chk2.setOnCheckedChangeListener((v, b) -> { |
221 | if (b) { | 223 | if (b) { |
222 | homeWork.state = 2; | 224 | homeWork.state = 2; |
223 | } | 225 | } |
224 | }); | 226 | }); |
225 | chk3.setOnCheckedChangeListener((v, b) -> { | 227 | chk3.setOnCheckedChangeListener((v, b) -> { |
226 | if (b) { | 228 | if (b) { |
227 | homeWork.state = 3; | 229 | homeWork.state = 3; |
228 | } | 230 | } |
229 | }); | 231 | }); |
230 | chk1.setChecked(homeWork.state == 1); | 232 | chk1.setChecked(homeWork.state == 1); |
231 | chk2.setChecked(homeWork.state == 2); | 233 | chk2.setChecked(homeWork.state == 2); |
232 | chk3.setChecked(homeWork.state == 3); | 234 | chk3.setChecked(homeWork.state == 3); |
233 | } | 235 | } |
234 | } | 236 | } |
235 | } | 237 | } |
236 | 238 |
app/src/main/java/com/hjx/parent/HomeworkSelectActivity.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.content.res.ColorStateList; | 5 | import android.content.res.ColorStateList; |
6 | import android.os.Bundle; | 6 | import android.os.Bundle; |
7 | import android.view.View; | 7 | import android.view.View; |
8 | import android.widget.CheckBox; | 8 | import android.widget.CheckBox; |
9 | import android.widget.ImageView; | 9 | import android.widget.ImageView; |
10 | import android.widget.TextView; | 10 | import android.widget.TextView; |
11 | 11 | ||
12 | import androidx.annotation.NonNull; | 12 | import androidx.annotation.NonNull; |
13 | import androidx.annotation.Nullable; | ||
13 | import androidx.lifecycle.MutableLiveData; | 14 | import androidx.lifecycle.MutableLiveData; |
14 | 15 | ||
15 | import com.bumptech.glide.Glide; | 16 | import com.bumptech.glide.Glide; |
16 | import com.chad.library.adapter.base.BaseQuickAdapter; | 17 | import com.chad.library.adapter.base.BaseQuickAdapter; |
17 | import com.chad.library.adapter.base.BaseViewHolder; | 18 | import com.chad.library.adapter.base.BaseViewHolder; |
18 | import com.hjx.parent.databinding.ActivityHomeworkSelectBinding; | 19 | import com.hjx.parent.databinding.ActivityHomeworkSelectBinding; |
19 | import com.hjx.parent.function.Function1; | 20 | import com.hjx.parent.function.Function1; |
20 | import com.hjx.parent.rx.BaseRxActivity; | 21 | import com.hjx.parent.rx.BaseRxActivity; |
21 | import com.prws.common.bean.Student; | 22 | import com.prws.common.bean.Student; |
22 | import com.prws.common.bean.homework.HomeWork; | 23 | import com.prws.common.bean.homework.HomeWork; |
23 | import com.prws.common.bean.homework.HomeworkList; | 24 | import com.prws.common.bean.homework.HomeworkList; |
24 | 25 | ||
25 | import java.util.ArrayList; | 26 | import java.util.ArrayList; |
26 | 27 | ||
27 | public class HomeworkSelectActivity extends BaseRxActivity<ActivityHomeworkSelectBinding> { | 28 | public class HomeworkSelectActivity extends BaseRxActivity<ActivityHomeworkSelectBinding> { |
28 | 29 | ||
29 | private Student student; | 30 | private Student student; |
30 | private HomeworkList mData; | 31 | private HomeworkList mData; |
31 | private ArrayList<HomeWork> mList; | 32 | private ArrayList<HomeWork> mList; |
32 | private Adapter mAdapter = new Adapter(); | 33 | private Adapter mAdapter = new Adapter(); |
33 | 34 | ||
34 | MutableLiveData<Integer> selectNum = new MutableLiveData<>(0); | 35 | MutableLiveData<Integer> selectNum = new MutableLiveData<>(0); |
35 | 36 | ||
36 | @SuppressLint("NotifyDataSetChanged") | 37 | @SuppressLint("NotifyDataSetChanged") |
37 | @SuppressWarnings("unchecked,ConstantConditions") | 38 | @SuppressWarnings("unchecked,ConstantConditions") |
38 | @Override | 39 | @Override |
39 | public void initView(Bundle savedInstanceState) { | 40 | public void initView(Bundle savedInstanceState) { |
40 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); | 41 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); |
41 | student = (Student) getIntent().getSerializableExtra("student"); | 42 | student = (Student) getIntent().getSerializableExtra("student"); |
42 | mData = (HomeworkList) getIntent().getSerializableExtra("data"); | 43 | mData = (HomeworkList) getIntent().getSerializableExtra("data"); |
43 | mList = (ArrayList<HomeWork>) getIntent().getSerializableExtra("list"); | 44 | mList = (ArrayList<HomeWork>) getIntent().getSerializableExtra("list"); |
44 | 45 | ||
45 | mAdapter.setNewData(mList); | 46 | mAdapter.setNewData(mList); |
46 | binding.recyclerView.setAdapter(mAdapter); | 47 | binding.recyclerView.setAdapter(mAdapter); |
47 | 48 | ||
48 | mAdapter.selectCall = i -> selectNum.setValue(selectNum.getValue() + i); | 49 | mAdapter.selectCall = i -> selectNum.setValue(selectNum.getValue() + i); |
49 | selectNum.observe(this, i -> { | 50 | selectNum.observe(this, i -> { |
50 | binding.tvNumber.setText(String.valueOf(i)); | 51 | binding.tvNumber.setText(String.valueOf(i)); |
51 | if (i == 0) { | 52 | if (i == 0) { |
52 | binding.btnConfirm.setText("作业全对"); | 53 | binding.btnConfirm.setText("作业全对"); |
53 | binding.btnConfirm.setBackgroundTintList(ColorStateList.valueOf(0xFF4ABC78)); | 54 | binding.btnConfirm.setBackgroundTintList(ColorStateList.valueOf(0xFF4ABC78)); |
54 | } else { | 55 | } else { |
55 | binding.btnConfirm.setText("下一步"); | 56 | binding.btnConfirm.setText("下一步"); |
56 | binding.btnConfirm.setBackgroundTintList(ColorStateList.valueOf(0xFF1C90F3)); | 57 | binding.btnConfirm.setBackgroundTintList(ColorStateList.valueOf(0xFF1C90F3)); |
57 | } | 58 | } |
58 | binding.chkAll.setChecked(i == mList.size() && i != 0); | 59 | binding.chkAll.setChecked(i == mList.size() && i != 0); |
59 | }); | 60 | }); |
60 | 61 | ||
61 | binding.chkAll.setOnClickListener(v -> { | 62 | binding.chkAll.setOnClickListener(v -> { |
62 | if (mList.size() == 0) return; | 63 | if (mList.size() == 0) return; |
63 | boolean b = binding.chkAll.isChecked(); | 64 | boolean b = binding.chkAll.isChecked(); |
64 | for (HomeWork item: mList) { | 65 | for (HomeWork item: mList) { |
65 | item.check = b; | 66 | item.check = b; |
66 | } | 67 | } |
67 | selectNum.setValue(b ? mList.size() : 0); | 68 | selectNum.setValue(b ? mList.size() : 0); |
68 | mAdapter.notifyDataSetChanged(); | 69 | mAdapter.notifyDataSetChanged(); |
69 | }); | 70 | }); |
70 | 71 | ||
71 | binding.btnConfirm.setOnClickListener(v -> { | 72 | binding.btnConfirm.setOnClickListener(v -> { |
72 | Intent intent = new Intent(this, HomeworkFeedbackActivity.class); | 73 | Intent intent = new Intent(this, HomeworkFeedbackActivity.class); |
73 | intent.putExtra("data", mData); | 74 | intent.putExtra("data", mData); |
74 | intent.putExtra("list", mList); | 75 | intent.putExtra("list", mList); |
75 | intent.putExtra("student", student); | 76 | intent.putExtra("student", student); |
76 | startActivity(intent); | 77 | startActivityForResult(intent, 0xA01); |
77 | }); | 78 | }); |
78 | } | 79 | } |
79 | 80 | ||
80 | @Override | 81 | @Override |
82 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | ||
83 | super.onActivityResult(requestCode, resultCode, data); | ||
84 | if (requestCode == 0xA01 && resultCode == RESULT_OK) { | ||
85 | setResult(RESULT_OK); | ||
86 | finish(); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | @Override | ||
81 | protected ActivityHomeworkSelectBinding getViewBinding() { | 91 | protected ActivityHomeworkSelectBinding getViewBinding() { |
82 | return ActivityHomeworkSelectBinding.inflate(getLayoutInflater()); | 92 | return ActivityHomeworkSelectBinding.inflate(getLayoutInflater()); |
83 | } | 93 | } |
84 | 94 | ||
85 | 95 | ||
86 | static class Adapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { | 96 | static class Adapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { |
87 | public Adapter() { | 97 | public Adapter() { |
88 | super(R.layout.item_homework_detail); | 98 | super(R.layout.item_homework_detail); |
89 | } | 99 | } |
90 | public Function1<Integer> selectCall; | 100 | public Function1<Integer> selectCall; |
91 | 101 | ||
92 | @SuppressLint("SetTextI18n") | 102 | @SuppressLint("SetTextI18n") |
93 | @Override | 103 | @Override |
94 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { | 104 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { |
95 | TextView tvNumber = holder.getView(R.id.tvNumber); | 105 | TextView tvNumber = holder.getView(R.id.tvNumber); |
96 | ImageView imageView = holder.getView(R.id.ivTopic); | 106 | ImageView imageView = holder.getView(R.id.ivTopic); |
97 | int number = getData().indexOf(homeWork) + 1; | 107 | int number = getData().indexOf(homeWork) + 1; |
98 | tvNumber.setText("第" + number + "题"); | 108 | tvNumber.setText("第" + number + "题"); |
99 | Glide.with(mContext).load(homeWork.url).into(imageView); | 109 | Glide.with(mContext).load(homeWork.url).into(imageView); |
100 | 110 | ||
101 | CheckBox checkBox = holder.getView(R.id.checkbox); | 111 | CheckBox checkBox = holder.getView(R.id.checkbox); |
102 | checkBox.setVisibility(View.VISIBLE); | 112 | checkBox.setVisibility(View.VISIBLE); |
103 | checkBox.setOnCheckedChangeListener(null); | 113 | checkBox.setOnCheckedChangeListener(null); |
104 | checkBox.setChecked(homeWork.check); | 114 | checkBox.setChecked(homeWork.check); |
105 | 115 | ||
106 | holder.itemView.setOnClickListener(v -> checkBox.performClick()); | 116 | holder.itemView.setOnClickListener(v -> checkBox.performClick()); |
107 | checkBox.setOnCheckedChangeListener((v, b) -> { | 117 | checkBox.setOnCheckedChangeListener((v, b) -> { |
108 | homeWork.check = b; | 118 | homeWork.check = b; |
109 | if (selectCall != null) { | 119 | if (selectCall != null) { |
110 | selectCall.invoke(b ? 1 : -1); | 120 | selectCall.invoke(b ? 1 : -1); |
111 | } | 121 | } |
112 | }); | 122 | }); |
113 | } | 123 | } |
114 | } | 124 | } |
115 | } | 125 | } |
116 | 126 |
app/src/main/java/com/hjx/parent/StuHomeworkActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import android.annotation.SuppressLint; | 3 | import android.annotation.SuppressLint; |
4 | import android.content.Intent; | 4 | import android.content.Intent; |
5 | import android.os.Bundle; | 5 | import android.os.Bundle; |
6 | import android.widget.LinearLayout; | 6 | import android.widget.LinearLayout; |
7 | import android.widget.PopupWindow; | 7 | import android.widget.PopupWindow; |
8 | 8 | ||
9 | import androidx.annotation.Nullable; | 9 | import androidx.annotation.Nullable; |
10 | import androidx.lifecycle.MutableLiveData; | 10 | import androidx.lifecycle.MutableLiveData; |
11 | 11 | ||
12 | import com.google.gson.Gson; | 12 | import com.google.gson.Gson; |
13 | import com.hjx.parent.adapter.HomeworkListAdapter; | 13 | import com.hjx.parent.adapter.HomeworkListAdapter; |
14 | import com.hjx.parent.databinding.ActivityStudentHomeworkBinding; | 14 | import com.hjx.parent.databinding.ActivityStudentHomeworkBinding; |
15 | import com.hjx.parent.databinding.PopupFilterFeedbackBinding; | 15 | import com.hjx.parent.databinding.PopupFilterFeedbackBinding; |
16 | import com.hjx.parent.databinding.PopupFilterGradeBinding; | 16 | import com.hjx.parent.databinding.PopupFilterGradeBinding; |
17 | import com.hjx.parent.databinding.PopupFilterSubjectBinding; | 17 | import com.hjx.parent.databinding.PopupFilterSubjectBinding; |
18 | import com.hjx.parent.databinding.PopupFilterTermBinding; | 18 | import com.hjx.parent.databinding.PopupFilterTermBinding; |
19 | import com.hjx.parent.dialog.MsgConfirmDialog; | 19 | import com.hjx.parent.dialog.MsgConfirmDialog; |
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.HomeworkList; | 22 | import com.prws.common.bean.homework.HomeworkList; |
23 | import com.prws.common.net.NetWorks; | 23 | import com.prws.common.net.NetWorks; |
24 | import com.prws.common.utils.SharedPreferencesUtil; | 24 | import com.prws.common.utils.SharedPreferencesUtil; |
25 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; | 25 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; |
26 | 26 | ||
27 | import java.util.Collections; | 27 | import java.util.Collections; |
28 | 28 | ||
29 | import io.reactivex.Observable; | 29 | import io.reactivex.Observable; |
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 | 32 | ||
33 | public class StuHomeworkActivity extends BaseRxActivity<ActivityStudentHomeworkBinding> { | 33 | public class StuHomeworkActivity extends BaseRxActivity<ActivityStudentHomeworkBinding> { |
34 | 34 | ||
35 | private final HomeworkListAdapter homeworkAdapter = new HomeworkListAdapter(); | 35 | private final HomeworkListAdapter homeworkAdapter = new HomeworkListAdapter(); |
36 | 36 | ||
37 | PopupWindow subjectFilter, gradeFilter, termFilter, feedbackFilter; | 37 | PopupWindow subjectFilter, gradeFilter, termFilter, feedbackFilter; |
38 | MsgConfirmDialog deleteDialog; | 38 | MsgConfirmDialog deleteDialog; |
39 | State state = new State(); | 39 | State state = new State(); |
40 | 40 | ||
41 | private void handlerIntent() { | 41 | private void handlerIntent() { |
42 | String json = getIntent().getStringExtra("studentJson"); | 42 | String json = getIntent().getStringExtra("studentJson"); |
43 | if (json == null) json = (String) SharedPreferencesUtil.getData("student", ""); | 43 | if (json == null) json = (String) SharedPreferencesUtil.getData("student", ""); |
44 | try { state.student = new Gson().fromJson(json, Student.class); } | 44 | try { state.student = new Gson().fromJson(json, Student.class); } |
45 | catch (Throwable t) { t.printStackTrace(); } | 45 | catch (Throwable t) { t.printStackTrace(); } |
46 | } | 46 | } |
47 | 47 | ||
48 | @SuppressLint("SetTextI18n") | 48 | @SuppressLint("SetTextI18n") |
49 | @Override | 49 | @Override |
50 | public void initView(Bundle savedInstanceState) { | 50 | public void initView(Bundle savedInstanceState) { |
51 | handlerIntent(); | 51 | handlerIntent(); |
52 | if (state.student == null) { | 52 | if (state.student == null) { |
53 | finish(); | 53 | finish(); |
54 | return; | 54 | return; |
55 | } | 55 | } |
56 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); | 56 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); |
57 | binding.tvTitle.setText(state.student.stuName + "的全部作业"); | 57 | binding.tvTitle.setText(state.student.stuName + "的全部作业"); |
58 | 58 | ||
59 | binding.recyclerView.setAdapter(homeworkAdapter); | 59 | binding.recyclerView.setAdapter(homeworkAdapter); |
60 | 60 | ||
61 | binding.ftSubject.setOnClickListener(v -> showSubjectFilter()); | 61 | binding.ftSubject.setOnClickListener(v -> showSubjectFilter()); |
62 | binding.ftGrade.setOnClickListener(v -> showGradeFilter()); | 62 | binding.ftGrade.setOnClickListener(v -> showGradeFilter()); |
63 | binding.ftTerm.setOnClickListener(v -> showTermFilter()); | 63 | binding.ftTerm.setOnClickListener(v -> showTermFilter()); |
64 | binding.ftFeedback.setOnClickListener(v -> showFeedbackFilter()); | 64 | binding.ftFeedback.setOnClickListener(v -> showFeedbackFilter()); |
65 | homeworkAdapter.deleteCall = data -> { | 65 | homeworkAdapter.deleteCall = data -> { |
66 | if (deleteDialog == null) { | 66 | if (deleteDialog == null) { |
67 | deleteDialog = new MsgConfirmDialog.Builder(this) | 67 | deleteDialog = new MsgConfirmDialog.Builder(this) |
68 | .setMessage("确认要删除吗?一旦删除不可恢复") | 68 | .setMessage("确认要删除吗?一旦删除不可恢复") |
69 | .setPositive("暂不删除") | 69 | .setPositive("暂不删除") |
70 | .setNegative("确定删除") | 70 | .setNegative("确定删除") |
71 | .build(); | 71 | .build(); |
72 | } | 72 | } |
73 | deleteDialog.show(() -> { | 73 | deleteDialog.show(() -> { |
74 | deleteHomework(data); | 74 | deleteHomework(data); |
75 | return true; | 75 | return true; |
76 | }, null); | 76 | }, null); |
77 | }; | 77 | }; |
78 | homeworkAdapter.detailCall = data -> { | 78 | homeworkAdapter.detailCall = data -> { |
79 | Intent intent = new Intent(this, HomeworkDetailActivity.class); | 79 | if (data.getRight() == null) { |
80 | intent.putExtra("data", data); | 80 | Intent intent = new Intent(this, HomeworkDetailActivity.class); |
81 | intent.putExtra("student", state.student); | 81 | intent.putExtra("data", data); |
82 | startActivity(intent); | 82 | intent.putExtra("student", state.student); |
83 | startActivity(intent); | ||
84 | } else { | ||
85 | // TODO | ||
86 | } | ||
83 | }; | 87 | }; |
84 | 88 | ||
85 | binding.btnChangeStudent.setOnClickListener(v -> { | 89 | binding.btnChangeStudent.setOnClickListener(v -> { |
86 | Intent intent = new Intent(this, TeacherChooseActivity.class); | 90 | Intent intent = new Intent(this, TeacherChooseActivity.class); |
87 | intent.putExtra("needBack", true); | 91 | intent.putExtra("needBack", true); |
88 | startActivityForResult(intent, 0xA01); | 92 | startActivityForResult(intent, 0xA01); |
89 | }); | 93 | }); |
90 | } | 94 | } |
91 | 95 | ||
92 | @Override | 96 | @Override |
93 | protected void onStart() { | 97 | protected void onStart() { |
94 | super.onStart(); | 98 | super.onStart(); |
95 | getHomework(); | 99 | getHomework(); |
96 | } | 100 | } |
97 | 101 | ||
98 | @SuppressLint("SetTextI18n") | 102 | @SuppressLint("SetTextI18n") |
99 | @Override | 103 | @Override |
100 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 104 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
101 | super.onActivityResult(requestCode, resultCode, data); | 105 | super.onActivityResult(requestCode, resultCode, data); |
102 | if (requestCode == 0xA01 && resultCode == RESULT_OK) { | 106 | if (requestCode == 0xA01 && resultCode == RESULT_OK) { |
103 | String json = (String) SharedPreferencesUtil.getData("student", ""); | 107 | String json = (String) SharedPreferencesUtil.getData("student", ""); |
104 | try { | 108 | try { |
105 | state.student = new Gson().fromJson(json, Student.class); | 109 | state.student = new Gson().fromJson(json, Student.class); |
106 | binding.tvTitle.setText(state.student.stuName + "的全部作业"); | 110 | binding.tvTitle.setText(state.student.stuName + "的全部作业"); |
107 | getHomework(); | 111 | getHomework(); |
108 | } | 112 | } |
109 | catch (Throwable t) { t.printStackTrace(); } | 113 | catch (Throwable t) { t.printStackTrace(); } |
110 | } | 114 | } |
111 | } | 115 | } |
112 | 116 | ||
113 | @SuppressLint("CheckResult") | 117 | @SuppressLint("CheckResult") |
114 | protected void deleteHomework(HomeworkList data) { | 118 | protected void deleteHomework(HomeworkList data) { |
115 | NetWorks.service_url.deleteHomework(NetWorks.getHeader(), data.getId()) | 119 | NetWorks.service_url.deleteHomework(NetWorks.getHeader(), data.getId()) |
116 | .subscribeOn(Schedulers.io()) | 120 | .subscribeOn(Schedulers.io()) |
117 | .observeOn(AndroidSchedulers.mainThread()) | 121 | .observeOn(AndroidSchedulers.mainThread()) |
118 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) | 122 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) |
119 | .subscribe((response, th) -> { | 123 | .subscribe((response, th) -> { |
120 | if (th != null) th.printStackTrace(); | 124 | if (th != null) th.printStackTrace(); |
121 | if (response != null && response.getSuccess()) { | 125 | if (response != null && response.getSuccess()) { |
122 | getHomework(); | 126 | getHomework(); |
123 | } | 127 | } |
124 | }); | 128 | }); |
125 | 129 | ||
126 | } | 130 | } |
127 | 131 | ||
128 | @SuppressLint("CheckResult") | 132 | @SuppressLint("CheckResult") |
129 | protected void getHomework() { | 133 | protected void getHomework() { |
130 | NetWorks.service_url.getStudentHomework(NetWorks.getHeader(), state.student.stuId) | 134 | NetWorks.service_url.getStudentHomework(NetWorks.getHeader(), state.student.stuId) |
131 | .subscribeOn(Schedulers.io()) | 135 | .subscribeOn(Schedulers.io()) |
132 | .observeOn(AndroidSchedulers.mainThread()) | 136 | .observeOn(AndroidSchedulers.mainThread()) |
133 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) | 137 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) |
134 | .toObservable() | 138 | .toObservable() |
135 | .flatMap(response -> Observable.fromIterable(response.getData())) | 139 | .flatMap(response -> Observable.fromIterable(response.getData())) |
136 | // 过滤 | 140 | // 过滤 |
137 | .filter(data -> { // 学科 | 141 | .filter(data -> { // 学科 |
138 | String subject = state.subject.getValue(); | 142 | String subject = state.subject.getValue(); |
139 | if (subject == null || subject.isEmpty()) return true; | 143 | if (subject == null || subject.isEmpty()) return true; |
140 | else return subject.equals(data.getSubject()); | 144 | else return subject.equals(data.getSubject()); |
141 | }) | 145 | }) |
142 | .filter(data -> { // 年级 | 146 | .filter(data -> { // 年级 |
143 | String grade = state.grade.getValue(); | 147 | String grade = state.grade.getValue(); |
144 | if (grade == null || grade.isEmpty()) return true; | 148 | if (grade == null || grade.isEmpty()) return true; |
145 | else return grade.equals(data.getGrade()); | 149 | else return grade.equals(data.getGrade()); |
146 | }) | 150 | }) |
147 | .filter(data -> { // 学期 | 151 | .filter(data -> { // 学期 |
148 | String term = state.term.getValue(); | 152 | String term = state.term.getValue(); |
149 | if (term == null || term.isEmpty()) return true; | 153 | if (term == null || term.isEmpty()) return true; |
150 | else return term.equals(data.getTerm()); | 154 | else return term.equals(data.getTerm()); |
151 | }) | 155 | }) |
152 | .filter(data -> { // 反馈 | 156 | .filter(data -> { // 反馈 |
153 | Integer feedback = state.feedback.getValue(); | 157 | Integer feedback = state.feedback.getValue(); |
154 | if (feedback == null || feedback == 0) return true; | 158 | if (feedback == null || feedback == 0) return true; |
155 | else return (feedback == 1 && data.getRight() != null) || (feedback == 2 && data.getRight() == null); | 159 | else return (feedback == 1 && data.getRight() != null) || (feedback == 2 && data.getRight() == null); |
156 | }) | 160 | }) |
157 | // 过滤完成, 收集 | 161 | // 过滤完成, 收集 |
158 | .toList() | 162 | .toList() |
159 | .subscribe((data, th) -> { | 163 | .subscribe((data, th) -> { |
160 | if (th != null) th.printStackTrace(); | 164 | if (th != null) th.printStackTrace(); |
161 | if (data != null) { | 165 | if (data != null) { |
162 | Collections.sort(data); | 166 | Collections.sort(data); |
163 | } | 167 | } |
164 | homeworkAdapter.setNewData(data); | 168 | homeworkAdapter.setNewData(data); |
165 | }); | 169 | }); |
166 | } | 170 | } |
167 | 171 | ||
168 | private void showSubjectFilter() { | 172 | private void showSubjectFilter() { |
169 | if (subjectFilter == null) { | 173 | if (subjectFilter == null) { |
170 | PopupFilterSubjectBinding db = PopupFilterSubjectBinding.inflate(getLayoutInflater()); | 174 | PopupFilterSubjectBinding db = PopupFilterSubjectBinding.inflate(getLayoutInflater()); |
171 | db.setLifecycleOwner(this); | 175 | db.setLifecycleOwner(this); |
172 | db.setState(state); | 176 | db.setState(state); |
173 | db.bg.setOnClickListener(v -> subjectFilter.dismiss()); | 177 | db.bg.setOnClickListener(v -> subjectFilter.dismiss()); |
174 | subjectFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 178 | subjectFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
175 | subjectFilter.setOutsideTouchable(true); | 179 | subjectFilter.setOutsideTouchable(true); |
176 | subjectFilter.setOnDismissListener(this::getHomework); | 180 | subjectFilter.setOnDismissListener(this::getHomework); |
177 | } | 181 | } |
178 | subjectFilter.showAsDropDown(binding.anchorView); | 182 | subjectFilter.showAsDropDown(binding.anchorView); |
179 | } | 183 | } |
180 | 184 | ||
181 | private void showGradeFilter() { | 185 | private void showGradeFilter() { |
182 | if (gradeFilter == null) { | 186 | if (gradeFilter == null) { |
183 | PopupFilterGradeBinding db = PopupFilterGradeBinding.inflate(getLayoutInflater()); | 187 | PopupFilterGradeBinding db = PopupFilterGradeBinding.inflate(getLayoutInflater()); |
184 | db.setLifecycleOwner(this); | 188 | db.setLifecycleOwner(this); |
185 | db.setState(state); | 189 | db.setState(state); |
186 | db.bg.setOnClickListener(v -> gradeFilter.dismiss()); | 190 | db.bg.setOnClickListener(v -> gradeFilter.dismiss()); |
187 | gradeFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 191 | gradeFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
188 | gradeFilter.setOutsideTouchable(true); | 192 | gradeFilter.setOutsideTouchable(true); |
189 | gradeFilter.setOnDismissListener(this::getHomework); | 193 | gradeFilter.setOnDismissListener(this::getHomework); |
190 | } | 194 | } |
191 | gradeFilter.showAsDropDown(binding.anchorView); | 195 | gradeFilter.showAsDropDown(binding.anchorView); |
192 | } | 196 | } |
193 | 197 | ||
194 | private void showTermFilter() { | 198 | private void showTermFilter() { |
195 | if (termFilter == null) { | 199 | if (termFilter == null) { |
196 | PopupFilterTermBinding db = PopupFilterTermBinding.inflate(getLayoutInflater()); | 200 | PopupFilterTermBinding db = PopupFilterTermBinding.inflate(getLayoutInflater()); |
197 | db.setLifecycleOwner(this); | 201 | db.setLifecycleOwner(this); |
198 | db.setState(state); | 202 | db.setState(state); |
199 | db.bg.setOnClickListener(v -> termFilter.dismiss()); | 203 | db.bg.setOnClickListener(v -> termFilter.dismiss()); |
200 | termFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 204 | termFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
201 | termFilter.setOutsideTouchable(true); | 205 | termFilter.setOutsideTouchable(true); |
202 | termFilter.setOnDismissListener(this::getHomework); | 206 | termFilter.setOnDismissListener(this::getHomework); |
203 | } | 207 | } |
204 | termFilter.showAsDropDown(binding.anchorView); | 208 | termFilter.showAsDropDown(binding.anchorView); |
205 | } | 209 | } |
206 | 210 | ||
207 | private void showFeedbackFilter() { | 211 | private void showFeedbackFilter() { |
208 | if (feedbackFilter == null) { | 212 | if (feedbackFilter == null) { |
209 | PopupFilterFeedbackBinding db = PopupFilterFeedbackBinding.inflate(getLayoutInflater()); | 213 | PopupFilterFeedbackBinding db = PopupFilterFeedbackBinding.inflate(getLayoutInflater()); |
210 | db.setLifecycleOwner(this); | 214 | db.setLifecycleOwner(this); |
211 | db.setState(state); | 215 | db.setState(state); |
212 | db.bg.setOnClickListener(v -> feedbackFilter.dismiss()); | 216 | db.bg.setOnClickListener(v -> feedbackFilter.dismiss()); |
213 | feedbackFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 217 | feedbackFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
214 | feedbackFilter.setOutsideTouchable(true); | 218 | feedbackFilter.setOutsideTouchable(true); |
215 | feedbackFilter.setOnDismissListener(this::getHomework); | 219 | feedbackFilter.setOnDismissListener(this::getHomework); |
216 | } | 220 | } |
217 | feedbackFilter.showAsDropDown(binding.anchorView); | 221 | feedbackFilter.showAsDropDown(binding.anchorView); |
218 | } | 222 | } |
219 | 223 | ||
220 | @Override | 224 | @Override |
221 | protected ActivityStudentHomeworkBinding getViewBinding() { | 225 | protected ActivityStudentHomeworkBinding getViewBinding() { |
222 | return ActivityStudentHomeworkBinding.inflate(getLayoutInflater()); | 226 | return ActivityStudentHomeworkBinding.inflate(getLayoutInflater()); |
223 | } | 227 | } |
224 | 228 | ||
225 | public static class State { | 229 | public static class State { |
226 | public Student student; | 230 | public Student student; |
227 | 231 | ||
228 | public MutableLiveData<String> subject = new MutableLiveData<>(""); | 232 | public MutableLiveData<String> subject = new MutableLiveData<>(""); |
229 | public void setSubject(String value) { | 233 | public void setSubject(String value) { |
230 | subject.setValue(value); | 234 | subject.setValue(value); |
231 | } | 235 | } |
232 | 236 | ||
233 | public MutableLiveData<String> grade = new MutableLiveData<>(""); | 237 | public MutableLiveData<String> grade = new MutableLiveData<>(""); |
234 | public void setGrade(String value) { | 238 | public void setGrade(String value) { |
235 | grade.setValue(value); | 239 | grade.setValue(value); |
236 | } | 240 | } |
237 | 241 | ||
238 | public MutableLiveData<String> term = new MutableLiveData<>(""); | 242 | public MutableLiveData<String> term = new MutableLiveData<>(""); |
239 | public void setTerm(String value) { | 243 | public void setTerm(String value) { |
240 | term.setValue(value); | 244 | term.setValue(value); |
241 | } | 245 | } |
242 | 246 | ||
243 | //0:全部, 1: 已反馈, 2:未反馈 | 247 | //0:全部, 1: 已反馈, 2:未反馈 |
244 | public MutableLiveData<Integer> feedback = new MutableLiveData<>(0); | 248 | public MutableLiveData<Integer> feedback = new MutableLiveData<>(0); |
245 | public void setFeedback(int value) { | 249 | public void setFeedback(int value) { |
246 | feedback.setValue(value); | 250 | feedback.setValue(value); |
247 | } | 251 | } |
248 | } | 252 | } |
249 | } | 253 | } |
250 | 254 |