Refactor preferences module
This commit is contained in:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user