mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 13:48:20 +01:00
[Refactor] Rewrite events to Kotlin.
This commit is contained in:
parent
0b1e7242bb
commit
ef4527f140
@ -39,17 +39,16 @@ class EdudziennikWebEvents(override val data: DataEdudziennik,
|
|||||||
?: return@forEach
|
?: return@forEach
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId = profileId,
|
||||||
id,
|
id = id,
|
||||||
date,
|
date = date,
|
||||||
null,
|
time = null,
|
||||||
title,
|
topic = title,
|
||||||
-1,
|
color = null,
|
||||||
Event.TYPE_CLASS_EVENT,
|
type = Event.TYPE_CLASS_EVENT,
|
||||||
false,
|
teacherId = -1,
|
||||||
-1,
|
subjectId = -1,
|
||||||
-1,
|
teamId = data.teamClass?.id ?: -1
|
||||||
data.teamClass?.id ?: -1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
|
@ -56,17 +56,16 @@ class EdudziennikWebExams(override val data: DataEdudziennik,
|
|||||||
val eventType = data.getEventType(eventTypeId, eventTypeName)
|
val eventType = data.getEventType(eventTypeId, eventTypeName)
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId = profileId,
|
||||||
id,
|
id = id,
|
||||||
date,
|
date = date,
|
||||||
startTime,
|
time = startTime,
|
||||||
topic,
|
topic = topic,
|
||||||
-1,
|
color = null,
|
||||||
eventType.id,
|
type = eventType.id,
|
||||||
false,
|
teacherId = -1,
|
||||||
-1,
|
subjectId = subject.id,
|
||||||
subject.id,
|
teamId = data.teamClass?.id ?: -1
|
||||||
data.teamClass?.id ?: -1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
|
@ -52,17 +52,16 @@ class EdudziennikWebHomework(override val data: DataEdudziennik,
|
|||||||
val topic = homeworkElement.child(4).text()
|
val topic = homeworkElement.child(4).text()
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId = profileId,
|
||||||
id,
|
id = id,
|
||||||
date,
|
date = date,
|
||||||
startTime,
|
time = startTime,
|
||||||
topic,
|
topic = topic,
|
||||||
-1,
|
color = null,
|
||||||
Event.TYPE_HOMEWORK,
|
type = Event.TYPE_HOMEWORK,
|
||||||
false,
|
teacherId = teacher.id,
|
||||||
teacher.id,
|
subjectId = subject.id,
|
||||||
subject.id,
|
teamId = data.teamClass?.id ?: -1
|
||||||
data.teamClass?.id ?: -1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
|
@ -80,17 +80,16 @@ class IdziennikWebExams(override val data: DataIdziennik,
|
|||||||
}
|
}
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId = profileId,
|
||||||
id,
|
id = id,
|
||||||
examDate,
|
date = examDate,
|
||||||
startTime,
|
time = startTime,
|
||||||
topic,
|
topic = topic,
|
||||||
-1,
|
color = null,
|
||||||
eventType,
|
type = eventType,
|
||||||
false,
|
teacherId = teacherId,
|
||||||
teacherId,
|
subjectId = subjectId,
|
||||||
subjectId,
|
teamId = data.teamClass?.id ?: -1
|
||||||
data.teamClass?.id ?: -1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
|
@ -67,17 +67,16 @@ class IdziennikWebHomework(override val data: DataIdziennik,
|
|||||||
|
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId = profileId,
|
||||||
id,
|
id = id,
|
||||||
eventDate,
|
date = eventDate,
|
||||||
startTime,
|
time = startTime,
|
||||||
topic,
|
topic = topic,
|
||||||
-1,
|
color = null,
|
||||||
Event.TYPE_HOMEWORK,
|
type = Event.TYPE_HOMEWORK,
|
||||||
false,
|
teacherId = teacherId,
|
||||||
teacherId,
|
subjectId = subjectId,
|
||||||
subjectId,
|
teamId = data.teamClass?.id ?: -1
|
||||||
data.teamClass?.id ?: -1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
|
@ -47,17 +47,16 @@ class LibrusApiEvents(override val data: DataLibrus,
|
|||||||
val addedDate = Date.fromIso(event.getString("AddDate"))
|
val addedDate = Date.fromIso(event.getString("AddDate"))
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId = profileId,
|
||||||
id,
|
id = id,
|
||||||
eventDate,
|
date = eventDate,
|
||||||
startTime,
|
time = startTime,
|
||||||
topic,
|
topic = topic,
|
||||||
-1,
|
color = null,
|
||||||
type,
|
type = type,
|
||||||
false,
|
teacherId = teacherId,
|
||||||
teacherId,
|
subjectId = subjectId,
|
||||||
subjectId,
|
teamId = teamId
|
||||||
teamId
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
|
@ -34,17 +34,16 @@ class LibrusApiHomework(override val data: DataLibrus,
|
|||||||
val addedDate = Date.fromY_m_d(homework.getString("Date"))
|
val addedDate = Date.fromY_m_d(homework.getString("Date"))
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId = profileId,
|
||||||
id,
|
id = id,
|
||||||
eventDate,
|
date = eventDate,
|
||||||
null,
|
time = null,
|
||||||
topic,
|
topic = topic,
|
||||||
-1,
|
color = null,
|
||||||
-1,
|
type = -1,
|
||||||
false,
|
teacherId = teacherId,
|
||||||
teacherId,
|
subjectId = -1,
|
||||||
-1,
|
teamId = -1
|
||||||
-1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
|
@ -39,17 +39,16 @@ class LibrusApiPtMeetings(override val data: DataLibrus,
|
|||||||
}
|
}
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId = profileId,
|
||||||
id,
|
id = id,
|
||||||
eventDate,
|
date = eventDate,
|
||||||
startTime,
|
time = startTime,
|
||||||
topic,
|
topic = topic,
|
||||||
-1,
|
color = null,
|
||||||
Event.TYPE_PT_MEETING,
|
type = Event.TYPE_PT_MEETING,
|
||||||
false,
|
teacherId = teacherId,
|
||||||
teacherId,
|
subjectId = -1,
|
||||||
-1,
|
teamId = data.teamClass?.id ?: -1
|
||||||
data.teamClass?.id ?: -1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
|
@ -89,17 +89,16 @@ class LibrusSynergiaHomework(override val data: DataLibrus,
|
|||||||
}
|
}
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId = profileId,
|
||||||
id,
|
id = id,
|
||||||
eventDate,
|
date = eventDate,
|
||||||
startTime,
|
time = startTime,
|
||||||
"$topic\n$description",
|
topic = "$topic\n$description",
|
||||||
-1,
|
color = null,
|
||||||
Event.TYPE_HOMEWORK,
|
type = Event.TYPE_HOMEWORK,
|
||||||
false,
|
teacherId = teacherId,
|
||||||
teacherId,
|
subjectId = subjectId,
|
||||||
subjectId,
|
teamId = data.teamClass?.id ?: -1
|
||||||
data.teamClass?.id ?: -1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
|
@ -51,17 +51,16 @@ class MobidziennikApiEvents(val data: DataMobidziennik, rows: List<String>) {
|
|||||||
|
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
data.profileId,
|
profileId = data.profileId,
|
||||||
id,
|
id = id,
|
||||||
eventDate,
|
date = eventDate,
|
||||||
startTime,
|
time = startTime,
|
||||||
topic,
|
topic = topic,
|
||||||
-1,
|
color = null,
|
||||||
type,
|
type = type,
|
||||||
false,
|
teacherId = teacherId,
|
||||||
teacherId,
|
subjectId = subjectId,
|
||||||
subjectId,
|
teamId = teamId)
|
||||||
teamId)
|
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
data.metadataList.add(
|
data.metadataList.add(
|
||||||
|
@ -31,17 +31,16 @@ class MobidziennikApiHomework(val data: DataMobidziennik, rows: List<String>) {
|
|||||||
val startTime = Time.fromYmdHm(cols[3])
|
val startTime = Time.fromYmdHm(cols[3])
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
data.profileId,
|
profileId = data.profileId,
|
||||||
id,
|
id = id,
|
||||||
eventDate,
|
date = eventDate,
|
||||||
startTime,
|
time = startTime,
|
||||||
topic,
|
topic = topic,
|
||||||
-1,
|
color = null,
|
||||||
Event.TYPE_HOMEWORK,
|
type = Event.TYPE_HOMEWORK,
|
||||||
false,
|
teacherId = teacherId,
|
||||||
teacherId,
|
subjectId = subjectId,
|
||||||
subjectId,
|
teamId = teamId)
|
||||||
teamId)
|
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
data.metadataList.add(
|
data.metadataList.add(
|
||||||
|
@ -61,26 +61,25 @@ class MobidziennikWebCalendar(override val data: DataMobidziennik,
|
|||||||
val title = event.getString("title")
|
val title = event.getString("title")
|
||||||
val comment = event.getString("comment")
|
val comment = event.getString("comment")
|
||||||
|
|
||||||
var topic = title
|
var topic = title ?: ""
|
||||||
if (title != comment) {
|
if (title != comment) {
|
||||||
topic += "\n" + comment
|
topic += "\n" + comment
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == -1L) {
|
if (id == -1L) {
|
||||||
id = crc16(topic?.toByteArray()).toLong()
|
id = crc16(topic.toByteArray()).toLong()
|
||||||
}
|
}
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId = profileId,
|
||||||
id,
|
id = id,
|
||||||
eventDate, null,
|
date = eventDate, time = null,
|
||||||
topic,
|
topic = topic,
|
||||||
-1,
|
color = null,
|
||||||
eventType,
|
type = eventType,
|
||||||
false,
|
teacherId = -1,
|
||||||
-1,
|
subjectId = -1,
|
||||||
-1,
|
teamId = data.teamClass?.id ?: -1
|
||||||
data.teamClass?.id ?: -1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
|
@ -72,17 +72,16 @@ class VulcanApiEvents(override val data: DataVulcan,
|
|||||||
val teamId = event.getLong("IdOddzial") ?: data.teamClass?.id ?: -1
|
val teamId = event.getLong("IdOddzial") ?: data.teamClass?.id ?: -1
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId = profileId,
|
||||||
id,
|
id = id,
|
||||||
eventDate,
|
date = eventDate,
|
||||||
startTime,
|
time = startTime,
|
||||||
topic,
|
topic = topic,
|
||||||
-1,
|
color = null,
|
||||||
type,
|
type = type,
|
||||||
false,
|
teacherId = teacherId,
|
||||||
teacherId,
|
subjectId = subjectId,
|
||||||
subjectId,
|
teamId = teamId
|
||||||
teamId
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
|
@ -196,6 +196,11 @@ class SzkolnyApi(val app: App) : CoroutineScope {
|
|||||||
// skip blacklisted events
|
// skip blacklisted events
|
||||||
if (event.id in blacklistedIds)
|
if (event.id in blacklistedIds)
|
||||||
return@forEach
|
return@forEach
|
||||||
|
|
||||||
|
// force nullable non-negative colors
|
||||||
|
if (event.color == -1)
|
||||||
|
event.color = null
|
||||||
|
|
||||||
// create the event for every matching team and profile
|
// create the event for every matching team and profile
|
||||||
teams.filter { it.code == event.teamCode }.onEach { team ->
|
teams.filter { it.code == event.teamCode }.onEach { team ->
|
||||||
val profile = profiles.firstOrNull { it.id == team.profileId } ?: return@onEach
|
val profile = profiles.firstOrNull { it.id == team.profileId } ?: return@onEach
|
||||||
|
@ -12,7 +12,8 @@ data class EventShareRequest (
|
|||||||
|
|
||||||
val action: String = "event",
|
val action: String = "event",
|
||||||
|
|
||||||
val sharedByName: String,
|
/* If null, the server shows an error */
|
||||||
|
val sharedByName: String?,
|
||||||
val shareTeamCode: String? = null,
|
val shareTeamCode: String? = null,
|
||||||
val unshareTeamCode: String? = null,
|
val unshareTeamCode: String? = null,
|
||||||
val requesterName: String? = null,
|
val requesterName: String? = null,
|
||||||
|
@ -34,7 +34,7 @@ class AppSync(val app: App, val notifications: MutableList<Notification>, val pr
|
|||||||
if (events.isNotEmpty()) {
|
if (events.isNotEmpty()) {
|
||||||
val today = Date.getToday()
|
val today = Date.getToday()
|
||||||
app.db.metadataDao().addAllIgnore(events.map { event ->
|
app.db.metadataDao().addAllIgnore(events.map { event ->
|
||||||
val isPast = event.eventDate < today
|
val isPast = event.date < today
|
||||||
Metadata(
|
Metadata(
|
||||||
event.profileId,
|
event.profileId,
|
||||||
Metadata.TYPE_EVENT,
|
Metadata.TYPE_EVENT,
|
||||||
|
@ -58,7 +58,7 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun eventNotifications() {
|
private fun eventNotifications() {
|
||||||
for (event in app.db.eventDao().notNotifiedNow.filter { it.eventDate >= today }) {
|
for (event in app.db.eventDao().notNotifiedNow.filter { it.date >= today }) {
|
||||||
val text = if (event.type == Event.TYPE_HOMEWORK)
|
val text = if (event.type == Event.TYPE_HOMEWORK)
|
||||||
app.getString(
|
app.getString(
|
||||||
if (event.subjectLongName.isNullOrEmpty())
|
if (event.subjectLongName.isNullOrEmpty())
|
||||||
@ -66,7 +66,7 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
|
|||||||
else
|
else
|
||||||
R.string.notification_homework_format,
|
R.string.notification_homework_format,
|
||||||
event.subjectLongName,
|
event.subjectLongName,
|
||||||
event.eventDate.formattedString
|
event.date.formattedString
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
app.getString(
|
app.getString(
|
||||||
@ -74,8 +74,8 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
|
|||||||
R.string.notification_event_no_subject_format
|
R.string.notification_event_no_subject_format
|
||||||
else
|
else
|
||||||
R.string.notification_event_format,
|
R.string.notification_event_format,
|
||||||
event.typeName,
|
event.typeName ?: "wydarzenie",
|
||||||
event.eventDate.formattedString,
|
event.date.formattedString,
|
||||||
event.subjectLongName
|
event.subjectLongName
|
||||||
)
|
)
|
||||||
val type = if (event.type == Event.TYPE_HOMEWORK) Notification.TYPE_NEW_HOMEWORK else Notification.TYPE_NEW_EVENT
|
val type = if (event.type == Event.TYPE_HOMEWORK) Notification.TYPE_NEW_HOMEWORK else Notification.TYPE_NEW_EVENT
|
||||||
@ -88,17 +88,17 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
|
|||||||
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.type == Event.TYPE_HOMEWORK) MainActivity.DRAWER_ITEM_HOMEWORK else MainActivity.DRAWER_ITEM_AGENDA,
|
||||||
addedDate = event.addedDate
|
addedDate = event.addedDate
|
||||||
).addExtra("eventId", event.id).addExtra("eventDate", event.eventDate.value.toLong())
|
).addExtra("eventId", event.id).addExtra("eventDate", event.date.value.toLong())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sharedEventNotifications() {
|
fun sharedEventNotifications() {
|
||||||
for (event in app.db.eventDao().notNotifiedNow.filter { it.eventDate >= today && it.sharedBy != null }) {
|
for (event in app.db.eventDao().notNotifiedNow.filter { it.date >= today && it.sharedBy != null }) {
|
||||||
val text = app.getString(
|
val text = app.getString(
|
||||||
R.string.notification_shared_event_format,
|
R.string.notification_shared_event_format,
|
||||||
event.sharedByName,
|
event.sharedByName,
|
||||||
event.typeName ?: "wydarzenie",
|
event.typeName ?: "wydarzenie",
|
||||||
event.eventDate.formattedString,
|
event.date.formattedString,
|
||||||
event.topic
|
event.topic
|
||||||
)
|
)
|
||||||
val type = if (event.type == Event.TYPE_HOMEWORK) Notification.TYPE_NEW_HOMEWORK else Notification.TYPE_NEW_EVENT
|
val type = if (event.type == Event.TYPE_HOMEWORK) Notification.TYPE_NEW_HOMEWORK else Notification.TYPE_NEW_EVENT
|
||||||
@ -111,7 +111,7 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
|
|||||||
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.type == Event.TYPE_HOMEWORK) MainActivity.DRAWER_ITEM_HOMEWORK else MainActivity.DRAWER_ITEM_AGENDA,
|
||||||
addedDate = event.addedDate
|
addedDate = event.addedDate
|
||||||
).addExtra("eventId", event.id).addExtra("eventDate", event.eventDate.value.toLong())
|
).addExtra("eventId", event.id).addExtra("eventDate", event.date.value.toLong())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ import pl.szczodrzynski.edziennik.data.db.migration.*
|
|||||||
LibrusLesson::class,
|
LibrusLesson::class,
|
||||||
TimetableManual::class,
|
TimetableManual::class,
|
||||||
Metadata::class
|
Metadata::class
|
||||||
], version = 79)
|
], version = 80)
|
||||||
@TypeConverters(
|
@TypeConverters(
|
||||||
ConverterTime::class,
|
ConverterTime::class,
|
||||||
ConverterDate::class,
|
ConverterDate::class,
|
||||||
@ -164,7 +164,8 @@ abstract class AppDb : RoomDatabase() {
|
|||||||
Migration76(),
|
Migration76(),
|
||||||
Migration77(),
|
Migration77(),
|
||||||
Migration78(),
|
Migration78(),
|
||||||
Migration79()
|
Migration79(),
|
||||||
|
Migration80()
|
||||||
).allowMainThreadQueries().build()
|
).allowMainThreadQueries().build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,186 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kacper Ziubryniewicz 2020-1-6
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.db.dao;
|
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.room.Dao;
|
|
||||||
import androidx.room.Insert;
|
|
||||||
import androidx.room.OnConflictStrategy;
|
|
||||||
import androidx.room.Query;
|
|
||||||
import androidx.room.RawQuery;
|
|
||||||
import androidx.room.Transaction;
|
|
||||||
import androidx.sqlite.db.SimpleSQLiteQuery;
|
|
||||||
import androidx.sqlite.db.SupportSQLiteQuery;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Event;
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull;
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
|
||||||
|
|
||||||
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_EVENT;
|
|
||||||
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_HOMEWORK;
|
|
||||||
import static pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_LESSON_CHANGE;
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
public abstract class EventDao {
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
public abstract long add(Event event);
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
public abstract long[] addAll(List<Event> eventList);
|
|
||||||
|
|
||||||
@Query("DELETE FROM events WHERE profileId = :profileId")
|
|
||||||
public abstract void clear(int profileId);
|
|
||||||
|
|
||||||
@Query("DELETE FROM events WHERE profileId = :profileId AND eventId = :id")
|
|
||||||
public abstract void remove(int profileId, long id);
|
|
||||||
@Query("DELETE FROM metadata WHERE profileId = :profileId AND thingType = :thingType AND thingId = :thingId")
|
|
||||||
public abstract void removeMetadata(int profileId, int thingType, long thingId);
|
|
||||||
@Transaction
|
|
||||||
public void remove(int profileId, long type, long id) {
|
|
||||||
remove(profileId, id);
|
|
||||||
removeMetadata(profileId, type == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, id);
|
|
||||||
}
|
|
||||||
@Transaction
|
|
||||||
public void remove(Event event) {
|
|
||||||
remove(event.profileId, event.type, event.id);
|
|
||||||
}
|
|
||||||
@Transaction
|
|
||||||
public void remove(int profileId, Event event) {
|
|
||||||
remove(profileId, event.type, event.id);
|
|
||||||
}
|
|
||||||
@Query("DELETE FROM events WHERE teamId = :teamId AND eventId = :id")
|
|
||||||
public abstract void removeByTeamId(long teamId, long id);
|
|
||||||
|
|
||||||
@RawQuery(observedEntities = {Event.class})
|
|
||||||
abstract LiveData<List<EventFull>> getAll(SupportSQLiteQuery query);
|
|
||||||
public LiveData<List<EventFull>> getAll(int profileId, String filter, String limit) {
|
|
||||||
String query = "SELECT \n" +
|
|
||||||
"*, \n" +
|
|
||||||
"teachers.teacherName || ' ' || teachers.teacherSurname AS teacherFullName,\n" +
|
|
||||||
"eventTypes.eventTypeName AS typeName,\n" +
|
|
||||||
"eventTypes.eventTypeColor AS typeColor\n" +
|
|
||||||
"FROM events\n" +
|
|
||||||
"LEFT JOIN subjects USING(profileId, subjectId)\n" +
|
|
||||||
"LEFT JOIN teachers USING(profileId, teacherId)\n" +
|
|
||||||
"LEFT JOIN teams USING(profileId, teamId)\n" +
|
|
||||||
"LEFT JOIN eventTypes USING(profileId, eventType)\n" +
|
|
||||||
"LEFT JOIN metadata ON eventId = thingId AND (thingType = " + TYPE_EVENT + " OR thingType = " + TYPE_HOMEWORK + ") AND metadata.profileId = "+profileId+"\n" +
|
|
||||||
"WHERE events.profileId = "+profileId+" AND events.eventBlacklisted = 0 AND "+filter+"\n" +
|
|
||||||
"GROUP BY eventId\n" +
|
|
||||||
"ORDER BY eventDate, eventStartTime ASC "+limit;
|
|
||||||
Log.d("DB", query);
|
|
||||||
return getAll(new SimpleSQLiteQuery(query));
|
|
||||||
}
|
|
||||||
public LiveData<List<EventFull>> getAll(int profileId) {
|
|
||||||
return getAll(profileId, "1", "");
|
|
||||||
}
|
|
||||||
public List<EventFull> getAllNow(int profileId) {
|
|
||||||
return getAllNow(profileId, "1");
|
|
||||||
}
|
|
||||||
public LiveData<List<EventFull>> getAllWhere(int profileId, String filter) {
|
|
||||||
return getAll(profileId, filter, "");
|
|
||||||
}
|
|
||||||
public LiveData<List<EventFull>> getAllByType(int profileId, long type, String filter) {
|
|
||||||
return getAll(profileId, "eventType = "+type+" AND "+filter, "");
|
|
||||||
}
|
|
||||||
public LiveData<List<EventFull>> getAllByDate(int profileId, @NonNull Date date) {
|
|
||||||
return getAll(profileId, "eventDate = '"+date.getStringY_m_d()+"'", "");
|
|
||||||
}
|
|
||||||
public List<EventFull> getAllByDateNow(int profileId, @NonNull Date date) {
|
|
||||||
return getAllNow(profileId, "eventDate = '"+date.getStringY_m_d()+"'");
|
|
||||||
}
|
|
||||||
public LiveData<List<EventFull>> getAllByDateTime(int profileId, @NonNull Date date, Time time) {
|
|
||||||
if (time == null)
|
|
||||||
return getAllByDate(profileId, date);
|
|
||||||
return getAll(profileId, "eventDate = '"+date.getStringY_m_d()+"' AND eventStartTime = '"+time.getStringValue()+"'", "");
|
|
||||||
}
|
|
||||||
public LiveData<List<EventFull>> getAllNearest(int profileId, @NonNull Date today, int limit) {
|
|
||||||
return getAll(profileId, "eventDate >= '"+today.getStringY_m_d()+"'", "LIMIT "+limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
@RawQuery
|
|
||||||
abstract List<EventFull> getAllNow(SupportSQLiteQuery query);
|
|
||||||
public List<EventFull> getAllNow(int profileId, String filter) {
|
|
||||||
return getAllNow(new SimpleSQLiteQuery("SELECT \n" +
|
|
||||||
"*, \n" +
|
|
||||||
"teachers.teacherName || ' ' || teachers.teacherSurname AS teacherFullName,\n" +
|
|
||||||
"eventTypes.eventTypeName AS typeName,\n" +
|
|
||||||
"eventTypes.eventTypeColor AS typeColor\n" +
|
|
||||||
"FROM events \n" +
|
|
||||||
"LEFT JOIN subjects USING(profileId, subjectId)\n" +
|
|
||||||
"LEFT JOIN teachers USING(profileId, teacherId)\n" +
|
|
||||||
"LEFT JOIN teams USING(profileId, teamId)\n" +
|
|
||||||
"LEFT JOIN eventTypes USING(profileId, eventType)\n" +
|
|
||||||
"LEFT JOIN metadata ON eventId = thingId AND (thingType = " + TYPE_EVENT + " OR thingType = " + TYPE_HOMEWORK + ") AND metadata.profileId = "+profileId+"\n" +
|
|
||||||
"WHERE events.profileId = "+profileId+" AND events.eventBlacklisted = 0 AND "+filter+"\n" +
|
|
||||||
"GROUP BY eventId\n" +
|
|
||||||
"ORDER BY eventStartTime, addedDate ASC"));
|
|
||||||
}
|
|
||||||
public List<EventFull> getNotNotifiedNow(int profileId) {
|
|
||||||
return getAllNow(profileId, "notified = 0");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Query("SELECT eventId FROM events WHERE profileId = :profileId AND eventBlacklisted = 1")
|
|
||||||
public abstract List<Long> getBlacklistedIds(int profileId);
|
|
||||||
@Query("SELECT eventId FROM events WHERE eventBlacklisted = 1")
|
|
||||||
public abstract List<Long> getBlacklistedIds();
|
|
||||||
|
|
||||||
@Query("SELECT " +
|
|
||||||
"*, " +
|
|
||||||
"eventTypes.eventTypeName AS typeName, " +
|
|
||||||
"eventTypes.eventTypeColor AS typeColor " +
|
|
||||||
"FROM events " +
|
|
||||||
"LEFT JOIN subjects USING(profileId, subjectId) " +
|
|
||||||
"LEFT JOIN eventTypes USING(profileId, eventType) " +
|
|
||||||
"LEFT JOIN metadata ON eventId = thingId AND (thingType = " + TYPE_EVENT + " OR thingType = " + TYPE_HOMEWORK + ") AND metadata.profileId = events.profileId " +
|
|
||||||
"WHERE events.eventBlacklisted = 0 AND notified = 0 " +
|
|
||||||
"GROUP BY eventId " +
|
|
||||||
"ORDER BY addedDate ASC")
|
|
||||||
public abstract List<EventFull> getNotNotifiedNow();
|
|
||||||
|
|
||||||
public EventFull getByIdNow(int profileId, long eventId) {
|
|
||||||
List<EventFull> eventList = getAllNow(profileId, "eventId = "+eventId);
|
|
||||||
return eventList.size() == 0 ? null : eventList.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Query("UPDATE events SET eventAddedManually = 1 WHERE profileId = :profileId AND eventDate < :date")
|
|
||||||
public abstract void convertOlderToManual(int profileId, Date date);
|
|
||||||
|
|
||||||
@Query("DELETE FROM events WHERE profileId = :profileId AND eventAddedManually = 0")
|
|
||||||
public abstract void removeNotManual(int profileId);
|
|
||||||
|
|
||||||
@RawQuery
|
|
||||||
abstract long removeFuture(SupportSQLiteQuery query);
|
|
||||||
@Transaction
|
|
||||||
public void removeFuture(int profileId, Date todayDate, String filter) {
|
|
||||||
removeFuture(new SimpleSQLiteQuery("DELETE FROM events WHERE profileId = " + profileId
|
|
||||||
+ " AND eventAddedManually = 0 AND eventDate >= '" + todayDate.getStringY_m_d() + "'" +
|
|
||||||
" AND " + filter));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Query("DELETE FROM events WHERE profileId = :profileId AND eventAddedManually = 0 AND eventDate >= :todayDate AND eventType = :type")
|
|
||||||
public abstract void removeFutureWithType(int profileId, Date todayDate, long type);
|
|
||||||
|
|
||||||
@Query("DELETE FROM events WHERE profileId = :profileId AND eventAddedManually = 0 AND eventDate >= :todayDate AND eventType != :exceptType")
|
|
||||||
public abstract void removeFutureExceptType(int profileId, Date todayDate, long exceptType);
|
|
||||||
|
|
||||||
@Transaction
|
|
||||||
public void removeFutureExceptTypes(int profileId, Date todayDate, List<Long> exceptTypes) {
|
|
||||||
removeFuture(profileId, todayDate, "eventType NOT IN " + exceptTypes.toString().replace('[', '(').replace(']', ')'));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Query("UPDATE metadata SET seen = :seen WHERE profileId = :profileId AND (thingType = "+TYPE_EVENT+" OR thingType = "+TYPE_LESSON_CHANGE+" OR thingType = "+TYPE_HOMEWORK+") AND thingId IN (SELECT eventId FROM events WHERE profileId = :profileId AND eventDate = :date)")
|
|
||||||
public abstract void setSeenByDate(int profileId, Date date, boolean seen);
|
|
||||||
|
|
||||||
@Query("UPDATE events SET eventBlacklisted = :blacklisted WHERE profileId = :profileId AND eventId = :eventId")
|
|
||||||
public abstract void setBlacklisted(int profileId, long eventId, boolean blacklisted);
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,184 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2020-1-6
|
||||||
|
*/
|
||||||
|
package pl.szczodrzynski.edziennik.data.db.dao
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.room.*
|
||||||
|
import androidx.sqlite.db.SimpleSQLiteQuery
|
||||||
|
import androidx.sqlite.db.SupportSQLiteQuery
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
abstract class EventDao {
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
abstract fun add(event: Event): Long
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
abstract fun addAll(eventList: List<Event>): LongArray
|
||||||
|
|
||||||
|
@Query("DELETE FROM events WHERE profileId = :profileId")
|
||||||
|
abstract fun clear(profileId: Int)
|
||||||
|
|
||||||
|
@Query("DELETE FROM events WHERE profileId = :profileId AND eventId = :id")
|
||||||
|
abstract fun remove(profileId: Int, id: Long)
|
||||||
|
|
||||||
|
@Query("DELETE FROM metadata WHERE profileId = :profileId AND thingType = :thingType AND thingId = :thingId")
|
||||||
|
abstract fun removeMetadata(profileId: Int, thingType: Int, thingId: Long)
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
open fun remove(profileId: Int, type: Long, id: Long) {
|
||||||
|
remove(profileId, id)
|
||||||
|
removeMetadata(profileId, if (type == Event.TYPE_HOMEWORK) Metadata.TYPE_HOMEWORK else Metadata.TYPE_EVENT, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
open fun remove(event: Event) {
|
||||||
|
remove(event.profileId, event.type, event.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
open fun remove(profileId: Int, event: Event) {
|
||||||
|
remove(profileId, event.type, event.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query("DELETE FROM events WHERE teamId = :teamId AND eventId = :id")
|
||||||
|
abstract fun removeByTeamId(teamId: Long, id: Long)
|
||||||
|
|
||||||
|
@RawQuery(observedEntities = [Event::class])
|
||||||
|
abstract fun getAll(query: SupportSQLiteQuery): LiveData<List<EventFull>>
|
||||||
|
|
||||||
|
fun getAll(profileId: Int, filter: String, limit: String): LiveData<List<EventFull>> {
|
||||||
|
return getAll(SimpleSQLiteQuery("SELECT \n" +
|
||||||
|
"*, \n" +
|
||||||
|
"teachers.teacherName || ' ' || teachers.teacherSurname AS teacherFullName,\n" +
|
||||||
|
"eventTypes.eventTypeName AS typeName,\n" +
|
||||||
|
"eventTypes.eventTypeColor AS typeColor\n" +
|
||||||
|
"FROM events\n" +
|
||||||
|
"LEFT JOIN subjects USING(profileId, subjectId)\n" +
|
||||||
|
"LEFT JOIN teachers USING(profileId, teacherId)\n" +
|
||||||
|
"LEFT JOIN teams USING(profileId, teamId)\n" +
|
||||||
|
"LEFT JOIN eventTypes USING(profileId, eventType)\n" +
|
||||||
|
"LEFT JOIN metadata ON eventId = thingId AND (thingType = " + Metadata.TYPE_EVENT + " OR thingType = " + Metadata.TYPE_HOMEWORK + ") AND metadata.profileId = " + profileId + "\n" +
|
||||||
|
"WHERE events.profileId = " + profileId + " AND events.eventBlacklisted = 0 AND " + filter + "\n" +
|
||||||
|
"GROUP BY eventId\n" +
|
||||||
|
"ORDER BY eventDate, eventTime ASC " + limit))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAll(profileId: Int): LiveData<List<EventFull>> {
|
||||||
|
return getAll(profileId, "1", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAllNow(profileId: Int): List<EventFull> {
|
||||||
|
return getAllNow(profileId, "1")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAllWhere(profileId: Int, filter: String): LiveData<List<EventFull>> {
|
||||||
|
return getAll(profileId, filter, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAllByType(profileId: Int, type: Long, filter: String): LiveData<List<EventFull>> {
|
||||||
|
return getAll(profileId, "eventType = $type AND $filter", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAllByDate(profileId: Int, date: Date): LiveData<List<EventFull>> {
|
||||||
|
return getAll(profileId, "eventDate = '" + date.stringY_m_d + "'", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAllByDateNow(profileId: Int, date: Date): List<EventFull> {
|
||||||
|
return getAllNow(profileId, "eventDate = '" + date.stringY_m_d + "'")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAllByDateTime(profileId: Int, date: Date, time: Time?): LiveData<List<EventFull>> {
|
||||||
|
return if (time == null) getAllByDate(profileId, date) else getAll(profileId, "eventDate = '" + date.stringY_m_d + "' AND eventTime = '" + time.stringValue + "'", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAllNearest(profileId: Int, today: Date, limit: Int): LiveData<List<EventFull>> {
|
||||||
|
return getAll(profileId, "eventDate >= '" + today.stringY_m_d + "'", "LIMIT $limit")
|
||||||
|
}
|
||||||
|
|
||||||
|
@RawQuery
|
||||||
|
abstract fun getAllNow(query: SupportSQLiteQuery): List<EventFull>
|
||||||
|
|
||||||
|
fun getAllNow(profileId: Int, filter: String): List<EventFull> {
|
||||||
|
return getAllNow(SimpleSQLiteQuery("SELECT \n" +
|
||||||
|
"*, \n" +
|
||||||
|
"teachers.teacherName || ' ' || teachers.teacherSurname AS teacherFullName,\n" +
|
||||||
|
"eventTypes.eventTypeName AS typeName,\n" +
|
||||||
|
"eventTypes.eventTypeColor AS typeColor\n" +
|
||||||
|
"FROM events \n" +
|
||||||
|
"LEFT JOIN subjects USING(profileId, subjectId)\n" +
|
||||||
|
"LEFT JOIN teachers USING(profileId, teacherId)\n" +
|
||||||
|
"LEFT JOIN teams USING(profileId, teamId)\n" +
|
||||||
|
"LEFT JOIN eventTypes USING(profileId, eventType)\n" +
|
||||||
|
"LEFT JOIN metadata ON eventId = thingId AND (thingType = " + Metadata.TYPE_EVENT + " OR thingType = " + Metadata.TYPE_HOMEWORK + ") AND metadata.profileId = " + profileId + "\n" +
|
||||||
|
"WHERE events.profileId = " + profileId + " AND events.eventBlacklisted = 0 AND " + filter + "\n" +
|
||||||
|
"GROUP BY eventId\n" +
|
||||||
|
"ORDER BY eventTime, addedDate ASC"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getNotNotifiedNow(profileId: Int): List<EventFull> {
|
||||||
|
return getAllNow(profileId, "notified = 0")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query("SELECT eventId FROM events WHERE profileId = :profileId AND eventBlacklisted = 1")
|
||||||
|
abstract fun getBlacklistedIds(profileId: Int): List<Long>
|
||||||
|
|
||||||
|
@get:Query("SELECT eventId FROM events WHERE eventBlacklisted = 1")
|
||||||
|
abstract val blacklistedIds: List<Long>
|
||||||
|
|
||||||
|
@get:Query("SELECT " +
|
||||||
|
"*, " +
|
||||||
|
"eventTypes.eventTypeName AS typeName, " +
|
||||||
|
"eventTypes.eventTypeColor AS typeColor " +
|
||||||
|
"FROM events " +
|
||||||
|
"LEFT JOIN subjects USING(profileId, subjectId) " +
|
||||||
|
"LEFT JOIN eventTypes USING(profileId, eventType) " +
|
||||||
|
"LEFT JOIN metadata ON eventId = thingId AND (thingType = " + Metadata.TYPE_EVENT + " OR thingType = " + Metadata.TYPE_HOMEWORK + ") AND metadata.profileId = events.profileId " +
|
||||||
|
"WHERE events.eventBlacklisted = 0 AND notified = 0 " +
|
||||||
|
"GROUP BY eventId " +
|
||||||
|
"ORDER BY addedDate ASC")
|
||||||
|
abstract val notNotifiedNow: List<EventFull>
|
||||||
|
|
||||||
|
fun getByIdNow(profileId: Int, eventId: Long): EventFull? {
|
||||||
|
val eventList = getAllNow(profileId, "eventId = $eventId")
|
||||||
|
return if (eventList.isEmpty()) null else eventList[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query("UPDATE events SET eventAddedManually = 1 WHERE profileId = :profileId AND eventDate < :date")
|
||||||
|
abstract fun convertOlderToManual(profileId: Int, date: Date?)
|
||||||
|
|
||||||
|
@Query("DELETE FROM events WHERE profileId = :profileId AND eventAddedManually = 0")
|
||||||
|
abstract fun removeNotManual(profileId: Int)
|
||||||
|
|
||||||
|
@RawQuery
|
||||||
|
abstract fun removeFuture(query: SupportSQLiteQuery?): Long
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
open fun removeFuture(profileId: Int, todayDate: Date, filter: String) {
|
||||||
|
removeFuture(SimpleSQLiteQuery("DELETE FROM events WHERE profileId = " + profileId
|
||||||
|
+ " AND eventAddedManually = 0 AND eventDate >= '" + todayDate.stringY_m_d + "'" +
|
||||||
|
" AND " + filter))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query("DELETE FROM events WHERE profileId = :profileId AND eventAddedManually = 0 AND eventDate >= :todayDate AND eventType = :type")
|
||||||
|
abstract fun removeFutureWithType(profileId: Int, todayDate: Date, type: Long)
|
||||||
|
|
||||||
|
@Query("DELETE FROM events WHERE profileId = :profileId AND eventAddedManually = 0 AND eventDate >= :todayDate AND eventType != :exceptType")
|
||||||
|
abstract fun removeFutureExceptType(profileId: Int, todayDate: Date, exceptType: Long)
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
open fun removeFutureExceptTypes(profileId: Int, todayDate: Date, exceptTypes: List<Long>) {
|
||||||
|
removeFuture(profileId, todayDate, "eventType NOT IN " + exceptTypes.toString().replace('[', '(').replace(']', ')'))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query("UPDATE metadata SET seen = :seen WHERE profileId = :profileId AND (thingType = " + Metadata.TYPE_EVENT + " OR thingType = " + Metadata.TYPE_LESSON_CHANGE + " OR thingType = " + Metadata.TYPE_HOMEWORK + ") AND thingId IN (SELECT eventId FROM events WHERE profileId = :profileId AND eventDate = :date)")
|
||||||
|
abstract fun setSeenByDate(profileId: Int, date: Date, seen: Boolean)
|
||||||
|
|
||||||
|
@Query("UPDATE events SET eventBlacklisted = :blacklisted WHERE profileId = :profileId AND eventId = :eventId")
|
||||||
|
abstract fun setBlacklisted(profileId: Int, eventId: Long, blacklisted: Boolean)
|
||||||
|
}
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kacper Ziubryniewicz 2020-1-6
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.db.dao;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.room.Dao;
|
|
||||||
import androidx.room.Insert;
|
|
||||||
import androidx.room.OnConflictStrategy;
|
|
||||||
import androidx.room.Query;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.EventType;
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
public interface EventTypeDao {
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
void add(EventType gradeCategory);
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
void addAll(List<EventType> gradeCategoryList);
|
|
||||||
|
|
||||||
@Query("DELETE FROM eventTypes WHERE profileId = :profileId")
|
|
||||||
void clear(int profileId);
|
|
||||||
|
|
||||||
@Query("SELECT * FROM eventTypes WHERE profileId = :profileId AND eventType = :typeId")
|
|
||||||
EventType getByIdNow(int profileId, long typeId);
|
|
||||||
|
|
||||||
@Query("SELECT * FROM eventTypes WHERE profileId = :profileId")
|
|
||||||
LiveData<List<EventType>> getAll(int profileId);
|
|
||||||
|
|
||||||
@Query("SELECT * FROM eventTypes WHERE profileId = :profileId")
|
|
||||||
List<EventType> getAllNow(int profileId);
|
|
||||||
|
|
||||||
@Query("SELECT * FROM eventTypes")
|
|
||||||
List<EventType> getAllNow();
|
|
||||||
}
|
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2020-1-6
|
||||||
|
*/
|
||||||
|
package pl.szczodrzynski.edziennik.data.db.dao
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
import pl.szczodrzynski.edziennik.R
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_CLASS_EVENT
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_DEFAULT
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_ESSAY
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_EXAM
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_EXCURSION
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_HOMEWORK
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_INFORMATION
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_PROJECT
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_PT_MEETING
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_READING
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.COLOR_SHORT_QUIZ
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_CLASS_EVENT
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_DEFAULT
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_ESSAY
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_EXAM
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_EXCURSION
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_HOMEWORK
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_INFORMATION
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_PROJECT
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_PT_MEETING
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_READING
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event.Companion.TYPE_SHORT_QUIZ
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.EventType
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
abstract class EventTypeDao {
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
abstract fun add(eventType: EventType)
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
abstract fun addAll(eventTypeList: List<EventType>)
|
||||||
|
|
||||||
|
@Query("DELETE FROM eventTypes WHERE profileId = :profileId")
|
||||||
|
abstract fun clear(profileId: Int)
|
||||||
|
|
||||||
|
@Query("SELECT * FROM eventTypes WHERE profileId = :profileId AND eventType = :typeId")
|
||||||
|
abstract fun getByIdNow(profileId: Int, typeId: Long): EventType?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM eventTypes WHERE profileId = :profileId")
|
||||||
|
abstract fun getAll(profileId: Int): LiveData<List<EventType>>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM eventTypes WHERE profileId = :profileId")
|
||||||
|
abstract fun getAllNow(profileId: Int): List<EventType>
|
||||||
|
|
||||||
|
@get:Query("SELECT * FROM eventTypes")
|
||||||
|
abstract val allNow: List<EventType>
|
||||||
|
|
||||||
|
fun addDefaultTypes(context: Context, profileId: Int): List<EventType> {
|
||||||
|
val typeList = listOf(
|
||||||
|
EventType(profileId, TYPE_HOMEWORK, context.getString(R.string.event_type_homework), COLOR_HOMEWORK),
|
||||||
|
EventType(profileId, TYPE_DEFAULT, context.getString(R.string.event_other), COLOR_DEFAULT),
|
||||||
|
EventType(profileId, TYPE_EXAM, context.getString(R.string.event_exam), COLOR_EXAM),
|
||||||
|
EventType(profileId, TYPE_SHORT_QUIZ, context.getString(R.string.event_short_quiz), COLOR_SHORT_QUIZ),
|
||||||
|
EventType(profileId, TYPE_ESSAY, context.getString(R.string.event_essay), COLOR_ESSAY),
|
||||||
|
EventType(profileId, TYPE_PROJECT, context.getString(R.string.event_project), COLOR_PROJECT),
|
||||||
|
EventType(profileId, TYPE_PT_MEETING, context.getString(R.string.event_pt_meeting), COLOR_PT_MEETING),
|
||||||
|
EventType(profileId, TYPE_EXCURSION, context.getString(R.string.event_excursion), COLOR_EXCURSION),
|
||||||
|
EventType(profileId, TYPE_READING, context.getString(R.string.event_reading), COLOR_READING),
|
||||||
|
EventType(profileId, TYPE_CLASS_EVENT, context.getString(R.string.event_class_event), COLOR_CLASS_EVENT),
|
||||||
|
EventType(profileId, TYPE_INFORMATION, context.getString(R.string.event_information), COLOR_INFORMATION)
|
||||||
|
)
|
||||||
|
addAll(typeList)
|
||||||
|
return typeList
|
||||||
|
}
|
||||||
|
}
|
@ -78,8 +78,8 @@ public abstract class MetadataDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (o instanceof Event) {
|
if (o instanceof Event) {
|
||||||
if (add(new Metadata(profileId, ((Event) o).type == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).id, seen, false, 0)) == -1) {
|
if (add(new Metadata(profileId, ((Event) o).getType() == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).getId(), seen, false, 0)) == -1) {
|
||||||
updateSeen(profileId, ((Event) o).type == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).id, seen);
|
updateSeen(profileId, ((Event) o).getType() == Event.TYPE_HOMEWORK ? 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).type == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).id, false, notified, 0)) == -1) {
|
if (add(new Metadata(profileId, ((Event) o).getType() == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).getId(), false, notified, 0)) == -1) {
|
||||||
updateNotified(profileId, ((Event) o).type == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, ((Event) o).id, notified);
|
updateNotified(profileId, ((Event) o).getType() == Event.TYPE_HOMEWORK ? 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.type == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, o.id, seen, notified, addedDate)) == -1) {
|
if (add(new Metadata(profileId, o.getType() == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, o.getId(), seen, notified, addedDate)) == -1) {
|
||||||
updateSeen(profileId, o.type == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, o.id, seen);
|
updateSeen(profileId, o.getType() == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, o.getId(), seen);
|
||||||
updateNotified(profileId, o.type == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, o.id, notified);
|
updateNotified(profileId, o.getType() == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, o.getId(), notified);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,161 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kacper Ziubryniewicz 2020-1-6
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.db.entity;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.room.ColumnInfo;
|
|
||||||
import androidx.room.Entity;
|
|
||||||
import androidx.room.Ignore;
|
|
||||||
import androidx.room.Index;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull;
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
|
||||||
|
|
||||||
@Entity(tableName = "events",
|
|
||||||
primaryKeys = {"profileId", "eventId"},
|
|
||||||
indices = {@Index(value = {"profileId", "eventDate", "eventStartTime"}), @Index(value = {"profileId", "eventType"})})
|
|
||||||
public class Event {
|
|
||||||
public int profileId;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "eventId")
|
|
||||||
public long id;
|
|
||||||
|
|
||||||
@ColumnInfo(name = "eventDate")
|
|
||||||
public Date eventDate;
|
|
||||||
@ColumnInfo(name = "eventStartTime")
|
|
||||||
@Nullable
|
|
||||||
public Time startTime; // null for allDay
|
|
||||||
@ColumnInfo(name = "eventTopic")
|
|
||||||
public String topic;
|
|
||||||
@ColumnInfo(name = "eventColor")
|
|
||||||
public int color = -1;
|
|
||||||
public static final long TYPE_UNDEFINED = -2;
|
|
||||||
public static final long TYPE_HOMEWORK = -1;
|
|
||||||
public static final long TYPE_DEFAULT = 0;
|
|
||||||
public static final long TYPE_EXAM = 1;
|
|
||||||
public static final long TYPE_SHORT_QUIZ = 2;
|
|
||||||
public static final long TYPE_ESSAY = 3;
|
|
||||||
public static final long TYPE_PROJECT = 4;
|
|
||||||
public static final long TYPE_PT_MEETING = 5;
|
|
||||||
public static final long TYPE_EXCURSION = 6;
|
|
||||||
public static final long TYPE_READING = 7;
|
|
||||||
public static final long TYPE_CLASS_EVENT = 8;
|
|
||||||
public static final long TYPE_INFORMATION = 9;
|
|
||||||
public static final long TYPE_TEACHER_ABSENCE = 10;
|
|
||||||
public static final int COLOR_HOMEWORK = 0xff795548;
|
|
||||||
public static final int COLOR_DEFAULT = 0xffffc107;
|
|
||||||
public static final int COLOR_EXAM = 0xfff44336;
|
|
||||||
public static final int COLOR_SHORT_QUIZ = 0xff76ff03;
|
|
||||||
public static final int COLOR_ESSAY = 0xFF4050B5;
|
|
||||||
public static final int COLOR_PROJECT = 0xFF673AB7;
|
|
||||||
public static final int COLOR_PT_MEETING = 0xff90caf9;
|
|
||||||
public static final int COLOR_EXCURSION = 0xFF4CAF50;
|
|
||||||
public static final int COLOR_READING = 0xFFFFEB3B;
|
|
||||||
public static final int COLOR_CLASS_EVENT = 0xff388e3c;
|
|
||||||
public static final int COLOR_INFORMATION = 0xff039be5;
|
|
||||||
public static final int COLOR_TEACHER_ABSENCE = 0xff039be5;
|
|
||||||
@ColumnInfo(name = "eventType")
|
|
||||||
public long type = TYPE_DEFAULT;
|
|
||||||
@ColumnInfo(name = "eventAddedManually")
|
|
||||||
public boolean addedManually;
|
|
||||||
@ColumnInfo(name = "eventSharedBy")
|
|
||||||
public String sharedBy = null;
|
|
||||||
@ColumnInfo(name = "eventSharedByName")
|
|
||||||
public String sharedByName = null;
|
|
||||||
@ColumnInfo(name = "eventBlacklisted")
|
|
||||||
public boolean blacklisted = false;
|
|
||||||
|
|
||||||
|
|
||||||
public long teacherId;
|
|
||||||
public long subjectId;
|
|
||||||
public long teamId;
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
public Event() {}
|
|
||||||
|
|
||||||
public Event(int profileId, long id, Date eventDate, @Nullable Time startTime, String topic, int color, long type, boolean addedManually, long teacherId, long subjectId, long teamId)
|
|
||||||
{
|
|
||||||
this.profileId = profileId;
|
|
||||||
this.id = id;
|
|
||||||
this.eventDate = eventDate;
|
|
||||||
this.startTime = startTime;
|
|
||||||
this.topic = topic;
|
|
||||||
this.color = color;
|
|
||||||
this.type = type;
|
|
||||||
this.addedManually = addedManually;
|
|
||||||
this.teacherId = teacherId;
|
|
||||||
this.subjectId = subjectId;
|
|
||||||
this.teamId = teamId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
public EventFull withMetadata(Metadata metadata) {
|
|
||||||
return new EventFull(this, metadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
public Calendar getStartTimeCalendar() {
|
|
||||||
Calendar c = Calendar.getInstance();
|
|
||||||
c.set(
|
|
||||||
eventDate.year,
|
|
||||||
eventDate.month - 1,
|
|
||||||
eventDate.day,
|
|
||||||
(startTime == null) ? 0 : startTime.hour,
|
|
||||||
(startTime == null) ? 0 : startTime.minute,
|
|
||||||
(startTime == null) ? 0 : startTime.second
|
|
||||||
);
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
public Calendar getEndTimeCalendar() {
|
|
||||||
Calendar c = Calendar.getInstance();
|
|
||||||
c.setTimeInMillis(getStartTimeCalendar().getTimeInMillis() + (45 * 60 * 1000));
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Event clone() {
|
|
||||||
Event event = new Event(
|
|
||||||
profileId,
|
|
||||||
id,
|
|
||||||
eventDate.clone(),
|
|
||||||
startTime == null ? null : startTime.clone(),
|
|
||||||
topic,
|
|
||||||
color,
|
|
||||||
type,
|
|
||||||
addedManually,
|
|
||||||
subjectId,
|
|
||||||
teacherId,
|
|
||||||
teamId
|
|
||||||
);
|
|
||||||
event.sharedBy = sharedBy;
|
|
||||||
event.sharedByName = sharedByName;
|
|
||||||
event.blacklisted = blacklisted;
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Event{" +
|
|
||||||
"profileId=" + profileId +
|
|
||||||
", id=" + id +
|
|
||||||
", eventDate=" + eventDate +
|
|
||||||
", startTime=" + startTime +
|
|
||||||
", topic='" + topic + '\'' +
|
|
||||||
", color=" + color +
|
|
||||||
", type=" + type +
|
|
||||||
", addedManually=" + addedManually +
|
|
||||||
", sharedBy='" + sharedBy + '\'' +
|
|
||||||
", sharedByName='" + sharedByName + '\'' +
|
|
||||||
", teacherId=" + teacherId +
|
|
||||||
", subjectId=" + subjectId +
|
|
||||||
", teamId=" + teamId +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2020-1-6
|
||||||
|
*/
|
||||||
|
package pl.szczodrzynski.edziennik.data.db.entity
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Ignore
|
||||||
|
import androidx.room.Index
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
import pl.szczodrzynski.edziennik.MINUTE
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@Entity(tableName = "events",
|
||||||
|
primaryKeys = ["profileId", "eventId"],
|
||||||
|
indices = [
|
||||||
|
Index(value = ["profileId", "eventDate", "eventTime"]),
|
||||||
|
Index(value = ["profileId", "eventType"])
|
||||||
|
])
|
||||||
|
open class Event(
|
||||||
|
/* This needs to be mutable: see SzkolnyApi.getEvents() */
|
||||||
|
var profileId: Int,
|
||||||
|
@ColumnInfo(name = "eventId")
|
||||||
|
var id: Long,
|
||||||
|
@ColumnInfo(name = "eventDate")
|
||||||
|
@SerializedName("eventDate")
|
||||||
|
var date: Date,
|
||||||
|
@ColumnInfo(name = "eventTime")
|
||||||
|
@SerializedName("startTime")
|
||||||
|
var time: Time?,
|
||||||
|
|
||||||
|
@ColumnInfo(name = "eventTopic")
|
||||||
|
var topic: String,
|
||||||
|
@ColumnInfo(name = "eventColor")
|
||||||
|
var color: Int?,
|
||||||
|
@ColumnInfo(name = "eventType")
|
||||||
|
var type: Long,
|
||||||
|
|
||||||
|
var teacherId: Long,
|
||||||
|
var subjectId: Long,
|
||||||
|
var teamId: Long
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
const val TYPE_UNDEFINED = -2L
|
||||||
|
const val TYPE_HOMEWORK = -1L
|
||||||
|
const val TYPE_DEFAULT = 0L
|
||||||
|
const val TYPE_EXAM = 1L
|
||||||
|
const val TYPE_SHORT_QUIZ = 2L
|
||||||
|
const val TYPE_ESSAY = 3L
|
||||||
|
const val TYPE_PROJECT = 4L
|
||||||
|
const val TYPE_PT_MEETING = 5L
|
||||||
|
const val TYPE_EXCURSION = 6L
|
||||||
|
const val TYPE_READING = 7L
|
||||||
|
const val TYPE_CLASS_EVENT = 8L
|
||||||
|
const val TYPE_INFORMATION = 9L
|
||||||
|
const val TYPE_TEACHER_ABSENCE = 10L
|
||||||
|
const val COLOR_HOMEWORK = 0xff795548.toInt()
|
||||||
|
const val COLOR_DEFAULT = 0xffffc107.toInt()
|
||||||
|
const val COLOR_EXAM = 0xfff44336.toInt()
|
||||||
|
const val COLOR_SHORT_QUIZ = 0xff76ff03.toInt()
|
||||||
|
const val COLOR_ESSAY = 0xFF4050B5.toInt()
|
||||||
|
const val COLOR_PROJECT = 0xFF673AB7.toInt()
|
||||||
|
const val COLOR_PT_MEETING = 0xff90caf9.toInt()
|
||||||
|
const val COLOR_EXCURSION = 0xFF4CAF50.toInt()
|
||||||
|
const val COLOR_READING = 0xFFFFEB3B.toInt()
|
||||||
|
const val COLOR_CLASS_EVENT = 0xff388e3c.toInt()
|
||||||
|
const val COLOR_INFORMATION = 0xff039be5.toInt()
|
||||||
|
const val COLOR_TEACHER_ABSENCE = 0xff039be5.toInt()
|
||||||
|
}
|
||||||
|
|
||||||
|
@ColumnInfo(name = "eventAddedManually")
|
||||||
|
var addedManually: Boolean = false
|
||||||
|
@ColumnInfo(name = "eventSharedBy")
|
||||||
|
var sharedBy: String? = null
|
||||||
|
@ColumnInfo(name = "eventSharedByName")
|
||||||
|
var sharedByName: String? = null
|
||||||
|
@ColumnInfo(name = "eventBlacklisted")
|
||||||
|
var blacklisted: Boolean = false
|
||||||
|
|
||||||
|
var homeworkBody: String? = null
|
||||||
|
var attachmentIds: List<Long>? = null
|
||||||
|
var attachmentNames: List<String>? = null
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
var showAsUnseen = false
|
||||||
|
|
||||||
|
val startTimeCalendar: Calendar
|
||||||
|
get() = Calendar.getInstance().also { it.set(
|
||||||
|
date.year,
|
||||||
|
date.month - 1,
|
||||||
|
date.day,
|
||||||
|
time?.hour ?: 0,
|
||||||
|
time?.minute ?: 0,
|
||||||
|
time?.second ?: 0
|
||||||
|
) }
|
||||||
|
|
||||||
|
val endTimeCalendar: Calendar
|
||||||
|
get() = startTimeCalendar.also {
|
||||||
|
it.timeInMillis += 45 * MINUTE * 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
fun withMetadata(metadata: Metadata) = EventFull(this, metadata)
|
||||||
|
}
|
@ -1,117 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kacper Ziubryniewicz 2020-1-6
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.db.full;
|
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Event;
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata;
|
|
||||||
|
|
||||||
public class EventFull extends Event {
|
|
||||||
public String typeName = "";
|
|
||||||
public int typeColor = -1;
|
|
||||||
|
|
||||||
public String teacherFullName = "";
|
|
||||||
|
|
||||||
public String subjectLongName = "";
|
|
||||||
public String subjectShortName = "";
|
|
||||||
|
|
||||||
public String teamName = "";
|
|
||||||
public String teamCode = null;
|
|
||||||
|
|
||||||
// metadata
|
|
||||||
public boolean seen;
|
|
||||||
public boolean notified;
|
|
||||||
public long addedDate;
|
|
||||||
|
|
||||||
public EventFull() {}
|
|
||||||
|
|
||||||
public EventFull(Event event) {
|
|
||||||
super(
|
|
||||||
event.profileId,
|
|
||||||
event.id,
|
|
||||||
event.eventDate.clone(),
|
|
||||||
event.startTime == null ? null : event.startTime.clone(),
|
|
||||||
event.topic,
|
|
||||||
event.color,
|
|
||||||
event.type,
|
|
||||||
event.addedManually,
|
|
||||||
event.teacherId,
|
|
||||||
event.subjectId,
|
|
||||||
event.teamId
|
|
||||||
);
|
|
||||||
|
|
||||||
this.sharedBy = event.sharedBy;
|
|
||||||
this.sharedByName = event.sharedByName;
|
|
||||||
this.blacklisted = event.blacklisted;
|
|
||||||
}
|
|
||||||
public EventFull(EventFull event) {
|
|
||||||
super(
|
|
||||||
event.profileId,
|
|
||||||
event.id,
|
|
||||||
event.eventDate.clone(),
|
|
||||||
event.startTime == null ? null : event.startTime.clone(),
|
|
||||||
event.topic,
|
|
||||||
event.color,
|
|
||||||
event.type,
|
|
||||||
event.addedManually,
|
|
||||||
event.teacherId,
|
|
||||||
event.subjectId,
|
|
||||||
event.teamId
|
|
||||||
);
|
|
||||||
|
|
||||||
this.sharedBy = event.sharedBy;
|
|
||||||
this.sharedByName = event.sharedByName;
|
|
||||||
this.blacklisted = event.blacklisted;
|
|
||||||
this.typeName = event.typeName;
|
|
||||||
this.typeColor = event.typeColor;
|
|
||||||
this.teacherFullName = event.teacherFullName;
|
|
||||||
this.subjectLongName = event.subjectLongName;
|
|
||||||
this.subjectShortName = event.subjectShortName;
|
|
||||||
this.teamName = event.teamName;
|
|
||||||
this.teamCode = event.teamCode;
|
|
||||||
this.seen = event.seen;
|
|
||||||
this.notified = event.notified;
|
|
||||||
this.addedDate = event.addedDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventFull(Event event, Metadata metadata) {
|
|
||||||
this(event);
|
|
||||||
|
|
||||||
this.seen = metadata.seen;
|
|
||||||
this.notified = metadata.notified;
|
|
||||||
this.addedDate = metadata.addedDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getColor() {
|
|
||||||
return color == -1 ? typeColor : color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "EventFull{" +
|
|
||||||
"profileId=" + profileId +
|
|
||||||
", id=" + id +
|
|
||||||
", eventDate=" + eventDate +
|
|
||||||
", startTime=" + startTime +
|
|
||||||
", topic='" + topic + '\'' +
|
|
||||||
", color=" + color +
|
|
||||||
", type=" + type +
|
|
||||||
", addedManually=" + addedManually +
|
|
||||||
", sharedBy='" + sharedBy + '\'' +
|
|
||||||
", sharedByName='" + sharedByName + '\'' +
|
|
||||||
", blacklisted=" + blacklisted +
|
|
||||||
", teacherId=" + teacherId +
|
|
||||||
", subjectId=" + subjectId +
|
|
||||||
", teamId=" + teamId +
|
|
||||||
", typeName='" + typeName + '\'' +
|
|
||||||
", teacherFullName='" + teacherFullName + '\'' +
|
|
||||||
", subjectLongName='" + subjectLongName + '\'' +
|
|
||||||
", subjectShortName='" + subjectShortName + '\'' +
|
|
||||||
", teamName='" + teamName + '\'' +
|
|
||||||
", seen=" + seen +
|
|
||||||
", notified=" + notified +
|
|
||||||
", addedDate=" + addedDate +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2020-1-6
|
||||||
|
*/
|
||||||
|
package pl.szczodrzynski.edziennik.data.db.full
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||||
|
|
||||||
|
class EventFull(
|
||||||
|
profileId: Int, id: Long, date: Date, time: Time?,
|
||||||
|
topic: String, color: Int?, type: Long,
|
||||||
|
teacherId: Long, subjectId: Long, teamId: Long
|
||||||
|
) : Event(
|
||||||
|
profileId, id, date, time,
|
||||||
|
topic, color, type,
|
||||||
|
teacherId, subjectId, teamId
|
||||||
|
) {
|
||||||
|
constructor(event: Event, metadata: Metadata? = null) : this(
|
||||||
|
event.profileId, event.id, event.date, event.time,
|
||||||
|
event.topic, event.color, event.type,
|
||||||
|
event.teacherId, event.subjectId, event.teamId) {
|
||||||
|
event.let {
|
||||||
|
addedManually = it.addedManually
|
||||||
|
sharedBy = it.sharedBy
|
||||||
|
sharedByName = it.sharedByName
|
||||||
|
blacklisted = it.blacklisted
|
||||||
|
homeworkBody = it.homeworkBody
|
||||||
|
attachmentIds = it.attachmentIds
|
||||||
|
attachmentNames = it.attachmentNames
|
||||||
|
}
|
||||||
|
metadata?.let {
|
||||||
|
seen = it.seen
|
||||||
|
notified = it.notified
|
||||||
|
addedDate = it.addedDate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var typeName: String? = null
|
||||||
|
var typeColor: Int? = null
|
||||||
|
|
||||||
|
var teacherFullName: String? = null
|
||||||
|
var subjectLongName: String? = null
|
||||||
|
var subjectShortName: String? = null
|
||||||
|
var teamName: String? = null
|
||||||
|
var teamCode: String? = null
|
||||||
|
// metadata
|
||||||
|
var seen = false
|
||||||
|
var notified = false
|
||||||
|
var addedDate: Long = 0
|
||||||
|
|
||||||
|
val eventColor
|
||||||
|
get() = color ?: typeColor ?: 0xff2196f3.toInt()
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kuba Szczodrzyński 2020-3-27.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.db.migration
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
class Migration80 : Migration(79, 80) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
// The Homework Update
|
||||||
|
database.execSQL("ALTER TABLE events RENAME TO _events;")
|
||||||
|
database.execSQL("""CREATE TABLE events (
|
||||||
|
profileId INTEGER NOT NULL,
|
||||||
|
eventId INTEGER NOT NULL,
|
||||||
|
eventDate TEXT NOT NULL,
|
||||||
|
eventTime TEXT,
|
||||||
|
eventTopic TEXT NOT NULL,
|
||||||
|
eventColor INTEGER,
|
||||||
|
eventType INTEGER NOT NULL,
|
||||||
|
teacherId INTEGER NOT NULL,
|
||||||
|
subjectId INTEGER NOT NULL,
|
||||||
|
teamId INTEGER NOT NULL,
|
||||||
|
eventAddedManually INTEGER NOT NULL DEFAULT 0,
|
||||||
|
eventSharedBy TEXT DEFAULT NULL,
|
||||||
|
eventSharedByName TEXT DEFAULT NULL,
|
||||||
|
eventBlacklisted INTEGER NOT NULL DEFAULT 0,
|
||||||
|
homeworkBody TEXT DEFAULT NULL,
|
||||||
|
attachmentIds TEXT DEFAULT NULL,
|
||||||
|
attachmentNames TEXT DEFAULT NULL,
|
||||||
|
PRIMARY KEY(profileId, eventId)
|
||||||
|
)""")
|
||||||
|
database.execSQL("DROP INDEX IF EXISTS index_events_profileId_eventDate_eventStartTime")
|
||||||
|
database.execSQL("DROP INDEX IF EXISTS index_events_profileId_eventType")
|
||||||
|
database.execSQL("CREATE INDEX index_events_profileId_eventDate_eventTime ON events (profileId, eventDate, eventTime)")
|
||||||
|
database.execSQL("CREATE INDEX index_events_profileId_eventType ON events (profileId, eventType)")
|
||||||
|
database.execSQL("""
|
||||||
|
INSERT INTO events (profileId, eventId, eventDate, eventTime, eventTopic, eventColor, eventType, teacherId, subjectId, teamId, eventAddedManually, eventSharedBy, eventSharedByName, eventBlacklisted)
|
||||||
|
SELECT profileId, eventId, eventDate, eventStartTime, eventTopic,
|
||||||
|
CASE eventColor WHEN -1 THEN NULL ELSE eventColor END,
|
||||||
|
eventType, teacherId, subjectId, teamId,
|
||||||
|
eventAddedManually, eventSharedBy, eventSharedByName, eventBlacklisted
|
||||||
|
FROM _events
|
||||||
|
""")
|
||||||
|
database.execSQL("DROP TABLE _events")
|
||||||
|
}
|
||||||
|
}
|
@ -105,18 +105,19 @@ class SzkolnyAppFirebase(val app: App, val profiles: List<Profile>, val message:
|
|||||||
if (profile.registration != Profile.REGISTRATION_ENABLED)
|
if (profile.registration != Profile.REGISTRATION_ENABLED)
|
||||||
return@forEach
|
return@forEach
|
||||||
val event = Event(
|
val event = Event(
|
||||||
team.profileId,
|
profileId = team.profileId,
|
||||||
json.getLong("id") ?: return,
|
id = json.getLong("id") ?: return,
|
||||||
json.getInt("eventDate")?.let { Date.fromValue(it) } ?: return,
|
date = json.getInt("eventDate")?.let { Date.fromValue(it) } ?: return,
|
||||||
json.getInt("startTime")?.let { Time.fromValue(it) },
|
time = json.getInt("startTime")?.let { Time.fromValue(it) },
|
||||||
json.getString("topic") ?: "",
|
topic = json.getString("topic") ?: "",
|
||||||
json.getInt("color") ?: -1,
|
color = json.getInt("color"),
|
||||||
json.getLong("type") ?: 0,
|
type = json.getLong("type") ?: 0,
|
||||||
true,
|
teacherId = json.getLong("teacherId") ?: -1,
|
||||||
json.getLong("teacherId") ?: -1,
|
subjectId = json.getLong("subjectId") ?: -1,
|
||||||
json.getLong("subjectId") ?: -1,
|
teamId = team.id
|
||||||
team.id
|
|
||||||
)
|
)
|
||||||
|
if (event.color == -1)
|
||||||
|
event.color = null
|
||||||
|
|
||||||
event.sharedBy = json.getString("sharedBy")
|
event.sharedBy = json.getString("sharedBy")
|
||||||
event.sharedByName = json.getString("sharedByName")
|
event.sharedByName = json.getString("sharedByName")
|
||||||
@ -144,7 +145,7 @@ class SzkolnyAppFirebase(val app: App, val profiles: List<Profile>, val message:
|
|||||||
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.type == Event.TYPE_HOMEWORK) MainActivity.DRAWER_ITEM_HOMEWORK else MainActivity.DRAWER_ITEM_AGENDA,
|
||||||
addedDate = metadata.addedDate
|
addedDate = metadata.addedDate
|
||||||
).addExtra("eventId", event.id).addExtra("eventDate", event.eventDate.value.toLong())
|
).addExtra("eventId", event.id).addExtra("eventDate", event.date.value.toLong())
|
||||||
notificationList += notification
|
notificationList += notification
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,11 +87,11 @@ class EventDetailsDialog(
|
|||||||
val colorSecondary = android.R.attr.textColorSecondary.resolveAttr(activity)
|
val colorSecondary = android.R.attr.textColorSecondary.resolveAttr(activity)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
b.monthName = app.resources.getStringArray(R.array.months_day_of_array)[event.eventDate.month - 1]
|
b.monthName = app.resources.getStringArray(R.array.months_day_of_array)[event.date.month - 1]
|
||||||
}
|
}
|
||||||
catch (_: Exception) {}
|
catch (_: Exception) {}
|
||||||
|
|
||||||
b.typeColor.background?.setTintColor(event.getColor())
|
b.typeColor.background?.setTintColor(event.eventColor)
|
||||||
|
|
||||||
b.details = mutableListOf(
|
b.details = mutableListOf(
|
||||||
event.subjectLongName,
|
event.subjectLongName,
|
||||||
@ -125,7 +125,7 @@ class EventDetailsDialog(
|
|||||||
|
|
||||||
b.goToTimetableButton.setOnClickListener {
|
b.goToTimetableButton.setOnClickListener {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
val dateStr = event.eventDate?.stringY_m_d ?: return@setOnClickListener
|
val dateStr = event.date.stringY_m_d
|
||||||
|
|
||||||
val intent =
|
val intent =
|
||||||
if (activity is MainActivity && activity.navTargetId == MainActivity.DRAWER_ITEM_TIMETABLE)
|
if (activity is MainActivity && activity.navTargetId == MainActivity.DRAWER_ITEM_TIMETABLE)
|
||||||
@ -245,7 +245,7 @@ class EventDetailsDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun openInCalendar() { launch {
|
private fun openInCalendar() { launch {
|
||||||
val title = (event.typeName ?: "") +
|
val title = event.typeName ?: "" +
|
||||||
(if (event.typeName.isNotNullNorBlank() && event.subjectLongName.isNotNullNorBlank()) " - " else " ") +
|
(if (event.typeName.isNotNullNorBlank() && event.subjectLongName.isNotNullNorBlank()) " - " else " ") +
|
||||||
(event.subjectLongName ?: "")
|
(event.subjectLongName ?: "")
|
||||||
|
|
||||||
@ -254,12 +254,12 @@ class EventDetailsDialog(
|
|||||||
putExtra(Events.TITLE, title)
|
putExtra(Events.TITLE, title)
|
||||||
putExtra(Events.DESCRIPTION, event.topic)
|
putExtra(Events.DESCRIPTION, event.topic)
|
||||||
|
|
||||||
if (event.startTime == null) {
|
if (event.time == null) {
|
||||||
putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true)
|
putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true)
|
||||||
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, event.eventDate.inMillis)
|
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, event.date.inMillis)
|
||||||
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, event.eventDate.inMillis)
|
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, event.date.inMillis)
|
||||||
} else {
|
} else {
|
||||||
val startTime = event.eventDate.combineWith(event.startTime)
|
val startTime = event.date.combineWith(event.time)
|
||||||
val endTime = startTime + 45 * 60 * 1000 /* 45 min */
|
val endTime = startTime + 45 * 60 * 1000 /* 45 min */
|
||||||
|
|
||||||
putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, false)
|
putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, false)
|
||||||
|
@ -50,10 +50,10 @@ class EventListAdapter(
|
|||||||
b.topic.text = event.topic
|
b.topic.text = event.topic
|
||||||
|
|
||||||
b.details.text = mutableListOf<CharSequence?>(
|
b.details.text = mutableListOf<CharSequence?>(
|
||||||
if (showWeekDay) Week.getFullDayName(event.eventDate.weekDay) else null,
|
if (showWeekDay) Week.getFullDayName(event.date.weekDay) else null,
|
||||||
if (showDate) event.eventDate.getRelativeString(context, 7) ?: event.eventDate.formattedStringShort else null,
|
if (showDate) event.date.getRelativeString(context, 7) ?: event.date.formattedStringShort else null,
|
||||||
event.typeName,
|
event.typeName,
|
||||||
if (simpleMode) null else event.startTime?.stringHM ?: app.getString(R.string.event_all_day),
|
if (simpleMode) null else event.time?.stringHM ?: app.getString(R.string.event_all_day),
|
||||||
if (simpleMode) null else event.subjectLongName
|
if (simpleMode) null else event.subjectLongName
|
||||||
).concat(bullet)
|
).concat(bullet)
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class EventListAdapter(
|
|||||||
event.teamName?.let { bullet+it } ?: ""
|
event.teamName?.let { bullet+it } ?: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
b.typeColor.background?.setTintColor(event.getColor())
|
b.typeColor.background?.setTintColor(event.eventColor)
|
||||||
|
|
||||||
b.editButton.visibility = if (event.addedManually && !simpleMode) View.VISIBLE else View.GONE
|
b.editButton.visibility = if (event.addedManually && !simpleMode) View.VISIBLE else View.GONE
|
||||||
b.editButton.onClick {
|
b.editButton.onClick {
|
||||||
|
@ -216,7 +216,7 @@ class EventManualDialog(
|
|||||||
progressDialog?.dismiss()
|
progressDialog?.dismiss()
|
||||||
launch {
|
launch {
|
||||||
b.timeDropdown.loadItems()
|
b.timeDropdown.loadItems()
|
||||||
b.timeDropdown.selectDefault(editingEvent?.startTime)
|
b.timeDropdown.selectDefault(editingEvent?.time)
|
||||||
b.timeDropdown.selectDefault(defaultLesson?.displayStartTime ?: defaultTime)
|
b.timeDropdown.selectDefault(defaultLesson?.displayStartTime ?: defaultTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ class EventManualDialog(
|
|||||||
nextLessonTeamId = it.displayTeamId
|
nextLessonTeamId = it.displayTeamId
|
||||||
}
|
}
|
||||||
loadItems()
|
loadItems()
|
||||||
selectDefault(editingEvent?.eventDate)
|
selectDefault(editingEvent?.date)
|
||||||
selectDefault(defaultLesson?.displayDate ?: defaultDate)
|
selectDefault(defaultLesson?.displayDate ?: defaultDate)
|
||||||
onDateSelected = { date, lesson ->
|
onDateSelected = { date, lesson ->
|
||||||
b.timeDropdown.deselect()
|
b.timeDropdown.deselect()
|
||||||
@ -276,8 +276,8 @@ class EventManualDialog(
|
|||||||
displayMode = DISPLAY_LESSONS
|
displayMode = DISPLAY_LESSONS
|
||||||
if (!loadItems())
|
if (!loadItems())
|
||||||
syncTimetable(lessonsDate ?: Date.getToday())
|
syncTimetable(lessonsDate ?: Date.getToday())
|
||||||
selectDefault(editingEvent?.startTime)
|
selectDefault(editingEvent?.time)
|
||||||
if (editingEvent != null && editingEvent.startTime == null)
|
if (editingEvent != null && editingEvent.time == null)
|
||||||
select(0L)
|
select(0L)
|
||||||
selectDefault(defaultLesson?.displayStartTime ?: defaultTime)
|
selectDefault(defaultLesson?.displayStartTime ?: defaultTime)
|
||||||
onLessonSelected = { lesson ->
|
onLessonSelected = { lesson ->
|
||||||
@ -319,7 +319,12 @@ class EventManualDialog(
|
|||||||
|
|
||||||
val deferred = async(Dispatchers.Default) {
|
val deferred = async(Dispatchers.Default) {
|
||||||
// get the event type list
|
// get the event type list
|
||||||
val eventTypes = app.db.eventTypeDao().getAllNow(profileId)
|
var eventTypes = app.db.eventTypeDao().getAllNow(profileId)
|
||||||
|
|
||||||
|
if (eventTypes.none { it.id in -1L..10L }) {
|
||||||
|
eventTypes = app.db.eventTypeDao().addDefaultTypes(activity, profileId)
|
||||||
|
}
|
||||||
|
|
||||||
b.typeDropdown.clear()
|
b.typeDropdown.clear()
|
||||||
b.typeDropdown += eventTypes.map { TextInputDropDown.Item(it.id, it.name, tag = it) }
|
b.typeDropdown += eventTypes.map { TextInputDropDown.Item(it.id, it.name, tag = it) }
|
||||||
}
|
}
|
||||||
@ -338,10 +343,10 @@ class EventManualDialog(
|
|||||||
// copy IDs from event being edited
|
// copy IDs from event being edited
|
||||||
editingEvent?.let {
|
editingEvent?.let {
|
||||||
b.topic.setText(it.topic)
|
b.topic.setText(it.topic)
|
||||||
b.typeDropdown.select(it.type.toLong())?.let { item ->
|
b.typeDropdown.select(it.type)?.let { item ->
|
||||||
customColor = (item.tag as EventType).color
|
customColor = (item.tag as EventType).color
|
||||||
}
|
}
|
||||||
if (it.color != -1)
|
if (it.color != null && it.color != -1)
|
||||||
customColor = it.color
|
customColor = it.color
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -464,22 +469,25 @@ class EventManualDialog(
|
|||||||
(timeSelected as? Pair<*, *>)?.first as? Time
|
(timeSelected as? Pair<*, *>)?.first as? Time
|
||||||
|
|
||||||
if (isError) return
|
if (isError) return
|
||||||
|
date ?: return
|
||||||
|
topic ?: return
|
||||||
|
|
||||||
val id = System.currentTimeMillis()
|
val id = System.currentTimeMillis()
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId = profileId,
|
||||||
editingEvent?.id ?: id,
|
id = editingEvent?.id ?: id,
|
||||||
date,
|
date = date,
|
||||||
startTime,
|
time = startTime,
|
||||||
topic,
|
topic = topic,
|
||||||
customColor ?: -1,
|
color = customColor,
|
||||||
type ?: Event.TYPE_DEFAULT,
|
type = type ?: Event.TYPE_DEFAULT,
|
||||||
true,
|
teacherId = teacherId ?: -1,
|
||||||
teacherId ?: -1,
|
subjectId = subjectId ?: -1,
|
||||||
subjectId ?: -1,
|
teamId = teamId ?: -1
|
||||||
teamId ?: -1
|
).also {
|
||||||
)
|
it.addedManually = true
|
||||||
|
}
|
||||||
|
|
||||||
val metadataObject = Metadata(
|
val metadataObject = Metadata(
|
||||||
profileId,
|
profileId,
|
||||||
@ -590,6 +598,7 @@ class EventManualDialog(
|
|||||||
activity.reloadTarget()
|
activity.reloadTarget()
|
||||||
}
|
}
|
||||||
private fun finishRemoving() {
|
private fun finishRemoving() {
|
||||||
|
editingEvent ?: return
|
||||||
launch {
|
launch {
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
app.db.eventDao().remove(editingEvent)
|
app.db.eventDao().remove(editingEvent)
|
||||||
|
@ -222,22 +222,22 @@ class AgendaFragment : Fragment(), CoroutineScope {
|
|||||||
|
|
||||||
events.forEach { event ->
|
events.forEach { event ->
|
||||||
eventList.add(BaseCalendarEvent(
|
eventList.add(BaseCalendarEvent(
|
||||||
"${event.typeName} - ${event.topic}",
|
"${event.typeName ?: "wydarzenie"} - ${event.topic}",
|
||||||
"",
|
"",
|
||||||
(if (event.startTime == null) getString(R.string.agenda_event_all_day) else event.startTime!!.stringHM) +
|
(if (event.time == null) getString(R.string.agenda_event_all_day) else event.time!!.stringHM) +
|
||||||
(event.subjectLongName?.let { ", $it" } ?: "") +
|
(event.subjectLongName?.let { ", $it" } ?: "") +
|
||||||
(event.teacherFullName?.let { ", $it" } ?: "") +
|
(event.teacherFullName?.let { ", $it" } ?: "") +
|
||||||
(event.teamName?.let { ", $it" } ?: ""),
|
(event.teamName?.let { ", $it" } ?: ""),
|
||||||
event.getColor(),
|
event.eventColor,
|
||||||
Colors.legibleTextColor(event.getColor()),
|
Colors.legibleTextColor(event.eventColor),
|
||||||
event.startTimeCalendar,
|
event.startTimeCalendar,
|
||||||
event.endTimeCalendar,
|
event.endTimeCalendar,
|
||||||
event.startTime == null,
|
event.time == null,
|
||||||
event.id,
|
event.id,
|
||||||
!event.seen
|
!event.seen
|
||||||
))
|
))
|
||||||
|
|
||||||
if (!event.seen) unreadEventDates.add(event.eventDate.value)
|
if (!event.seen) unreadEventDates.add(event.date.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
b.agendaDefaultView.init(eventList, minDate, maxDate, Locale.getDefault(), object : CalendarPickerController {
|
b.agendaDefaultView.init(eventList, minDate, maxDate, Locale.getDefault(), object : CalendarPickerController {
|
||||||
@ -281,11 +281,11 @@ class AgendaFragment : Fragment(), CoroutineScope {
|
|||||||
val eventIcon = IconicsDrawable(activity)
|
val eventIcon = IconicsDrawable(activity)
|
||||||
.icon(CommunityMaterial.Icon.cmd_checkbox_blank_circle)
|
.icon(CommunityMaterial.Icon.cmd_checkbox_blank_circle)
|
||||||
.size(IconicsSize.dp(10))
|
.size(IconicsSize.dp(10))
|
||||||
.color(IconicsColor.colorInt(event.getColor()))
|
.color(IconicsColor.colorInt(event.eventColor))
|
||||||
|
|
||||||
dayList.add(EventDay(event.startTimeCalendar, eventIcon))
|
dayList.add(EventDay(event.startTimeCalendar, eventIcon))
|
||||||
|
|
||||||
if (!event.seen) unreadEventDates.add(event.eventDate.value)
|
if (!event.seen) unreadEventDates.add(event.date.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
b.agendaCalendarView.setEvents(dayList)
|
b.agendaCalendarView.setEvents(dayList)
|
||||||
|
@ -50,17 +50,17 @@ public class HomeworkAdapter extends RecyclerView.Adapter<HomeworkAdapter.ViewHo
|
|||||||
|
|
||||||
EventFull homework = homeworkList.get(position);
|
EventFull homework = homeworkList.get(position);
|
||||||
|
|
||||||
int diffDays = Date.diffDays(homework.eventDate, Date.getToday());
|
int diffDays = Date.diffDays(homework.getDate(), Date.getToday());
|
||||||
|
|
||||||
holder.homeworkItemHomeworkDate.setText(app.getString(R.string.date_relative_format, homework.eventDate.getFormattedString(), Date.dayDiffString(context, diffDays)));
|
holder.homeworkItemHomeworkDate.setText(app.getString(R.string.date_relative_format, homework.getDate().getFormattedString(), Date.dayDiffString(context, diffDays)));
|
||||||
holder.homeworkItemTopic.setText(homework.topic);
|
holder.homeworkItemTopic.setText(homework.getTopic());
|
||||||
holder.homeworkItemSubjectTeacher.setText(context.getString(R.string.homework_subject_teacher_format, bs(homework.subjectLongName), bs(homework.teacherFullName)));
|
holder.homeworkItemSubjectTeacher.setText(context.getString(R.string.homework_subject_teacher_format, bs(homework.getSubjectLongName()), bs(homework.getTeacherFullName())));
|
||||||
holder.homeworkItemTeamDate.setText(context.getString(R.string.homework_team_date_format, bs(homework.teamName), Date.fromMillis(homework.addedDate).getFormattedStringShort()));
|
holder.homeworkItemTeamDate.setText(context.getString(R.string.homework_team_date_format, bs(homework.getTeamName()), Date.fromMillis(homework.getAddedDate()).getFormattedStringShort()));
|
||||||
|
|
||||||
if (!homework.seen) {
|
if (!homework.getSeen()) {
|
||||||
holder.homeworkItemTopic.setBackground(context.getResources().getDrawable(R.drawable.bg_rounded_8dp));
|
holder.homeworkItemTopic.setBackground(context.getResources().getDrawable(R.drawable.bg_rounded_8dp));
|
||||||
holder.homeworkItemTopic.getBackground().setColorFilter(new PorterDuffColorFilter(0x692196f3, PorterDuff.Mode.MULTIPLY));
|
holder.homeworkItemTopic.getBackground().setColorFilter(new PorterDuffColorFilter(0x692196f3, PorterDuff.Mode.MULTIPLY));
|
||||||
homework.seen = true;
|
homework.setSeen(true);
|
||||||
AsyncTask.execute(() -> {
|
AsyncTask.execute(() -> {
|
||||||
App.db.metadataDao().setSeen(App.Companion.getProfileId(), homework, true);
|
App.db.metadataDao().setSeen(App.Companion.getProfileId(), homework, true);
|
||||||
});
|
});
|
||||||
@ -69,11 +69,11 @@ public class HomeworkAdapter extends RecyclerView.Adapter<HomeworkAdapter.ViewHo
|
|||||||
holder.homeworkItemTopic.setBackground(null);
|
holder.homeworkItemTopic.setBackground(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.homeworkItemEdit.setVisibility((homework.addedManually ? View.VISIBLE : View.GONE));
|
holder.homeworkItemEdit.setVisibility((homework.getAddedManually() ? View.VISIBLE : View.GONE));
|
||||||
holder.homeworkItemEdit.setOnClickListener(v -> {
|
holder.homeworkItemEdit.setOnClickListener(v -> {
|
||||||
new EventManualDialog(
|
new EventManualDialog(
|
||||||
(MainActivity) context,
|
(MainActivity) context,
|
||||||
homework.profileId,
|
homework.getProfileId(),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@ -83,11 +83,11 @@ public class HomeworkAdapter extends RecyclerView.Adapter<HomeworkAdapter.ViewHo
|
|||||||
null);
|
null);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (homework.sharedBy == null) {
|
if (homework.getSharedBy() == null) {
|
||||||
holder.homeworkItemSharedBy.setVisibility(View.GONE);
|
holder.homeworkItemSharedBy.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
else if (homework.sharedByName != null) {
|
else if (homework.getSharedByName() != null) {
|
||||||
holder.homeworkItemSharedBy.setText(app.getString(R.string.event_shared_by_format, (homework.sharedBy.equals("self") ? app.getString(R.string.event_shared_by_self) : homework.sharedByName)));
|
holder.homeworkItemSharedBy.setText(app.getString(R.string.event_shared_by_format, (homework.getSharedBy().equals("self") ? app.getString(R.string.event_shared_by_self) : homework.getSharedByName())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,6 @@ import pl.szczodrzynski.edziennik.data.api.events.ApiTaskAllFinishedEvent
|
|||||||
import pl.szczodrzynski.edziennik.data.api.events.ApiTaskErrorEvent
|
import pl.szczodrzynski.edziennik.data.api.events.ApiTaskErrorEvent
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.ApiTaskProgressEvent
|
import pl.szczodrzynski.edziennik.data.api.events.ApiTaskProgressEvent
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.ApiTaskStartedEvent
|
import pl.szczodrzynski.edziennik.data.api.events.ApiTaskStartedEvent
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Event.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.EventType
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile.Companion.REGISTRATION_DISABLED
|
import pl.szczodrzynski.edziennik.data.db.entity.Profile.Companion.REGISTRATION_DISABLED
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile.Companion.REGISTRATION_ENABLED
|
import pl.szczodrzynski.edziennik.data.db.entity.Profile.Companion.REGISTRATION_ENABLED
|
||||||
import pl.szczodrzynski.edziennik.databinding.FragmentLoginSyncBinding
|
import pl.szczodrzynski.edziennik.databinding.FragmentLoginSyncBinding
|
||||||
@ -62,20 +60,7 @@ class LoginSyncFragment : Fragment(), CoroutineScope {
|
|||||||
else
|
else
|
||||||
REGISTRATION_DISABLED
|
REGISTRATION_DISABLED
|
||||||
|
|
||||||
val typeList = listOf(
|
app.db.eventTypeDao().addDefaultTypes(activity, it.id)
|
||||||
EventType(it.id, TYPE_HOMEWORK, getString(R.string.event_type_homework), COLOR_HOMEWORK),
|
|
||||||
EventType(it.id, TYPE_DEFAULT, getString(R.string.event_other), COLOR_DEFAULT),
|
|
||||||
EventType(it.id, TYPE_EXAM, getString(R.string.event_exam), COLOR_EXAM),
|
|
||||||
EventType(it.id, TYPE_SHORT_QUIZ, getString(R.string.event_short_quiz), COLOR_SHORT_QUIZ),
|
|
||||||
EventType(it.id, TYPE_ESSAY, getString(R.string.event_essay), COLOR_SHORT_QUIZ),
|
|
||||||
EventType(it.id, TYPE_PROJECT, getString(R.string.event_project), COLOR_PROJECT),
|
|
||||||
EventType(it.id, TYPE_PT_MEETING, getString(R.string.event_pt_meeting), COLOR_PT_MEETING),
|
|
||||||
EventType(it.id, TYPE_EXCURSION, getString(R.string.event_excursion), COLOR_EXCURSION),
|
|
||||||
EventType(it.id, TYPE_READING, getString(R.string.event_reading), COLOR_READING),
|
|
||||||
EventType(it.id, TYPE_CLASS_EVENT, getString(R.string.event_class_event), COLOR_CLASS_EVENT),
|
|
||||||
EventType(it.id, TYPE_INFORMATION, getString(R.string.event_information), COLOR_INFORMATION)
|
|
||||||
)
|
|
||||||
app.db.eventTypeDao().addAll(typeList)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.db.profileDao().addAll(profiles)
|
app.db.profileDao().addAll(profiles)
|
||||||
|
@ -216,23 +216,23 @@ class TimetableDayFragment : PagerFragment(), CoroutineScope {
|
|||||||
LessonDetailsDialog(activity, it.tag as LessonFull)
|
LessonDetailsDialog(activity, it.tag as LessonFull)
|
||||||
}
|
}
|
||||||
|
|
||||||
val eventList = events.filter { it.startTime != null && it.startTime == lesson.displayStartTime }.take(3)
|
val eventList = events.filter { it.time != null && it.time == lesson.displayStartTime }.take(3)
|
||||||
eventList.getOrNull(0).let {
|
eventList.getOrNull(0).let {
|
||||||
lb.event1.visibility = if (it == null) View.GONE else View.VISIBLE
|
lb.event1.visibility = if (it == null) View.GONE else View.VISIBLE
|
||||||
lb.event1.background = it?.let {
|
lb.event1.background = it?.let {
|
||||||
R.drawable.bg_circle.resolveDrawable(activity).setTintColor(it.getColor())
|
R.drawable.bg_circle.resolveDrawable(activity).setTintColor(it.eventColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
eventList.getOrNull(1).let {
|
eventList.getOrNull(1).let {
|
||||||
lb.event2.visibility = if (it == null) View.GONE else View.VISIBLE
|
lb.event2.visibility = if (it == null) View.GONE else View.VISIBLE
|
||||||
lb.event2.background = it?.let {
|
lb.event2.background = it?.let {
|
||||||
R.drawable.bg_circle.resolveDrawable(activity).setTintColor(it.getColor())
|
R.drawable.bg_circle.resolveDrawable(activity).setTintColor(it.eventColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
eventList.getOrNull(2).let {
|
eventList.getOrNull(2).let {
|
||||||
lb.event3.visibility = if (it == null) View.GONE else View.VISIBLE
|
lb.event3.visibility = if (it == null) View.GONE else View.VISIBLE
|
||||||
lb.event3.background = it?.let {
|
lb.event3.background = it?.let {
|
||||||
R.drawable.bg_circle.resolveDrawable(activity).setTintColor(it.getColor())
|
R.drawable.bg_circle.resolveDrawable(activity).setTintColor(it.eventColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ 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.TYPE_HOMEWORK
|
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
|
||||||
@ -289,7 +289,7 @@ class WidgetTimetableProvider : AppWidgetProvider() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get all events for the current date
|
// get all events for the current date
|
||||||
val events = app.db.eventDao().getAllByDateNow(profile.id, timetableDate)?.filterNotNull() ?: emptyList()
|
val events = app.db.eventDao().getAllByDateNow(profile.id, timetableDate)
|
||||||
|
|
||||||
lessons.forEachIndexed { pos, lesson ->
|
lessons.forEachIndexed { pos, lesson ->
|
||||||
if (lesson.type == TYPE_NO_LESSONS)
|
if (lesson.type == TYPE_NO_LESSONS)
|
||||||
@ -345,9 +345,9 @@ class WidgetTimetableProvider : AppWidgetProvider() {
|
|||||||
|
|
||||||
// add every event on this lesson
|
// add every event on this lesson
|
||||||
for (event in events) {
|
for (event in events) {
|
||||||
if (event.startTime == null || event.startTime != 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.getColor())
|
model.eventColors.add(if (event.type == TYPE_HOMEWORK) ItemWidgetTimetableModel.EVENT_COLOR_HOMEWORK else event.eventColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
models += model
|
models += model
|
||||||
|
@ -254,6 +254,7 @@ public class Date implements Comparable<Date> {
|
|||||||
/**
|
/**
|
||||||
* @return 2019-06-02
|
* @return 2019-06-02
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public String getStringY_m_d() {
|
public String getStringY_m_d() {
|
||||||
return year + (month < 10 ? "-0" : "-") + month + (day < 10 ? "-0" : "-") + day;
|
return year + (month < 10 ? "-0" : "-") + month + (day < 10 ? "-0" : "-") + day;
|
||||||
}
|
}
|
||||||
|
@ -81,14 +81,14 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="@style/NavView.TextView.Helper"
|
android:textAppearance="@style/NavView.TextView.Helper"
|
||||||
android:text="@{event.startTime == null ? @string/event_all_day : event.startTime.stringHM}"
|
android:text="@{event.time == null ? @string/event_all_day : event.time.stringHM}"
|
||||||
tools:text="14:50"/>
|
tools:text="14:50"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:fontFamily="sans-serif-light"
|
android:fontFamily="sans-serif-light"
|
||||||
android:text="@{Integer.toString(event.eventDate.day)}"
|
android:text="@{Integer.toString(event.date.day)}"
|
||||||
android:textSize="36sp"
|
android:textSize="36sp"
|
||||||
tools:text="14" />
|
tools:text="14" />
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user