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 1de74fd..a29c4e3 100644 --- a/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/CalendarFragment.java @@ -111,6 +111,8 @@ int month; int day; + HashMap books; + HashMap> schedules; public TextView[][] calendar(int firstDayOfWeek, int prevMonthDay, int lastDay) { @@ -170,8 +172,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - //AdapterはそれぞれのRecyclerViewに入れる必要があるため、for文を用いて、それぞれにセットする。(後期の作業) - Citrus citrus = (Citrus)(getActivity().getApplication()); String token = citrus.getToken(); String accountId = citrus.getAccountId(); @@ -185,6 +185,18 @@ } }); + booksViewModel.getBookLiveData().observe(getViewLifecycleOwner(), new Observer>() { + @Override + public void onChanged(HashMap integerBookHashMap) { + books = integerBookHashMap; + if(books != null) { + TextView curMonth = view.findViewById(R.id.month); + updateCalendar(curMonth); + } + } + }); + booksViewModel.loadBooks(accountId, token); + tableLayout = view.findViewById(R.id.calendarlayout); Calendar calendar = Calendar.getInstance(); @@ -268,7 +280,7 @@ List schedules = new ArrayList<>(); - recyclerView.setAdapter(new MyScheduleAdapter(schedules, integerBookHashMap)); + recyclerView.setAdapter(new MyScheduleAdapter(schedules, books)); layout.addView(recyclerView); layout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override @@ -318,9 +330,8 @@ } } - ((MyScheduleAdapter) recyclerView.getAdapter()).setSchedules(schedules, integerBookHashMap); + ((MyScheduleAdapter) recyclerView.getAdapter()).setSchedules(schedules, books); ((TextView) layout.getChildAt(0)).setText(days[i][j]); - //if(i == 2 && j == 1) Log.i("kjda", layout.getLayoutParams().height + ""); } } }