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
@@ -0,0 +1,33 @@
package com.subtracks.data.prefs
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
enum class AlbumSort { Name, Artist, Year, RecentlyAdded }
private val Context.preferences: DataStore<Preferences> by preferencesDataStore("user_prefs")
class UserPreferences(
private val store: DataStore<Preferences>,
) {
val albumSort: Flow<AlbumSort> =
store.data.map { prefs ->
prefs[ALBUM_SORT]?.let { stored -> AlbumSort.entries.firstOrNull { it.name == stored } } ?: AlbumSort.Name
}
suspend fun setAlbumSort(sort: AlbumSort) {
store.edit { prefs -> prefs[ALBUM_SORT] = sort.name }
}
private companion object {
val ALBUM_SORT = stringPreferencesKey("album_sort")
}
}
fun createUserPreferences(context: Context): UserPreferences = UserPreferences(context.preferences)