Add color scheme backup / restore

This commit is contained in:
MM20
2023-08-26 18:52:35 +02:00
parent f223e9307d
commit ff7a72f7c4
9 changed files with 75 additions and 8 deletions
+1
View File
@@ -46,5 +46,6 @@ dependencies {
implementation(project(":core:preferences"))
implementation(project(":core:ktx"))
implementation(project(":data:customattrs"))
implementation(project(":data:themes"))
}
@@ -5,11 +5,12 @@ enum class BackupComponent(val value: String) {
Favorites("favorites"),
Widgets("widgets2"),
Customizations("customizations"),
SearchActions("searchactions");
SearchActions("searchactions"),
Themes("themes");
companion object {
fun fromValue(value: String): BackupComponent? {
return values().firstOrNull { it.value == value }
return entries.firstOrNull { it.value == value }
}
}
}
@@ -9,6 +9,7 @@ import de.mm20.launcher2.preferences.LauncherDataStore
import de.mm20.launcher2.preferences.export
import de.mm20.launcher2.preferences.import
import de.mm20.launcher2.searchactions.SearchActionRepository
import de.mm20.launcher2.themes.ThemeRepository
import de.mm20.launcher2.widgets.WidgetRepository
import kotlinx.coroutines.*
import java.io.File
@@ -25,6 +26,7 @@ class BackupManager(
private val widgetRepository: WidgetRepository,
private val searchActionRepository: SearchActionRepository,
private val customAttrsRepository: CustomAttributesRepository,
private val themesRepository: ThemeRepository,
) {
private val scope = CoroutineScope(Dispatchers.Default + Job())
@@ -34,7 +36,7 @@ class BackupManager(
*/
suspend fun backup(
uri: Uri,
include: Set<BackupComponent> = BackupComponent.values().toSet()
include: Set<BackupComponent> = BackupComponent.entries.toSet()
) {
val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0)
@@ -78,6 +80,10 @@ class BackupManager(
customAttrsRepository.export(backupDir)
}
if (include.contains(BackupComponent.Themes)) {
themesRepository.export(backupDir)
}
createArchive(backupDir, outputStream)
outputStream.close()
@@ -118,6 +124,10 @@ class BackupManager(
if (include.contains(BackupComponent.Customizations)) {
customAttrsRepository.import(restoreDir)
}
if (include.contains(BackupComponent.Themes)) {
themesRepository.import(restoreDir)
}
}
}
job.join()
@@ -188,7 +198,7 @@ class BackupManager(
*/
private const val BackupFormatMajor = 1
private const val BackupFormatMinor = 6
private const val BackupFormatMinor = 7
internal const val BackupFormat = "$BackupFormatMajor.$BackupFormatMinor"
}
}
@@ -4,5 +4,5 @@ import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module
val backupModule = module {
single { BackupManager(androidContext(), get(), get(), get(), get(), get()) }
single { BackupManager(androidContext(), get(), get(), get(), get(), get(), get()) }
}