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..53bc700 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(); @@ -231,7 +243,6 @@ year++; } scheduleViewModel.updateSchedulesByMonth(accountId, year, month, token); - } }); @@ -262,13 +273,24 @@ p2.weight = 1; tableRow.addView(layout); layout.addView(days[i][j]); + final int ii = i; + final int jj = j; + layout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + citrus.setCurMonth(month); + citrus.setCurYear(year); + citrus.setCurDay(Integer.parseInt(daysString[ii][jj])); + ((MainActivity) getActivity()).showFragment(new HomeFragment()); + } + }); RecyclerView recyclerView = new RecyclerView(requireContext()); RecyclerView.LayoutManager layoutmanager = new LinearLayoutManager(requireContext()); recyclerView.setLayoutManager(layoutmanager); 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 @@ -303,6 +325,7 @@ int lastDay = CurLastDay.getDayOfMonth(); String[][] days = calendarString(firstDayOfWeek, prevMonthDay, lastDay); + int one = 0; for(int i = 0; i < 6; i++) { TableRow tableRow = (TableRow) tableLayout.getChildAt(i); @@ -310,7 +333,10 @@ LinearLayout layout = (LinearLayout) tableRow.getChildAt(j); RecyclerView recyclerView = (RecyclerView) layout.getChildAt(1); List schedules = new ArrayList<>(); - if(this.schedules != null) { + 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); @@ -318,9 +344,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 + ""); } } }