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 feb32ee..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,7 +128,7 @@ int month; int day; - String modo = "todoSchedule"; + String modo; public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -140,6 +142,10 @@ 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 + "日"); @@ -151,7 +157,7 @@ todoRecyclerView.setLayoutManager(layoutManager); MyTodoshelfAdapter todoAdapter = new MyTodoshelfAdapter(todoList, integerBookHashMap, todosViewModel, getActivity()); todoRecyclerView.setAdapter(todoAdapter); - todoAdapter.setItemWidth(dpToPx(130)); + todoAdapter.setItemWidth(dpToPx(todoWidth)); //ScheduleAdapter設定 RecyclerView scheduleRecyclerView = view.findViewById(R.id.my_schedule_list); scheduleRecyclerView.setHasFixedSize(true); @@ -159,7 +165,7 @@ scheduleRecyclerView.setLayoutManager(scheduleLayoutManager); MyScheduleshelfAdapter scheduleAdapter = new MyScheduleshelfAdapter(scheduleList, integerBookHashMap, curDate, getActivity()); scheduleRecyclerView.setAdapter(scheduleAdapter); - scheduleAdapter.setItemWidth(dpToPx(160)); + scheduleAdapter.setItemWidth(dpToPx(scheduleWidth)); //ボタン処理 @@ -170,51 +176,58 @@ 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 params = modoTodoButton.getLayoutParams(); - ViewGroup.LayoutParams todoparams = todoRecyclerView.getLayoutParams(); + ViewGroup.LayoutParams todoButtonParams = modoTodoButton.getLayoutParams(); + ViewGroup.LayoutParams todoRecyclerViewLayoutParams = todoRecyclerView.getLayoutParams(); if(modo == "todoSchedule") { modoScheduleButton.setVisibility(View.GONE); scheduleRecyclerView.setVisibility(View.GONE); - params.width = dpToPx(370); // 幅を全体に - modoTodoButton.setLayoutParams(params); - todoparams.width = dpToPx(370); - todoRecyclerView.setLayoutParams(todoparams); + 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"){ - params.width = dpToPx(180); // 幅を全体に - modoTodoButton.setLayoutParams(params); - todoparams.width = dpToPx(180); - todoRecyclerView.setLayoutParams(todoparams); + 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(130)); + todoAdapter.setItemWidth(dpToPx(todoWidth)); + verticalLine.setVisibility(View.VISIBLE); modo = "todoSchedule"; } }); + //上のScheduleButtonを押したときScheduleだけを表示 modoScheduleButton.setOnClickListener(v -> { - ViewGroup.LayoutParams params = modoScheduleButton.getLayoutParams(); + ViewGroup.LayoutParams scheuleButtonParams = modoScheduleButton.getLayoutParams(); ViewGroup.LayoutParams scheduleRecyclerViewLayoutParams = scheduleRecyclerView.getLayoutParams(); if(modo == "todoSchedule") { modoTodoButton.setVisibility(View.GONE); todoRecyclerView.setVisibility(View.GONE); - params.width = dpToPx(370); // 幅を全体に - modoScheduleButton.setLayoutParams(params); - scheduleRecyclerViewLayoutParams.width = dpToPx(370); + 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"){ - params.width = dpToPx(180); // 幅を全体に - modoScheduleButton.setLayoutParams(params); - scheduleRecyclerViewLayoutParams.width = dpToPx(180); + 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(160)); + scheduleAdapter.setItemWidth(dpToPx(scheduleWidth)); + verticalLine.setVisibility(View.VISIBLE); modo = "todoSchedule"; } });