From 8482c27689cd2fdfdd8a22bb029dbc40fd630157 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Sun, 1 Dec 2019 20:23:48 +0100 Subject: [PATCH] [Timetable] Add marking lessons as seen in timetable. --- .../data/db/modules/metadata/MetadataDao.java | 12 +++++++++++- .../ui/modules/timetable/v2/TimetableFragment.kt | 15 +++++++++++++++ .../timetable/v2/day/TimetableDayFragment.kt | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/metadata/MetadataDao.java b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/metadata/MetadataDao.java index d86b9f16..37238a6d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/metadata/MetadataDao.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/metadata/MetadataDao.java @@ -9,7 +9,6 @@ import androidx.room.Transaction; import java.util.List; -import pl.szczodrzynski.edziennik.data.db.modules.notices.Notice; import pl.szczodrzynski.edziennik.data.db.modules.announcements.Announcement; import pl.szczodrzynski.edziennik.data.db.modules.attendance.Attendance; import pl.szczodrzynski.edziennik.data.db.modules.events.Event; @@ -17,6 +16,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade; import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange; import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull; import pl.szczodrzynski.edziennik.data.db.modules.messages.Message; +import pl.szczodrzynski.edziennik.data.db.modules.notices.Notice; import pl.szczodrzynski.edziennik.utils.models.UnreadCounter; import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_ANNOUNCEMENT; @@ -85,6 +85,11 @@ public abstract class MetadataDao { updateSeen(profileId, TYPE_LESSON_CHANGE, ((LessonFull) o).changeId, seen); } } + if (o instanceof pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull) { + if (add(new Metadata(profileId, TYPE_LESSON_CHANGE, ((pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull) o).getId(), seen, false, 0)) == -1) { + updateSeen(profileId, TYPE_LESSON_CHANGE, ((pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull) o).getId(), seen); + } + } if (o instanceof Announcement) { if (add(new Metadata(profileId, TYPE_ANNOUNCEMENT, ((Announcement) o).id, seen, false, 0)) == -1) { updateSeen(profileId, TYPE_ANNOUNCEMENT, ((Announcement) o).id, seen); @@ -129,6 +134,11 @@ public abstract class MetadataDao { updateNotified(profileId, TYPE_LESSON_CHANGE, ((LessonFull) o).changeId, notified); } } + if (o instanceof pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull) { + if (add(new Metadata(profileId, TYPE_LESSON_CHANGE, ((pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull) o).getId(), false, notified, 0)) == -1) { + updateNotified(profileId, TYPE_LESSON_CHANGE, ((pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull) o).getId(), notified); + } + } if (o instanceof Announcement) { if (add(new Metadata(profileId, TYPE_ANNOUNCEMENT, ((Announcement) o).id, false, notified, 0)) == -1) { updateNotified(profileId, TYPE_ANNOUNCEMENT, ((Announcement) o).id, notified); diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/TimetableFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/TimetableFragment.kt index 5944f591..7d001273 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/TimetableFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/TimetableFragment.kt @@ -11,6 +11,7 @@ import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.fragment.app.Fragment +import androidx.lifecycle.Observer import androidx.viewpager.widget.ViewPager import com.google.android.material.datepicker.MaterialDatePicker import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial @@ -21,7 +22,9 @@ import pl.szczodrzynski.edziennik.MainActivity import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.api.v2.LOGIN_TYPE_LIBRUS import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata +import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson import pl.szczodrzynski.edziennik.databinding.FragmentTimetableV2Binding +import pl.szczodrzynski.edziennik.observeOnce import pl.szczodrzynski.edziennik.utils.Themes import pl.szczodrzynski.edziennik.utils.models.Date import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem @@ -152,6 +155,7 @@ class TimetableFragment : Fragment(), CoroutineScope { activity.gainAttentionFAB() fabShown = true } + markLessonsAsSeen() } }) @@ -196,4 +200,15 @@ class TimetableFragment : Fragment(), CoroutineScope { b.tabLayout.setCurrentItem(items.indexOfFirst { it.value == today }, true) }) }} + + private fun markLessonsAsSeen() = pageSelection?.let { date -> + app.db.timetableDao().getForDate(App.profileId, date).observeOnce(this@TimetableFragment, Observer { lessons -> + lessons.forEach { lesson -> + if (lesson.type != Lesson.TYPE_NORMAL && lesson.type != Lesson.TYPE_NO_LESSONS + && !lesson.seen) { + app.db.metadataDao().setSeen(lesson.profileId, lesson, true) + } + } + }) + } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/day/TimetableDayFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/day/TimetableDayFragment.kt index 44cc6ff7..9fbbfa51 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/day/TimetableDayFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/day/TimetableDayFragment.kt @@ -108,7 +108,7 @@ class TimetableDayFragment : Fragment(), CoroutineScope { Log.d(TAG, "onViewCreated, date=$date") // observe lesson database - app.db.timetableDao().getForDate(App.profileId, date).observe(this, Observer> { lessons -> + app.db.timetableDao().getForDate(App.profileId, date).observe(this, Observer { lessons -> processLessonList(lessons) }) }