forked from github/szkolny
[Timetable] Add marking lessons as seen in timetable.
This commit is contained in:
parent
d1265dc1f2
commit
8482c27689
@ -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);
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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<List<LessonFull>> { lessons ->
|
||||
app.db.timetableDao().getForDate(App.profileId, date).observe(this, Observer { lessons ->
|
||||
processLessonList(lessons)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user