Merge pull request #202 from nitta-lab-2024/OtherHomeFragment
OtherHomeFragment
commit 2ce602365c1895742d4f7dcaa5eb5ff87d2a5ff3
2 parents ba7e3e4 + 2c77931
渡辺智裕 authored on 17 Oct
Showing 8 changed files
View
121
app/src/main/java/com/example/citrusclient/views/HomeFragment.java
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);
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));
});
scheduleAddButton.setOnClickListener(v -> {
((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();
month = curDate.getMonthValue();
clearTodoSchedule(todoAdapter, scheduleAdapter);
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();
month = curDate.getMonthValue();
clearTodoSchedule(todoAdapter, scheduleAdapter);
updateTodoSchedule(integerBookHashMap);
});
 
 
booksViewModel.loadBooks(accountId, token);
System.out.println(token);
 
booksViewModel.loadBooks(accountId, token);//ViewModel呼び出し
 
//ViewModel.observe(onChanged)
booksViewModel.getBookLiveData().observe(getViewLifecycleOwner(), new Observer<HashMap<Integer, Book>>() {
@Override
public void onChanged(HashMap<Integer, Book> idBookHashMap) {
clearTodoSchedule(todoAdapter, scheduleAdapter);
scheduleList.clear();
scheduleAdapter.setSchedules(scheduleList, integerBookHashMap);
}
 
 
// 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 HashMap<Integer, Book> idBookHashMap;
private TodosViewModel todosViewModel;
private Context context;
private int itemWidth; // アイテムの幅を保持
 
 
MyTodoshelfAdapter(List<Todo> todos, HashMap<Integer, Book> idBookHashMap, TodosViewModel todosViewModel, Context context) {
this.todoList = todos;
Activity activity = (Activity) context;
Citrus citrus = (Citrus)(activity.getApplication());
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());
}
});
}
 
public void setItemWidth(int width) {
this.itemWidth = width;
notifyDataSetChanged(); // 幅が変更されたことを通知
}
 
 
static class MyTodoViewHolder extends RecyclerView.ViewHolder {
Button todoButton;
CheckBox todoCheckBox;
private List<Schedule> scheduleList;
private HashMap<Integer, Book> idBookHashMap;
private Context context;
private LocalDate curDate;
private int itemWidth; // アイテムの幅を保持
 
MyScheduleshelfAdapter(List<Schedule> schedules, HashMap<Integer, Book> idBookHashMap, LocalDate curDate, Context context) {
this.scheduleList = schedules;
if (idBookHashMap != null) {
 
@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();
}
View
187
app/src/main/java/com/example/citrusclient/views/OtherHomeFragment.java
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());
});
 
ImageButton prevBotton = view.findViewById(R.id.prev_day_botton);
((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();
month = curDate.getMonthValue();
clearTodoSchedule(todoAdapter, scheduleAdapter);
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();
month = curDate.getMonthValue();
updateTodoSchedule(book);
 
});
 
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<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();
}
View
app/src/main/res/drawable/baseline_arrow_back_24.xml 0 → 100644
View
app/src/main/res/drawable/vertical_dotted_line.xml 0 → 100644
View
app/src/main/res/layout/a_schedule.xml
View
app/src/main/res/layout/a_todo.xml
View
app/src/main/res/layout/fragment_home.xml
View
app/src/main/res/layout/fragment_other_home.xml