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