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 91d0f1f..f0b35ff 100644 --- a/app/src/main/java/com/example/citrusclient/views/HomeFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/HomeFragment.java @@ -1,6 +1,9 @@ package com.example.citrusclient.views; +import android.app.Activity; +import android.content.Context; import android.graphics.Color; +import android.media.Image; import android.os.Bundle; import androidx.annotation.NonNull; @@ -17,6 +20,7 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.CheckBox; +import android.widget.TextView; import com.example.citrusclient.Citrus; import com.example.citrusclient.R; @@ -112,19 +116,23 @@ String accountId = citrus.getAccountId(); int year = citrus.getCurYear(); int month = citrus.getCurMouth(); - int day = citrus.getCurDay(); +// int day = citrus.getCurDay(); + int day = 14; int curBookId = citrus.getCurBookId(); - todoList = new ArrayList<>(); + todoList = new ArrayList<>(); scheduleList = new ArrayList<>(); + TextView curYMD = view.findViewById(R.id.year_month_day); + curYMD.setText(year + "年" + month + "月" + day + "日"); + 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); + MyTodoshelfAdapter todoAdapter = new MyTodoshelfAdapter(todoList, integerBookHashMap, todosViewModel, citrus); todoRecyclerView.setAdapter(todoAdapter); RecyclerView scheduleRecyclerView = view.findViewById(R.id.my_schedule_list); @@ -141,10 +149,18 @@ booksViewModel.getBookLiveData().observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(HashMap idBookHashMap) { - if(idBookHashMap != null) { - integerBookHashMap = new HashMap<>(idBookHashMap); - for (Book book : integerBookHashMap.values()){ - todosViewModel.loadTodosByDay(accountId, book.getBookId(), year , month, day, token); + if (idBookHashMap != null) { + if(curBookId != -1) { + integerBookHashMap = new HashMap<>(); + Book book = idBookHashMap.get(curBookId); + integerBookHashMap.put(curBookId, book); + todosViewModel.loadTodosByDay(accountId, curBookId, year, month, day, token); + citrus.setCurBookId(-1); + } else { + integerBookHashMap = new HashMap<>(idBookHashMap); + for (Book book : integerBookHashMap.values()) { + todosViewModel.loadTodosByDay(accountId, book.getBookId(), year, month, day, token); + } } scheduleViewModel.updateSchedulesByDay(accountId, year, month, day, token); } @@ -171,24 +187,34 @@ } }); + } - + void setCheck(){ } } class MyTodoshelfAdapter extends RecyclerView.Adapter { - private List todoList; private HashMap idBookHashMap; - MyTodoshelfAdapter(List todos, HashMap idBookHashMap) { + private TodosViewModel todosViewModel; + private Citrus citrus; + private String accountId; + private String token; + + MyTodoshelfAdapter(List todos, HashMap idBookHashMap, TodosViewModel todosViewModel, Citrus citrus) { + this.citrus = citrus; + this.token = citrus.getToken(); + this.accountId = citrus.getAccountId(); this.todoList = todos; + this.todosViewModel = todosViewModel; if (idBookHashMap != null) { this.idBookHashMap = new HashMap<>(idBookHashMap); } else { this.idBookHashMap = new HashMap<>(); // 空のHashMapを作成 - } } + } + } public void setTodos(List todos ,HashMap idBookHashMap) { todoList = todos; @@ -221,6 +247,17 @@ holder.todoButton.setTextColor(Color.rgb(255 - red, 255 - green, 255 - blue)); } + holder.todoCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> { + // チェック状態が変更された時の処理を記述 + if (isChecked) { + // チェックされた時の処理 + todosViewModel.setCheck(accountId, book.getBookId(), todoData.getYear(), todoData.getMonth(), todoData.getDay(), todoData.getTodoId(), true, token); + } else { + // チェックが外された時の処理 + todosViewModel.setCheck(accountId, book.getBookId(), todoData.getYear(), todoData.getMonth(), todoData.getDay(), todoData.getTodoId(), false, token); + } + }); + } @Override @@ -270,16 +307,19 @@ @Override public void onBindViewHolder(@NonNull MyScheduleViewHolder holder, int position) { + int red = 169; + int green = 169; + int blue = 169; Schedule scheduleData = this.scheduleList.get(position); holder.scheduleButton.setText(scheduleData.getTitle()); Book book = idBookHashMap.get(scheduleData.getBookId()); 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.scheduleButton.setBackgroundColor(Color.rgb(red, green, blue)); - holder.scheduleButton.setTextColor(Color.rgb(255 - red, 255 - green, 255 - blue)); + 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); } + holder.scheduleButton.setBackgroundColor(Color.rgb(red, green, blue)); + holder.scheduleButton.setTextColor(Color.rgb(255 - red, 255 - green, 255 - blue)); }