| |
---|
| | mParam1 = getArguments().getString(ARG_PARAM1); |
---|
| | mParam2 = getArguments().getString(ARG_PARAM2); |
---|
| | } |
---|
| | |
---|
| | Citrus citrus = (Citrus)(getActivity().getApplication()); |
---|
| | year = citrus.getCurYear(); |
---|
| | month = citrus.getCurMonth(); |
---|
| | day = citrus.getCurDay(); |
---|
| | |
---|
| | todosViewModel = new ViewModelProvider(this).get(TodosViewModel.class); |
---|
| | scheduleViewModel = new ViewModelProvider(this).get(ScheduleViewModel.class); |
---|
| | booksViewModel = new ViewModelProvider(this).get(BooksViewModel.class); |
---|
| | |
---|
| | } |
---|
| | |
---|
| | @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, |
---|
| |
---|
| | |
---|
| | private HashMap<Integer, Book> integerBookHashMap; |
---|
| | BooksViewModel booksViewModel; |
---|
| | |
---|
| | private LocalDate openDate; |
---|
| | int year; |
---|
| | LocalDate curDate; |
---|
| | |
---|
| | int year ; |
---|
| | int month; |
---|
| | int day; |
---|
| | |
---|
| | |
---|
| | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
---|
| | super.onViewCreated(view, savedInstanceState); |
---|
| | |
---|
| | |
---|
| | Citrus citrus = (Citrus)(getActivity().getApplication()); |
---|
| | String token = citrus.getToken(); |
---|
| | String accountId = citrus.getAccountId(); |
---|
| | year = citrus.getCurYear(); |
---|
| | month = citrus.getCurMonth(); |
---|
| | day = citrus.getCurDay(); |
---|
| | |
---|
| | int curBookId = citrus.getCurBookId(); |
---|
| | |
---|
| | openDate = LocalDate.of(year, month, day); |
---|
| | |
---|
| | curDate = LocalDate.of(year, month, day); |
---|
| | |
---|
| | todoList = new ArrayList<>(); |
---|
| | scheduleList = new ArrayList<>(); |
---|
| | |
---|
| | TextView curDate = view.findViewById(R.id.year_month_day); |
---|
| | curDate.setText(year + "年" + month + "月" + day + "日"); |
---|
| | TextView curDateText = view.findViewById(R.id.year_month_day); |
---|
| | curDateText.setText(year + "年" + month + "月" + day + "日"); |
---|
| | |
---|
| | |
---|
| | RecyclerView todoRecyclerView = view.findViewById(R.id.my_todos_list); |
---|
| | todoRecyclerView.setHasFixedSize(true); |
---|
| |
---|
| | MyScheduleshelfAdapter scheduleAdapter = new MyScheduleshelfAdapter(scheduleList, integerBookHashMap); |
---|
| | scheduleRecyclerView.setAdapter(scheduleAdapter); |
---|
| | |
---|
| | |
---|
| | FloatingActionButton todoAddButton = view.findViewById(R.id.todo_add_button); |
---|
| | todoAddButton.setOnClickListener(v -> { |
---|
| | ((MainActivity) getActivity()).showFragment(new CreateTodoFragment()); |
---|
| | }); |
---|
| | |
---|
| | FloatingActionButton scheduleAddButton = view.findViewById(R.id.schedule_add_button); |
---|
| | scheduleAddButton.setOnClickListener(v -> { |
---|
| | ((MainActivity) getActivity()).showFragment(new CreateScheduleFragment()); |
---|
| | }); |
---|
| | |
---|
| | FloatingActionButton prevBotton = view.findViewById(R.id.prev_day_botton); |
---|
| | prevBotton.setOnClickListener(v -> { |
---|
| | curDate = curDate.minusDays(1); |
---|
| | year = curDate.getYear(); |
---|
| | month = curDate.getMonthValue(); |
---|
| | day = curDate.getDayOfMonth(); |
---|
| | curDateText.setText(year + "年" + month + "月" + day + "日"); |
---|
| | |
---|
| | updateTodoSchedule(integerBookHashMap); |
---|
| | }); |
---|
| | |
---|
| | FloatingActionButton nextBotton = view.findViewById(R.id.next_day_botton); |
---|
| | nextBotton.setOnClickListener(v -> { |
---|
| | curDate = curDate.plusDays(1); |
---|
| | year = curDate.getYear(); |
---|
| | month = curDate.getMonthValue(); |
---|
| | day = curDate.getDayOfMonth(); |
---|
| | curDateText.setText(year + "年" + month + "月" + day + "日"); |
---|
| | updateTodoSchedule(integerBookHashMap); |
---|
| | }); |
---|
| | |
---|
| | |
---|
| | booksViewModel.loadBooks(accountId, token); |
---|
| | scheduleViewModel.updateSchedulesByDay(accountId, year, month, day, token); |
---|
| | System.out.println(token); |
---|
| | |
---|
| | booksViewModel.getBookLiveData().observe(getViewLifecycleOwner(), new Observer<HashMap<Integer, Book>>() { |
---|
| | @Override |
---|
| | public void onChanged(HashMap<Integer, Book> idBookHashMap) { |
---|
| | if (idBookHashMap != null) { |
---|
| | if(curBookId != -1) { |
---|
| | integerBookHashMap = new HashMap<>(); |
---|
| | Book book = idBookHashMap.get(curBookId); |
---|
| | integerBookHashMap.put(curBookId, book); |
---|
| | todosViewModel.loadTodosByDay(accountId, curBookId, year, month, day, token); |
---|
| | citrus.setCurBookId(-1); |
---|
| | } else { |
---|
| | todoList = new ArrayList<>(); |
---|
| | integerBookHashMap = new HashMap<>(idBookHashMap); |
---|
| | for (Book book : integerBookHashMap.values()) { |
---|
| | todosViewModel.loadTodosByDay(accountId, book.getBookId(), year, month, day, token); |
---|
| | } |
---|
| | } |
---|
| | scheduleViewModel.updateSchedulesByDay(accountId, year, month, day, token); |
---|
| | } |
---|
| | updateTodoSchedule(idBookHashMap); |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | todosViewModel.getTodosByDayLiveData().observe(getViewLifecycleOwner(), new Observer<HashMap<Integer, Todo>>() { |
---|
| | @Override |
---|
| | public void onChanged(HashMap<Integer, Todo> idTodoHashMap) { |
---|
| | if(idTodoHashMap != null) { |
---|
| | todoList.addAll(idTodoHashMap.values()); |
---|
| | for(Todo todo : idTodoHashMap.values()){ |
---|
| | if(!todo.containsTodo(todoList)){ |
---|
| | todoList.add(todo); |
---|
| | todoAdapter.setTodos(todoList, integerBookHashMap); |
---|
| | } |
---|
| | } |
---|
| | } else { |
---|
| | todoAdapter.setTodos(todoList, integerBookHashMap); |
---|
| | } |
---|
| | } |
---|
| | }); |
---|
| |
---|
| | public void onChanged(HashMap<Integer, Schedule> idScheduleHashMap) { |
---|
| | if(idScheduleHashMap != null) { |
---|
| | scheduleList = new ArrayList<>(idScheduleHashMap.values()); |
---|
| | scheduleAdapter.setSchedules(scheduleList, integerBookHashMap); |
---|
| | } else { |
---|
| | scheduleList = new ArrayList<>(); |
---|
| | scheduleAdapter.setSchedules(scheduleList, integerBookHashMap); |
---|
| | } |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | FloatingActionButton todoAddButton = view.findViewById(R.id.todo_add_button); |
---|
| | todoAddButton.setOnClickListener(v -> { |
---|
| | ((MainActivity) getActivity()).showFragment(new CreateTodoFragment()); |
---|
| | }); |
---|
| | |
---|
| | FloatingActionButton scheduleAddButton = view.findViewById(R.id.schedule_add_button); |
---|
| | scheduleAddButton.setOnClickListener(v -> { |
---|
| | ((MainActivity) getActivity()).showFragment(new CreateScheduleFragment()); |
---|
| | }); |
---|
| | |
---|
| | // FloatingActionButton prevBotton = view.findViewById(R.id.prev_day_botton); |
---|
| | // prevBotton.setOnClickListener(v -> { |
---|
| | // openDate = openDate.minusDays(1); |
---|
| | // year = openDate.getYear(); |
---|
| | // month = openDate.getMonthValue(); |
---|
| | // day = openDate.getDayOfMonth(); |
---|
| | // }); |
---|
| | |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |
---|
| | |
---|
| | private void updateTodoSchedule(HashMap<Integer, Book> idBookHashMap) { |
---|
| | Citrus citrus = (Citrus)(getActivity().getApplication()); |
---|
| | String token = citrus.getToken(); |
---|
| | String accountId = citrus.getAccountId(); |
---|
| | int curBookId = citrus.getCurBookId(); |
---|
| | |
---|
| | if (idBookHashMap != null) { |
---|
| | if(curBookId != -1) { |
---|
| | todoList = new ArrayList<>(); |
---|
| | integerBookHashMap = new HashMap<>(); |
---|
| | Book book = idBookHashMap.get(curBookId); |
---|
| | integerBookHashMap.put(curBookId, book); |
---|
| | todosViewModel.loadTodosByDay(accountId, curBookId, year, month, day, token); |
---|
| | citrus.setCurBookId(-1); |
---|
| | } else { |
---|
| | todoList = new ArrayList<>(); |
---|
| | integerBookHashMap = new HashMap<>(idBookHashMap); |
---|
| | for (Book book : integerBookHashMap.values()) { |
---|
| | todosViewModel.loadTodosByDay(accountId, book.getBookId(), year, month, day, token); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | scheduleViewModel.updateSchedulesByDay(accountId, year, month, day, token); |
---|
| | } |
---|
| | |
---|
| | |
---|
| | |
---|
| | @Override |
---|
| | public void onStop() { |
---|
| | super.onStop(); |
---|
| | booksViewModel.getBookLiveData().removeObservers(getViewLifecycleOwner()); |
---|
| | } |
---|
| | |
---|
| | |
---|
| | } |
---|
| | |
---|
| | class MyTodoshelfAdapter extends RecyclerView.Adapter<MyTodoshelfAdapter.MyTodoViewHolder> { |
---|
| |
---|
| | |