| |
---|
| | year = citrus.getCurYear(); |
---|
| | month = citrus.getCurMonth(); |
---|
| | day = citrus.getCurDay(); |
---|
| | |
---|
| | modo = "todoSchedule"; |
---|
| | |
---|
| | todosViewModel = new ViewModelProvider(this).get(TodosViewModel.class); |
---|
| | scheduleViewModel = new ViewModelProvider(this).get(ScheduleViewModel.class); |
---|
| | booksViewModel = new ViewModelProvider(this).get(BooksViewModel.class); |
---|
| | |
---|
| |
---|
| | int year ; |
---|
| | int month; |
---|
| | int day; |
---|
| | |
---|
| | String modo; |
---|
| | |
---|
| | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
---|
| | super.onViewCreated(view, savedInstanceState); |
---|
| | |
---|
| |
---|
| | |
---|
| | todoList = new ArrayList<>(); |
---|
| | scheduleList = new ArrayList<>(); |
---|
| | |
---|
| | int todoWidth = 140; |
---|
| | int scheduleWidth = 170; |
---|
| | int modoButtonWidth = 180; |
---|
| | int wholeButtonWidth = 370; |
---|
| | |
---|
| | Button curDateButton = view.findViewById(R.id.date_button); |
---|
| | curDateButton.setText(year + "年" + month + "月" + day + "日"); |
---|
| | |
---|
| | |
---|
| | //TodoAdapter設定 |
---|
| | RecyclerView todoRecyclerView = view.findViewById(R.id.my_todos_list); |
---|
| | todoRecyclerView.setHasFixedSize(true); |
---|
| | RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(view.getContext()); |
---|
| | todoRecyclerView.setLayoutManager(layoutManager); |
---|
| | MyOtherTodoshelfAdapter todoAdapter = new MyOtherTodoshelfAdapter(todoList, book, todosViewModel, getActivity()); |
---|
| | todoRecyclerView.setAdapter(todoAdapter); |
---|
| | |
---|
| | todoAdapter.setItemWidth(dpToPx(todoWidth)); |
---|
| | //ScheduleAdapter設定 |
---|
| | RecyclerView scheduleRecyclerView = view.findViewById(R.id.my_schedule_list); |
---|
| | scheduleRecyclerView.setHasFixedSize(true); |
---|
| | RecyclerView.LayoutManager scheduleLayoutManager = new LinearLayoutManager(view.getContext()); |
---|
| | scheduleRecyclerView.setLayoutManager(scheduleLayoutManager); |
---|
| | MyOtherScheduleshelfAdapter scheduleAdapter = new MyOtherScheduleshelfAdapter(scheduleList, book, curDate, getActivity()); |
---|
| | scheduleRecyclerView.setAdapter(scheduleAdapter); |
---|
| | scheduleAdapter.setItemWidth(dpToPx(scheduleWidth)); |
---|
| | |
---|
| | Button dateButton = view.findViewById(R.id.date_button); |
---|
| | dateButton.setOnClickListener(v -> { |
---|
| | ((MainActivity) getActivity()).showFragment(new OtherCalendarFragment()); |
---|
| | }); |
---|
| | |
---|
| | ((MainActivity) getActivity()).showFragment(new OtherCalendarFragment(year, month)); |
---|
| | }); |
---|
| | |
---|
| | Button modoTodoButton = view.findViewById(R.id.modo_todo_button); |
---|
| | Button modoScheduleButton = view.findViewById(R.id.modo_schedule_button); |
---|
| | View verticalLine = view.findViewById(R.id.vertical_line); // IDを指定して取得 |
---|
| | |
---|
| | //上のTodoButtonを押したときTodoだけを表示 |
---|
| | modoTodoButton.setOnClickListener(v -> { |
---|
| | ViewGroup.LayoutParams todoButtonParams = modoTodoButton.getLayoutParams(); |
---|
| | ViewGroup.LayoutParams todoRecyclerViewLayoutParams = todoRecyclerView.getLayoutParams(); |
---|
| | if(modo == "todoSchedule") { |
---|
| | modoScheduleButton.setVisibility(View.GONE); |
---|
| | scheduleRecyclerView.setVisibility(View.GONE); |
---|
| | todoButtonParams.width = dpToPx(wholeButtonWidth); // 幅を全体に |
---|
| | modoTodoButton.setLayoutParams(todoButtonParams); |
---|
| | todoRecyclerViewLayoutParams.width = dpToPx(wholeButtonWidth); |
---|
| | todoRecyclerView.setLayoutParams(todoRecyclerViewLayoutParams); |
---|
| | todoAdapter.setItemWidth(dpToPx(330)); |
---|
| | verticalLine.setVisibility(View.GONE); |
---|
| | modo = "todo"; |
---|
| | } else if(modo == "todo"){ |
---|
| | todoButtonParams.width = dpToPx(modoButtonWidth); // 幅を全体に |
---|
| | modoTodoButton.setLayoutParams(todoButtonParams); |
---|
| | todoRecyclerViewLayoutParams.width = dpToPx(modoButtonWidth); |
---|
| | todoRecyclerView.setLayoutParams(todoRecyclerViewLayoutParams); |
---|
| | modoScheduleButton.setVisibility(View.VISIBLE); |
---|
| | scheduleRecyclerView.setVisibility(View.VISIBLE); |
---|
| | todoAdapter.setItemWidth(dpToPx(todoWidth)); |
---|
| | verticalLine.setVisibility(View.VISIBLE); |
---|
| | modo = "todoSchedule"; |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | //上のScheduleButtonを押したときScheduleだけを表示 |
---|
| | modoScheduleButton.setOnClickListener(v -> { |
---|
| | ViewGroup.LayoutParams scheuleButtonParams = modoScheduleButton.getLayoutParams(); |
---|
| | ViewGroup.LayoutParams scheduleRecyclerViewLayoutParams = scheduleRecyclerView.getLayoutParams(); |
---|
| | if(modo == "todoSchedule") { |
---|
| | modoTodoButton.setVisibility(View.GONE); |
---|
| | todoRecyclerView.setVisibility(View.GONE); |
---|
| | scheuleButtonParams.width = dpToPx(wholeButtonWidth); // 幅を全体に |
---|
| | modoScheduleButton.setLayoutParams(scheuleButtonParams); |
---|
| | scheduleRecyclerViewLayoutParams.width = dpToPx(wholeButtonWidth); |
---|
| | scheduleRecyclerView.setLayoutParams(scheduleRecyclerViewLayoutParams); |
---|
| | scheduleAdapter.setItemWidth(dpToPx(360)); |
---|
| | verticalLine.setVisibility(View.GONE); |
---|
| | modo = "schedule"; |
---|
| | } else if(modo == "schedule"){ |
---|
| | scheuleButtonParams.width = dpToPx(modoButtonWidth); // 幅を全体に |
---|
| | modoScheduleButton.setLayoutParams(scheuleButtonParams); |
---|
| | scheduleRecyclerViewLayoutParams.width = dpToPx(modoButtonWidth); |
---|
| | scheduleRecyclerView.setLayoutParams(scheduleRecyclerViewLayoutParams); |
---|
| | modoTodoButton.setVisibility(View.VISIBLE); |
---|
| | todoRecyclerView.setVisibility(View.VISIBLE); |
---|
| | scheduleAdapter.setItemWidth(dpToPx(scheduleWidth)); |
---|
| | verticalLine.setVisibility(View.VISIBLE); |
---|
| | modo = "todoSchedule"; |
---|
| | } |
---|
| | }); |
---|
| | ImageButton prevBotton = view.findViewById(R.id.prev_day_button); |
---|
| | prevBotton.setOnClickListener(v -> { |
---|
| | curDate = curDate.minusDays(1); |
---|
| | year = curDate.getYear(); |
---|
| |
---|
| | |
---|
| | booksViewModel.loadBook(accountId, token, curBookId); |
---|
| | todosViewModel.loadTodosByDay(accountId, curBookId, year, month, day, token); |
---|
| | scheduleViewModel.updateSchedulesByDayAndBookId(accountId, year, month, day, token, curBookId); |
---|
| | System.out.println(token); |
---|
| | |
---|
| | booksViewModel.getBook().observe(getViewLifecycleOwner(), new Observer<Book>() { |
---|
| | @Override |
---|
| | public void onChanged(Book book) { |
---|
| |
---|
| | scheduleAdapter.setSchedules(scheduleList, book); |
---|
| | } |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | |
---|
| | } |
---|
| | |
---|
| | |
---|
| | private void updateTodoSchedule(Book book) { |
---|
| |
---|
| | scheduleList.clear(); |
---|
| | scheduleAdapter.setSchedules(scheduleList, book); |
---|
| | } |
---|
| | |
---|
| | |
---|
| | // dp を px に変換するためのメソッド |
---|
| | private int dpToPx(int dp) { |
---|
| | return Math.round(dp * getResources().getDisplayMetrics().density); |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public void onStop() { |
---|
| | super.onStop(); |
---|
| |
---|
| | private List<Todo> todoList; |
---|
| | private Book book; |
---|
| | private TodosViewModel todosViewModel; |
---|
| | private Context context; |
---|
| | private int itemWidth; // アイテムの幅を保持 |
---|
| | |
---|
| | |
---|
| | MyOtherTodoshelfAdapter(List<Todo> todos, Book book, TodosViewModel todosViewModel, Context context) { |
---|
| | this.todoList = todos; |
---|
| |
---|
| | // Citrus citrus = (Citrus)(activity.getApplication()); |
---|
| | // String token = citrus.getToken(); |
---|
| | // String accountId = citrus.getCurLookingAccountId(); |
---|
| | |
---|
| | // アイテムの幅を設定 |
---|
| | ViewGroup.LayoutParams params = holder.todoButton.getLayoutParams(); |
---|
| | params.width = itemWidth; // 動的に設定した幅を使用 |
---|
| | holder.todoButton.setLayoutParams(params); |
---|
| | |
---|
| | Todo todoData = this.todoList.get(position); |
---|
| | holder.todoButton.setText(todoData.getTitle()); |
---|
| | holder.todoCheckBox.setChecked(todoData.getCheck()); |
---|
| | holder.todoCheckBox.setEnabled(false); |
---|
| | |
---|
| | if(book != null) { |
---|
| | int red = Integer.parseInt(book.getColor().substring(1, 3), 16); |
---|
| | int green = Integer.parseInt(book.getColor().substring(3, 5), 16); |
---|
| | int blue = Integer.parseInt(book.getColor().substring(5, 7), 16); |
---|
| |
---|
| | // }); |
---|
| | |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public int getItemCount() { |
---|
| | return todoList.size(); |
---|
| | } |
---|
| | |
---|
| | private void sortTodosById() { |
---|
| | Collections.sort(todoList, new Comparator<Todo>() { |
---|
| | @Override |
---|
| | public int compare(Todo todo1, Todo todo2) { |
---|
| |
---|
| | } |
---|
| | }); |
---|
| | } |
---|
| | |
---|
| | public void setItemWidth(int width) { |
---|
| | this.itemWidth = width; |
---|
| | notifyDataSetChanged(); // 幅が変更されたことを通知 |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public int getItemCount() { |
---|
| | return todoList.size(); |
---|
| | } |
---|
| | |
---|
| | static class MyTodoViewHolder extends RecyclerView.ViewHolder { |
---|
| | Button todoButton; |
---|
| | CheckBox todoCheckBox; |
---|
| |
---|
| | private List<Schedule> scheduleList; |
---|
| | Book book; |
---|
| | private Context context; |
---|
| | private LocalDate curDate; |
---|
| | private int itemWidth; // アイテムの幅を保持 |
---|
| | |
---|
| | MyOtherScheduleshelfAdapter(List<Schedule> schedules, Book book, LocalDate curDate, Context context) { |
---|
| | this.scheduleList = schedules; |
---|
| | this.book = book; |
---|
| |
---|
| | |
---|
| | @Override |
---|
| | public void onBindViewHolder(@NonNull MyScheduleViewHolder holder, int position) { |
---|
| | // Activity activity = (Activity) context; |
---|
| | |
---|
| | // アイテムの幅を設定 |
---|
| | ViewGroup.LayoutParams params = holder.scheduleButton.getLayoutParams(); |
---|
| | params.width = itemWidth; // 動的に設定した幅を使用 |
---|
| | holder.scheduleButton.setLayoutParams(params); |
---|
| | |
---|
| | int red = 169; |
---|
| | int green = 169; |
---|
| | int blue = 169; |
---|
| |
---|
| | this.curDate = newCurDate; |
---|
| | notifyDataSetChanged(); // 必要に応じてアダプターをリフレッシュ |
---|
| | } |
---|
| | |
---|
| | public void setItemWidth(int width) { |
---|
| | this.itemWidth = width; |
---|
| | notifyDataSetChanged(); // 幅が変更されたことを通知 |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public int getItemCount() { |
---|
| | return scheduleList.size(); |
---|
| | } |
---|
| |
---|
| | |