mirror of
https://github.com/Matte23/circolapp.git
synced 2025-12-06 07:29:10 +00:00
Highlight unread circulars on Android
This commit is contained in:
@@ -26,6 +26,7 @@ data class Circular(
|
||||
val date: String,
|
||||
var favourite: Boolean = false,
|
||||
var reminder: Boolean = false,
|
||||
var read: Boolean = false,
|
||||
val attachmentsNames: MutableList<String> = mutableListOf(),
|
||||
val attachmentsUrls: MutableList<String> = mutableListOf()
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ class CircularDao(
|
||||
private val appDatabaseQueries = database.appDatabaseQueries
|
||||
|
||||
private val circularMapper =
|
||||
{ id: Long, school: Long, name: String, url: String, date: String, favourite: Long, reminder: Long, attachmentsNames: String, attachmentsUrls: String ->
|
||||
{ id: Long, school: Long, name: String, url: String, date: String, favourite: Long, reminder: Long, read: Long, attachmentsNames: String, attachmentsUrls: String ->
|
||||
Circular(
|
||||
id,
|
||||
school.toInt(),
|
||||
@@ -25,6 +25,7 @@ class CircularDao(
|
||||
date,
|
||||
favourite.toBoolean(),
|
||||
reminder.toBoolean(),
|
||||
read.toBoolean(),
|
||||
attachmentsNames.toList(),
|
||||
attachmentsUrls.toList()
|
||||
)
|
||||
@@ -40,6 +41,7 @@ class CircularDao(
|
||||
it.date,
|
||||
it.favourite.toLong(),
|
||||
it.reminder.toLong(),
|
||||
it.read.toLong(),
|
||||
it.attachmentsNames.joinToString(),
|
||||
it.attachmentsUrls.joinToString()
|
||||
)
|
||||
@@ -56,11 +58,28 @@ class CircularDao(
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun markRead(id: Long, school: Int, read: Boolean) =
|
||||
withContext(PlatformDispatcher.IO) {
|
||||
appDatabaseQueries.markCircularRead(
|
||||
read.toLong(),
|
||||
id,
|
||||
school.toLong()
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun markAllRead(read: Boolean) =
|
||||
withContext(PlatformDispatcher.IO) {
|
||||
appDatabaseQueries.markAllRead(
|
||||
read.toLong()
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun deleteAll() = withContext(PlatformDispatcher.IO) {
|
||||
appDatabaseQueries.deleteAllCirculars()
|
||||
}
|
||||
|
||||
fun getCircular(id: Long, school: Int) = appDatabaseQueries.getCircular(id, school.toLong(), circularMapper).executeAsOne()
|
||||
fun getCircular(id: Long, school: Int) =
|
||||
appDatabaseQueries.getCircular(id, school.toLong(), circularMapper).executeAsOne()
|
||||
|
||||
fun getCirculars(school: Int) =
|
||||
appDatabaseQueries.getCirculars(school.toLong(), circularMapper).executeAsList()
|
||||
|
||||
@@ -6,20 +6,30 @@ CREATE TABLE Circulars (
|
||||
date TEXT NOT NULL,
|
||||
favourite INTEGER NOT NULL DEFAULT 0,
|
||||
reminder INTEGER NOT NULL DEFAULT 0,
|
||||
read INTEGER NOT NULL DEFAULT 0,
|
||||
attachmentsNames TEXT NOT NULL,
|
||||
attachmentsUrls TEXT NOT NULL,
|
||||
PRIMARY KEY (id, school)
|
||||
);
|
||||
|
||||
insertCircular:
|
||||
INSERT OR IGNORE INTO Circulars(id, school, name, url, date, favourite, reminder, attachmentsNames, attachmentsUrls)
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?);
|
||||
INSERT OR IGNORE INTO Circulars(id, school, name, url, date, favourite, reminder, read, attachmentsNames, attachmentsUrls)
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
|
||||
|
||||
updateCircular:
|
||||
UPDATE Circulars
|
||||
SET favourite = ?, reminder = ?
|
||||
WHERE id = ? AND school = ?;
|
||||
|
||||
markCircularRead:
|
||||
UPDATE Circulars
|
||||
SET read = ?
|
||||
WHERE id = ? AND school = ?;
|
||||
|
||||
markAllRead:
|
||||
UPDATE Circulars
|
||||
SET read = ?;
|
||||
|
||||
deleteAllCirculars:
|
||||
DELETE FROM Circulars;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user