Commit bd79e76cddec67897be48aba154bb57ba032e5ed
1 parent
0c498d9a4e
Exists in
master
页面跳转
Showing
2 changed files
with
24 additions
and
1 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 | 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 | ||
101 | Toast.makeText(this, "反馈成功", Toast.LENGTH_SHORT).show(); | 100 | Toast.makeText(this, "反馈成功", Toast.LENGTH_SHORT).show(); |
101 | |||
102 | Intent intent = new Intent(this, HomeworkShareActivity.class); | ||
103 | intent.putExtra("student", student); | ||
104 | intent.putExtra("id", mData.getId()); | ||
105 | intent.putExtra("grade", mData.getGrade()); | ||
106 | intent.putExtra("subject", mData.getSubject()); | ||
107 | startActivity(intent); | ||
108 | |||
102 | setResult(RESULT_OK); | 109 | setResult(RESULT_OK); |
103 | finish(); | 110 | finish(); |
104 | } | 111 | } |
105 | }); | 112 | }); |
106 | } | 113 | } |
107 | 114 | ||
108 | @SuppressLint("CheckResult") | 115 | @SuppressLint("CheckResult") |
109 | private List<CorrectionPoint> countPoint() { | 116 | private List<CorrectionPoint> countPoint() { |
110 | Set<KeyValue> set = new HashSet<>(); | 117 | Set<KeyValue> set = new HashSet<>(); |
111 | Map<String, Integer> totalTimes = new HashMap<>(); | 118 | Map<String, Integer> totalTimes = new HashMap<>(); |
112 | Map<String, Integer> correctTimes = new HashMap<>(); | 119 | Map<String, Integer> correctTimes = new HashMap<>(); |
113 | Map<String, Integer> underTimes = new HashMap<>(); | 120 | Map<String, Integer> underTimes = new HashMap<>(); |
114 | Map<String, Integer> baseTimes = new HashMap<>(); | 121 | Map<String, Integer> baseTimes = new HashMap<>(); |
115 | Map<String, Integer> normalTimes = new HashMap<>(); | 122 | Map<String, Integer> normalTimes = new HashMap<>(); |
116 | Gson gson = new Gson(); | 123 | Gson gson = new Gson(); |
117 | for (HomeWork homeWork: mList) { | 124 | for (HomeWork homeWork: mList) { |
118 | homeWork.formatPoints(gson); | 125 | homeWork.formatPoints(gson); |
119 | 126 | ||
120 | set.addAll(homeWork.pointsObj); | 127 | set.addAll(homeWork.pointsObj); |
121 | for (KeyValue keyValue: homeWork.pointsObj) { | 128 | for (KeyValue keyValue: homeWork.pointsObj) { |
122 | String key = keyValue.Key; | 129 | String key = keyValue.Key; |
123 | if (totalTimes.containsKey(key)) { | 130 | if (totalTimes.containsKey(key)) { |
124 | totalTimes.put(key, totalTimes.get(key) + 1); | 131 | totalTimes.put(key, totalTimes.get(key) + 1); |
125 | } else { | 132 | } else { |
126 | totalTimes.put(key, 1); | 133 | totalTimes.put(key, 1); |
127 | } | 134 | } |
128 | if (!homeWork.check) { | 135 | if (!homeWork.check) { |
129 | if (correctTimes.containsKey(key)) { | 136 | if (correctTimes.containsKey(key)) { |
130 | correctTimes.put(key, correctTimes.get(key) + 1); | 137 | correctTimes.put(key, correctTimes.get(key) + 1); |
131 | } else { | 138 | } else { |
132 | correctTimes.put(key, 1); | 139 | correctTimes.put(key, 1); |
133 | } | 140 | } |
134 | } else if (homeWork.state == 1) { | 141 | } else if (homeWork.state == 1) { |
135 | if (underTimes.containsKey(key)) { | 142 | if (underTimes.containsKey(key)) { |
136 | underTimes.put(key, underTimes.get(key) + 1); | 143 | underTimes.put(key, underTimes.get(key) + 1); |
137 | } else { | 144 | } else { |
138 | underTimes.put(key, 1); | 145 | underTimes.put(key, 1); |
139 | } | 146 | } |
140 | } else if (homeWork.state == 2) { | 147 | } else if (homeWork.state == 2) { |
141 | if (baseTimes.containsKey(key)) { | 148 | if (baseTimes.containsKey(key)) { |
142 | baseTimes.put(key, baseTimes.get(key) + 1); | 149 | baseTimes.put(key, baseTimes.get(key) + 1); |
143 | } else { | 150 | } else { |
144 | baseTimes.put(key, 1); | 151 | baseTimes.put(key, 1); |
145 | } | 152 | } |
146 | } else if (homeWork.state == 3) { | 153 | } else if (homeWork.state == 3) { |
147 | if (normalTimes.containsKey(key)) { | 154 | if (normalTimes.containsKey(key)) { |
148 | normalTimes.put(key, normalTimes.get(key) + 1); | 155 | normalTimes.put(key, normalTimes.get(key) + 1); |
149 | } else { | 156 | } else { |
150 | normalTimes.put(key, 1); | 157 | normalTimes.put(key, 1); |
151 | } | 158 | } |
152 | } | 159 | } |
153 | } | 160 | } |
154 | } | 161 | } |
155 | List<CorrectionPoint> points = new ArrayList<>(); | 162 | List<CorrectionPoint> points = new ArrayList<>(); |
156 | for (KeyValue obj: set) { | 163 | for (KeyValue obj: set) { |
157 | CorrectionPoint point = new CorrectionPoint(); | 164 | CorrectionPoint point = new CorrectionPoint(); |
158 | point.pointId = obj.Key; | 165 | point.pointId = obj.Key; |
159 | point.pointName = obj.Value; | 166 | point.pointName = obj.Value; |
160 | point.totalCount = ifNull(totalTimes.get(obj.Key), 1); | 167 | point.totalCount = ifNull(totalTimes.get(obj.Key), 1); |
161 | point.correctCount = ifNull(correctTimes.get(obj.Key), 0); | 168 | point.correctCount = ifNull(correctTimes.get(obj.Key), 0); |
162 | point.understandCount = ifNull(underTimes.get(obj.Key), 0); | 169 | point.understandCount = ifNull(underTimes.get(obj.Key), 0); |
163 | point.basicCount = ifNull(baseTimes.get(obj.Key), 0); | 170 | point.basicCount = ifNull(baseTimes.get(obj.Key), 0); |
164 | point.normalCount = ifNull(normalTimes.get(obj.Key), 0); | 171 | point.normalCount = ifNull(normalTimes.get(obj.Key), 0); |
165 | 172 | ||
166 | points.add(point); | 173 | points.add(point); |
167 | } | 174 | } |
168 | 175 | ||
169 | return points; | 176 | return points; |
170 | } | 177 | } |
171 | 178 | ||
172 | private int ifNull(Integer src, int defaultVal) { | 179 | private int ifNull(Integer src, int defaultVal) { |
173 | if (src == null) return defaultVal; | 180 | if (src == null) return defaultVal; |
174 | else return src; | 181 | else return src; |
175 | } | 182 | } |
176 | 183 | ||
177 | 184 | ||
178 | @Override | 185 | @Override |
179 | protected ActivityHomeworkFeedbackBinding getViewBinding() { | 186 | protected ActivityHomeworkFeedbackBinding getViewBinding() { |
180 | return ActivityHomeworkFeedbackBinding.inflate(getLayoutInflater()); | 187 | return ActivityHomeworkFeedbackBinding.inflate(getLayoutInflater()); |
181 | } | 188 | } |
182 | 189 | ||
183 | static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { | 190 | static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { |
184 | 191 | ||
185 | public NumberAdapter(List<HomeWork> list) { | 192 | public NumberAdapter(List<HomeWork> list) { |
186 | super(R.layout.item_feedback_num, list); | 193 | super(R.layout.item_feedback_num, list); |
187 | } | 194 | } |
188 | 195 | ||
189 | @Override | 196 | @Override |
190 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { | 197 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { |
191 | int position = getData().indexOf(homeWork); | 198 | int position = getData().indexOf(homeWork); |
192 | holder.setText(R.id.tvNum, String.valueOf(position + 1)); | 199 | holder.setText(R.id.tvNum, String.valueOf(position + 1)); |
193 | if (homeWork.check) { | 200 | if (homeWork.check) { |
194 | holder.setImageResource(R.id.ivType, R.drawable.ic_wrong_small); | 201 | holder.setImageResource(R.id.ivType, R.drawable.ic_wrong_small); |
195 | } else { | 202 | } else { |
196 | holder.setImageResource(R.id.ivType, R.drawable.ic_correct_small); | 203 | holder.setImageResource(R.id.ivType, R.drawable.ic_correct_small); |
197 | } | 204 | } |
198 | } | 205 | } |
199 | } | 206 | } |
200 | 207 | ||
201 | static class EvalAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { | 208 | static class EvalAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { |
202 | 209 | ||
203 | public EvalAdapter(@Nullable List<HomeWork> data) { | 210 | public EvalAdapter(@Nullable List<HomeWork> data) { |
204 | super(R.layout.item_homework_eval, data); | 211 | super(R.layout.item_homework_eval, data); |
205 | } | 212 | } |
206 | 213 | ||
207 | @Override | 214 | @Override |
208 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { | 215 | protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { |
209 | holder.itemView.setClipToOutline(true); | 216 | holder.itemView.setClipToOutline(true); |
210 | holder.setText(R.id.tvNo, "题目" + (homeWork.index + 1)); | 217 | holder.setText(R.id.tvNo, "题目" + (homeWork.index + 1)); |
211 | ImageView iv = holder.getView(R.id.ivTopic); | 218 | ImageView iv = holder.getView(R.id.ivTopic); |
212 | Glide.with(mContext).load(homeWork.url).into(iv); | 219 | Glide.with(mContext).load(homeWork.url).into(iv); |
213 | 220 | ||
214 | RadioButton chk1 = holder.getView(R.id.chk1); | 221 | RadioButton chk1 = holder.getView(R.id.chk1); |
215 | RadioButton chk2 = holder.getView(R.id.chk2); | 222 | RadioButton chk2 = holder.getView(R.id.chk2); |
216 | RadioButton chk3 = holder.getView(R.id.chk3); | 223 | RadioButton chk3 = holder.getView(R.id.chk3); |
217 | chk1.setOnCheckedChangeListener((v, b) -> { | 224 | chk1.setOnCheckedChangeListener((v, b) -> { |
218 | if (b) { | 225 | if (b) { |
219 | homeWork.state = 1; | 226 | homeWork.state = 1; |
220 | } | 227 | } |
221 | }); | 228 | }); |
222 | chk2.setOnCheckedChangeListener((v, b) -> { | 229 | chk2.setOnCheckedChangeListener((v, b) -> { |
223 | if (b) { | 230 | if (b) { |
224 | homeWork.state = 2; | 231 | homeWork.state = 2; |
225 | } | 232 | } |
226 | }); | 233 | }); |
227 | chk3.setOnCheckedChangeListener((v, b) -> { | 234 | chk3.setOnCheckedChangeListener((v, b) -> { |
228 | if (b) { | 235 | if (b) { |
229 | homeWork.state = 3; | 236 | homeWork.state = 3; |
230 | } | 237 | } |
231 | }); | 238 | }); |
232 | chk1.setChecked(homeWork.state == 1); | 239 | chk1.setChecked(homeWork.state == 1); |
233 | chk2.setChecked(homeWork.state == 2); | 240 | chk2.setChecked(homeWork.state == 2); |
234 | chk3.setChecked(homeWork.state == 3); | 241 | chk3.setChecked(homeWork.state == 3); |
235 | } | 242 | } |
236 | } | 243 | } |
237 | } | 244 | } |
app/src/main/java/com/hjx/parent/fragment/ErrorFragment.java
1 | package com.hjx.parent.fragment; | 1 | package com.hjx.parent.fragment; |
2 | 2 | ||
3 | import static android.app.Activity.RESULT_OK; | 3 | import static android.app.Activity.RESULT_OK; |
4 | 4 | ||
5 | import android.annotation.SuppressLint; | 5 | import android.annotation.SuppressLint; |
6 | import android.content.Intent; | 6 | import android.content.Intent; |
7 | import android.graphics.Bitmap; | 7 | import android.graphics.Bitmap; |
8 | import android.graphics.BitmapFactory; | 8 | import android.graphics.BitmapFactory; |
9 | import android.net.Uri; | 9 | import android.net.Uri; |
10 | import android.os.Bundle; | 10 | import android.os.Bundle; |
11 | import android.provider.MediaStore; | 11 | import android.provider.MediaStore; |
12 | import android.text.TextUtils; | 12 | import android.text.TextUtils; |
13 | import android.util.Log; | 13 | import android.util.Log; |
14 | import android.view.LayoutInflater; | 14 | import android.view.LayoutInflater; |
15 | import android.view.View; | 15 | import android.view.View; |
16 | import android.view.ViewGroup; | 16 | import android.view.ViewGroup; |
17 | import android.widget.Toast; | 17 | import android.widget.Toast; |
18 | 18 | ||
19 | import androidx.annotation.NonNull; | 19 | import androidx.annotation.NonNull; |
20 | import androidx.annotation.Nullable; | 20 | import androidx.annotation.Nullable; |
21 | import androidx.core.content.FileProvider; | 21 | import androidx.core.content.FileProvider; |
22 | import androidx.recyclerview.widget.RecyclerView; | 22 | import androidx.recyclerview.widget.RecyclerView; |
23 | 23 | ||
24 | import com.bumptech.glide.Glide; | 24 | import com.bumptech.glide.Glide; |
25 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 25 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
26 | import com.bumptech.glide.request.RequestOptions; | 26 | import com.bumptech.glide.request.RequestOptions; |
27 | import com.chad.library.adapter.base.BaseQuickAdapter; | 27 | import com.chad.library.adapter.base.BaseQuickAdapter; |
28 | import com.chad.library.adapter.base.BaseViewHolder; | 28 | import com.chad.library.adapter.base.BaseViewHolder; |
29 | import com.google.android.material.tabs.TabLayout; | 29 | import com.google.android.material.tabs.TabLayout; |
30 | import com.google.gson.Gson; | 30 | import com.google.gson.Gson; |
31 | import com.hjq.permissions.OnPermissionCallback; | 31 | import com.hjq.permissions.OnPermissionCallback; |
32 | import com.hjq.permissions.Permission; | 32 | import com.hjq.permissions.Permission; |
33 | import com.hjq.permissions.XXPermissions; | 33 | import com.hjq.permissions.XXPermissions; |
34 | import com.hjx.parent.ErrorListActivity; | 34 | import com.hjx.parent.ErrorListActivity; |
35 | import com.hjx.parent.HomeworkDetailActivity; | ||
35 | import com.hjx.parent.ImageActivity; | 36 | import com.hjx.parent.ImageActivity; |
36 | import com.hjx.parent.R; | 37 | import com.hjx.parent.R; |
37 | import com.hjx.parent.StuHomeworkActivity; | 38 | import com.hjx.parent.StuHomeworkActivity; |
38 | import com.hjx.parent.TeacherChooseActivity; | 39 | import com.hjx.parent.TeacherChooseActivity; |
39 | import com.hjx.parent.adapter.ErrorAdapter; | 40 | import com.hjx.parent.adapter.ErrorAdapter; |
40 | import com.hjx.parent.adapter.HomeworkAdapter; | 41 | import com.hjx.parent.adapter.HomeworkAdapter; |
41 | import com.hjx.parent.bean.StudentBean; | 42 | import com.hjx.parent.bean.StudentBean; |
42 | import com.hjx.parent.databinding.FragmentErrorBookBinding; | 43 | import com.hjx.parent.databinding.FragmentErrorBookBinding; |
43 | import com.hjx.parent.rx.BaseRxFragment; | 44 | import com.hjx.parent.rx.BaseRxFragment; |
44 | import com.prws.common.bean.PageInfo; | 45 | import com.prws.common.bean.PageInfo; |
45 | import com.prws.common.bean.ResponseResult; | 46 | import com.prws.common.bean.ResponseResult; |
47 | import com.prws.common.bean.Student; | ||
46 | import com.prws.common.bean.TopicBean; | 48 | import com.prws.common.bean.TopicBean; |
47 | import com.prws.common.net.NetWorks; | 49 | import com.prws.common.net.NetWorks; |
48 | import com.prws.common.utils.BitmapUtils; | 50 | import com.prws.common.utils.BitmapUtils; |
49 | import com.prws.common.utils.CommonUtil; | 51 | import com.prws.common.utils.CommonUtil; |
50 | import com.prws.common.utils.ScreenUtils; | 52 | import com.prws.common.utils.ScreenUtils; |
51 | import com.prws.common.utils.SharedPreferencesUtil; | 53 | import com.prws.common.utils.SharedPreferencesUtil; |
52 | import com.prws.common.utils.dialog.MyButtomDialog; | 54 | import com.prws.common.utils.dialog.MyButtomDialog; |
53 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; | 55 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; |
54 | import com.zhangteng.imagepicker.bean.ImageInfo; | 56 | import com.zhangteng.imagepicker.bean.ImageInfo; |
55 | import com.zhangteng.imagepicker.config.ImagePickerConfig; | 57 | import com.zhangteng.imagepicker.config.ImagePickerConfig; |
56 | import com.zhangteng.imagepicker.config.ImagePickerEnum; | 58 | import com.zhangteng.imagepicker.config.ImagePickerEnum; |
57 | import com.zhangteng.imagepicker.config.ImagePickerOpen; | 59 | import com.zhangteng.imagepicker.config.ImagePickerOpen; |
58 | import com.zhangteng.imagepicker.imageloader.GlideImageLoader; | 60 | import com.zhangteng.imagepicker.imageloader.GlideImageLoader; |
59 | import com.zhangteng.utils.IHandlerCallBack; | 61 | import com.zhangteng.utils.IHandlerCallBack; |
60 | 62 | ||
61 | import java.io.File; | 63 | import java.io.File; |
62 | import java.util.ArrayList; | 64 | import java.util.ArrayList; |
63 | import java.util.Arrays; | 65 | import java.util.Arrays; |
64 | import java.util.Collections; | 66 | import java.util.Collections; |
65 | import java.util.HashMap; | 67 | import java.util.HashMap; |
66 | import java.util.List; | 68 | import java.util.List; |
67 | import java.util.Map; | 69 | import java.util.Map; |
68 | 70 | ||
69 | import io.reactivex.Observable; | 71 | import io.reactivex.Observable; |
70 | import io.reactivex.Observer; | 72 | import io.reactivex.Observer; |
71 | import io.reactivex.android.schedulers.AndroidSchedulers; | 73 | import io.reactivex.android.schedulers.AndroidSchedulers; |
72 | import io.reactivex.disposables.Disposable; | 74 | import io.reactivex.disposables.Disposable; |
73 | import io.reactivex.schedulers.Schedulers; | 75 | import io.reactivex.schedulers.Schedulers; |
74 | 76 | ||
75 | public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { | 77 | public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { |
76 | StudentBean studentBean; | 78 | StudentBean studentBean; |
77 | private int subject; | 79 | private int subject; |
78 | private ErrorAdapter errorAdapter; | 80 | private ErrorAdapter errorAdapter; |
79 | private HomeworkAdapter homeworkAdapter; | 81 | private HomeworkAdapter homeworkAdapter; |
80 | private String filePath; | 82 | private String filePath; |
81 | 83 | ||
82 | @Override | 84 | @Override |
83 | protected FragmentErrorBookBinding onCreateViewBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup parent) { | 85 | protected FragmentErrorBookBinding onCreateViewBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup parent) { |
84 | return FragmentErrorBookBinding.inflate(inflater, parent, false); | 86 | return FragmentErrorBookBinding.inflate(inflater, parent, false); |
85 | } | 87 | } |
86 | 88 | ||
87 | public void refreshStudent() { | 89 | public void refreshStudent() { |
88 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 90 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
89 | try { | 91 | try { |
90 | studentBean = new Gson().fromJson(student, StudentBean.class); | 92 | studentBean = new Gson().fromJson(student, StudentBean.class); |
91 | getBinding().tvChoose.setText(studentBean.getStuName()); | 93 | getBinding().tvChoose.setText(studentBean.getStuName()); |
92 | } catch (Exception e) { | 94 | } catch (Exception e) { |
93 | e.printStackTrace(); | 95 | e.printStackTrace(); |
94 | } | 96 | } |
95 | } | 97 | } |
96 | 98 | ||
97 | @Override | 99 | @Override |
98 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | 100 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
99 | super.onViewCreated(view, savedInstanceState); | 101 | super.onViewCreated(view, savedInstanceState); |
100 | String photo = (String) SharedPreferencesUtil.getData("photo", ""); | 102 | String photo = (String) SharedPreferencesUtil.getData("photo", ""); |
101 | if (!TextUtils.isEmpty(photo)) { | 103 | if (!TextUtils.isEmpty(photo)) { |
102 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); | 104 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); |
103 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 105 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
104 | Glide.with(getContext()).load(photo).apply(options).into(getBinding().ivStudent); | 106 | Glide.with(getContext()).load(photo).apply(options).into(getBinding().ivStudent); |
105 | } | 107 | } |
106 | String name = (String) SharedPreferencesUtil.getData("name", ""); | 108 | String name = (String) SharedPreferencesUtil.getData("name", ""); |
107 | getBinding().tvName.setText(name); | 109 | getBinding().tvName.setText(name); |
108 | refreshStudent(); | 110 | refreshStudent(); |
109 | getBinding().tvChoose.setOnClickListener(v -> startActivity(new Intent(getContext(), TeacherChooseActivity.class))); | 111 | getBinding().tvChoose.setOnClickListener(v -> startActivity(new Intent(getContext(), TeacherChooseActivity.class))); |
110 | getBinding().rlTakePhoto.setOnClickListener(v -> takePhoto(0)); | 112 | getBinding().rlTakePhoto.setOnClickListener(v -> takePhoto(0)); |
111 | getBinding().flEntryHomework.setOnClickListener(v -> takePhoto(1)); | 113 | getBinding().flEntryHomework.setOnClickListener(v -> takePhoto(1)); |
112 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_subject, Arrays.asList(getResources().getStringArray(R.array.filter_subject))) { | 114 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_subject, Arrays.asList(getResources().getStringArray(R.array.filter_subject))) { |
113 | @Override | 115 | @Override |
114 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | 116 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
115 | 117 | ||
116 | } | 118 | } |
117 | 119 | ||
118 | @Override | 120 | @Override |
119 | protected void convert(@NonNull BaseViewHolder item, Object o) { | 121 | protected void convert(@NonNull BaseViewHolder item, Object o) { |
120 | item.setText(R.id.tv_subject, getResources().getStringArray(R.array.filter_subject)[item.getAdapterPosition()]); | 122 | item.setText(R.id.tv_subject, getResources().getStringArray(R.array.filter_subject)[item.getAdapterPosition()]); |
121 | switch (item.getAdapterPosition()) { | 123 | switch (item.getAdapterPosition()) { |
122 | case 0: | 124 | case 0: |
123 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_chinese); | 125 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_chinese); |
124 | break; | 126 | break; |
125 | case 1: | 127 | case 1: |
126 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_math); | 128 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_math); |
127 | break; | 129 | break; |
128 | case 2: | 130 | case 2: |
129 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_english); | 131 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_english); |
130 | break; | 132 | break; |
131 | case 3: | 133 | case 3: |
132 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_physics); | 134 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_physics); |
133 | break; | 135 | break; |
134 | case 4: | 136 | case 4: |
135 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_chemistry); | 137 | item.setImageResource(R.id.iv_subject, R.mipmap.ic_chemistry); |
136 | break; | 138 | break; |
137 | } | 139 | } |
138 | ViewGroup.LayoutParams layoutParams = item.getView(R.id.rl_subject).getLayoutParams(); | 140 | ViewGroup.LayoutParams layoutParams = item.getView(R.id.rl_subject).getLayoutParams(); |
139 | layoutParams.width = (CommonUtil.getScreenWidth(getContext()) - CommonUtil.dpToPx(getContext(), 30)) / 4; | 141 | layoutParams.width = (CommonUtil.getScreenWidth(getContext()) - CommonUtil.dpToPx(getContext(), 30)) / 4; |
140 | item.getView(R.id.rl_subject).setLayoutParams(layoutParams); | 142 | item.getView(R.id.rl_subject).setLayoutParams(layoutParams); |
141 | item.getConvertView().setOnClickListener(v -> { | 143 | item.getConvertView().setOnClickListener(v -> { |
142 | if (subject != item.getAdapterPosition()) { | 144 | if (subject != item.getAdapterPosition()) { |
143 | subject = item.getAdapterPosition(); | 145 | subject = item.getAdapterPosition(); |
144 | String subStr = getResources().getStringArray(R.array.filter_subject)[subject]; | 146 | String subStr = getResources().getStringArray(R.array.filter_subject)[subject]; |
145 | getError(subStr); | 147 | getError(subStr); |
146 | getHomework(subStr); | 148 | getHomework(subStr); |
147 | } | 149 | } |
148 | }); | 150 | }); |
149 | } | 151 | } |
150 | }; | 152 | }; |
151 | getBinding().rvSubject.setAdapter(adapter); | 153 | getBinding().rvSubject.setAdapter(adapter); |
152 | subject = 0; | 154 | subject = 0; |
153 | getError(getResources().getStringArray(R.array.filter_subject)[subject]); | 155 | getError(getResources().getStringArray(R.array.filter_subject)[subject]); |
154 | getBinding().llAll.setOnClickListener(v -> { | 156 | getBinding().llAll.setOnClickListener(v -> { |
155 | if (binding.tabLayout.getSelectedTabPosition() == 0) { | 157 | if (binding.tabLayout.getSelectedTabPosition() == 0) { |
156 | Intent intent = new Intent(getContext(), ErrorListActivity.class); | 158 | Intent intent = new Intent(getContext(), ErrorListActivity.class); |
157 | startActivity(intent); | 159 | startActivity(intent); |
158 | } else { | 160 | } else { |
159 | Intent intent = new Intent(getContext(), StuHomeworkActivity.class); | 161 | Intent intent = new Intent(getContext(), StuHomeworkActivity.class); |
160 | startActivity(intent); | 162 | startActivity(intent); |
161 | } | 163 | } |
162 | }); | 164 | }); |
163 | 165 | ||
164 | errorAdapter = new ErrorAdapter(getActivity(), new ArrayList<>(), false); | 166 | errorAdapter = new ErrorAdapter(getActivity(), new ArrayList<>(), false); |
165 | homeworkAdapter = new HomeworkAdapter(); | 167 | homeworkAdapter = new HomeworkAdapter(); |
168 | homeworkAdapter.setOnItemClickListener((baseQuickAdapter, view1, i) -> { | ||
169 | Gson gson = new Gson(); | ||
170 | String json = gson.toJson(studentBean); | ||
171 | Student s = gson.fromJson(json, Student.class); | ||
172 | Intent intent = new Intent(requireContext(), HomeworkDetailActivity.class); | ||
173 | intent.putExtra("student", s); | ||
174 | intent.putExtra("data", homeworkAdapter.getData().get(i)); | ||
175 | startActivity(intent); | ||
176 | }); | ||
166 | binding.rvMain.setAdapter(errorAdapter); | 177 | binding.rvMain.setAdapter(errorAdapter); |
167 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("最近错题")); | 178 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("最近错题")); |
168 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("最近作业")); | 179 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("最近作业")); |
169 | binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { | 180 | binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { |
170 | @Override | 181 | @Override |
171 | public void onTabSelected(TabLayout.Tab tab) { | 182 | public void onTabSelected(TabLayout.Tab tab) { |
172 | if (tab.getPosition() == 0) { | 183 | if (tab.getPosition() == 0) { |
173 | binding.rvMain.setAdapter(errorAdapter); | 184 | binding.rvMain.setAdapter(errorAdapter); |
174 | binding.rvMain.setVisibility(errorAdapter.list.isEmpty() ? View.GONE : View.VISIBLE); | 185 | binding.rvMain.setVisibility(errorAdapter.list.isEmpty() ? View.GONE : View.VISIBLE); |
175 | binding.llEmpty.setVisibility(errorAdapter.list.isEmpty() ? View.VISIBLE : View.GONE); | 186 | binding.llEmpty.setVisibility(errorAdapter.list.isEmpty() ? View.VISIBLE : View.GONE); |
176 | binding.tvListTitle.setText("最近错题"); | 187 | binding.tvListTitle.setText("最近错题"); |
177 | binding.tvEmpty.setText("暂无错题~"); | 188 | binding.tvEmpty.setText("暂无错题~"); |
178 | } else { | 189 | } else { |
179 | binding.rvMain.setAdapter(homeworkAdapter); | 190 | binding.rvMain.setAdapter(homeworkAdapter); |
180 | binding.rvMain.setVisibility(homeworkAdapter.getData().isEmpty() ? View.GONE : View.VISIBLE); | 191 | binding.rvMain.setVisibility(homeworkAdapter.getData().isEmpty() ? View.GONE : View.VISIBLE); |
181 | binding.llEmpty.setVisibility(homeworkAdapter.getData().isEmpty() ? View.VISIBLE : View.GONE); | 192 | binding.llEmpty.setVisibility(homeworkAdapter.getData().isEmpty() ? View.VISIBLE : View.GONE); |
182 | binding.tvListTitle.setText("最近作业"); | 193 | binding.tvListTitle.setText("最近作业"); |
183 | binding.tvEmpty.setText("暂无作业~"); | 194 | binding.tvEmpty.setText("暂无作业~"); |
184 | } | 195 | } |
185 | } | 196 | } |
186 | @Override | 197 | @Override |
187 | public void onTabUnselected(TabLayout.Tab tab) { | 198 | public void onTabUnselected(TabLayout.Tab tab) { |
188 | } | 199 | } |
189 | @Override | 200 | @Override |
190 | public void onTabReselected(TabLayout.Tab tab) { | 201 | public void onTabReselected(TabLayout.Tab tab) { |
191 | } | 202 | } |
192 | }); | 203 | }); |
193 | } | 204 | } |
194 | 205 | ||
195 | private void takePhoto(int type) { | 206 | private void takePhoto(int type) { |
196 | if (!XXPermissions.isGranted(getContext(), Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE)) { | 207 | if (!XXPermissions.isGranted(getContext(), Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE)) { |
197 | XXPermissions.with(getContext()) | 208 | XXPermissions.with(getContext()) |
198 | // 申请多个权限 | 209 | // 申请多个权限 |
199 | .permission(Permission.CAMERA).request(new OnPermissionCallback() { | 210 | .permission(Permission.CAMERA).request(new OnPermissionCallback() { |
200 | @Override | 211 | @Override |
201 | public void onGranted(List<String> permissions, boolean all) { | 212 | public void onGranted(List<String> permissions, boolean all) { |
202 | if (all) { | 213 | if (all) { |
203 | //开启扫码界面 | 214 | //开启扫码界面 |
204 | showButtonDialog(type); | 215 | showButtonDialog(type); |
205 | } else { | 216 | } else { |
206 | Toast.makeText(getContext(), "需要权限", Toast.LENGTH_SHORT).show(); | 217 | Toast.makeText(getContext(), "需要权限", Toast.LENGTH_SHORT).show(); |
207 | } | 218 | } |
208 | } | 219 | } |
209 | 220 | ||
210 | @Override | 221 | @Override |
211 | public void onDenied(List<String> permissions, boolean never) { | 222 | public void onDenied(List<String> permissions, boolean never) { |
212 | XXPermissions.startPermissionActivity(getContext(), permissions); | 223 | XXPermissions.startPermissionActivity(getContext(), permissions); |
213 | } | 224 | } |
214 | }); | 225 | }); |
215 | } else { | 226 | } else { |
216 | showButtonDialog(type); | 227 | showButtonDialog(type); |
217 | } | 228 | } |
218 | } | 229 | } |
219 | 230 | ||
220 | private void showButtonDialog(int type) { | 231 | private void showButtonDialog(int type) { |
221 | MyButtomDialog dialog = new MyButtomDialog(getActivity(), R.style.BottomSheetDialog); | 232 | MyButtomDialog dialog = new MyButtomDialog(getActivity(), R.style.BottomSheetDialog); |
222 | View bottomView = LayoutInflater.from(getActivity()).inflate(R.layout.bottom_sheet_layout, null); | 233 | View bottomView = LayoutInflater.from(getActivity()).inflate(R.layout.bottom_sheet_layout, null); |
223 | dialog.setContentView(bottomView); | 234 | dialog.setContentView(bottomView); |
224 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { | 235 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { |
225 | @Override | 236 | @Override |
226 | public void onClick(View view) { | 237 | public void onClick(View view) { |
227 | dialog.dismiss(); | 238 | dialog.dismiss(); |
228 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 239 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
229 | //确保有相机来处理Intent | 240 | //确保有相机来处理Intent |
230 | filePath = requireActivity().getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; | 241 | filePath = requireActivity().getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; |
231 | File photoFile = new File(filePath); | 242 | File photoFile = new File(filePath); |
232 | 243 | ||
233 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri | 244 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri |
234 | Uri photoUri = FileProvider.getUriForFile(requireActivity(), "com.hjx.parent.fileprovider", photoFile); | 245 | Uri photoUri = FileProvider.getUriForFile(requireActivity(), "com.hjx.parent.fileprovider", photoFile); |
235 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | 246 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
236 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); | 247 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); |
237 | startActivityForResult(takePictureIntent, type == 0 ? 0xA01 : 0xA02); | 248 | startActivityForResult(takePictureIntent, type == 0 ? 0xA01 : 0xA02); |
238 | } | 249 | } |
239 | }); | 250 | }); |
240 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { | 251 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { |
241 | @Override | 252 | @Override |
242 | public void onClick(View view) { | 253 | public void onClick(View view) { |
243 | dialog.dismiss(); | 254 | dialog.dismiss(); |
244 | ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder().provider(getActivity().getPackageName() + ".fileprovider").imageLoader(new GlideImageLoader()) //图片加载器 | 255 | ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder().provider(getActivity().getPackageName() + ".fileprovider").imageLoader(new GlideImageLoader()) //图片加载器 |
245 | .iHandlerCallBack(new HandlerCallBack(type)) //图片选择器生命周期监听(直接打开摄像头时无效) | 256 | .iHandlerCallBack(new HandlerCallBack(type)) //图片选择器生命周期监听(直接打开摄像头时无效) |
246 | .multiSelect(true) //是否多选 | 257 | .multiSelect(true) //是否多选 |
247 | .isShowCamera(false).isVideoPicker(false) //是否选择视频 默认false | 258 | .isShowCamera(false).isVideoPicker(false) //是否选择视频 默认false |
248 | .isImagePicker(true).imagePickerType(ImagePickerEnum.PHOTO_PICKER) //选择器打开类型 | 259 | .isImagePicker(true).imagePickerType(ImagePickerEnum.PHOTO_PICKER) //选择器打开类型 |
249 | .maxImageSelectable(5) //图片可选择数 | 260 | .maxImageSelectable(5) //图片可选择数 |
250 | .maxHeight(1920) //图片最大高度 | 261 | .maxHeight(1920) //图片最大高度 |
251 | .maxWidth(1920) //图片最大宽度 | 262 | .maxWidth(1920) //图片最大宽度 |
252 | .maxImageSize(3) //图片最大大小Mb | 263 | .maxImageSize(3) //图片最大大小Mb |
253 | .isCrop(false).pathList(new ArrayList<>()).pickerThemeColorRes(R.color.image_picker_white).pickerTitleColorRes(R.color.image_picker_text_black).cropThemeColorRes(R.color.image_picker_white).cropTitleColorRes(R.color.image_picker_text_black).pickerBackRes(R.mipmap.image_picker_back_black).pickerFolderRes(R.mipmap.image_picker_folder_black).build(); | 264 | .isCrop(false).pathList(new ArrayList<>()).pickerThemeColorRes(R.color.image_picker_white).pickerTitleColorRes(R.color.image_picker_text_black).cropThemeColorRes(R.color.image_picker_white).cropTitleColorRes(R.color.image_picker_text_black).pickerBackRes(R.mipmap.image_picker_back_black).pickerFolderRes(R.mipmap.image_picker_folder_black).build(); |
254 | ImagePickerOpen.getInstance().setImagePickerConfig(imagePickerConfig).pathList(new ArrayList<>()).open(getActivity()); | 265 | ImagePickerOpen.getInstance().setImagePickerConfig(imagePickerConfig).pathList(new ArrayList<>()).open(getActivity()); |
255 | 266 | ||
256 | } | 267 | } |
257 | }); | 268 | }); |
258 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { | 269 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { |
259 | @Override | 270 | @Override |
260 | public void onClick(View view) { | 271 | public void onClick(View view) { |
261 | dialog.dismiss(); | 272 | dialog.dismiss(); |
262 | } | 273 | } |
263 | }); | 274 | }); |
264 | dialog.show(); | 275 | dialog.show(); |
265 | } | 276 | } |
266 | 277 | ||
267 | @SuppressLint("CheckResult") | 278 | @SuppressLint("CheckResult") |
268 | protected void getHomework(String subject) { | 279 | protected void getHomework(String subject) { |
269 | if (studentBean == null) return; | 280 | if (studentBean == null) return; |
270 | NetWorks.service_url.getStudentHomework(NetWorks.getHeader(), studentBean.getStuId()) | 281 | NetWorks.service_url.getStudentHomework(NetWorks.getHeader(), studentBean.getStuId()) |
271 | .subscribeOn(Schedulers.io()) | 282 | .subscribeOn(Schedulers.io()) |
272 | .observeOn(AndroidSchedulers.mainThread()) | 283 | .observeOn(AndroidSchedulers.mainThread()) |
273 | .compose(RxLifecycleAndroid.bindFragment(getRxLifecycle())) | 284 | .compose(RxLifecycleAndroid.bindFragment(getRxLifecycle())) |
274 | .map(ResponseResult::getData) | 285 | .map(ResponseResult::getData) |
275 | .toObservable() | 286 | .toObservable() |
276 | .flatMap(Observable::fromIterable) | 287 | .flatMap(Observable::fromIterable) |
277 | .filter(data -> subject.equals(data.getSubject())) | 288 | .filter(data -> subject.equals(data.getSubject())) |
289 | .filter(data -> data.getRight() == null) | ||
278 | .toList() | 290 | .toList() |
279 | .subscribe((data, th) -> { | 291 | .subscribe((data, th) -> { |
280 | if (th != null) th.printStackTrace(); | 292 | if (th != null) th.printStackTrace(); |
281 | if (data != null) { | 293 | if (data != null) { |
282 | Collections.sort(data); | 294 | Collections.sort(data); |
283 | } | 295 | } |
284 | homeworkAdapter.setNewData(data); | 296 | homeworkAdapter.setNewData(data); |
297 | if (binding.tabLayout.getSelectedTabPosition() == 1) { | ||
298 | binding.rvMain.setVisibility(data == null || data.isEmpty() ? View.GONE : View.VISIBLE); | ||
299 | binding.llEmpty.setVisibility(data == null || data.isEmpty() ? View.VISIBLE : View.GONE); | ||
300 | } | ||
285 | }); | 301 | }); |
286 | } | 302 | } |
287 | 303 | ||
288 | private void getError(String subject) { | 304 | private void getError(String subject) { |
289 | if (studentBean == null) { | 305 | if (studentBean == null) { |
290 | return; | 306 | return; |
291 | } | 307 | } |
292 | Map<String, Object> map = new HashMap<>(); | 308 | Map<String, Object> map = new HashMap<>(); |
293 | map.put("subject", subject); | 309 | map.put("subject", subject); |
294 | map.put("stuId", studentBean.getStuId()); | 310 | map.put("stuId", studentBean.getStuId()); |
295 | map.put("pageSize", 5); | 311 | map.put("pageSize", 5); |
296 | map.put("pageNum", 1); | 312 | map.put("pageNum", 1); |
297 | NetWorks.getError(map, new Observer<ResponseResult<PageInfo<TopicBean>>>() { | 313 | NetWorks.getError(map, new Observer<ResponseResult<PageInfo<TopicBean>>>() { |
298 | @Override | 314 | @Override |
299 | public void onSubscribe(Disposable d) { | 315 | public void onSubscribe(Disposable d) { |
300 | } | 316 | } |
301 | @Override | 317 | @Override |
302 | public void onNext(ResponseResult<PageInfo<TopicBean>> result) { | 318 | public void onNext(ResponseResult<PageInfo<TopicBean>> result) { |
303 | if (result.getData() != null && result.getCode() == 200) { | 319 | if (result.getData() != null && result.getCode() == 200) { |
304 | List<TopicBean> topicBeans = result.getData().getList(); | 320 | List<TopicBean> topicBeans = result.getData().getList(); |
305 | errorAdapter.refresh(topicBeans); | 321 | errorAdapter.refresh(topicBeans); |
306 | if (binding.tabLayout.getSelectedTabPosition() == 0) { | 322 | if (binding.tabLayout.getSelectedTabPosition() == 0) { |
307 | if (topicBeans.size() > 0) { | 323 | if (topicBeans.size() > 0) { |
308 | getBinding().rvMain.setVisibility(View.VISIBLE); | 324 | getBinding().rvMain.setVisibility(View.VISIBLE); |
309 | getBinding().llEmpty.setVisibility(View.GONE); | 325 | getBinding().llEmpty.setVisibility(View.GONE); |
310 | } else { | 326 | } else { |
311 | getBinding().rvMain.setVisibility(View.GONE); | 327 | getBinding().rvMain.setVisibility(View.GONE); |
312 | getBinding().llEmpty.setVisibility(View.VISIBLE); | 328 | getBinding().llEmpty.setVisibility(View.VISIBLE); |
313 | } | 329 | } |
314 | } | 330 | } |
315 | } | 331 | } |
316 | } | 332 | } |
317 | @Override | 333 | @Override |
318 | public void onError(Throwable e) { | 334 | public void onError(Throwable e) { |
319 | e.printStackTrace(); | 335 | e.printStackTrace(); |
320 | } | 336 | } |
321 | @Override | 337 | @Override |
322 | public void onComplete() { | 338 | public void onComplete() { |
323 | } | 339 | } |
324 | }); | 340 | }); |
325 | } | 341 | } |
326 | 342 | ||
327 | @Override | 343 | @Override |
328 | public void onResume() { | 344 | public void onResume() { |
329 | super.onResume(); | 345 | super.onResume(); |
330 | String subStr = getResources().getStringArray(R.array.filter_subject)[subject]; | 346 | String subStr = getResources().getStringArray(R.array.filter_subject)[subject]; |
331 | getError(subStr); | 347 | getError(subStr); |
332 | getHomework(subStr); | 348 | getHomework(subStr); |
333 | } | 349 | } |
334 | 350 | ||
335 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { | 351 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { |
336 | int type; | 352 | int type; |
337 | public HandlerCallBack(int type) { | 353 | public HandlerCallBack(int type) { |
338 | this.type = type; | 354 | this.type = type; |
339 | } | 355 | } |
340 | 356 | ||
341 | private String TAG = "---ImagePicker---"; | 357 | private String TAG = "---ImagePicker---"; |
342 | List<ImageInfo> photoList = new ArrayList<>(); | 358 | List<ImageInfo> photoList = new ArrayList<>(); |
343 | 359 | ||
344 | @Override | 360 | @Override |
345 | public void onStart() { | 361 | public void onStart() { |
346 | Log.i(TAG, "onStart: 开启"); | 362 | Log.i(TAG, "onStart: 开启"); |
347 | } | 363 | } |
348 | 364 | ||
349 | @Override | 365 | @Override |
350 | public void onSuccess(List<ImageInfo> photoList) { | 366 | public void onSuccess(List<ImageInfo> photoList) { |
351 | this.photoList = photoList; | 367 | this.photoList = photoList; |
352 | Log.i(TAG, "onSuccess: 返回数据"); | 368 | Log.i(TAG, "onSuccess: 返回数据"); |
353 | } | 369 | } |
354 | 370 | ||
355 | @Override | 371 | @Override |
356 | public void onCancel() { | 372 | public void onCancel() { |
357 | Log.i(TAG, "onCancel: 取消"); | 373 | Log.i(TAG, "onCancel: 取消"); |
358 | } | 374 | } |
359 | 375 | ||
360 | @Override | 376 | @Override |
361 | public void onFinish(List<ImageInfo> selectImage) { | 377 | public void onFinish(List<ImageInfo> selectImage) { |
362 | if (selectImage.size() == photoList.size()) { | 378 | if (selectImage.size() == photoList.size()) { |
363 | ArrayList<String> strings = new ArrayList<>(); | 379 | ArrayList<String> strings = new ArrayList<>(); |
364 | Intent intent = new Intent(getActivity(), ImageActivity.class); | 380 | Intent intent = new Intent(getActivity(), ImageActivity.class); |
365 | for (ImageInfo imageInfo : selectImage) { | 381 | for (ImageInfo imageInfo : selectImage) { |
366 | strings.add(imageInfo.getPath()); | 382 | strings.add(imageInfo.getPath()); |
367 | } | 383 | } |
368 | intent.putStringArrayListExtra("images", strings); | 384 | intent.putStringArrayListExtra("images", strings); |
369 | intent.putExtra("type", type); | 385 | intent.putExtra("type", type); |
370 | startActivity(intent); | 386 | startActivity(intent); |
371 | } | 387 | } |
372 | } | 388 | } |
373 | 389 | ||
374 | @Override | 390 | @Override |
375 | public void onError() { | 391 | public void onError() { |
376 | Log.i(TAG, "onError: 出错"); | 392 | Log.i(TAG, "onError: 出错"); |
377 | } | 393 | } |
378 | } | 394 | } |
379 | 395 | ||
380 | @Override | 396 | @Override |
381 | public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 397 | public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
382 | super.onActivityResult(requestCode, resultCode, data); | 398 | super.onActivityResult(requestCode, resultCode, data); |
383 | if (resultCode != RESULT_OK) return; | 399 | if (resultCode != RESULT_OK) return; |
384 | if (requestCode == 0xA01 || requestCode == 0xA02 && !TextUtils.isEmpty(filePath)) { | 400 | if (requestCode == 0xA01 || requestCode == 0xA02 && !TextUtils.isEmpty(filePath)) { |
385 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); | 401 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); |
386 | String path = getContext().getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; | 402 | String path = getContext().getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; |
387 | CommonUtil.saveBitmapToUri(b, path); | 403 | CommonUtil.saveBitmapToUri(b, path); |
388 | ArrayList<String> strings = new ArrayList<>(); | 404 | ArrayList<String> strings = new ArrayList<>(); |
389 | Intent intent = new Intent(getContext(), ImageActivity.class); | 405 | Intent intent = new Intent(getContext(), ImageActivity.class); |
390 | strings.add(path); | 406 | strings.add(path); |
391 | intent.putStringArrayListExtra("images", strings); | 407 | intent.putStringArrayListExtra("images", strings); |
392 | intent.putExtra("type", requestCode == 0xA01 ? 0 : 1); | 408 | intent.putExtra("type", requestCode == 0xA01 ? 0 : 1); |
393 | startActivity(intent); | 409 | startActivity(intent); |
394 | } | 410 | } |
395 | } | 411 | } |
396 | } | 412 | } |
397 | 413 |