diff --git a/app/src/main/java/com/example/citrusclient/views/HomeFragment.java b/app/src/main/java/com/example/citrusclient/views/HomeFragment.java index 0b808fe..8c23744 100644 --- a/app/src/main/java/com/example/citrusclient/views/HomeFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/HomeFragment.java @@ -105,15 +105,6 @@ } @Override - public void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - outState.putInt("year", year); - outState.putInt("month", month); - outState.putInt("day", day); - } - - - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment @@ -188,9 +179,8 @@ month = curDate.getMonthValue(); day = curDate.getDayOfMonth(); curDateButton.setText(year + "年" + month + "月" + day + "日"); - scheduleList.clear(); - scheduleAdapter.setSchedules(scheduleList, integerBookHashMap); scheduleAdapter.updateCurDate(curDate); + clearTodoSchedule(todoAdapter, scheduleAdapter); updateTodoSchedule(integerBookHashMap); }); @@ -201,11 +191,9 @@ month = curDate.getMonthValue(); day = curDate.getDayOfMonth(); curDateButton.setText(year + "年" + month + "月" + day + "日"); - scheduleList.clear(); - scheduleAdapter.setSchedules(scheduleList, integerBookHashMap); scheduleAdapter.updateCurDate(curDate); + clearTodoSchedule(todoAdapter, scheduleAdapter); updateTodoSchedule(integerBookHashMap); - }); @@ -215,6 +203,7 @@ booksViewModel.getBookLiveData().observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(HashMap idBookHashMap) { + clearTodoSchedule(todoAdapter, scheduleAdapter); updateTodoSchedule(idBookHashMap); } }); @@ -259,7 +248,6 @@ int curBookId = citrus.getCurBookId(); if (idBookHashMap != null) { - todoList.clear(); if(curBookId != -1) { integerBookHashMap = new HashMap<>(); Book book = idBookHashMap.get(curBookId); @@ -275,6 +263,13 @@ scheduleViewModel.updateSchedulesByDay(accountId, year, month, day, token); } + private void clearTodoSchedule(MyTodoshelfAdapter todoAdapter, MyScheduleshelfAdapter scheduleAdapter) { + todoList.clear(); + todoAdapter.setTodos(todoList, integerBookHashMap); + scheduleList.clear(); + scheduleAdapter.setSchedules(scheduleList, integerBookHashMap); + } + @Override