Refactor preferences module

This commit is contained in:
MM20
2024-01-19 22:29:37 +01:00
parent 94aee6baba
commit 92ddc75060
171 changed files with 3202 additions and 2962 deletions
+1
View File
@@ -46,6 +46,7 @@ dependencies {
implementation(project(":core:base"))
implementation(project(":data:database"))
implementation(project(":core:crashreporter"))
implementation(project(":core:preferences"))
implementation(project(":libs:material-color-utilities"))
}
@@ -4,6 +4,7 @@ import android.content.Context
import de.mm20.launcher2.backup.Backupable
import de.mm20.launcher2.crashreporter.CrashReporter
import de.mm20.launcher2.database.AppDatabase
import de.mm20.launcher2.preferences.ThemeDescriptor
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@@ -49,9 +50,15 @@ class ThemeRepository(
}
}
fun getThemeOrDefault(id: UUID?): Flow<Theme> {
if (id == null) return flowOf(getDefaultTheme())
return getTheme(id).map { it ?: getDefaultTheme() }
fun getThemeOrDefault(theme: ThemeDescriptor?): Flow<Theme> {
return when(theme) {
is ThemeDescriptor.BlackAndWhite -> flowOf(getBlackAndWhiteTheme())
is ThemeDescriptor.Custom -> {
val id = UUID.fromString(theme.id)
getTheme(id).map { it ?: getDefaultTheme() }
}
else -> flowOf(getDefaultTheme())
}
}
private fun getBuiltInThemes(): List<Theme> {