Fix: Pinned sources were not restored from backup (#787)
* Fix: Pinned sources were not restored from backup * improve code readability * rename migrateSourceIds function
This commit is contained in:
parent
0828057650
commit
259a00ebaf
2 changed files with 29 additions and 14 deletions
|
|
@ -113,7 +113,11 @@ class PreferenceRestorer(
|
|||
// KMK -->
|
||||
when (key) {
|
||||
SourcePreferences.PINNED_SOURCES_PREF_KEY ->
|
||||
EXHMigrations.migratePinnedSources(value.value)
|
||||
restorePinnedSourcesPreference(
|
||||
key,
|
||||
value.value,
|
||||
preferenceStore,
|
||||
)
|
||||
else ->
|
||||
// KMK <--
|
||||
preferenceStore.getStringSet(key).set(value.value)
|
||||
|
|
@ -151,4 +155,15 @@ class PreferenceRestorer(
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun restorePinnedSourcesPreference(
|
||||
key: String,
|
||||
value: Set<String>,
|
||||
preferenceStore: PreferenceStore,
|
||||
) {
|
||||
if (value.isEmpty()) return
|
||||
|
||||
val valueToSet = EXHMigrations.migrateSourceIds(value)
|
||||
preferenceStore.getStringSet(key).set(valueToSet)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,29 +140,29 @@ object EXHMigrations {
|
|||
/**
|
||||
* Migrate old source ID of delegated sources in old backup
|
||||
*/
|
||||
fun migratePinnedSources(pinnedSources: Set<String>): Set<String> {
|
||||
var pinned = pinnedSources
|
||||
if (NHENTAI_OLD_ID.toString() in pinned) {
|
||||
pinned = pinned.minus(NHENTAI_OLD_ID.toString())
|
||||
fun migrateSourceIds(oldSourceIds: Set<String>): Set<String> {
|
||||
var newSourceIds = oldSourceIds
|
||||
if (NHENTAI_OLD_ID.toString() in newSourceIds) {
|
||||
newSourceIds = newSourceIds.minus(NHENTAI_OLD_ID.toString())
|
||||
.plus(NHENTAI_SOURCE_ID.toString())
|
||||
}
|
||||
if (TSUMINO_OLD_ID.toString() in pinned) {
|
||||
pinned = pinned.minus(TSUMINO_OLD_ID.toString())
|
||||
if (TSUMINO_OLD_ID.toString() in newSourceIds) {
|
||||
newSourceIds = newSourceIds.minus(TSUMINO_OLD_ID.toString())
|
||||
.plus(TSUMINO_SOURCE_ID.toString())
|
||||
}
|
||||
if (HBROWSE_OLD_ID.toString() in pinned) {
|
||||
pinned = pinned.minus(HBROWSE_OLD_ID.toString())
|
||||
if (HBROWSE_OLD_ID.toString() in newSourceIds) {
|
||||
newSourceIds = newSourceIds.minus(HBROWSE_OLD_ID.toString())
|
||||
.plus(HBROWSE_SOURCE_ID.toString())
|
||||
}
|
||||
if (EH_OLD_ID.toString() in pinned) {
|
||||
pinned = pinned.minus(EH_OLD_ID.toString())
|
||||
if (EH_OLD_ID.toString() in newSourceIds) {
|
||||
newSourceIds = newSourceIds.minus(EH_OLD_ID.toString())
|
||||
.plus(EH_SOURCE_ID.toString())
|
||||
}
|
||||
if (EXH_OLD_ID.toString() in pinned) {
|
||||
pinned = pinned.minus(EXH_OLD_ID.toString())
|
||||
if (EXH_OLD_ID.toString() in newSourceIds) {
|
||||
newSourceIds = newSourceIds.minus(EXH_OLD_ID.toString())
|
||||
.plus(EXH_SOURCE_ID.toString())
|
||||
}
|
||||
return pinned
|
||||
return newSourceIds
|
||||
}
|
||||
// KMK -->
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue