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 8c23744..cd900b8 100644 --- a/app/src/main/java/com/example/citrusclient/views/HomeFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/HomeFragment.java @@ -98,6 +98,8 @@ 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); @@ -126,6 +128,7 @@ int month; int day; + String modo; public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -139,29 +142,96 @@ 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); MyTodoshelfAdapter todoAdapter = new MyTodoshelfAdapter(todoList, integerBookHashMap, 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); MyScheduleshelfAdapter scheduleAdapter = new MyScheduleshelfAdapter(scheduleList, integerBookHashMap, curDate, getActivity()); scheduleRecyclerView.setAdapter(scheduleAdapter); + scheduleAdapter.setItemWidth(dpToPx(scheduleWidth)); + + //ボタン処理 Button dateButton = view.findViewById(R.id.date_button); dateButton.setOnClickListener(v -> { ((MainActivity) getActivity()).showFragment(new CalendarFragment(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"; + } + }); + FloatingActionButton todoAddButton = view.findViewById(R.id.todo_add_button); todoAddButton.setOnClickListener(v -> { ((MainActivity) getActivity()).showFragment(new CreateTodoFragment(year, month, day)); @@ -172,7 +242,7 @@ ((MainActivity) getActivity()).showFragment(new CreateScheduleFragment(year, month, day)); }); - ImageButton prevBotton = view.findViewById(R.id.prev_day_botton); + ImageButton prevBotton = view.findViewById(R.id.prev_day_button); prevBotton.setOnClickListener(v -> { curDate = curDate.minusDays(1); year = curDate.getYear(); @@ -184,7 +254,7 @@ updateTodoSchedule(integerBookHashMap); }); - ImageButton nextBotton = view.findViewById(R.id.next_day_botton); + ImageButton nextBotton = view.findViewById(R.id.next_day_button); nextBotton.setOnClickListener(v -> { curDate = curDate.plusDays(1); year = curDate.getYear(); @@ -196,10 +266,9 @@ updateTodoSchedule(integerBookHashMap); }); + booksViewModel.loadBooks(accountId, token);//ViewModel呼び出し - booksViewModel.loadBooks(accountId, token); - System.out.println(token); - + //ViewModel.observe(onChanged) booksViewModel.getBookLiveData().observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(HashMap idBookHashMap) { @@ -270,7 +339,10 @@ scheduleAdapter.setSchedules(scheduleList, integerBookHashMap); } - + // dp を px に変換するためのメソッド + private int dpToPx(int dp) { + return Math.round(dp * getResources().getDisplayMetrics().density); + } @Override public void onStop() { @@ -286,6 +358,7 @@ private HashMap idBookHashMap; private TodosViewModel todosViewModel; private Context context; + private int itemWidth; // アイテムの幅を保持 MyTodoshelfAdapter(List todos, HashMap idBookHashMap, TodosViewModel todosViewModel, Context context) { @@ -325,6 +398,11 @@ String token = citrus.getToken(); String accountId = citrus.getAccountId(); + // アイテムの幅を設定 + 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()); @@ -372,6 +450,11 @@ }); } + public void setItemWidth(int width) { + this.itemWidth = width; + notifyDataSetChanged(); // 幅が変更されたことを通知 + } + static class MyTodoViewHolder extends RecyclerView.ViewHolder { Button todoButton; @@ -390,6 +473,7 @@ private HashMap idBookHashMap; private Context context; private LocalDate curDate; + private int itemWidth; // アイテムの幅を保持 MyScheduleshelfAdapter(List schedules, HashMap idBookHashMap, LocalDate curDate, Context context) { this.scheduleList = schedules; @@ -424,6 +508,11 @@ 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; @@ -511,6 +600,10 @@ notifyDataSetChanged(); // 必要に応じてアダプターをリフレッシュ } + public void setItemWidth(int width) { + this.itemWidth = width; + notifyDataSetChanged(); // 幅が変更されたことを通知 + } @Override public int getItemCount() { return scheduleList.size(); diff --git a/app/src/main/java/com/example/citrusclient/views/OtherHomeFragment.java b/app/src/main/java/com/example/citrusclient/views/OtherHomeFragment.java index 5eed4ef..46c84ff 100644 --- a/app/src/main/java/com/example/citrusclient/views/OtherHomeFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/OtherHomeFragment.java @@ -91,6 +91,8 @@ 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); @@ -128,6 +130,7 @@ int month; int day; + String modo; public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -144,30 +147,94 @@ 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)); }); - ImageButton prevBotton = view.findViewById(R.id.prev_day_botton); + 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(); @@ -181,7 +248,7 @@ updateTodoSchedule(book); }); - ImageButton nextBotton = view.findViewById(R.id.next_day_botton); + ImageButton nextBotton = view.findViewById(R.id.next_day_button); nextBotton.setOnClickListener(v -> { curDate = curDate.plusDays(1); year = curDate.getYear(); @@ -195,10 +262,14 @@ }); + ImageButton backButton = view.findViewById(R.id.back_button); + backButton.setOnClickListener(v -> { + ((MainActivity) getActivity()).backFragment(); + }); + 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() { @Override @@ -232,8 +303,6 @@ } } }); - - } @@ -257,7 +326,10 @@ scheduleAdapter.setSchedules(scheduleList, book); } - + // dp を px に変換するためのメソッド + private int dpToPx(int dp) { + return Math.round(dp * getResources().getDisplayMetrics().density); + } @Override public void onStop() { @@ -273,6 +345,7 @@ private Book book; private TodosViewModel todosViewModel; private Context context; + private int itemWidth; // アイテムの幅を保持 MyOtherTodoshelfAdapter(List todos, Book book, TodosViewModel todosViewModel, Context context) { @@ -304,10 +377,16 @@ // 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); @@ -333,11 +412,6 @@ } - @Override - public int getItemCount() { - return todoList.size(); - } - private void sortTodosById() { Collections.sort(todoList, new Comparator() { @Override @@ -351,6 +425,15 @@ }); } + public void setItemWidth(int width) { + this.itemWidth = width; + notifyDataSetChanged(); // 幅が変更されたことを通知 + } + + @Override + public int getItemCount() { + return todoList.size(); + } static class MyTodoViewHolder extends RecyclerView.ViewHolder { Button todoButton; @@ -369,6 +452,7 @@ Book book; private Context context; private LocalDate curDate; + private int itemWidth; // アイテムの幅を保持 MyOtherScheduleshelfAdapter(List schedules, Book book, LocalDate curDate, Context context) { this.scheduleList = schedules; @@ -395,6 +479,11 @@ 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; @@ -481,6 +570,11 @@ notifyDataSetChanged(); // 必要に応じてアダプターをリフレッシュ } + public void setItemWidth(int width) { + this.itemWidth = width; + notifyDataSetChanged(); // 幅が変更されたことを通知 + } + @Override public int getItemCount() { return scheduleList.size(); diff --git a/app/src/main/res/drawable/baseline_arrow_back_24.xml b/app/src/main/res/drawable/baseline_arrow_back_24.xml new file mode 100644 index 0000000..075e95d --- /dev/null +++ b/app/src/main/res/drawable/baseline_arrow_back_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/vertical_dotted_line.xml b/app/src/main/res/drawable/vertical_dotted_line.xml new file mode 100644 index 0000000..1f09ce1 --- /dev/null +++ b/app/src/main/res/drawable/vertical_dotted_line.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/a_schedule.xml b/app/src/main/res/layout/a_schedule.xml index 3a793d5..f4102db 100644 --- a/app/src/main/res/layout/a_schedule.xml +++ b/app/src/main/res/layout/a_schedule.xml @@ -8,11 +8,13 @@