add preferences, paging reads, repositories and sync status

This commit is contained in:
austinried
2026-10-04 00:29:51 +00:00
parent 46bc95104d
commit 3f91a29850
18 changed files with 691 additions and 239 deletions
@@ -1,11 +1,12 @@
package com.subtracks.data.db
import androidx.room3.Dao
import androidx.room3.Insert
import androidx.room3.Query
import androidx.room3.Transaction
import androidx.room3.Upsert
import com.subtracks.data.model.AppSettings
import com.subtracks.data.model.Source
import com.subtracks.data.model.SubsonicConfig
import com.subtracks.data.model.SubsonicSource
import kotlinx.coroutines.flow.Flow
@@ -23,6 +24,15 @@ interface SourcesDao {
@Query("SELECT * FROM subsonic_sources WHERE sourceId = :sourceId")
fun subsonicSource(sourceId: Long): Flow<SubsonicSource?>
@Query("SELECT id FROM sources WHERE isActive = 1 LIMIT 1")
suspend fun activeSourceIdOnce(): Long?
@Query("SELECT id FROM sources ORDER BY createdAt LIMIT 1")
suspend fun firstSourceId(): Long?
@Insert
suspend fun insertSource(source: Source): Long
@Upsert
suspend fun upsertSource(source: Source)
@@ -44,9 +54,19 @@ interface SourcesDao {
@Query("UPDATE sources SET isActive = (id = :sourceId)")
suspend fun setActiveSource(sourceId: Long)
@Query("SELECT * FROM app_settings WHERE id = 1")
fun appSettings(): Flow<AppSettings?>
@Query(
"SELECT s.id AS id, s.name AS name, s.address AS address, c.username AS username, " +
"c.password AS password, c.useTokenAuth AS useTokenAuth " +
"FROM sources s JOIN subsonic_sources c ON c.sourceId = s.id " +
"WHERE s.isActive = 1 LIMIT 1",
)
fun activeSubsonicConfig(): Flow<SubsonicConfig?>
@Upsert
suspend fun upsertAppSettings(settings: AppSettings)
@Query(
"SELECT s.id AS id, s.name AS name, s.address AS address, c.username AS username, " +
"c.password AS password, c.useTokenAuth AS useTokenAuth " +
"FROM sources s JOIN subsonic_sources c ON c.sourceId = s.id " +
"WHERE s.isActive = 1 LIMIT 1",
)
suspend fun activeSubsonicConfigOnce(): SubsonicConfig?
}