Commit 7d8ce5d27289e41065b5b0e2d2bd681afacb1e37
1 parent
19e49b3575
Exists in
master
错题列表展示日期
Showing
3 changed files
with
36 additions
and
1 deletions
Show diff stats
app/src/main/java/com/hjx/parent/adapter/HomeworkAdapter.java
1 | 1 | package com.hjx.parent.adapter; |
2 | 2 | |
3 | +import android.view.View; | |
4 | +import android.widget.TextView; | |
5 | + | |
3 | 6 | import androidx.annotation.NonNull; |
4 | 7 | |
5 | 8 | import com.chad.library.adapter.base.BaseQuickAdapter; |
... | ... | @@ -36,5 +39,16 @@ public class HomeworkAdapter extends BaseQuickAdapter<HomeworkList, BaseViewHold |
36 | 39 | subjectImg = R.drawable.ic_math; |
37 | 40 | } |
38 | 41 | helper.setImageResource(R.id.ivSubject, subjectImg); |
42 | + | |
43 | + TextView tvDate = helper.getView(R.id.tvDate); | |
44 | + int index = getData().indexOf(homework); | |
45 | + if (index == 0) { | |
46 | + tvDate.setVisibility(View.VISIBLE); | |
47 | + } else if (!homework.getFormatTime().equals(getData().get(index - 1).getFormatTime())) { | |
48 | + tvDate.setVisibility(View.VISIBLE); | |
49 | + } else { | |
50 | + tvDate.setVisibility(View.GONE); | |
51 | + } | |
52 | + tvDate.setText(homework.getFormatTime()); | |
39 | 53 | } |
40 | 54 | } | ... | ... |
app/src/main/java/com/hjx/parent/fragment/ErrorFragment.java
... | ... | @@ -60,6 +60,7 @@ import com.zhangteng.utils.IHandlerCallBack; |
60 | 60 | import java.io.File; |
61 | 61 | import java.util.ArrayList; |
62 | 62 | import java.util.Arrays; |
63 | +import java.util.Collections; | |
63 | 64 | import java.util.HashMap; |
64 | 65 | import java.util.List; |
65 | 66 | import java.util.Map; |
... | ... | @@ -265,6 +266,9 @@ public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { |
265 | 266 | .map(ResponseResult::getData) |
266 | 267 | .subscribe((data, th) -> { |
267 | 268 | if (th != null) th.printStackTrace(); |
269 | + if (data != null) { | |
270 | + Collections.sort(data); | |
271 | + } | |
268 | 272 | homeworkAdapter.setNewData(data); |
269 | 273 | }); |
270 | 274 | } | ... | ... |
libs/common/src/main/java/com/prws/common/bean/homework/HomeworkList.java
... | ... | @@ -2,9 +2,11 @@ package com.prws.common.bean.homework; |
2 | 2 | |
3 | 3 | import com.google.gson.annotations.SerializedName; |
4 | 4 | |
5 | +import java.text.SimpleDateFormat; | |
5 | 6 | import java.util.Date; |
7 | +import java.util.Locale; | |
6 | 8 | |
7 | -public class HomeworkList { | |
9 | +public class HomeworkList implements Comparable<HomeworkList> { | |
8 | 10 | |
9 | 11 | @SerializedName(value = "homeworkId", alternate = "id") |
10 | 12 | private Integer homeworkId; |
... | ... | @@ -87,4 +89,19 @@ public class HomeworkList { |
87 | 89 | return completeFlag; |
88 | 90 | } |
89 | 91 | |
92 | + @Override | |
93 | + public int compareTo(HomeworkList other) { | |
94 | + long time1 = this.uploadTime == null ? 0 : this.uploadTime.getTime(); | |
95 | + long time2 = other.uploadTime == null ? 0 : other.uploadTime.getTime(); | |
96 | + return (int) (time2 - time1); | |
97 | + } | |
98 | + | |
99 | + private String time; | |
100 | + private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA); | |
101 | + public String getFormatTime() { | |
102 | + if (uploadTime == null) return ""; | |
103 | + if (time != null) return time; | |
104 | + time = format.format(uploadTime); | |
105 | + return time; | |
106 | + } | |
90 | 107 | } | ... | ... |