Commit 3119571af64165607fadec75eed47b5a85eafc85
1 parent
c694ab53aa
Exists in
master
周统计删除
Showing
1 changed file
with
37 additions
and
9 deletions
Show diff stats
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.view.Gravity; | 6 | import android.view.Gravity; |
7 | import android.view.View; | 7 | import android.view.View; |
8 | import android.widget.ImageView; | 8 | import android.widget.ImageView; |
9 | import android.widget.LinearLayout; | 9 | import android.widget.LinearLayout; |
10 | import android.widget.PopupMenu; | 10 | import android.widget.PopupMenu; |
11 | import android.widget.PopupWindow; | 11 | import android.widget.PopupWindow; |
12 | import android.widget.TextView; | 12 | import android.widget.TextView; |
13 | 13 | ||
14 | import androidx.annotation.NonNull; | 14 | import androidx.annotation.NonNull; |
15 | import androidx.annotation.Nullable; | 15 | import androidx.annotation.Nullable; |
16 | import androidx.lifecycle.MutableLiveData; | 16 | import androidx.lifecycle.MutableLiveData; |
17 | 17 | ||
18 | import com.chad.library.adapter.base.BaseQuickAdapter; | 18 | import com.chad.library.adapter.base.BaseQuickAdapter; |
19 | import com.chad.library.adapter.base.BaseViewHolder; | 19 | import com.chad.library.adapter.base.BaseViewHolder; |
20 | import com.google.android.material.tabs.TabLayout; | 20 | import com.google.android.material.tabs.TabLayout; |
21 | import com.google.gson.Gson; | 21 | import com.google.gson.Gson; |
22 | import com.hjx.parent.adapter.HomeworkListAdapter; | 22 | import com.hjx.parent.adapter.HomeworkListAdapter; |
23 | import com.hjx.parent.databinding.ActivityStudentHomeworkBinding; | 23 | import com.hjx.parent.databinding.ActivityStudentHomeworkBinding; |
24 | import com.hjx.parent.databinding.PopupFilterFeedbackBinding; | 24 | import com.hjx.parent.databinding.PopupFilterFeedbackBinding; |
25 | import com.hjx.parent.databinding.PopupFilterGradeBinding; | 25 | import com.hjx.parent.databinding.PopupFilterGradeBinding; |
26 | import com.hjx.parent.databinding.PopupFilterSubjectBinding; | 26 | import com.hjx.parent.databinding.PopupFilterSubjectBinding; |
27 | import com.hjx.parent.databinding.PopupFilterTermBinding; | 27 | import com.hjx.parent.databinding.PopupFilterTermBinding; |
28 | import com.hjx.parent.dialog.MsgConfirmDialog; | 28 | import com.hjx.parent.dialog.MsgConfirmDialog; |
29 | import com.hjx.parent.dialog.StageHuyouDialog; | 29 | import com.hjx.parent.dialog.StageHuyouDialog; |
30 | import com.hjx.parent.function.Function1; | 30 | import com.hjx.parent.function.Function1; |
31 | import com.hjx.parent.rx.BaseRxActivity; | 31 | import com.hjx.parent.rx.BaseRxActivity; |
32 | import com.prws.common.bean.ResponseResult; | 32 | import com.prws.common.bean.ResponseResult; |
33 | import com.prws.common.bean.Student; | 33 | import com.prws.common.bean.Student; |
34 | import com.prws.common.bean.homework.HomeworkList; | 34 | import com.prws.common.bean.homework.HomeworkList; |
35 | import com.prws.common.bean.homework.StDetail; | 35 | import com.prws.common.bean.homework.StDetail; |
36 | import com.prws.common.net.NetWorks; | 36 | import com.prws.common.net.NetWorks; |
37 | import com.prws.common.utils.SharedPreferencesUtil; | 37 | import com.prws.common.utils.SharedPreferencesUtil; |
38 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; | 38 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; |
39 | 39 | ||
40 | import java.text.DecimalFormat; | 40 | import java.text.DecimalFormat; |
41 | import java.text.SimpleDateFormat; | 41 | import java.text.SimpleDateFormat; |
42 | import java.util.ArrayList; | 42 | import java.util.ArrayList; |
43 | import java.util.Calendar; | 43 | import java.util.Calendar; |
44 | import java.util.Collections; | 44 | import java.util.Collections; |
45 | import java.util.Date; | 45 | import java.util.Date; |
46 | import java.util.HashMap; | 46 | import java.util.HashMap; |
47 | import java.util.List; | 47 | import java.util.List; |
48 | import java.util.Locale; | 48 | import java.util.Locale; |
49 | import java.util.Map; | 49 | import java.util.Map; |
50 | 50 | ||
51 | import io.reactivex.Observable; | 51 | import io.reactivex.Observable; |
52 | import io.reactivex.android.schedulers.AndroidSchedulers; | 52 | import io.reactivex.android.schedulers.AndroidSchedulers; |
53 | import io.reactivex.schedulers.Schedulers; | 53 | import io.reactivex.schedulers.Schedulers; |
54 | 54 | ||
55 | public class StuHomeworkActivity extends BaseRxActivity<ActivityStudentHomeworkBinding> { | 55 | public class StuHomeworkActivity extends BaseRxActivity<ActivityStudentHomeworkBinding> { |
56 | 56 | ||
57 | private final HomeworkListAdapter homeworkAdapter = new HomeworkListAdapter(); | 57 | private final HomeworkListAdapter homeworkAdapter = new HomeworkListAdapter(); |
58 | 58 | ||
59 | private final List<StDetail> mWeekList = new ArrayList<>(); | 59 | private final List<StDetail> mWeekList = new ArrayList<>(); |
60 | private final List<StDetail> mStageList = new ArrayList<>(); | 60 | private final List<StDetail> mStageList = new ArrayList<>(); |
61 | private final HuyouAdapter weekAdapter = new HuyouAdapter(mWeekList); | 61 | private final HuyouAdapter weekAdapter = new HuyouAdapter(mWeekList); |
62 | private final HuyouAdapter stageAdapter = new HuyouAdapter(mStageList); | 62 | private final HuyouAdapter stageAdapter = new HuyouAdapter(mStageList); |
63 | 63 | ||
64 | PopupWindow subjectFilter, gradeFilter, termFilter, feedbackFilter; | 64 | PopupWindow subjectFilter, gradeFilter, termFilter, feedbackFilter; |
65 | MsgConfirmDialog deleteDialog; | 65 | MsgConfirmDialog deleteDialog; |
66 | StageHuyouDialog stageHuyouDialog; | 66 | StageHuyouDialog stageHuyouDialog; |
67 | State state = new State(); | 67 | State state = new State(); |
68 | 68 | ||
69 | private void handlerIntent() { | 69 | private void handlerIntent() { |
70 | String json = getIntent().getStringExtra("studentJson"); | 70 | String json = getIntent().getStringExtra("studentJson"); |
71 | if (json == null) json = (String) SharedPreferencesUtil.getData("student", ""); | 71 | if (json == null) json = (String) SharedPreferencesUtil.getData("student", ""); |
72 | try { state.student = new Gson().fromJson(json, Student.class); } | 72 | try { state.student = new Gson().fromJson(json, Student.class); } |
73 | catch (Throwable t) { t.printStackTrace(); } | 73 | catch (Throwable t) { t.printStackTrace(); } |
74 | } | 74 | } |
75 | 75 | ||
76 | @SuppressLint("SetTextI18n") | 76 | @SuppressLint("SetTextI18n") |
77 | @Override | 77 | @Override |
78 | public void initView(Bundle savedInstanceState) { | 78 | public void initView(Bundle savedInstanceState) { |
79 | handlerIntent(); | 79 | handlerIntent(); |
80 | if (state.student == null) { | 80 | if (state.student == null) { |
81 | finish(); | 81 | finish(); |
82 | return; | 82 | return; |
83 | } | 83 | } |
84 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); | 84 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); |
85 | binding.tvTitle.setText(state.student.stuName + "的全部作业"); | 85 | binding.tvTitle.setText(state.student.stuName + "的全部作业"); |
86 | setupTab(); | 86 | setupTab(); |
87 | binding.recyclerView.setAdapter(homeworkAdapter); | 87 | binding.recyclerView.setAdapter(homeworkAdapter); |
88 | 88 | ||
89 | deleteDialog = new MsgConfirmDialog.Builder(this) | ||
90 | .setMessage("确认要删除吗?一旦删除不可恢复") | ||
91 | .setPositive("暂不删除") | ||
92 | .setNegative("确定删除") | ||
93 | .build(); | ||
94 | |||
89 | binding.ftSubject.setOnClickListener(v -> showSubjectFilter()); | 95 | binding.ftSubject.setOnClickListener(v -> showSubjectFilter()); |
90 | binding.ftGrade.setOnClickListener(v -> showGradeFilter()); | 96 | binding.ftGrade.setOnClickListener(v -> showGradeFilter()); |
91 | binding.ftTerm.setOnClickListener(v -> showTermFilter()); | 97 | binding.ftTerm.setOnClickListener(v -> showTermFilter()); |
92 | binding.ftFeedback.setOnClickListener(v -> showFeedbackFilter()); | 98 | binding.ftFeedback.setOnClickListener(v -> showFeedbackFilter()); |
93 | homeworkAdapter.deleteCall = data -> { | 99 | homeworkAdapter.deleteCall = data -> { |
94 | if (deleteDialog == null) { | 100 | deleteDialog.show(null, () -> { |
95 | deleteDialog = new MsgConfirmDialog.Builder(this) | ||
96 | .setMessage("确认要删除吗?一旦删除不可恢复") | ||
97 | .setPositive("暂不删除") | ||
98 | .setNegative("确定删除") | ||
99 | .build(); | ||
100 | } | ||
101 | deleteDialog.show(() -> { | ||
102 | deleteHomework(data); | 101 | deleteHomework(data); |
103 | return true; | 102 | return true; |
104 | }, null); | 103 | }); |
105 | }; | 104 | }; |
106 | homeworkAdapter.detailCall = data -> { | 105 | homeworkAdapter.detailCall = data -> { |
107 | if (data.getRight() == null) { | 106 | if (data.getRight() == null) { |
108 | Intent intent = new Intent(this, HomeworkDetailActivity.class); | 107 | Intent intent = new Intent(this, HomeworkDetailActivity.class); |
109 | intent.putExtra("data", data); | 108 | intent.putExtra("data", data); |
110 | intent.putExtra("student", state.student); | 109 | intent.putExtra("student", state.student); |
111 | startActivity(intent); | 110 | startActivity(intent); |
112 | } else { | 111 | } else { |
113 | Intent intent = new Intent(this, HomeworkShareActivity.class); | 112 | Intent intent = new Intent(this, HomeworkShareActivity.class); |
114 | intent.putExtra("student", state.student); | 113 | intent.putExtra("student", state.student); |
115 | intent.putExtra("id", data.getId()); | 114 | intent.putExtra("id", data.getId()); |
116 | intent.putExtra("grade", data.getGrade()); | 115 | intent.putExtra("grade", data.getGrade()); |
117 | intent.putExtra("subject", data.getSubject()); | 116 | intent.putExtra("subject", data.getSubject()); |
118 | startActivity(intent); | 117 | startActivity(intent); |
119 | } | 118 | } |
120 | }; | 119 | }; |
121 | 120 | ||
122 | binding.btnChangeStudent.setOnClickListener(v -> { | 121 | binding.btnChangeStudent.setOnClickListener(v -> { |
123 | Intent intent = new Intent(this, TeacherChooseActivity.class); | 122 | Intent intent = new Intent(this, TeacherChooseActivity.class); |
124 | intent.putExtra("needBack", true); | 123 | intent.putExtra("needBack", true); |
125 | startActivityForResult(intent, 0xA01); | 124 | startActivityForResult(intent, 0xA01); |
126 | }); | 125 | }); |
127 | 126 | ||
128 | binding.btnGeneralHuyou.setOnClickListener(v -> generalWeek()); | 127 | binding.btnGeneralHuyou.setOnClickListener(v -> generalWeek()); |
129 | binding.btnStageHuyou.setOnClickListener(v -> { | 128 | binding.btnStageHuyou.setOnClickListener(v -> { |
130 | if (stageHuyouDialog == null) stageHuyouDialog = new StageHuyouDialog(this); | 129 | if (stageHuyouDialog == null) stageHuyouDialog = new StageHuyouDialog(this); |
131 | stageHuyouDialog.show(this::generalStage); | 130 | stageHuyouDialog.show(this::generalStage); |
132 | }); | 131 | }); |
133 | 132 | ||
134 | weekAdapter.detailCall = data -> goHuyou(data, 0); | 133 | weekAdapter.detailCall = data -> goHuyou(data, 0); |
135 | stageAdapter.detailCall = data -> goHuyou(data, 1); | 134 | stageAdapter.detailCall = data -> goHuyou(data, 1); |
135 | weekAdapter.deleteCall = data -> { | ||
136 | deleteDialog.show(null, () -> { | ||
137 | deleteHuyou(data); | ||
138 | return true; | ||
139 | }); | ||
140 | }; | ||
141 | stageAdapter.deleteCall = weekAdapter.deleteCall; | ||
136 | 142 | ||
137 | getWeekHuyou(); | 143 | getWeekHuyou(); |
138 | getStageHuyou(); | 144 | getStageHuyou(); |
139 | } | 145 | } |
140 | 146 | ||
141 | private void goHuyou(StDetail data, int type) { | 147 | private void goHuyou(StDetail data, int type) { |
142 | Intent intent = new Intent(this, HuyouDetailActivity.class); | 148 | Intent intent = new Intent(this, HuyouDetailActivity.class); |
143 | intent.putExtra("id", data.id); | 149 | intent.putExtra("id", data.id); |
144 | intent.putExtra("type", type); | 150 | intent.putExtra("type", type); |
145 | intent.putExtra("student", state.student); | 151 | intent.putExtra("student", state.student); |
146 | startActivity(intent); | 152 | startActivity(intent); |
147 | } | 153 | } |
148 | 154 | ||
149 | @Override | 155 | @Override |
150 | protected void onStart() { | 156 | protected void onStart() { |
151 | super.onStart(); | 157 | super.onStart(); |
152 | getHomework(); | 158 | getHomework(); |
153 | } | 159 | } |
154 | 160 | ||
155 | @SuppressLint("SetTextI18n") | 161 | @SuppressLint("SetTextI18n") |
156 | @Override | 162 | @Override |
157 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 163 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
158 | super.onActivityResult(requestCode, resultCode, data); | 164 | super.onActivityResult(requestCode, resultCode, data); |
159 | if (requestCode == 0xA01 && resultCode == RESULT_OK) { | 165 | if (requestCode == 0xA01 && resultCode == RESULT_OK) { |
160 | String json = (String) SharedPreferencesUtil.getData("student", ""); | 166 | String json = (String) SharedPreferencesUtil.getData("student", ""); |
161 | try { | 167 | try { |
162 | state.student = new Gson().fromJson(json, Student.class); | 168 | state.student = new Gson().fromJson(json, Student.class); |
163 | binding.tvTitle.setText(state.student.stuName + "的全部作业"); | 169 | binding.tvTitle.setText(state.student.stuName + "的全部作业"); |
164 | getHomework(); | 170 | getHomework(); |
165 | getWeekHuyou(); | 171 | getWeekHuyou(); |
166 | getStageHuyou(); | 172 | getStageHuyou(); |
167 | } | 173 | } |
168 | catch (Throwable t) { t.printStackTrace(); } | 174 | catch (Throwable t) { t.printStackTrace(); } |
169 | } | 175 | } |
170 | } | 176 | } |
171 | 177 | ||
172 | private void setupTab() { | 178 | private void setupTab() { |
173 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("每日作业")); | 179 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("每日作业")); |
174 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("每周总结")); | 180 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("每周总结")); |
175 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("阶段性总结")); | 181 | binding.tabLayout.addTab(binding.tabLayout.newTab().setText("阶段性总结")); |
176 | binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { | 182 | binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { |
177 | @Override | 183 | @Override |
178 | public void onTabSelected(TabLayout.Tab tab) { | 184 | public void onTabSelected(TabLayout.Tab tab) { |
179 | binding.filterBar.setVisibility(View.GONE); | 185 | binding.filterBar.setVisibility(View.GONE); |
180 | binding.weekBar.setVisibility(View.GONE); | 186 | binding.weekBar.setVisibility(View.GONE); |
181 | binding.stageBar.setVisibility(View.GONE); | 187 | binding.stageBar.setVisibility(View.GONE); |
182 | if (tab.getPosition() == 0) { //每日 | 188 | if (tab.getPosition() == 0) { //每日 |
183 | binding.filterBar.setVisibility(View.VISIBLE); | 189 | binding.filterBar.setVisibility(View.VISIBLE); |
184 | binding.recyclerView.setAdapter(homeworkAdapter); | 190 | binding.recyclerView.setAdapter(homeworkAdapter); |
185 | } else if (tab.getPosition() == 1) { //每周 | 191 | } else if (tab.getPosition() == 1) { //每周 |
186 | binding.weekBar.setVisibility(View.VISIBLE); | 192 | binding.weekBar.setVisibility(View.VISIBLE); |
187 | binding.recyclerView.setAdapter(weekAdapter); | 193 | binding.recyclerView.setAdapter(weekAdapter); |
188 | } else if (tab.getPosition() == 2) { //阶段 | 194 | } else if (tab.getPosition() == 2) { //阶段 |
189 | binding.stageBar.setVisibility(View.VISIBLE); | 195 | binding.stageBar.setVisibility(View.VISIBLE); |
190 | binding.recyclerView.setAdapter(stageAdapter); | 196 | binding.recyclerView.setAdapter(stageAdapter); |
191 | } | 197 | } |
192 | } | 198 | } |
193 | @Override | 199 | @Override |
194 | public void onTabUnselected(TabLayout.Tab tab) { | 200 | public void onTabUnselected(TabLayout.Tab tab) { |
195 | } | 201 | } |
196 | @Override | 202 | @Override |
197 | public void onTabReselected(TabLayout.Tab tab) { | 203 | public void onTabReselected(TabLayout.Tab tab) { |
198 | } | 204 | } |
199 | }); | 205 | }); |
200 | } | 206 | } |
201 | 207 | ||
202 | @SuppressLint("CheckResult") | 208 | @SuppressLint("CheckResult") |
203 | protected void deleteHomework(HomeworkList data) { | 209 | protected void deleteHomework(HomeworkList data) { |
204 | NetWorks.service_url.deleteHomework(NetWorks.getHeader(), data.getId()) | 210 | NetWorks.service_url.deleteHomework(NetWorks.getHeader(), data.getId()) |
205 | .subscribeOn(Schedulers.io()) | 211 | .subscribeOn(Schedulers.io()) |
206 | .observeOn(AndroidSchedulers.mainThread()) | 212 | .observeOn(AndroidSchedulers.mainThread()) |
207 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) | 213 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) |
208 | .subscribe((response, th) -> { | 214 | .subscribe((response, th) -> { |
209 | if (th != null) th.printStackTrace(); | 215 | if (th != null) th.printStackTrace(); |
210 | if (response != null && response.getSuccess()) { | 216 | if (response != null && response.getSuccess()) { |
211 | getHomework(); | 217 | getHomework(); |
212 | } | 218 | } |
213 | }); | 219 | }); |
214 | 220 | ||
215 | } | 221 | } |
216 | 222 | ||
217 | @SuppressLint("CheckResult") | 223 | @SuppressLint("CheckResult") |
218 | protected void getHomework() { | 224 | protected void getHomework() { |
219 | NetWorks.service_url.getStudentHomework(NetWorks.getHeader(), state.student.stuId) | 225 | NetWorks.service_url.getStudentHomework(NetWorks.getHeader(), state.student.stuId) |
220 | .subscribeOn(Schedulers.io()) | 226 | .subscribeOn(Schedulers.io()) |
221 | .observeOn(AndroidSchedulers.mainThread()) | 227 | .observeOn(AndroidSchedulers.mainThread()) |
222 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) | 228 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) |
223 | .toObservable() | 229 | .toObservable() |
224 | .flatMap(response -> Observable.fromIterable(response.getData())) | 230 | .flatMap(response -> Observable.fromIterable(response.getData())) |
225 | // 过滤 | 231 | // 过滤 |
226 | .filter(data -> { // 学科 | 232 | .filter(data -> { // 学科 |
227 | String subject = state.subject.getValue(); | 233 | String subject = state.subject.getValue(); |
228 | if (subject == null || subject.isEmpty()) return true; | 234 | if (subject == null || subject.isEmpty()) return true; |
229 | else return subject.equals(data.getSubject()); | 235 | else return subject.equals(data.getSubject()); |
230 | }) | 236 | }) |
231 | .filter(data -> { // 年级 | 237 | .filter(data -> { // 年级 |
232 | String grade = state.grade.getValue(); | 238 | String grade = state.grade.getValue(); |
233 | if (grade == null || grade.isEmpty()) return true; | 239 | if (grade == null || grade.isEmpty()) return true; |
234 | else return grade.equals(data.getGrade()); | 240 | else return grade.equals(data.getGrade()); |
235 | }) | 241 | }) |
236 | .filter(data -> { // 学期 | 242 | .filter(data -> { // 学期 |
237 | String term = state.term.getValue(); | 243 | String term = state.term.getValue(); |
238 | if (term == null || term.isEmpty()) return true; | 244 | if (term == null || term.isEmpty()) return true; |
239 | else return term.equals(data.getTerm()); | 245 | else return term.equals(data.getTerm()); |
240 | }) | 246 | }) |
241 | .filter(data -> { // 反馈 | 247 | .filter(data -> { // 反馈 |
242 | Integer feedback = state.feedback.getValue(); | 248 | Integer feedback = state.feedback.getValue(); |
243 | if (feedback == null || feedback == 0) return true; | 249 | if (feedback == null || feedback == 0) return true; |
244 | else return (feedback == 1 && data.getRight() != null) || (feedback == 2 && data.getRight() == null); | 250 | else return (feedback == 1 && data.getRight() != null) || (feedback == 2 && data.getRight() == null); |
245 | }) | 251 | }) |
246 | // 过滤完成, 收集 | 252 | // 过滤完成, 收集 |
247 | .toList() | 253 | .toList() |
248 | .subscribe((data, th) -> { | 254 | .subscribe((data, th) -> { |
249 | if (th != null) th.printStackTrace(); | 255 | if (th != null) th.printStackTrace(); |
250 | if (data != null) { | 256 | if (data != null) { |
251 | Collections.sort(data); | 257 | Collections.sort(data); |
252 | } | 258 | } |
253 | homeworkAdapter.setNewData(data); | 259 | homeworkAdapter.setNewData(data); |
254 | }); | 260 | }); |
255 | } | 261 | } |
256 | 262 | ||
257 | @SuppressLint({"CheckResult", "NotifyDataSetChanged"}) | 263 | @SuppressLint({"CheckResult", "NotifyDataSetChanged"}) |
258 | private void getWeekHuyou() { | 264 | private void getWeekHuyou() { |
259 | NetWorks.service_url.getHuyouList(NetWorks.getHeader(), state.student.stuId, 0) | 265 | NetWorks.service_url.getHuyouList(NetWorks.getHeader(), state.student.stuId, 0) |
260 | .compose(transformSingle()) | 266 | .compose(transformSingle()) |
261 | .map(ResponseResult::getData) | 267 | .map(ResponseResult::getData) |
262 | .subscribe((list, throwable) -> { | 268 | .subscribe((list, throwable) -> { |
263 | if (throwable != null) { | 269 | if (throwable != null) { |
264 | throwable.printStackTrace(); | 270 | throwable.printStackTrace(); |
265 | return; | 271 | return; |
266 | } | 272 | } |
267 | if (list != null) { | 273 | if (list != null) { |
268 | mWeekList.clear(); | 274 | mWeekList.clear(); |
269 | mWeekList.addAll(list); | 275 | mWeekList.addAll(list); |
270 | weekAdapter.notifyDataSetChanged(); | 276 | weekAdapter.notifyDataSetChanged(); |
271 | 277 | ||
272 | boolean exist = false; | 278 | boolean exist = false; |
273 | int thisWeek = Calendar.getInstance().get(Calendar.WEEK_OF_YEAR); | 279 | int thisWeek = Calendar.getInstance().get(Calendar.WEEK_OF_YEAR); |
274 | for (StDetail bean: mWeekList) { | 280 | for (StDetail bean: mWeekList) { |
275 | Calendar other = Calendar.getInstance(); | 281 | Calendar other = Calendar.getInstance(); |
276 | other.setTime(bean.endTime); | 282 | other.setTime(bean.endTime); |
277 | if (other.get(Calendar.WEEK_OF_YEAR) == thisWeek) { | 283 | if (other.get(Calendar.WEEK_OF_YEAR) == thisWeek) { |
278 | exist = true; | 284 | exist = true; |
279 | break; | 285 | break; |
280 | } | 286 | } |
281 | } | 287 | } |
282 | binding.btnGeneralHuyou.setVisibility(exist ? View.GONE : View.VISIBLE); | 288 | binding.btnGeneralHuyou.setVisibility(exist ? View.GONE : View.VISIBLE); |
283 | } | 289 | } |
284 | }); | 290 | }); |
285 | } | 291 | } |
286 | 292 | ||
287 | @SuppressLint({"CheckResult", "NotifyDataSetChanged"}) | 293 | @SuppressLint({"CheckResult", "NotifyDataSetChanged"}) |
288 | private void getStageHuyou() { | 294 | private void getStageHuyou() { |
289 | NetWorks.service_url.getHuyouList(NetWorks.getHeader(), state.student.stuId, 1) | 295 | NetWorks.service_url.getHuyouList(NetWorks.getHeader(), state.student.stuId, 1) |
290 | .compose(transformSingle()) | 296 | .compose(transformSingle()) |
291 | .map(ResponseResult::getData) | 297 | .map(ResponseResult::getData) |
292 | .subscribe((list, throwable) -> { | 298 | .subscribe((list, throwable) -> { |
293 | if (throwable != null) { | 299 | if (throwable != null) { |
294 | throwable.printStackTrace(); | 300 | throwable.printStackTrace(); |
295 | return; | 301 | return; |
296 | } | 302 | } |
297 | if (list != null) { | 303 | if (list != null) { |
298 | mStageList.clear(); | 304 | mStageList.clear(); |
299 | mStageList.addAll(list); | 305 | mStageList.addAll(list); |
300 | stageAdapter.notifyDataSetChanged(); | 306 | stageAdapter.notifyDataSetChanged(); |
301 | } | 307 | } |
302 | }); | 308 | }); |
303 | } | 309 | } |
304 | 310 | ||
305 | @SuppressLint("CheckResult") | 311 | @SuppressLint("CheckResult") |
306 | private void generalWeek() { | 312 | private void generalWeek() { |
307 | showLoadingDialog("稍等..."); | 313 | showLoadingDialog("稍等..."); |
308 | NetWorks.service_url.generalHuyou() | 314 | NetWorks.service_url.generalHuyou() |
309 | .compose(transformSingle()) | 315 | .compose(transformSingle()) |
310 | .subscribe((response, throwable) -> { | 316 | .subscribe((response, throwable) -> { |
311 | cancelLoadingDialog(); | 317 | cancelLoadingDialog(); |
312 | if (throwable != null) { | 318 | if (throwable != null) { |
313 | loadFail("失败"); | 319 | loadFail("失败"); |
314 | throwable.printStackTrace(); | 320 | throwable.printStackTrace(); |
315 | return; | 321 | return; |
316 | } | 322 | } |
317 | if (response != null && response.getSuccess()) { | 323 | if (response != null && response.getSuccess()) { |
318 | binding.btnGeneralHuyou.setVisibility(View.GONE); | 324 | binding.btnGeneralHuyou.setVisibility(View.GONE); |
319 | getWeekHuyou(); | 325 | getWeekHuyou(); |
320 | } | 326 | } |
321 | }); | 327 | }); |
322 | } | 328 | } |
323 | 329 | ||
324 | @SuppressLint("CheckResult") | 330 | @SuppressLint("CheckResult") |
325 | private void generalStage(Date startDate, Date endDate, String subject) { | 331 | private void generalStage(Date startDate, Date endDate, String subject) { |
326 | SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd HH:mm:ss", Locale.CHINA); | 332 | SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd HH:mm:ss", Locale.CHINA); |
327 | Map<String, Object> body = new HashMap<>(); | 333 | Map<String, Object> body = new HashMap<>(); |
328 | body.put("stuId", state.student.stuId); | 334 | body.put("stuId", state.student.stuId); |
329 | body.put("startTime", format.format(startDate)); | 335 | body.put("startTime", format.format(startDate)); |
330 | body.put("endTime", format.format(endDate)); | 336 | body.put("endTime", format.format(endDate)); |
331 | body.put("subject", subject); | 337 | body.put("subject", subject); |
332 | showLoadingDialog("稍等..."); | 338 | showLoadingDialog("稍等..."); |
333 | NetWorks.service_url.generalStageHuyou(NetWorks.getHeader(), body) | 339 | NetWorks.service_url.generalStageHuyou(NetWorks.getHeader(), body) |
334 | .subscribeOn(Schedulers.io()) | 340 | .subscribeOn(Schedulers.io()) |
335 | .observeOn(AndroidSchedulers.mainThread()) | 341 | .observeOn(AndroidSchedulers.mainThread()) |
336 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) | 342 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) |
337 | .subscribe((response, throwable) -> { | 343 | .subscribe((response, throwable) -> { |
338 | if (throwable != null) { | 344 | if (throwable != null) { |
339 | loadFail("失败"); | 345 | loadFail("失败"); |
340 | throwable.printStackTrace(); | 346 | throwable.printStackTrace(); |
341 | return; | 347 | return; |
342 | } | 348 | } |
343 | if (response.getSuccess()) { | 349 | if (response.getSuccess()) { |
344 | getStageHuyou(); | 350 | getStageHuyou(); |
345 | cancelLoadingDialog(); | 351 | cancelLoadingDialog(); |
346 | } else { | 352 | } else { |
347 | loadFail(response.getMsg()); | 353 | loadFail(response.getMsg()); |
348 | } | 354 | } |
349 | }); | 355 | }); |
350 | } | 356 | } |
351 | 357 | ||
358 | @SuppressLint("CheckResult") | ||
359 | private void deleteHuyou(StDetail detail) { | ||
360 | showLoadingDialog("稍等..."); | ||
361 | NetWorks.service_url.deleteHuyou(NetWorks.getHeader(), detail.id) | ||
362 | .subscribeOn(Schedulers.io()) | ||
363 | .observeOn(AndroidSchedulers.mainThread()) | ||
364 | .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) | ||
365 | .subscribe((response, throwable) -> { | ||
366 | cancelLoadingDialog(); | ||
367 | if (throwable != null) { | ||
368 | loadFail("失败"); | ||
369 | throwable.printStackTrace(); | ||
370 | return; | ||
371 | } | ||
372 | if (detail.type == 0) { | ||
373 | getWeekHuyou(); | ||
374 | } else { | ||
375 | getStageHuyou(); | ||
376 | } | ||
377 | }); | ||
378 | } | ||
379 | |||
352 | private void showSubjectFilter() { | 380 | private void showSubjectFilter() { |
353 | if (subjectFilter == null) { | 381 | if (subjectFilter == null) { |
354 | PopupFilterSubjectBinding db = PopupFilterSubjectBinding.inflate(getLayoutInflater()); | 382 | PopupFilterSubjectBinding db = PopupFilterSubjectBinding.inflate(getLayoutInflater()); |
355 | db.setLifecycleOwner(this); | 383 | db.setLifecycleOwner(this); |
356 | db.setState(state); | 384 | db.setState(state); |
357 | db.bg.setOnClickListener(v -> subjectFilter.dismiss()); | 385 | db.bg.setOnClickListener(v -> subjectFilter.dismiss()); |
358 | subjectFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 386 | subjectFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
359 | subjectFilter.setOutsideTouchable(true); | 387 | subjectFilter.setOutsideTouchable(true); |
360 | subjectFilter.setOnDismissListener(this::getHomework); | 388 | subjectFilter.setOnDismissListener(this::getHomework); |
361 | } | 389 | } |
362 | subjectFilter.showAsDropDown(binding.anchorView); | 390 | subjectFilter.showAsDropDown(binding.anchorView); |
363 | } | 391 | } |
364 | 392 | ||
365 | private void showGradeFilter() { | 393 | private void showGradeFilter() { |
366 | if (gradeFilter == null) { | 394 | if (gradeFilter == null) { |
367 | PopupFilterGradeBinding db = PopupFilterGradeBinding.inflate(getLayoutInflater()); | 395 | PopupFilterGradeBinding db = PopupFilterGradeBinding.inflate(getLayoutInflater()); |
368 | db.setLifecycleOwner(this); | 396 | db.setLifecycleOwner(this); |
369 | db.setState(state); | 397 | db.setState(state); |
370 | db.bg.setOnClickListener(v -> gradeFilter.dismiss()); | 398 | db.bg.setOnClickListener(v -> gradeFilter.dismiss()); |
371 | gradeFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 399 | gradeFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
372 | gradeFilter.setOutsideTouchable(true); | 400 | gradeFilter.setOutsideTouchable(true); |
373 | gradeFilter.setOnDismissListener(this::getHomework); | 401 | gradeFilter.setOnDismissListener(this::getHomework); |
374 | } | 402 | } |
375 | gradeFilter.showAsDropDown(binding.anchorView); | 403 | gradeFilter.showAsDropDown(binding.anchorView); |
376 | } | 404 | } |
377 | 405 | ||
378 | private void showTermFilter() { | 406 | private void showTermFilter() { |
379 | if (termFilter == null) { | 407 | if (termFilter == null) { |
380 | PopupFilterTermBinding db = PopupFilterTermBinding.inflate(getLayoutInflater()); | 408 | PopupFilterTermBinding db = PopupFilterTermBinding.inflate(getLayoutInflater()); |
381 | db.setLifecycleOwner(this); | 409 | db.setLifecycleOwner(this); |
382 | db.setState(state); | 410 | db.setState(state); |
383 | db.bg.setOnClickListener(v -> termFilter.dismiss()); | 411 | db.bg.setOnClickListener(v -> termFilter.dismiss()); |
384 | termFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 412 | termFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
385 | termFilter.setOutsideTouchable(true); | 413 | termFilter.setOutsideTouchable(true); |
386 | termFilter.setOnDismissListener(this::getHomework); | 414 | termFilter.setOnDismissListener(this::getHomework); |
387 | } | 415 | } |
388 | termFilter.showAsDropDown(binding.anchorView); | 416 | termFilter.showAsDropDown(binding.anchorView); |
389 | } | 417 | } |
390 | 418 | ||
391 | private void showFeedbackFilter() { | 419 | private void showFeedbackFilter() { |
392 | if (feedbackFilter == null) { | 420 | if (feedbackFilter == null) { |
393 | PopupFilterFeedbackBinding db = PopupFilterFeedbackBinding.inflate(getLayoutInflater()); | 421 | PopupFilterFeedbackBinding db = PopupFilterFeedbackBinding.inflate(getLayoutInflater()); |
394 | db.setLifecycleOwner(this); | 422 | db.setLifecycleOwner(this); |
395 | db.setState(state); | 423 | db.setState(state); |
396 | db.bg.setOnClickListener(v -> feedbackFilter.dismiss()); | 424 | db.bg.setOnClickListener(v -> feedbackFilter.dismiss()); |
397 | feedbackFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); | 425 | feedbackFilter = new PopupWindow(db.getRoot(), LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
398 | feedbackFilter.setOutsideTouchable(true); | 426 | feedbackFilter.setOutsideTouchable(true); |
399 | feedbackFilter.setOnDismissListener(this::getHomework); | 427 | feedbackFilter.setOnDismissListener(this::getHomework); |
400 | } | 428 | } |
401 | feedbackFilter.showAsDropDown(binding.anchorView); | 429 | feedbackFilter.showAsDropDown(binding.anchorView); |
402 | } | 430 | } |
403 | 431 | ||
404 | @Override | 432 | @Override |
405 | protected ActivityStudentHomeworkBinding getViewBinding() { | 433 | protected ActivityStudentHomeworkBinding getViewBinding() { |
406 | return ActivityStudentHomeworkBinding.inflate(getLayoutInflater()); | 434 | return ActivityStudentHomeworkBinding.inflate(getLayoutInflater()); |
407 | } | 435 | } |
408 | 436 | ||
409 | public static class State { | 437 | public static class State { |
410 | public Student student; | 438 | public Student student; |
411 | 439 | ||
412 | public MutableLiveData<String> subject = new MutableLiveData<>(""); | 440 | public MutableLiveData<String> subject = new MutableLiveData<>(""); |
413 | public void setSubject(String value) { | 441 | public void setSubject(String value) { |
414 | subject.setValue(value); | 442 | subject.setValue(value); |
415 | } | 443 | } |
416 | 444 | ||
417 | public MutableLiveData<String> grade = new MutableLiveData<>(""); | 445 | public MutableLiveData<String> grade = new MutableLiveData<>(""); |
418 | public void setGrade(String value) { | 446 | public void setGrade(String value) { |
419 | grade.setValue(value); | 447 | grade.setValue(value); |
420 | } | 448 | } |
421 | 449 | ||
422 | public MutableLiveData<String> term = new MutableLiveData<>(""); | 450 | public MutableLiveData<String> term = new MutableLiveData<>(""); |
423 | public void setTerm(String value) { | 451 | public void setTerm(String value) { |
424 | term.setValue(value); | 452 | term.setValue(value); |
425 | } | 453 | } |
426 | 454 | ||
427 | //0:全部, 1: 已反馈, 2:未反馈 | 455 | //0:全部, 1: 已反馈, 2:未反馈 |
428 | public MutableLiveData<Integer> feedback = new MutableLiveData<>(0); | 456 | public MutableLiveData<Integer> feedback = new MutableLiveData<>(0); |
429 | public void setFeedback(int value) { | 457 | public void setFeedback(int value) { |
430 | feedback.setValue(value); | 458 | feedback.setValue(value); |
431 | } | 459 | } |
432 | } | 460 | } |
433 | 461 | ||
434 | static class HuyouAdapter extends BaseQuickAdapter<StDetail, BaseViewHolder> { | 462 | static class HuyouAdapter extends BaseQuickAdapter<StDetail, BaseViewHolder> { |
435 | public Function1<StDetail> deleteCall; | 463 | public Function1<StDetail> deleteCall; |
436 | public Function1<StDetail> detailCall; | 464 | public Function1<StDetail> detailCall; |
437 | public Student student; | 465 | public Student student; |
438 | 466 | ||
439 | public HuyouAdapter(@Nullable List<StDetail> data) { | 467 | public HuyouAdapter(@Nullable List<StDetail> data) { |
440 | super(R.layout.item_homework_list, data); | 468 | super(R.layout.item_homework_list, data); |
441 | } | 469 | } |
442 | 470 | ||
443 | @SuppressLint("SetTextI18n,SimpleDateFormat") | 471 | @SuppressLint("SetTextI18n,SimpleDateFormat") |
444 | @Override | 472 | @Override |
445 | protected void convert(@NonNull BaseViewHolder holder, StDetail data) { | 473 | protected void convert(@NonNull BaseViewHolder holder, StDetail data) { |
446 | holder.setGone(R.id.tvFlag, false); | 474 | holder.setGone(R.id.tvFlag, false); |
447 | int subjectImg; | 475 | int subjectImg; |
448 | switch (data.homeworkSubject) { | 476 | switch (data.homeworkSubject) { |
449 | case "语文": | 477 | case "语文": |
450 | subjectImg = R.drawable.ic_chinese; | 478 | subjectImg = R.drawable.ic_chinese; |
451 | break; | 479 | break; |
452 | case "英语": | 480 | case "英语": |
453 | subjectImg = R.drawable.ic_english; | 481 | subjectImg = R.drawable.ic_english; |
454 | break; | 482 | break; |
455 | case "物理": | 483 | case "物理": |
456 | subjectImg = R.drawable.ic_physics; | 484 | subjectImg = R.drawable.ic_physics; |
457 | break; | 485 | break; |
458 | case "化学": | 486 | case "化学": |
459 | subjectImg = R.drawable.ic_chemistry; | 487 | subjectImg = R.drawable.ic_chemistry; |
460 | break; | 488 | break; |
461 | case "数学": | 489 | case "数学": |
462 | default: | 490 | default: |
463 | subjectImg = R.drawable.ic_math; | 491 | subjectImg = R.drawable.ic_math; |
464 | } | 492 | } |
465 | holder.setImageResource(R.id.ivSubject, subjectImg); | 493 | holder.setImageResource(R.id.ivSubject, subjectImg); |
466 | Date endDate = new Date(data.endTime.getTime() - 1000); | 494 | Date endDate = new Date(data.endTime.getTime() - 1000); |
467 | String startStr = new SimpleDateFormat("yyyy.M.d").format(data.startTime); | 495 | String startStr = new SimpleDateFormat("yyyy.M.d").format(data.startTime); |
468 | String endStr = new SimpleDateFormat("-M.d").format(endDate); | 496 | String endStr = new SimpleDateFormat("-M.d").format(endDate); |
469 | String typeStr = data.type == 0 ? "作业周总结" : "作业阶段性总结"; | 497 | String typeStr = data.type == 0 ? "作业周总结" : "作业阶段性总结"; |
470 | String title = startStr + endStr + data.homeworkSubject + typeStr; | 498 | String title = startStr + endStr + data.homeworkSubject + typeStr; |
471 | holder.setText(R.id.tvName, title); | 499 | holder.setText(R.id.tvName, title); |
472 | holder.setText(R.id.tvGrade, data.grade); | 500 | holder.setText(R.id.tvGrade, data.grade); |
473 | View btnDelete = holder.getView(R.id.btnDelete); | 501 | View btnDelete = holder.getView(R.id.btnDelete); |
474 | View btnDetail = holder.getView(R.id.btnDetail); | 502 | View btnDetail = holder.getView(R.id.btnDetail); |
475 | btnDelete.setOnClickListener(v -> { | 503 | btnDelete.setOnClickListener(v -> { |
476 | if (deleteCall != null) deleteCall.invoke(data); | 504 | if (deleteCall != null) deleteCall.invoke(data); |
477 | }); | 505 | }); |
478 | btnDetail.setOnClickListener(v -> { | 506 | btnDetail.setOnClickListener(v -> { |
479 | if (detailCall != null) detailCall.invoke(data); | 507 | if (detailCall != null) detailCall.invoke(data); |
480 | }); | 508 | }); |
481 | } | 509 | } |
482 | 510 | ||
483 | private SimpleDateFormat getFormatWithGmt8(String pattern) { | 511 | private SimpleDateFormat getFormatWithGmt8(String pattern) { |
484 | SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.CHINA); | 512 | SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.CHINA); |