diff --git a/app/src/main/java/com/example/citrusclient/models/Book.java b/app/src/main/java/com/example/citrusclient/models/Book.java index eea8a6d..b536741 100644 --- a/app/src/main/java/com/example/citrusclient/models/Book.java +++ b/app/src/main/java/com/example/citrusclient/models/Book.java @@ -8,6 +8,7 @@ private String color; private String accountId; private String time; + private int favoriteCount; public Book(String accountId, Integer bookId, String title, boolean publicity, String color) { @@ -16,6 +17,7 @@ this.title = title; this.publicity = publicity; this.color = color; + this.favoriteCount = 0; } public Book(){ @@ -29,6 +31,7 @@ public void setBookId(int id) {bookId = id;} public void setAccountId(String a) {accountId = a;} public void setTime(String ti) {time = ti;} + public void setFavoritedCount(int f) {favoriteCount = f;} //Getter public String getTitle() {return title;} @@ -37,4 +40,5 @@ public int getBookId() {return bookId;} public String getAccountId() {return accountId;} public String getTime() {return time;} + public int getFavoritedCount() {return favoriteCount;} } diff --git a/app/src/main/java/com/example/citrusclient/rest/BooksRest.java b/app/src/main/java/com/example/citrusclient/rest/BooksRest.java index 420da7f..0119071 100644 --- a/app/src/main/java/com/example/citrusclient/rest/BooksRest.java +++ b/app/src/main/java/com/example/citrusclient/rest/BooksRest.java @@ -94,4 +94,16 @@ @Field("color") String color, @Field("token") String token ); + + @PUT("/{account_id}/books/{book_id}/registerFavoriteCount") + Call registerFavoriteCount( + @Path("account_id") String account_id, + @Path("book_id") Integer book_id + ); + + @PUT("/{account_id}/books/{book_id}/unregisterFavoriteCount") + Call unregisterFavoriteCount( + @Path("account_id") String account_id, + @Path("book_id") Integer book_id + ); } diff --git a/app/src/main/java/com/example/citrusclient/rest/FavoritesRest.java b/app/src/main/java/com/example/citrusclient/rest/FavoritesRest.java index 46a31f7..2b4313c 100644 --- a/app/src/main/java/com/example/citrusclient/rest/FavoritesRest.java +++ b/app/src/main/java/com/example/citrusclient/rest/FavoritesRest.java @@ -26,18 +26,16 @@ ); //主{account_id}がいいねした誰か{other_account_id}の本の一覧 - @FormUrlEncoded @GET("accounts/{account_id}/favorites/{other_account_id}") - Call> getFavoritesBooksById( + Call> getFavoritesBooksById( @Path("account_id") String accountId, @Path("other_account_id") String otherAccountId, @Query("token") String token ); //主{account_id}のある本{book_id}をいいねした人の一覧 - @FormUrlEncoded @GET("accounts/{account_id}/books/{book_id}/favorited") - Call> getFavoritedAccount( + Call> getFavoritedAccount( @Path("account_id") String accountId, @Path("book_id") Integer bookId, @Query("token") String token diff --git a/app/src/main/java/com/example/citrusclient/viewmodels/BooksViewModel.java b/app/src/main/java/com/example/citrusclient/viewmodels/BooksViewModel.java index e96c043..ea47647 100644 --- a/app/src/main/java/com/example/citrusclient/viewmodels/BooksViewModel.java +++ b/app/src/main/java/com/example/citrusclient/viewmodels/BooksViewModel.java @@ -192,6 +192,46 @@ }); } + public void registerFavoriteCount(String accountId, Integer bookId){ + Call call = booksRest.registerFavoriteCount(accountId, bookId); + + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()){ + System.out.println("Success registerFavorited"); + } else { + System.out.println("response error"); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + System.out.println("NetWorkError" + t); + } + }); + } + + public void unregisterFavoriteCount(String accountId, Integer bookId){ + Call call = booksRest.unregisterFavoriteCount(accountId, bookId); + + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()){ + System.out.println("Success unresterFavorited"); + } else { + System.out.println("response error"); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + System.out.println("NetWorkError" + t); + } + }); + } + private String parseStatusCode(Integer code) { switch (code) { case 404: diff --git a/app/src/main/java/com/example/citrusclient/viewmodels/FavoritesViewModel.java b/app/src/main/java/com/example/citrusclient/viewmodels/FavoritesViewModel.java index 002c5fb..825dbdd 100644 --- a/app/src/main/java/com/example/citrusclient/viewmodels/FavoritesViewModel.java +++ b/app/src/main/java/com/example/citrusclient/viewmodels/FavoritesViewModel.java @@ -23,8 +23,8 @@ private final FavoritesRest favoritesRest; private final MutableLiveData> favoritesBooksLiveData; - private final MutableLiveData> favoritesBookIdLiveData; - private final MutableLiveData> favoritedAccountsLiveData; + private final MutableLiveData> favoritesBookIdLiveData; + private final MutableLiveData> favoritedAccountsLiveData; public FavoritesViewModel(){ @@ -38,8 +38,8 @@ this.favoritedAccountsLiveData = new MutableLiveData<>(); } public MutableLiveData> getFavoritesBooksLiveData(){return favoritesBooksLiveData;} - public MutableLiveData> getFavoritesBookIdLiveData(){return favoritesBookIdLiveData;} - public MutableLiveData> getFavoritedAccountsLiveData(){return favoritedAccountsLiveData;} + public MutableLiveData> getFavoritesBookIdLiveData(){return favoritesBookIdLiveData;} + public MutableLiveData> getFavoritedAccountsLiveData(){return favoritedAccountsLiveData;} public void loadFavoritesBooks(String accountId, String token){ Call> call = favoritesRest.getFavoritesBooks(accountId,token); @@ -60,10 +60,10 @@ } public void loadFavoritesBookId(String accountId, String otherAccountId, String token){ - Call> call = favoritesRest.getFavoritesBooksById(accountId,otherAccountId,token); - call.enqueue(new Callback>() { + Call> call = favoritesRest.getFavoritesBooksById(accountId,otherAccountId,token); + call.enqueue(new Callback>() { @Override - public void onResponse(Call> call, Response> response) { + public void onResponse(Call> call, Response> response) { if(response.isSuccessful()){ System.out.println("success : getFavoritesBooksById"); favoritesBookIdLiveData.setValue(response.body()); @@ -71,17 +71,17 @@ } @Override - public void onFailure(Call> call, Throwable t) { + public void onFailure(Call> call, Throwable t) { System.out.println("NetworkError : getFavoritesBooksById" + t); } }); } public void loadFavoritedAccounts(String accountId, Integer bookId, String token){ - Call> call = favoritesRest.getFavoritedAccount(accountId,bookId,token); - call.enqueue(new Callback>() { + Call> call = favoritesRest.getFavoritedAccount(accountId,bookId,token); + call.enqueue(new Callback>() { @Override - public void onResponse(Call> call, Response> response) { + public void onResponse(Call> call, Response> response) { if(response.isSuccessful()){ System.out.println("success : getFavoritedAccount"); favoritedAccountsLiveData.setValue(response.body()); @@ -89,7 +89,7 @@ } @Override - public void onFailure(Call> call, Throwable t) { + public void onFailure(Call> call, Throwable t) { System.out.println("NetworkError : getFavoritedAccount" + t); } }); diff --git a/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java b/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java index 5b0d307..bc701ca 100644 --- a/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java @@ -18,6 +18,7 @@ import android.view.ViewTreeObserver; import android.widget.Button; import android.widget.LinearLayout; +import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TableLayout; import android.widget.TableRow; @@ -129,7 +130,7 @@ HashMap books; HashMap> schedules; - HashMap> todos; + HashMap> todos; public TextView[][] calendar(int firstDayOfWeek, int prevMonthDay, int lastDay) { int curDay = 1; @@ -232,10 +233,10 @@ if(integerHashMapHashMap != null && !integerHashMapHashMap.isEmpty()) { for (int day : integerHashMapHashMap.keySet()) { if (todos.get(day) == null) { - todos.put(day, new HashMap<>()); + todos.put(day, new ArrayList<>()); } for (int todoId : integerHashMapHashMap.get(day).keySet()) { - todos.get(day).put(todoId, integerHashMapHashMap.get(day).get(todoId)); + todos.get(day).add(integerHashMapHashMap.get(day).get(todoId)); } } } @@ -276,7 +277,16 @@ createBook.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - ((MainActivity) getActivity()).showFragment(new CreateScheduleFragment(year, month, day)); + RadioButton rbSchedule = getActivity().findViewById(R.id.rbSchedule); + RadioButton rbTodo = getActivity().findViewById(R.id.rbTodo); + RadioButton rbBoth = getActivity().findViewById(R.id.rbBoth); + if(rbSchedule != null && rbSchedule.isChecked()) { + ((MainActivity) getActivity()).showFragment(new CreateScheduleFragment(year, month, day)); + } else if(rbTodo != null && rbTodo.isChecked()) { + ((MainActivity) getActivity()).showFragment(new CreateTodoFragment(year, month, day)); + } else if(rbBoth != null && rbBoth.isChecked()) { + ((MainActivity) getActivity()).showFragment(new CreateScheduleFragment(year, month, day)); + } } }); @@ -289,7 +299,10 @@ month = 1; year++; } + todos.clear(); scheduleViewModel.updateSchedulesByMonth(accountId, year, month, token); + booksViewModel.loadBooks(accountId, token); + updateCalendar(curMonth); } }); @@ -302,7 +315,10 @@ month = 12; year--; } + todos.clear(); scheduleViewModel.updateSchedulesByMonth(accountId, year, month, token); + booksViewModel.loadBooks(accountId, token); + updateCalendar(curMonth); } }); @@ -428,7 +444,7 @@ if(select != -1){ if(select == R.id.rbTodo){ if (this.todos.get(Integer.parseInt(days[i][j])) != null) { - for (Todo schedule : this.todos.get(Integer.parseInt(days[i][j])).values()) { + for (Todo schedule : this.todos.get(Integer.parseInt(days[i][j]))) { schedules.add(schedule); } } @@ -440,7 +456,7 @@ } } else { if (this.todos.get(Integer.parseInt(days[i][j])) != null) { - for (Todo schedule : this.todos.get(Integer.parseInt(days[i][j])).values()) { + for (Todo schedule : this.todos.get(Integer.parseInt(days[i][j]))) { schedules.add(schedule); } } 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/OtherCalendarFragment.java b/app/src/main/java/com/example/citrusclient/views/OtherCalendarFragment.java index 0161adb..4001914 100644 --- a/app/src/main/java/com/example/citrusclient/views/OtherCalendarFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/OtherCalendarFragment.java @@ -68,6 +68,11 @@ month = calendar.get(Calendar.MONTH) + 1; //現在の月 } + public OtherCalendarFragment(int year, int month) { + this.year = year; + this.month = month; + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -106,7 +111,7 @@ HashMap books; private Book book; HashMap> schedules; - HashMap> todos; + HashMap> todos; public TextView[][] calendar(int firstDayOfWeek, int prevMonthDay, int lastDay) { int curDay = 1; @@ -195,8 +200,6 @@ } todosViewModel.loadTodosByMonth(accountId, book.getBookId(), year, month, token); updateCalendar(curMonth); - Log.d("Debug", "Book: " + book); - Log.d("Debug", "Color: " + (book != null ? book.getColor() : "No color")); } } }); @@ -207,11 +210,9 @@ TextView curMonth = view.findViewById(R.id.otherMonth); if(integerHashMapHashMap != null && !integerHashMapHashMap.isEmpty()) { for (int day : integerHashMapHashMap.keySet()) { - if (todos.get(day) == null) { - todos.put(day, new HashMap<>()); - } + todos.put(day, new ArrayList<>()); for (int todoId : integerHashMapHashMap.get(day).keySet()) { - todos.get(day).put(todoId, integerHashMapHashMap.get(day).get(todoId)); + todos.get(day).add(integerHashMapHashMap.get(day).get(todoId)); } } } @@ -260,8 +261,11 @@ month = 1; year++; } + todos.clear(); scheduleViewModel.updateSchedulesByMonthAndBookId(accountId, year, month, token, bookId); + booksViewModel.loadBook(accountId, token, bookId); todosViewModel.loadTodosByMonth(accountId, bookId, year, month, token); + updateCalendar(curMonth); } }); @@ -274,8 +278,11 @@ month = 12; year--; } + todos.clear(); scheduleViewModel.updateSchedulesByMonthAndBookId(accountId, year, month, token, bookId); + booksViewModel.loadBook(accountId, token, bookId); todosViewModel.loadTodosByMonth(accountId, bookId, year, month, token); + updateCalendar(curMonth); } }); @@ -407,7 +414,7 @@ if(select != -1){ if(select == R.id.otherRbTodo){ if (this.todos.get(Integer.parseInt(days[i][j])) != null) { - for (Todo schedule : this.todos.get(Integer.parseInt(days[i][j])).values()) { + for (Todo schedule : this.todos.get(Integer.parseInt(days[i][j]))) { schedules.add(schedule); } } @@ -419,7 +426,7 @@ } } else { if (this.todos.get(Integer.parseInt(days[i][j])) != null) { - for (Todo schedule : this.todos.get(Integer.parseInt(days[i][j])).values()) { + for (Todo schedule : this.todos.get(Integer.parseInt(days[i][j]))) { schedules.add(schedule); } } 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..fb5656a 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); +// todosViewModel.loadTodosByDay(accountId, curBookId, year, month, day, token); +// scheduleViewModel.updateSchedulesByDayAndBookId(accountId, year, month, day, token, curBookId); booksViewModel.getBook().observe(getViewLifecycleOwner(), new Observer() { @Override @@ -232,8 +303,6 @@ } } }); - - } @@ -247,7 +316,7 @@ this.book = book; } todosViewModel.loadTodosByDay(accountId, curBookId, year, month, day, token); - scheduleViewModel.updateSchedulesByDayAndBookId(accountId, year, month, day, token, curBookId); + scheduleViewModel.updateSchedulesByDay(accountId, year, month, day, token); } private void clearTodoSchedule(MyOtherTodoshelfAdapter todoAdapter, MyOtherScheduleshelfAdapter scheduleAdapter) { @@ -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,17 +377,22 @@ // 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); - holder.todoButton.setBackgroundColor(Color.rgb(red, green, blue)); - holder.todoButton.setTextColor(Color.rgb(255 - red, 255 - green, 255 - blue)); - } + + + 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); + holder.todoButton.setBackgroundColor(Color.rgb(red, green, blue)); + holder.todoButton.setTextColor(Color.rgb(255 - red, 255 - green, 255 - blue)); // holder.todoButton.setOnClickListener(v -> { // ((MainActivity) activity).showFragment(new CreateTodoFragment(todoData, book)); @@ -333,11 +411,6 @@ } - @Override - public int getItemCount() { - return todoList.size(); - } - private void sortTodosById() { Collections.sort(todoList, new Comparator() { @Override @@ -351,6 +424,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 +451,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,13 +478,18 @@ 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; Schedule scheduleData = this.scheduleList.get(position); holder.scheduleButton.setText(scheduleData.getTitle()); holder.scheduleButton.setText(scheduleData.getTitle() + "\n" + extractionTime(scheduleData.getStartTime(), curDate) + " ~ " + extractionTime(scheduleData.getEndTime(), curDate)); - if(book != null) { + if(book.getBookId() == scheduleData.getBookId()) { red = Integer.parseInt(book.getColor().substring(1, 3), 16); green = Integer.parseInt(book.getColor().substring(3, 5), 16); blue = Integer.parseInt(book.getColor().substring(5, 7), 16); @@ -481,6 +569,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 @@