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 -->
|
// KMK -->
|
||||||
when (key) {
|
when (key) {
|
||||||
SourcePreferences.PINNED_SOURCES_PREF_KEY ->
|
SourcePreferences.PINNED_SOURCES_PREF_KEY ->
|
||||||
EXHMigrations.migratePinnedSources(value.value)
|
restorePinnedSourcesPreference(
|
||||||
|
key,
|
||||||
|
value.value,
|
||||||
|
preferenceStore,
|
||||||
|
)
|
||||||
else ->
|
else ->
|
||||||
// KMK <--
|
// KMK <--
|
||||||
preferenceStore.getStringSet(key).set(value.value)
|
preferenceStore.getStringSet(key).set(value.value)
|
||||||
|
|
@ -151,4 +155,15 @@ class PreferenceRestorer(
|
||||||
}
|
}
|
||||||
return true
|
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
|
* Migrate old source ID of delegated sources in old backup
|
||||||
*/
|
*/
|
||||||
fun migratePinnedSources(pinnedSources: Set<String>): Set<String> {
|
fun migrateSourceIds(oldSourceIds: Set<String>): Set<String> {
|
||||||
var pinned = pinnedSources
|
var newSourceIds = oldSourceIds
|
||||||
if (NHENTAI_OLD_ID.toString() in pinned) {
|
if (NHENTAI_OLD_ID.toString() in newSourceIds) {
|
||||||
pinned = pinned.minus(NHENTAI_OLD_ID.toString())
|
newSourceIds = newSourceIds.minus(NHENTAI_OLD_ID.toString())
|
||||||
.plus(NHENTAI_SOURCE_ID.toString())
|
.plus(NHENTAI_SOURCE_ID.toString())
|
||||||
}
|
}
|
||||||
if (TSUMINO_OLD_ID.toString() in pinned) {
|
if (TSUMINO_OLD_ID.toString() in newSourceIds) {
|
||||||
pinned = pinned.minus(TSUMINO_OLD_ID.toString())
|
newSourceIds = newSourceIds.minus(TSUMINO_OLD_ID.toString())
|
||||||
.plus(TSUMINO_SOURCE_ID.toString())
|
.plus(TSUMINO_SOURCE_ID.toString())
|
||||||
}
|
}
|
||||||
if (HBROWSE_OLD_ID.toString() in pinned) {
|
if (HBROWSE_OLD_ID.toString() in newSourceIds) {
|
||||||
pinned = pinned.minus(HBROWSE_OLD_ID.toString())
|
newSourceIds = newSourceIds.minus(HBROWSE_OLD_ID.toString())
|
||||||
.plus(HBROWSE_SOURCE_ID.toString())
|
.plus(HBROWSE_SOURCE_ID.toString())
|
||||||
}
|
}
|
||||||
if (EH_OLD_ID.toString() in pinned) {
|
if (EH_OLD_ID.toString() in newSourceIds) {
|
||||||
pinned = pinned.minus(EH_OLD_ID.toString())
|
newSourceIds = newSourceIds.minus(EH_OLD_ID.toString())
|
||||||
.plus(EH_SOURCE_ID.toString())
|
.plus(EH_SOURCE_ID.toString())
|
||||||
}
|
}
|
||||||
if (EXH_OLD_ID.toString() in pinned) {
|
if (EXH_OLD_ID.toString() in newSourceIds) {
|
||||||
pinned = pinned.minus(EXH_OLD_ID.toString())
|
newSourceIds = newSourceIds.minus(EXH_OLD_ID.toString())
|
||||||
.plus(EXH_SOURCE_ID.toString())
|
.plus(EXH_SOURCE_ID.toString())
|
||||||
}
|
}
|
||||||
return pinned
|
return newSourceIds
|
||||||
}
|
}
|
||||||
// KMK -->
|
// KMK -->
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue