Browse Source

fix: 👍 切换页面导致首页日期错乱

master
niushuai233 1 year ago
parent
commit
7e565e98a4
  1. 24
      app/src/main/java/cc/niushuai/dididone/ui/calendar/CalendarFragment.java

24
app/src/main/java/cc/niushuai/dididone/ui/calendar/CalendarFragment.java

@ -32,6 +32,8 @@ import com.necer.painter.InnerPainter;
import com.necer.utils.CalendarUtil; import com.necer.utils.CalendarUtil;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import org.reactivestreams.Subscription; import org.reactivestreams.Subscription;
import java.util.List; import java.util.List;
@ -85,7 +87,11 @@ public class CalendarFragment extends BaseFragment {
XLog.d("lastDate: {}", lastDate); XLog.d("lastDate: {}", lastDate);
if (StrUtil.isNotEmpty(lastDate)) { if (StrUtil.isNotEmpty(lastDate)) {
binding.miui10Calendar.setInitializeDate(lastDate);
rebuildRecordListViewByDate(lastDate); rebuildRecordListViewByDate(lastDate);
LocalDate localDate = LocalDate.parse(lastDate, ISODateTimeFormat.date());
setLunarDateLabel(localDate);
} }
// 构建弹出框内容 // 构建弹出框内容
@ -224,13 +230,7 @@ public class CalendarFragment extends BaseFragment {
} }
XLog.d("当前选中 " + localDate); XLog.d("当前选中 " + localDate);
Lunar lunar = CalendarUtil.getCalendarDate(localDate).lunar; setLunarDateLabel(localDate);
String lunarDate = lunar.chineseEra + "年" + lunar.lunarMonthStr + lunar.lunarDayStr;
// 重置上次选中日期
lastDate = localDate.toString();
binding.tvResult.setText(StrUtil.format("{} | {}", lastDate, lunarDate));
// 重组日期 // 重组日期
rebuildRecordListViewByDate(lastDate); rebuildRecordListViewByDate(lastDate);
@ -239,6 +239,16 @@ public class CalendarFragment extends BaseFragment {
} }
private void setLunarDateLabel(LocalDate localDate) {
Lunar lunar = CalendarUtil.getCalendarDate(localDate).lunar;
String lunarDate = lunar.chineseEra + "年" + lunar.lunarMonthStr + lunar.lunarDayStr;
// 重置上次选中日期
lastDate = localDate.toString();
binding.tvResult.setText(StrUtil.format("{} | {}", lastDate, lunarDate));
}
private void rebuildRecordListViewByDate(String date) { private void rebuildRecordListViewByDate(String date) {
DateTime dateTime = DateUtil.parseDate(date); DateTime dateTime = DateUtil.parseDate(date);
// 移除所有旧内容项 // 移除所有旧内容项

Loading…
Cancel
Save