diff --git a/app/src/main/java/com/example/citrusclient/models/Schedule.java b/app/src/main/java/com/example/citrusclient/models/Schedule.java index 27d70ca..d8b2c06 100644 --- a/app/src/main/java/com/example/citrusclient/models/Schedule.java +++ b/app/src/main/java/com/example/citrusclient/models/Schedule.java @@ -1,11 +1,9 @@ package com.example.citrusclient.models; -public class Schedule { +public class Schedule extends Task{ - private String title; private String startTime; private String endTime; - private int bookId; private int scheduleId; public Schedule(){} @@ -18,13 +16,7 @@ this.scheduleId = scheduleId; } - public String getTitle() { - return title; - } - public void setTitle(String title) { - this.title = title; - } public String getStartTime() { return startTime; @@ -42,13 +34,7 @@ this.endTime = endTime; } - public int getBookId() { - return bookId; - } - public void setBookId(int bookId) { - this.bookId = bookId; - } public int getScheduleId() { return scheduleId; diff --git a/app/src/main/java/com/example/citrusclient/models/Task.java b/app/src/main/java/com/example/citrusclient/models/Task.java new file mode 100644 index 0000000..c6e5c7f --- /dev/null +++ b/app/src/main/java/com/example/citrusclient/models/Task.java @@ -0,0 +1,23 @@ +package com.example.citrusclient.models; + +import android.content.pm.LauncherApps; + +public class Task { + int bookId; + String title; + + public int getBookId(){ + return bookId; + } + public String getTitle(){ + return title; + } + + public void setBookId(int bookId){ + this.bookId = bookId; + } + + public void setTitle(String title){ + this.title = title; + } +} diff --git a/app/src/main/java/com/example/citrusclient/models/Todo.java b/app/src/main/java/com/example/citrusclient/models/Todo.java index 8458c6b..8094845 100644 --- a/app/src/main/java/com/example/citrusclient/models/Todo.java +++ b/app/src/main/java/com/example/citrusclient/models/Todo.java @@ -2,15 +2,14 @@ import java.util.List; -public class Todo { +public class Todo extends Task{ - String title; + boolean check; int year; int month; int day; Integer todoId; - Integer bookId; //コンストラクタ public Todo(String title, boolean check, int year, int month, int day, Integer tid, Integer bid) { @@ -28,16 +27,13 @@ //セッター - public void setTitle(String title) {this.title = title;} public void setCheck(boolean check) {this.check = check;} public void setYear(int year) {this.year = year;} public void setMonth(int month) {this.month = month;} public void setDay(int day) {this.day = day;} public void setTodoId(Integer tid) {this.todoId = tid;} - public void setBookId(Integer bid) {this.bookId = bid; } //ゲッター - public String getTitle() {return title;} public boolean getCheck() {return check;} @@ -50,7 +46,6 @@ public Integer getTodoId() { return todoId; } - public Integer getBookId(){return bookId;} public boolean containsTodo(List todoList){ for(Todo todo : todoList) { 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 53bc700..0982a48 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,8 @@ import android.view.ViewTreeObserver; import android.widget.Button; import android.widget.LinearLayout; +import android.widget.RadioGroup; +import android.widget.RatingBar; import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; @@ -26,8 +28,11 @@ import com.example.citrusclient.R; import com.example.citrusclient.models.Book; import com.example.citrusclient.models.Schedule; +import com.example.citrusclient.models.Task; +import com.example.citrusclient.models.Todo; import com.example.citrusclient.viewmodels.BooksViewModel; import com.example.citrusclient.viewmodels.ScheduleViewModel; +import com.example.citrusclient.viewmodels.TodosViewModel; import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.time.DayOfWeek; @@ -90,6 +95,7 @@ scheduleViewModel = new ViewModelProvider(this).get(ScheduleViewModel.class); booksViewModel = new ViewModelProvider(this).get(BooksViewModel.class); + todosViewModel = new ViewModelProvider(this).get(TodosViewModel.class); schedules = new HashMap<>(); } @@ -105,6 +111,7 @@ BooksViewModel booksViewModel; private List scheduleList; ScheduleViewModel scheduleViewModel; + TodosViewModel todosViewModel; private HashMap integerBookHashMap; int year; @@ -114,6 +121,7 @@ HashMap books; HashMap> schedules; + HashMap> todos; public TextView[][] calendar(int firstDayOfWeek, int prevMonthDay, int lastDay) { int curDay = 1; @@ -176,6 +184,9 @@ String token = citrus.getToken(); String accountId = citrus.getAccountId(); + todos = new HashMap<>(); + schedules = new HashMap<>(); + scheduleViewModel.getSchedulesByMonth().observe(getViewLifecycleOwner(), new Observer>>() { @Override public void onChanged(HashMap> integerHashMapHashMap) { @@ -191,10 +202,37 @@ books = integerBookHashMap; if(books != null) { TextView curMonth = view.findViewById(R.id.month); + if(todos != null) { + todos.clear(); + } else { + todos = new HashMap<>(); + } + + for(int bookId:books.keySet()){ + todosViewModel.loadTodosByMonth(accountId, bookId, year, month, token); + } + updateCalendar(curMonth); } } }); + + todosViewModel.getTodosByMonthLiveData().observe(getViewLifecycleOwner(), new Observer>>() { + @Override + public void onChanged(HashMap> integerHashMapHashMap) { + TextView curMonth = view.findViewById(R.id.month); + for (int day:integerHashMapHashMap.keySet()){ + if(todos.get(day) == null){ + todos.put(day, new HashMap<>()); + } + for(int todoId:integerHashMapHashMap.get(day).keySet()){ + todos.get(day).put(todoId, integerHashMapHashMap.get(day).get(todoId)); + } + } + updateCalendar(curMonth); + } + }); + booksViewModel.loadBooks(accountId, token); @@ -259,6 +297,16 @@ } }); + view.findViewById(R.id.rbTodo).setOnClickListener(view1 -> { + updateCalendar(curMonth); + }); + view.findViewById(R.id.rbSchedule).setOnClickListener(view1 -> { + updateCalendar(curMonth); + }); + view.findViewById(R.id.rbBoth).setOnClickListener(view1 -> { + updateCalendar(curMonth); + }); + //カレンダーの初期表示 TableLayout tableLayout = view.findViewById(R.id.calendarlayout); TextView[][] days = calendar(firstDayOfWeek, prevMonthDay, lastDay); @@ -288,7 +336,7 @@ RecyclerView.LayoutManager layoutmanager = new LinearLayoutManager(requireContext()); recyclerView.setLayoutManager(layoutmanager); - List schedules = new ArrayList<>(); + List schedules = new ArrayList<>(); recyclerView.setAdapter(new MyScheduleAdapter(schedules, books)); layout.addView(recyclerView); @@ -326,21 +374,47 @@ String[][] days = calendarString(firstDayOfWeek, prevMonthDay, lastDay); int one = 0; + RadioGroup selectButton = getView().findViewById(R.id.selectButton); for(int i = 0; i < 6; i++) { TableRow tableRow = (TableRow) tableLayout.getChildAt(i); for(int j = 0; j < 7; j++) { LinearLayout layout = (LinearLayout) tableRow.getChildAt(j); RecyclerView recyclerView = (RecyclerView) layout.getChildAt(1); - List schedules = new ArrayList<>(); + List schedules = new ArrayList<>(); if(days[i][j].equals("1")){ one++; } if(this.schedules != null && one == 1) { - if (this.schedules.get(Integer.parseInt(days[i][j])) != null) { - for (Schedule schedule : this.schedules.get(Integer.parseInt(days[i][j])).values()) { - schedules.add(schedule); - } + + int select = selectButton.getCheckedRadioButtonId(); + 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()) { + schedules.add(schedule); + } + } + } else if(select == R.id.rbSchedule){ + if (this.schedules.get(Integer.parseInt(days[i][j])) != null) { + for (Schedule schedule : this.schedules.get(Integer.parseInt(days[i][j])).values()) { + schedules.add(schedule); + } + } + } else { + if (this.todos.get(Integer.parseInt(days[i][j])) != null) { + for (Todo schedule : this.todos.get(Integer.parseInt(days[i][j])).values()) { + schedules.add(schedule); + } + } + if (this.schedules.get(Integer.parseInt(days[i][j])) != null) { + for (Schedule schedule : this.schedules.get(Integer.parseInt(days[i][j])).values()) { + schedules.add(schedule); + } + } + } + + } } @@ -353,10 +427,10 @@ class MyScheduleAdapter extends RecyclerView.Adapter { - private List scheduleList; + private List scheduleList; private HashMap integerBookHashMap; - MyScheduleAdapter(List schedules, HashMap integerBookHashMap) { + MyScheduleAdapter(List schedules, HashMap integerBookHashMap) { this.scheduleList = schedules; if(integerBookHashMap != null) { this.integerBookHashMap = new HashMap<>(integerBookHashMap); @@ -365,7 +439,7 @@ } } - public void setSchedules(List schedules, HashMap integerBookHashMap) { + public void setSchedules(List schedules, HashMap integerBookHashMap) { scheduleList = schedules; if(integerBookHashMap != null) { this.integerBookHashMap = new HashMap<>(integerBookHashMap); @@ -386,7 +460,7 @@ int red = 169; int green = 169; int blue = 169; - Schedule scheduleData = this.scheduleList.get(position); + Task scheduleData = this.scheduleList.get(position); holder.scheduleText.setText(scheduleData.getTitle()); Book book = integerBookHashMap.get(scheduleData.getBookId()); if(book != null) { diff --git a/app/src/main/res/layout/fragment_calendar.xml b/app/src/main/res/layout/fragment_calendar.xml index 30349d4..ac66c68 100644 --- a/app/src/main/res/layout/fragment_calendar.xml +++ b/app/src/main/res/layout/fragment_calendar.xml @@ -101,7 +101,7 @@ + android:text="todo" /> + android:text="schedule" /> + android:text="todoANDschedule" />