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 11adefe..5f5762f 100644 --- a/app/src/main/java/com/example/citrusclient/views/HomeFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/HomeFragment.java @@ -20,6 +20,7 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.CheckBox; +import android.widget.ImageButton; import android.widget.TextView; import com.example.citrusclient.Citrus; @@ -148,8 +149,8 @@ todoList = new ArrayList<>(); scheduleList = new ArrayList<>(); - TextView curDateText = view.findViewById(R.id.year_month_day); - curDateText.setText(year + "年" + month + "月" + day + "日"); + Button curDateButton = view.findViewById(R.id.date_button); + curDateButton.setText(year + "年" + month + "月" + day + "日"); RecyclerView todoRecyclerView = view.findViewById(R.id.my_todos_list); @@ -177,24 +178,24 @@ ((MainActivity) getActivity()).showFragment(new CreateScheduleFragment()); }); - FloatingActionButton prevBotton = view.findViewById(R.id.prev_day_botton); + ImageButton 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 + "日"); + curDateButton.setText(year + "年" + month + "月" + day + "日"); updateTodoSchedule(integerBookHashMap); }); - FloatingActionButton nextBotton = view.findViewById(R.id.next_day_botton); + ImageButton 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 + "日"); + curDateButton.setText(year + "年" + month + "月" + day + "日"); updateTodoSchedule(integerBookHashMap); }); @@ -305,12 +306,6 @@ } public void setTodos(List todos ,HashMap idBookHashMap) { -// Collections.sort(books, new Comparator() { -// @Override -// public int compare(Book b1, Book b2) { -// return Integer.compare(b1.getBookId(), b2.getBookId()); -// } -// }); todoList = todos; if (idBookHashMap != null) { this.idBookHashMap = new HashMap<>(idBookHashMap); @@ -414,7 +409,9 @@ this.idBookHashMap = new HashMap<>(idBookHashMap); } else { this.idBookHashMap = new HashMap<>(); // 空のHashMapを作成 - } notifyDataSetChanged(); + } + sortScheduleByTime(); + notifyDataSetChanged(); } @NonNull @@ -431,7 +428,7 @@ int blue = 169; Schedule scheduleData = this.scheduleList.get(position); holder.scheduleButton.setText(scheduleData.getTitle()); -// holder.scheduleButton.setText(scheduleData.getTitle() + extractionTime(scheduleData.getStartTime()) + " ~ " + extractionTime(scheduleData.getEndTime())); + holder.scheduleButton.setText(scheduleData.getTitle() + "\n" + extractionTime(scheduleData.getStartTime()) + " ~ " + extractionTime(scheduleData.getEndTime())); Book book = idBookHashMap.get(scheduleData.getBookId()); if(book != null) { red = Integer.parseInt(book.getColor().substring(1, 3), 16); @@ -443,17 +440,19 @@ } -// private void sortScheduleByTime() { -// Collections.sort(scheduleList, new Comparator() { -// @Override -// public int compare(Schedule schedule1, Schedule schedule2) { -// return Integer.compare(schedule1.getStartTime(), schedule2.getStartTime()); -// } -// }); -// notifyDataSetChanged(); // データ変更をアダプタに通知 -// } + private void sortScheduleByTime() { + Collections.sort(scheduleList, new Comparator() { + @Override + public int compare(Schedule schedule1, Schedule schedule2) { + long start = convertTimeInteger(schedule1.getStartTime()); + long end = convertTimeInteger(schedule2.getStartTime()); + return Long.compare(start, end); + } + }); + notifyDataSetChanged(); // データ変更をアダプタに通知 + } - private static int convertTimeInteger(String scheduleTime) { + private static long convertTimeInteger(String scheduleTime) { try { // フォーマッタを定義 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm"); @@ -463,13 +462,15 @@ System.out.println(dateTime); // 年、月、日、時、分を抽出 - int year = dateTime.getYear(); - int month = dateTime.getMonthValue(); - int day = dateTime.getDayOfMonth(); - int hour = dateTime.getHour(); - int minute = dateTime.getMinute(); + long year = dateTime.getYear(); + long month = dateTime.getMonthValue(); + long day = dateTime.getDayOfMonth(); + long hour = dateTime.getHour(); + long minute = dateTime.getMinute(); + System.out.println(year); + // 必要に応じて整数を組み合わせる(例: YYYYMMDDHHMM) - int result = year * 100000 + month * 1000000 + day * 10000 + hour * 100 + minute; + long result = year *100000000 +month * 1000000 + day * 10000 + hour * 100 + minute; System.out.println(result); return result; @@ -479,11 +480,8 @@ } } - private static int extractionTime(String scheduleTime) { - int time = convertTimeInteger(scheduleTime); - int result = time % 10000; - return result; - + private static String extractionTime(String scheduleTime) { + return scheduleTime.substring(scheduleTime.length() - 5); } @Override