|
@@ -46,6 +46,7 @@ class ThemeManageViewModel(
|
|
|
is ThemeManageIntent.SaveTheme -> saveTheme(intent)
|
|
is ThemeManageIntent.SaveTheme -> saveTheme(intent)
|
|
|
is ThemeManageIntent.ApplySavedTheme -> applySavedTheme(intent.theme)
|
|
is ThemeManageIntent.ApplySavedTheme -> applySavedTheme(intent.theme)
|
|
|
is ThemeManageIntent.DeleteSavedTheme -> deleteSavedTheme(intent.theme)
|
|
is ThemeManageIntent.DeleteSavedTheme -> deleteSavedTheme(intent.theme)
|
|
|
|
|
+ ThemeManageIntent.MigrateLegacyThemes -> migrateLegacyThemes()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -53,10 +54,12 @@ class ThemeManageViewModel(
|
|
|
launchExclusive {
|
|
launchExclusive {
|
|
|
_uiState.update { it.copy(loading = true) }
|
|
_uiState.update { it.copy(loading = true) }
|
|
|
val themes = themePackageManager.loadSavedThemes()
|
|
val themes = themePackageManager.loadSavedThemes()
|
|
|
|
|
+ val hasLegacyThemes = themePackageManager.hasLegacySavedThemes()
|
|
|
_uiState.update {
|
|
_uiState.update {
|
|
|
it.copy(
|
|
it.copy(
|
|
|
loading = false,
|
|
loading = false,
|
|
|
savedThemes = themes.toImmutableList(),
|
|
savedThemes = themes.toImmutableList(),
|
|
|
|
|
+ hasLegacyThemes = hasLegacyThemes,
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -187,6 +190,21 @@ class ThemeManageViewModel(
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private fun migrateLegacyThemes() {
|
|
|
|
|
+ launchExclusive {
|
|
|
|
|
+ _uiState.update { it.copy(loading = true) }
|
|
|
|
|
+ val result = themePackageManager.migrateLegacySavedThemes()
|
|
|
|
|
+ refreshSavedThemes()
|
|
|
|
|
+ _uiState.update { it.copy(hasLegacyThemes = result.failedCount > 0) }
|
|
|
|
|
+ _effects.emit(
|
|
|
|
|
+ ThemeManageEffect.LegacyMigrationFinished(
|
|
|
|
|
+ migratedCount = result.migratedCount,
|
|
|
|
|
+ failedCount = result.failedCount,
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private fun launchExclusive(block: suspend () -> Unit) {
|
|
private fun launchExclusive(block: suspend () -> Unit) {
|
|
|
if (!operationMutex.tryLock()) return
|
|
if (!operationMutex.tryLock()) return
|
|
|
viewModelScope.launch {
|
|
viewModelScope.launch {
|
|
@@ -203,6 +221,7 @@ class ThemeManageViewModel(
|
|
|
data class ThemeManageUiState(
|
|
data class ThemeManageUiState(
|
|
|
val loading: Boolean = false,
|
|
val loading: Boolean = false,
|
|
|
val savedThemes: ImmutableList<SavedTheme> = persistentListOf(),
|
|
val savedThemes: ImmutableList<SavedTheme> = persistentListOf(),
|
|
|
|
|
+ val hasLegacyThemes: Boolean = false,
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
sealed interface ThemeManageIntent {
|
|
sealed interface ThemeManageIntent {
|
|
@@ -225,11 +244,17 @@ sealed interface ThemeManageIntent {
|
|
|
|
|
|
|
|
data class ApplySavedTheme(val theme: SavedTheme) : ThemeManageIntent
|
|
data class ApplySavedTheme(val theme: SavedTheme) : ThemeManageIntent
|
|
|
data class DeleteSavedTheme(val theme: SavedTheme) : ThemeManageIntent
|
|
data class DeleteSavedTheme(val theme: SavedTheme) : ThemeManageIntent
|
|
|
|
|
+ data object MigrateLegacyThemes : ThemeManageIntent
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
sealed interface ThemeManageEffect {
|
|
sealed interface ThemeManageEffect {
|
|
|
data object RestartRequired : ThemeManageEffect
|
|
data object RestartRequired : ThemeManageEffect
|
|
|
|
|
|
|
|
|
|
+ data class LegacyMigrationFinished(
|
|
|
|
|
+ val migratedCount: Int,
|
|
|
|
|
+ val failedCount: Int,
|
|
|
|
|
+ ) : ThemeManageEffect
|
|
|
|
|
+
|
|
|
data class ShowResult(
|
|
data class ShowResult(
|
|
|
@param:StringRes val messageRes: Int,
|
|
@param:StringRes val messageRes: Int,
|
|
|
val detail: String? = null,
|
|
val detail: String? = null,
|