forked from github/szkolny
[UI] Make shared notes for lessons use a stable ID.
This commit is contained in:
parent
c90ad97f55
commit
f52cc1b197
2320
app/schemas/pl.szczodrzynski.edziennik.data.db.AppDb/100.json
Normal file
2320
app/schemas/pl.szczodrzynski.edziennik.data.db.AppDb/100.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -190,6 +190,7 @@ class LibrusApiTimetables(override val data: DataLibrus,
|
||||
}
|
||||
|
||||
lessonObject.id = lessonObject.buildId()
|
||||
lessonObject.ownerId = lessonObject.buildOwnerId()
|
||||
|
||||
val seen = profile.empty || lessonDate < Date.getToday()
|
||||
|
||||
|
@ -88,6 +88,7 @@ class MobidziennikApiTimetable(val data: DataMobidziennik, rows: List<String>) {
|
||||
}
|
||||
|
||||
it.id = it.buildId()
|
||||
it.ownerId = it.buildOwnerId()
|
||||
|
||||
val seen = profile.empty || date < Date.getToday()
|
||||
|
||||
|
@ -336,6 +336,7 @@ class MobidziennikWebTimetable(
|
||||
}
|
||||
|
||||
it.id = it.buildId()
|
||||
it.ownerId = it.buildOwnerId()
|
||||
it.isExtra = isExtra
|
||||
|
||||
val seen = profile?.empty == false || lessonDate < Date.getToday()
|
||||
|
@ -72,6 +72,7 @@ class PodlasieApiTimetable(val data: DataPodlasie, rows: List<JsonObject>) {
|
||||
it.classroom = classroom
|
||||
|
||||
it.id = it.buildId()
|
||||
it.ownerId = it.buildOwnerId()
|
||||
data.lessonList += it
|
||||
}
|
||||
}
|
||||
|
@ -106,6 +106,7 @@ class UsosApiTimetable(
|
||||
val groupName = classTypeId?.plus(groupNumber)?.let { s -> "($s)" }
|
||||
it.classroom = "Sala $roomNumber / bud. $buildingId ${groupName ?: ""}"
|
||||
it.id = it.buildId()
|
||||
it.ownerId = it.buildOwnerId()
|
||||
|
||||
it.color = when (classTypeId) {
|
||||
"WYK" -> 0xff0d6091
|
||||
|
@ -247,7 +247,9 @@ class VulcanHebeTimetable(
|
||||
}
|
||||
|
||||
lessonObject.id = lessonObject.buildId()
|
||||
lessonObject.ownerId = lessonObject.buildOwnerId()
|
||||
lessonShift?.id = lessonShift?.buildId() ?: -1
|
||||
lessonShift?.ownerId = lessonShift?.buildOwnerId() ?: -1
|
||||
|
||||
lessonList.add(lessonObject)
|
||||
lessonShift?.let { lessonList.add(it) }
|
||||
|
@ -44,7 +44,7 @@ import pl.szczodrzynski.edziennik.data.db.migration.*
|
||||
TimetableManual::class,
|
||||
Note::class,
|
||||
Metadata::class
|
||||
], version = 99)
|
||||
], version = 100)
|
||||
@TypeConverters(
|
||||
ConverterTime::class,
|
||||
ConverterDate::class,
|
||||
@ -188,6 +188,7 @@ abstract class AppDb : RoomDatabase() {
|
||||
Migration97(),
|
||||
Migration98(),
|
||||
Migration99(),
|
||||
Migration100(),
|
||||
).allowMainThreadQueries().build()
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,9 @@ abstract class TimetableDao : BaseDao<Lesson, LessonFull> {
|
||||
fun getByIdNow(profileId: Int, id: Long) =
|
||||
getOneNow("$QUERY WHERE timetable.profileId = $profileId AND timetable.id = $id")
|
||||
|
||||
fun getByOwnerIdNow(profileId: Int, ownerId: Long) =
|
||||
getOneNow("$QUERY WHERE timetable.profileId = $profileId AND timetable.ownerId = $ownerId")
|
||||
|
||||
@Query("UPDATE timetable SET keep = 0 WHERE profileId = :profileId AND isExtra = :isExtra AND type != -1 AND ((type != 3 AND date >= :dateFrom) OR ((type = 3 OR type = 1) AND oldDate >= :dateFrom))")
|
||||
abstract fun dontKeepFromDate(profileId: Int, dateFrom: Date, isExtra: Boolean)
|
||||
|
||||
|
@ -50,6 +50,13 @@ open class Lesson(
|
||||
|
||||
var isExtra: Boolean = false
|
||||
|
||||
/**
|
||||
* Stable ID denoting this lesson, used for note sharing (i.e. [profileId]-independent).
|
||||
*
|
||||
* This is simply the Unix timestamp of the lesson (in seconds).
|
||||
*/
|
||||
var ownerId: Long = id
|
||||
|
||||
val displayDate: Date?
|
||||
get() {
|
||||
if (type == TYPE_SHIFTED_SOURCE)
|
||||
@ -69,7 +76,12 @@ open class Lesson(
|
||||
val isChange
|
||||
get() = type == TYPE_CHANGE || type == TYPE_SHIFTED_TARGET
|
||||
|
||||
fun buildId(): Long = (displayDate?.combineWith(displayStartTime) ?: 0L) / 6L * 10L + (hashCode() and 0xFFFF)
|
||||
fun buildId(): Long =
|
||||
(displayDate?.combineWith(displayStartTime) ?: 0L) / 6L * 10L +
|
||||
(hashCode() and 0xFFFF)
|
||||
|
||||
fun buildOwnerId(): Long =
|
||||
(displayDate?.combineWith(displayStartTime) ?: 0L)
|
||||
|
||||
@Ignore
|
||||
var showAsUnseen = false
|
||||
|
@ -137,9 +137,9 @@ class LessonFull(
|
||||
var seen: Boolean = false
|
||||
var notified: Boolean = false
|
||||
|
||||
@Relation(parentColumn = "id", entityColumn = "noteOwnerId", entity = Note::class)
|
||||
@Relation(parentColumn = "ownerId", entityColumn = "noteOwnerId", entity = Note::class)
|
||||
override lateinit var notes: MutableList<Note>
|
||||
override fun getNoteType() = Note.OwnerType.LESSON
|
||||
override fun getNoteOwnerProfileId() = profileId
|
||||
override fun getNoteOwnerId() = id
|
||||
override fun getNoteOwnerId() = ownerId
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2022-10-25.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.db.migration
|
||||
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration100 : Migration(99, 100) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
// add Note Owner ID to Lesson, to make it profileId-independent
|
||||
// calculate the new owner ID based on the old ID
|
||||
database.execSQL("ALTER TABLE timetable ADD COLUMN ownerId INT NOT NULL DEFAULT 0;")
|
||||
// set new ID for actual lessons
|
||||
database.execSQL("UPDATE timetable SET ownerId = ROUND((id & ~65535) / 500000.0) * 300000;")
|
||||
// copy the old ID (date value) for NO_LESSONS
|
||||
database.execSQL("UPDATE timetable SET ownerId = id WHERE type = -1;")
|
||||
// update ID for notes as well
|
||||
database.execSQL("UPDATE notes SET noteOwnerId = ROUND((noteOwnerId & ~65535) / 500000.0) * 300000 WHERE noteOwnerType = 'LESSON' AND noteOwnerId > 2000000000000;")
|
||||
// force full app sync to download notes with new IDs
|
||||
database.execSQL("DELETE FROM config WHERE `key` = 'hash';")
|
||||
database.execSQL("DELETE FROM config WHERE `key` = 'lastAppSync';")
|
||||
}
|
||||
}
|
@ -80,7 +80,7 @@ class NoteManager(private val app: App) {
|
||||
OwnerType.GRADE ->
|
||||
app.db.gradeDao().getByIdNow(note.profileId, note.ownerId)
|
||||
OwnerType.LESSON ->
|
||||
app.db.timetableDao().getByIdNow(note.profileId, note.ownerId)
|
||||
app.db.timetableDao().getByOwnerIdNow(note.profileId, note.ownerId)
|
||||
OwnerType.MESSAGE ->
|
||||
app.db.messageDao().getByIdNow(note.profileId, note.ownerId)
|
||||
else -> null
|
||||
|
Loading…
Reference in New Issue
Block a user