forked from github/szkolny
[Data] Refactor checking homework event type.
This commit is contained in:
parent
959168771b
commit
325efd8b14
@ -70,7 +70,7 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
|
|||||||
|
|
||||||
private fun eventNotifications() {
|
private fun eventNotifications() {
|
||||||
for (event in app.db.eventDao().getNotNotifiedNow().filter { it.date >= today }) {
|
for (event in app.db.eventDao().getNotNotifiedNow().filter { it.date >= today }) {
|
||||||
val text = if (event.type == Event.TYPE_HOMEWORK)
|
val text = if (event.isHomework)
|
||||||
app.getString(
|
app.getString(
|
||||||
if (event.subjectLongName.isNullOrEmpty())
|
if (event.subjectLongName.isNullOrEmpty())
|
||||||
R.string.notification_homework_no_subject_format
|
R.string.notification_homework_no_subject_format
|
||||||
@ -98,7 +98,7 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
|
|||||||
event.time?.stringHM ?: app.getString(R.string.event_all_day),
|
event.time?.stringHM ?: app.getString(R.string.event_all_day),
|
||||||
event.topic.take(200)
|
event.topic.take(200)
|
||||||
)
|
)
|
||||||
val type = if (event.type == Event.TYPE_HOMEWORK) Notification.TYPE_NEW_HOMEWORK else Notification.TYPE_NEW_EVENT
|
val type = if (event.isHomework) Notification.TYPE_NEW_HOMEWORK else Notification.TYPE_NEW_EVENT
|
||||||
notifications += Notification(
|
notifications += Notification(
|
||||||
id = Notification.buildId(event.profileId, type, event.id),
|
id = Notification.buildId(event.profileId, type, event.id),
|
||||||
title = app.getNotificationTitle(type),
|
title = app.getNotificationTitle(type),
|
||||||
@ -107,7 +107,7 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
|
|||||||
type = type,
|
type = type,
|
||||||
profileId = event.profileId,
|
profileId = event.profileId,
|
||||||
profileName = profiles.singleOrNull { it.id == event.profileId }?.name,
|
profileName = profiles.singleOrNull { it.id == event.profileId }?.name,
|
||||||
viewId = if (event.type == Event.TYPE_HOMEWORK) MainActivity.DRAWER_ITEM_HOMEWORK else MainActivity.DRAWER_ITEM_AGENDA,
|
viewId = if (event.isHomework) MainActivity.DRAWER_ITEM_HOMEWORK else MainActivity.DRAWER_ITEM_AGENDA,
|
||||||
addedDate = event.addedDate
|
addedDate = event.addedDate
|
||||||
).addExtra("eventId", event.id).addExtra("eventDate", event.date.value.toLong())
|
).addExtra("eventId", event.id).addExtra("eventDate", event.date.value.toLong())
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
|
|||||||
event.time?.stringHM ?: app.getString(R.string.event_all_day),
|
event.time?.stringHM ?: app.getString(R.string.event_all_day),
|
||||||
event.topic.take(200)
|
event.topic.take(200)
|
||||||
)
|
)
|
||||||
val type = if (event.type == Event.TYPE_HOMEWORK) Notification.TYPE_NEW_HOMEWORK else Notification.TYPE_NEW_EVENT
|
val type = if (event.isHomework) Notification.TYPE_NEW_HOMEWORK else Notification.TYPE_NEW_EVENT
|
||||||
notifications += Notification(
|
notifications += Notification(
|
||||||
id = Notification.buildId(event.profileId, type, event.id),
|
id = Notification.buildId(event.profileId, type, event.id),
|
||||||
title = app.getNotificationTitle(type),
|
title = app.getNotificationTitle(type),
|
||||||
@ -141,7 +141,7 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
|
|||||||
type = type,
|
type = type,
|
||||||
profileId = event.profileId,
|
profileId = event.profileId,
|
||||||
profileName = profiles.singleOrNull { it.id == event.profileId }?.name,
|
profileName = profiles.singleOrNull { it.id == event.profileId }?.name,
|
||||||
viewId = if (event.type == Event.TYPE_HOMEWORK) MainActivity.DRAWER_ITEM_HOMEWORK else MainActivity.DRAWER_ITEM_AGENDA,
|
viewId = if (event.isHomework) MainActivity.DRAWER_ITEM_HOMEWORK else MainActivity.DRAWER_ITEM_AGENDA,
|
||||||
addedDate = event.addedDate
|
addedDate = event.addedDate
|
||||||
).addExtra("eventId", event.id).addExtra("eventDate", event.date.value.toLong())
|
).addExtra("eventId", event.id).addExtra("eventDate", event.date.value.toLong())
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,15 @@
|
|||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.db.dao;
|
package pl.szczodrzynski.edziennik.data.db.dao;
|
||||||
|
|
||||||
|
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_ANNOUNCEMENT;
|
||||||
|
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_ATTENDANCE;
|
||||||
|
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_EVENT;
|
||||||
|
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_GRADE;
|
||||||
|
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_HOMEWORK;
|
||||||
|
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_LESSON_CHANGE;
|
||||||
|
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_MESSAGE;
|
||||||
|
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_NOTICE;
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.room.Dao;
|
import androidx.room.Dao;
|
||||||
import androidx.room.Insert;
|
import androidx.room.Insert;
|
||||||
@ -23,15 +32,6 @@ import pl.szczodrzynski.edziennik.data.db.entity.Notice;
|
|||||||
import pl.szczodrzynski.edziennik.data.db.full.LessonFull;
|
import pl.szczodrzynski.edziennik.data.db.full.LessonFull;
|
||||||
import pl.szczodrzynski.edziennik.utils.models.UnreadCounter;
|
import pl.szczodrzynski.edziennik.utils.models.UnreadCounter;
|
||||||
|
|
||||||
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_ANNOUNCEMENT;
|
|
||||||
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_ATTENDANCE;
|
|
||||||
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_EVENT;
|
|
||||||
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_GRADE;
|
|
||||||
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_HOMEWORK;
|
|
||||||
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_LESSON_CHANGE;
|
|
||||||
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_MESSAGE;
|
|
||||||
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_NOTICE;
|
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
public abstract class MetadataDao {
|
public abstract class MetadataDao {
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
@ -78,8 +78,8 @@ public abstract class MetadataDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (o instanceof Event) {
|
if (o instanceof Event) {
|
||||||
if (add(new Metadata(profileId, ((Event) o).getType() == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).getId(), seen, false)) == -1) {
|
if (add(new Metadata(profileId, ((Event) o).isHomework() ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).getId(), seen, false)) == -1) {
|
||||||
updateSeen(profileId, ((Event) o).getType() == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).getId(), seen);
|
updateSeen(profileId, ((Event) o).isHomework() ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).getId(), seen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (o instanceof LessonFull) {
|
if (o instanceof LessonFull) {
|
||||||
@ -117,8 +117,8 @@ public abstract class MetadataDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (o instanceof Event) {
|
if (o instanceof Event) {
|
||||||
if (add(new Metadata(profileId, ((Event) o).getType() == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).getId(), false, notified)) == -1) {
|
if (add(new Metadata(profileId, ((Event) o).isHomework() ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).getId(), false, notified)) == -1) {
|
||||||
updateNotified(profileId, ((Event) o).getType() == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).getId(), notified);
|
updateNotified(profileId, ((Event) o).isHomework() ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).getId(), notified);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (o instanceof LessonFull) {
|
if (o instanceof LessonFull) {
|
||||||
@ -141,9 +141,9 @@ public abstract class MetadataDao {
|
|||||||
@Transaction
|
@Transaction
|
||||||
public void setBoth(int profileId, Event o, boolean seen, boolean notified, long addedDate) {
|
public void setBoth(int profileId, Event o, boolean seen, boolean notified, long addedDate) {
|
||||||
if (o != null) {
|
if (o != null) {
|
||||||
if (add(new Metadata(profileId, o.getType() == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, o.getId(), seen, notified)) == -1) {
|
if (add(new Metadata(profileId, o.isHomework() ? TYPE_HOMEWORK : TYPE_EVENT, o.getId(), seen, notified)) == -1) {
|
||||||
updateSeen(profileId, o.getType() == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, o.getId(), seen);
|
updateSeen(profileId, o.isHomework() ? TYPE_HOMEWORK : TYPE_EVENT, o.getId(), seen);
|
||||||
updateNotified(profileId, o.getType() == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, o.getId(), notified);
|
updateNotified(profileId, o.isHomework() ? TYPE_HOMEWORK : TYPE_EVENT, o.getId(), notified);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,6 +123,9 @@ open class Event(
|
|||||||
it.timeInMillis += 45 * MINUTE * 1000
|
it.timeInMillis += 45 * MINUTE * 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val isHomework
|
||||||
|
get() = type == TYPE_HOMEWORK
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
fun withMetadata(metadata: Metadata) = EventFull(this, metadata)
|
fun withMetadata(metadata: Metadata) = EventFull(this, metadata)
|
||||||
}
|
}
|
||||||
|
@ -139,13 +139,13 @@ class SzkolnyAppFirebase(val app: App, val profiles: List<Profile>, val message:
|
|||||||
|
|
||||||
val metadata = Metadata(
|
val metadata = Metadata(
|
||||||
event.profileId,
|
event.profileId,
|
||||||
if (event.type == Event.TYPE_HOMEWORK) Metadata.TYPE_HOMEWORK else Metadata.TYPE_EVENT,
|
if (event.isHomework) Metadata.TYPE_HOMEWORK else Metadata.TYPE_EVENT,
|
||||||
event.id,
|
event.id,
|
||||||
false,
|
false,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
val type = if (event.type == Event.TYPE_HOMEWORK) Notification.TYPE_NEW_SHARED_HOMEWORK else Notification.TYPE_NEW_SHARED_EVENT
|
val type = if (event.isHomework) Notification.TYPE_NEW_SHARED_HOMEWORK else Notification.TYPE_NEW_SHARED_EVENT
|
||||||
val notificationFilter = app.config.getFor(event.profileId).sync.notificationFilter
|
val notificationFilter = app.config.getFor(event.profileId).sync.notificationFilter
|
||||||
|
|
||||||
if (!notificationFilter.contains(type)) {
|
if (!notificationFilter.contains(type)) {
|
||||||
@ -156,7 +156,7 @@ class SzkolnyAppFirebase(val app: App, val profiles: List<Profile>, val message:
|
|||||||
type = type,
|
type = type,
|
||||||
profileId = profile.id,
|
profileId = profile.id,
|
||||||
profileName = profile.name,
|
profileName = profile.name,
|
||||||
viewId = if (event.type == Event.TYPE_HOMEWORK) MainActivity.DRAWER_ITEM_HOMEWORK else MainActivity.DRAWER_ITEM_AGENDA,
|
viewId = if (event.isHomework) MainActivity.DRAWER_ITEM_HOMEWORK else MainActivity.DRAWER_ITEM_AGENDA,
|
||||||
addedDate = event.addedDate
|
addedDate = event.addedDate
|
||||||
).addExtra("eventId", event.id).addExtra("eventDate", event.date.value.toLong())
|
).addExtra("eventId", event.id).addExtra("eventDate", event.date.value.toLong())
|
||||||
notificationList += notification
|
notificationList += notification
|
||||||
|
@ -22,7 +22,6 @@ import pl.szczodrzynski.edziennik.*
|
|||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.EventGetEvent
|
import pl.szczodrzynski.edziennik.data.api.events.EventGetEvent
|
||||||
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||||
import pl.szczodrzynski.edziennik.databinding.DialogEventDetailsBinding
|
import pl.szczodrzynski.edziennik.databinding.DialogEventDetailsBinding
|
||||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment
|
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment
|
||||||
@ -227,7 +226,7 @@ class EventDetailsDialog(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.homeworkBody == null && !event.addedManually && event.type == Event.TYPE_HOMEWORK) {
|
if (!event.addedManually && event.isHomework && event.homeworkBody == null) {
|
||||||
b.bodyTitle.isVisible = true
|
b.bodyTitle.isVisible = true
|
||||||
b.bodyProgressBar.isVisible = true
|
b.bodyProgressBar.isVisible = true
|
||||||
b.body.isVisible = false
|
b.body.isVisible = false
|
||||||
|
@ -17,7 +17,6 @@ import kotlinx.coroutines.Job
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import pl.szczodrzynski.edziennik.*
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.config.Config
|
import pl.szczodrzynski.edziennik.config.Config
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
|
||||||
import pl.szczodrzynski.edziennik.databinding.LabFragmentBinding
|
import pl.szczodrzynski.edziennik.databinding.LabFragmentBinding
|
||||||
import pl.szczodrzynski.edziennik.ui.dialogs.profile.ProfileRemoveDialog
|
import pl.szczodrzynski.edziennik.ui.dialogs.profile.ProfileRemoveDialog
|
||||||
import pl.szczodrzynski.edziennik.ui.modules.base.lazypager.LazyFragment
|
import pl.szczodrzynski.edziennik.ui.modules.base.lazypager.LazyFragment
|
||||||
@ -55,7 +54,7 @@ class LabPageFragment : LazyFragment(), CoroutineScope {
|
|||||||
b.last10unseen.onClick {
|
b.last10unseen.onClick {
|
||||||
launch(Dispatchers.Default) {
|
launch(Dispatchers.Default) {
|
||||||
val events = app.db.eventDao().getAllNow(App.profileId)
|
val events = app.db.eventDao().getAllNow(App.profileId)
|
||||||
val ids = events.sortedBy { it.date }.filter { it.type == Event.TYPE_HOMEWORK }.takeLast(10)
|
val ids = events.sortedBy { it.date }.filter { it.isHomework }.takeLast(10)
|
||||||
ids.forEach {
|
ids.forEach {
|
||||||
app.db.metadataDao().setSeen(App.profileId, it, false)
|
app.db.metadataDao().setSeen(App.profileId, it, false)
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ import com.mikepenz.iconics.utils.colorInt
|
|||||||
import com.mikepenz.iconics.utils.sizeDp
|
import com.mikepenz.iconics.utils.sizeDp
|
||||||
import pl.szczodrzynski.edziennik.*
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_HOMEWORK
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Lesson
|
import pl.szczodrzynski.edziennik.data.db.entity.Lesson
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Lesson.Companion.TYPE_NO_LESSONS
|
import pl.szczodrzynski.edziennik.data.db.entity.Lesson.Companion.TYPE_NO_LESSONS
|
||||||
import pl.szczodrzynski.edziennik.ui.widgets.LessonDialogActivity
|
import pl.szczodrzynski.edziennik.ui.widgets.LessonDialogActivity
|
||||||
@ -355,7 +354,7 @@ class WidgetTimetableProvider : AppWidgetProvider() {
|
|||||||
for (event in events) {
|
for (event in events) {
|
||||||
if (event.time == null || event.time != lesson.displayStartTime)
|
if (event.time == null || event.time != lesson.displayStartTime)
|
||||||
continue
|
continue
|
||||||
model.eventColors.add(if (event.type == TYPE_HOMEWORK) ItemWidgetTimetableModel.EVENT_COLOR_HOMEWORK else event.eventColor)
|
model.eventColors.add(if (event.isHomework) ItemWidgetTimetableModel.EVENT_COLOR_HOMEWORK else event.eventColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
models += model
|
models += model
|
||||||
|
Loading…
Reference in New Issue
Block a user