2017-05-21 13:42:06 +02:00
|
|
|
package eu.kanade.tachiyomi
|
|
|
|
|
2022-09-17 17:48:24 +02:00
|
|
|
import android.content.Context
|
2020-09-14 23:52:00 +02:00
|
|
|
import androidx.core.content.edit
|
|
|
|
import androidx.preference.PreferenceManager
|
2022-09-25 16:07:06 +02:00
|
|
|
import eu.kanade.domain.base.BasePreferences
|
2022-09-18 16:36:41 +02:00
|
|
|
import eu.kanade.domain.source.service.SourcePreferences
|
2022-09-25 16:07:06 +02:00
|
|
|
import eu.kanade.domain.ui.UiPreferences
|
2022-09-18 19:07:48 +02:00
|
|
|
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
2023-03-19 22:28:59 +01:00
|
|
|
import eu.kanade.tachiyomi.data.backup.BackupCreateJob
|
2017-05-21 13:42:06 +02:00
|
|
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
2023-09-26 05:22:16 +02:00
|
|
|
import eu.kanade.tachiyomi.data.track.TrackerManager
|
2022-09-17 17:48:24 +02:00
|
|
|
import eu.kanade.tachiyomi.network.NetworkPreferences
|
2021-04-11 19:10:03 +02:00
|
|
|
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
|
2023-11-05 16:01:19 +01:00
|
|
|
import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation
|
2022-09-20 14:36:57 +02:00
|
|
|
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
|
2022-02-06 05:02:13 +01:00
|
|
|
import eu.kanade.tachiyomi.util.system.DeviceUtil
|
2020-12-13 23:52:21 +01:00
|
|
|
import eu.kanade.tachiyomi.util.system.toast
|
2023-03-19 23:19:40 +01:00
|
|
|
import eu.kanade.tachiyomi.util.system.workManager
|
2023-10-08 17:07:42 +02:00
|
|
|
import tachiyomi.core.preference.Preference
|
2023-01-28 04:31:12 +01:00
|
|
|
import tachiyomi.core.preference.PreferenceStore
|
2023-07-10 23:25:52 +02:00
|
|
|
import tachiyomi.core.preference.TriState
|
2023-08-25 04:25:29 +02:00
|
|
|
import tachiyomi.core.preference.getAndSet
|
2023-02-24 22:09:47 +01:00
|
|
|
import tachiyomi.core.preference.getEnum
|
2023-07-20 03:57:22 +02:00
|
|
|
import tachiyomi.core.preference.minusAssign
|
|
|
|
import tachiyomi.core.preference.plusAssign
|
2023-03-05 18:38:31 +01:00
|
|
|
import tachiyomi.domain.backup.service.BackupPreferences
|
2023-03-08 04:38:02 +01:00
|
|
|
import tachiyomi.domain.library.service.LibraryPreferences
|
|
|
|
import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_NON_COMPLETED
|
2023-11-18 19:54:56 +01:00
|
|
|
import tachiyomi.i18n.MR
|
2017-05-21 13:42:06 +02:00
|
|
|
import java.io.File
|
|
|
|
|
|
|
|
object Migrations {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs a migration when the application is updated.
|
|
|
|
*
|
|
|
|
* @return true if a migration is performed, false otherwise.
|
|
|
|
*/
|
2022-09-17 17:48:24 +02:00
|
|
|
fun upgrade(
|
|
|
|
context: Context,
|
2022-09-25 16:07:06 +02:00
|
|
|
preferenceStore: PreferenceStore,
|
|
|
|
basePreferences: BasePreferences,
|
|
|
|
uiPreferences: UiPreferences,
|
2022-09-17 17:48:24 +02:00
|
|
|
networkPreferences: NetworkPreferences,
|
2022-09-18 16:36:41 +02:00
|
|
|
sourcePreferences: SourcePreferences,
|
2022-09-18 19:07:48 +02:00
|
|
|
securityPreferences: SecurityPreferences,
|
2022-09-20 05:55:07 +02:00
|
|
|
libraryPreferences: LibraryPreferences,
|
2022-09-20 14:36:57 +02:00
|
|
|
readerPreferences: ReaderPreferences,
|
2022-09-22 14:57:42 +02:00
|
|
|
backupPreferences: BackupPreferences,
|
2023-09-26 05:22:16 +02:00
|
|
|
trackerManager: TrackerManager,
|
2022-09-17 17:48:24 +02:00
|
|
|
): Boolean {
|
2023-11-22 04:11:44 +01:00
|
|
|
val lastVersionCode = preferenceStore.getInt(Preference.appStateKey("last_version_code"), 0)
|
2022-09-25 16:07:06 +02:00
|
|
|
val oldVersion = lastVersionCode.get()
|
2017-05-21 13:42:06 +02:00
|
|
|
if (oldVersion < BuildConfig.VERSION_CODE) {
|
2022-09-25 16:07:06 +02:00
|
|
|
lastVersionCode.set(BuildConfig.VERSION_CODE)
|
2017-05-21 13:42:06 +02:00
|
|
|
|
2021-08-14 00:28:07 +02:00
|
|
|
// Always set up background tasks to ensure they're running
|
|
|
|
LibraryUpdateJob.setupTask(context)
|
2023-03-19 22:28:59 +01:00
|
|
|
BackupCreateJob.setupTask(context)
|
2021-08-14 00:28:07 +02:00
|
|
|
|
2020-03-07 19:11:02 +01:00
|
|
|
// Fresh install
|
|
|
|
if (oldVersion == 0) {
|
|
|
|
return false
|
|
|
|
}
|
2017-05-21 13:42:06 +02:00
|
|
|
|
2021-12-17 15:57:37 +01:00
|
|
|
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
|
|
|
|
2017-05-21 13:42:06 +02:00
|
|
|
if (oldVersion < 14) {
|
2020-03-07 19:00:58 +01:00
|
|
|
// Restore jobs after upgrading to Evernote's job scheduler.
|
|
|
|
LibraryUpdateJob.setupTask(context)
|
2017-05-21 13:42:06 +02:00
|
|
|
}
|
|
|
|
if (oldVersion < 15) {
|
|
|
|
// Delete internal chapter cache dir.
|
|
|
|
File(context.cacheDir, "chapter_disk_cache").deleteRecursively()
|
|
|
|
}
|
|
|
|
if (oldVersion < 19) {
|
|
|
|
// Move covers to external files dir.
|
|
|
|
val oldDir = File(context.externalCacheDir, "cover_disk_cache")
|
|
|
|
if (oldDir.exists()) {
|
|
|
|
val destDir = context.getExternalFilesDir("covers")
|
|
|
|
if (destDir != null) {
|
2020-03-07 19:00:58 +01:00
|
|
|
oldDir.listFiles()?.forEach {
|
2017-05-21 13:42:06 +02:00
|
|
|
it.renameTo(File(destDir, it.name))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-10 12:29:04 +02:00
|
|
|
if (oldVersion < 26) {
|
|
|
|
// Delete external chapter cache dir.
|
|
|
|
val extCache = context.externalCacheDir
|
|
|
|
if (extCache != null) {
|
|
|
|
val chapterCache = File(extCache, "chapter_disk_cache")
|
|
|
|
if (chapterCache.exists()) {
|
|
|
|
chapterCache.deleteRecursively()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-13 22:29:51 +01:00
|
|
|
if (oldVersion < 43) {
|
|
|
|
// Restore jobs after migrating from Evernote's job scheduler to WorkManager.
|
|
|
|
LibraryUpdateJob.setupTask(context)
|
2023-03-19 22:28:59 +01:00
|
|
|
BackupCreateJob.setupTask(context)
|
2020-03-13 22:29:51 +01:00
|
|
|
}
|
2020-05-02 01:59:08 +02:00
|
|
|
if (oldVersion < 44) {
|
|
|
|
// Reset sorting preference if using removed sort by source
|
2023-08-25 04:25:29 +02:00
|
|
|
val oldSortingMode = prefs.getInt(libraryPreferences.sortingMode().key(), 0)
|
2021-06-26 19:30:16 +02:00
|
|
|
|
2022-08-18 20:06:32 +02:00
|
|
|
if (oldSortingMode == 5) { // SOURCE = 5
|
2021-06-26 19:30:16 +02:00
|
|
|
prefs.edit {
|
2023-08-25 04:25:29 +02:00
|
|
|
putInt(libraryPreferences.sortingMode().key(), 0) // ALPHABETICAL = 0
|
2021-06-26 19:30:16 +02:00
|
|
|
}
|
2020-05-02 01:59:08 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-14 23:52:00 +02:00
|
|
|
if (oldVersion < 52) {
|
|
|
|
// Migrate library filters to tri-state versions
|
|
|
|
fun convertBooleanPrefToTriState(key: String): Int {
|
|
|
|
val oldPrefValue = prefs.getBoolean(key, false)
|
2022-09-11 05:57:03 +02:00
|
|
|
return if (oldPrefValue) {
|
2023-02-24 22:09:47 +01:00
|
|
|
1
|
2022-09-11 05:57:03 +02:00
|
|
|
} else {
|
2023-02-24 22:09:47 +01:00
|
|
|
0
|
2022-09-11 05:57:03 +02:00
|
|
|
}
|
2020-09-14 23:52:00 +02:00
|
|
|
}
|
|
|
|
prefs.edit {
|
2023-11-05 04:28:41 +01:00
|
|
|
putInt(
|
|
|
|
libraryPreferences.filterDownloaded().key(),
|
|
|
|
convertBooleanPrefToTriState("pref_filter_downloaded_key"),
|
|
|
|
)
|
2020-09-14 23:52:00 +02:00
|
|
|
remove("pref_filter_downloaded_key")
|
2020-09-15 23:53:01 +02:00
|
|
|
|
2023-11-05 04:28:41 +01:00
|
|
|
putInt(
|
|
|
|
libraryPreferences.filterUnread().key(),
|
|
|
|
convertBooleanPrefToTriState("pref_filter_unread_key"),
|
|
|
|
)
|
2020-09-14 23:52:00 +02:00
|
|
|
remove("pref_filter_unread_key")
|
2020-09-15 23:53:01 +02:00
|
|
|
|
2023-11-05 04:28:41 +01:00
|
|
|
putInt(
|
|
|
|
libraryPreferences.filterCompleted().key(),
|
|
|
|
convertBooleanPrefToTriState("pref_filter_completed_key"),
|
|
|
|
)
|
2020-09-14 23:52:00 +02:00
|
|
|
remove("pref_filter_completed_key")
|
|
|
|
}
|
2020-12-19 05:20:42 +01:00
|
|
|
}
|
2020-12-21 23:10:08 +01:00
|
|
|
if (oldVersion < 54) {
|
2020-12-12 17:26:42 +01:00
|
|
|
// Force MAL log out due to login flow change
|
2020-12-19 05:20:42 +01:00
|
|
|
// v52: switched from scraping to WebView
|
|
|
|
// v53: switched from WebView to OAuth
|
2023-09-26 05:22:16 +02:00
|
|
|
if (trackerManager.myAnimeList.isLoggedIn) {
|
|
|
|
trackerManager.myAnimeList.logout()
|
2023-11-18 19:54:56 +01:00
|
|
|
context.toast(MR.strings.myanimelist_relogin)
|
2020-12-13 23:52:21 +01:00
|
|
|
}
|
2020-09-14 23:52:00 +02:00
|
|
|
}
|
2021-04-11 19:10:03 +02:00
|
|
|
if (oldVersion < 57) {
|
|
|
|
// Migrate DNS over HTTPS setting
|
|
|
|
val wasDohEnabled = prefs.getBoolean("enable_doh", false)
|
|
|
|
if (wasDohEnabled) {
|
|
|
|
prefs.edit {
|
2022-09-17 17:48:24 +02:00
|
|
|
putInt(networkPreferences.dohProvider().key(), PREF_DOH_CLOUDFLARE)
|
2021-04-11 19:10:03 +02:00
|
|
|
remove("enable_doh")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-24 04:37:43 +02:00
|
|
|
if (oldVersion < 59) {
|
|
|
|
// Reset rotation to Free after replacing Lock
|
2021-04-28 14:32:47 +02:00
|
|
|
if (prefs.contains("pref_rotation_type_key")) {
|
|
|
|
prefs.edit {
|
|
|
|
putInt("pref_rotation_type_key", 1)
|
|
|
|
}
|
|
|
|
}
|
2021-04-24 04:37:43 +02:00
|
|
|
}
|
2021-04-28 14:32:47 +02:00
|
|
|
if (oldVersion < 60) {
|
|
|
|
// Migrate Rotation and Viewer values to default values for viewer_flags
|
|
|
|
val newOrientation = when (prefs.getInt("pref_rotation_type_key", 1)) {
|
2023-11-05 16:01:19 +01:00
|
|
|
1 -> ReaderOrientation.FREE.flagValue
|
|
|
|
2 -> ReaderOrientation.PORTRAIT.flagValue
|
|
|
|
3 -> ReaderOrientation.LANDSCAPE.flagValue
|
|
|
|
4 -> ReaderOrientation.LOCKED_PORTRAIT.flagValue
|
|
|
|
5 -> ReaderOrientation.LOCKED_LANDSCAPE.flagValue
|
|
|
|
else -> ReaderOrientation.FREE.flagValue
|
2021-04-28 14:32:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reading mode flag and prefValue is the same value
|
|
|
|
val newReadingMode = prefs.getInt("pref_default_viewer_key", 1)
|
|
|
|
|
|
|
|
prefs.edit {
|
|
|
|
putInt("pref_default_orientation_type_key", newOrientation)
|
|
|
|
remove("pref_rotation_type_key")
|
|
|
|
putInt("pref_default_reading_mode_key", newReadingMode)
|
|
|
|
remove("pref_default_viewer_key")
|
|
|
|
}
|
|
|
|
}
|
2021-05-22 17:52:28 +02:00
|
|
|
if (oldVersion < 61) {
|
|
|
|
// Handle removed every 1 or 2 hour library updates
|
2023-08-25 04:25:29 +02:00
|
|
|
val updateInterval = libraryPreferences.autoUpdateInterval().get()
|
2021-05-22 17:52:28 +02:00
|
|
|
if (updateInterval == 1 || updateInterval == 2) {
|
2023-08-25 04:25:29 +02:00
|
|
|
libraryPreferences.autoUpdateInterval().set(3)
|
2021-05-22 17:52:28 +02:00
|
|
|
LibraryUpdateJob.setupTask(context, 3)
|
|
|
|
}
|
|
|
|
}
|
2021-06-26 19:30:16 +02:00
|
|
|
if (oldVersion < 64) {
|
2023-08-25 04:25:29 +02:00
|
|
|
val oldSortingMode = prefs.getInt(libraryPreferences.sortingMode().key(), 0)
|
2022-08-29 19:10:30 +02:00
|
|
|
val oldSortingDirection = prefs.getBoolean("library_sorting_ascending", true)
|
2021-06-26 19:30:16 +02:00
|
|
|
|
|
|
|
val newSortingMode = when (oldSortingMode) {
|
2022-08-29 19:10:30 +02:00
|
|
|
0 -> "ALPHABETICAL"
|
|
|
|
1 -> "LAST_READ"
|
|
|
|
2 -> "LAST_CHECKED"
|
|
|
|
3 -> "UNREAD"
|
|
|
|
4 -> "TOTAL_CHAPTERS"
|
|
|
|
6 -> "LATEST_CHAPTER"
|
|
|
|
8 -> "DATE_FETCHED"
|
|
|
|
7 -> "DATE_ADDED"
|
|
|
|
else -> "ALPHABETICAL"
|
2021-06-26 19:30:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
val newSortingDirection = when (oldSortingDirection) {
|
2022-08-29 19:10:30 +02:00
|
|
|
true -> "ASCENDING"
|
|
|
|
else -> "DESCENDING"
|
2021-06-26 19:30:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
prefs.edit(commit = true) {
|
2023-08-25 04:25:29 +02:00
|
|
|
remove(libraryPreferences.sortingMode().key())
|
2022-08-29 19:10:30 +02:00
|
|
|
remove("library_sorting_ascending")
|
2021-06-26 19:30:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
prefs.edit {
|
2023-08-25 04:25:29 +02:00
|
|
|
putString(libraryPreferences.sortingMode().key(), newSortingMode)
|
2022-08-29 19:10:30 +02:00
|
|
|
putString("library_sorting_ascending", newSortingDirection)
|
2021-06-26 19:30:16 +02:00
|
|
|
}
|
|
|
|
}
|
2021-10-13 00:31:27 +02:00
|
|
|
if (oldVersion < 70) {
|
2022-09-18 16:36:41 +02:00
|
|
|
if (sourcePreferences.enabledLanguages().isSet()) {
|
|
|
|
sourcePreferences.enabledLanguages() += "all"
|
2021-10-13 00:31:27 +02:00
|
|
|
}
|
|
|
|
}
|
2021-10-18 15:54:09 +02:00
|
|
|
if (oldVersion < 71) {
|
|
|
|
// Handle removed every 3, 4, 6, and 8 hour library updates
|
2023-08-25 04:25:29 +02:00
|
|
|
val updateInterval = libraryPreferences.autoUpdateInterval().get()
|
2021-10-18 15:54:09 +02:00
|
|
|
if (updateInterval in listOf(3, 4, 6, 8)) {
|
2023-08-25 04:25:29 +02:00
|
|
|
libraryPreferences.autoUpdateInterval().set(12)
|
2021-10-18 15:54:09 +02:00
|
|
|
LibraryUpdateJob.setupTask(context, 12)
|
|
|
|
}
|
|
|
|
}
|
2021-12-17 15:57:37 +01:00
|
|
|
if (oldVersion < 72) {
|
|
|
|
val oldUpdateOngoingOnly = prefs.getBoolean("pref_update_only_non_completed_key", true)
|
|
|
|
if (!oldUpdateOngoingOnly) {
|
2023-08-25 04:25:29 +02:00
|
|
|
libraryPreferences.autoUpdateMangaRestrictions() -= MANGA_NON_COMPLETED
|
2021-12-17 15:57:37 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-06 00:51:08 +01:00
|
|
|
if (oldVersion < 75) {
|
|
|
|
val oldSecureScreen = prefs.getBoolean("secure_screen", false)
|
|
|
|
if (oldSecureScreen) {
|
2022-09-18 19:07:48 +02:00
|
|
|
securityPreferences.secureScreen().set(SecurityPreferences.SecureScreenMode.ALWAYS)
|
2022-02-06 00:51:08 +01:00
|
|
|
}
|
2023-11-05 04:28:41 +01:00
|
|
|
if (
|
|
|
|
DeviceUtil.isMiui &&
|
|
|
|
basePreferences.extensionInstaller().get() == BasePreferences.ExtensionInstaller.PACKAGEINSTALLER
|
|
|
|
) {
|
2023-03-20 03:38:14 +01:00
|
|
|
basePreferences.extensionInstaller().set(BasePreferences.ExtensionInstaller.LEGACY)
|
2022-02-06 05:02:13 +01:00
|
|
|
}
|
2022-02-06 00:51:08 +01:00
|
|
|
}
|
2022-03-06 14:36:47 +01:00
|
|
|
if (oldVersion < 76) {
|
2023-03-19 22:28:59 +01:00
|
|
|
BackupCreateJob.setupTask(context)
|
2022-03-06 14:36:47 +01:00
|
|
|
}
|
2022-04-08 22:44:13 +02:00
|
|
|
if (oldVersion < 77) {
|
|
|
|
val oldReaderTap = prefs.getBoolean("reader_tap", false)
|
|
|
|
if (!oldReaderTap) {
|
2022-09-20 14:36:57 +02:00
|
|
|
readerPreferences.navigationModePager().set(5)
|
|
|
|
readerPreferences.navigationModeWebtoon().set(5)
|
2022-04-08 22:44:13 +02:00
|
|
|
}
|
|
|
|
}
|
2022-05-08 05:48:53 +02:00
|
|
|
if (oldVersion < 81) {
|
|
|
|
// Handle renamed enum values
|
2022-08-29 19:10:30 +02:00
|
|
|
prefs.edit {
|
2023-11-05 04:28:41 +01:00
|
|
|
val newSortingMode = when (
|
|
|
|
val oldSortingMode = prefs.getString(
|
|
|
|
libraryPreferences.sortingMode().key(),
|
|
|
|
"ALPHABETICAL",
|
|
|
|
)
|
|
|
|
) {
|
2022-08-29 19:10:30 +02:00
|
|
|
"LAST_CHECKED" -> "LAST_MANGA_UPDATE"
|
|
|
|
"UNREAD" -> "UNREAD_COUNT"
|
|
|
|
"DATE_FETCHED" -> "CHAPTER_FETCH_DATE"
|
|
|
|
else -> oldSortingMode
|
|
|
|
}
|
2023-08-25 04:25:29 +02:00
|
|
|
putString(libraryPreferences.sortingMode().key(), newSortingMode)
|
2022-08-29 19:10:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (oldVersion < 82) {
|
|
|
|
prefs.edit {
|
2023-08-25 04:25:29 +02:00
|
|
|
val sort = prefs.getString(libraryPreferences.sortingMode().key(), null) ?: return@edit
|
2022-08-29 19:10:30 +02:00
|
|
|
val direction = prefs.getString("library_sorting_ascending", "ASCENDING")!!
|
2023-08-25 04:25:29 +02:00
|
|
|
putString(libraryPreferences.sortingMode().key(), "$sort,$direction")
|
2022-08-29 19:10:30 +02:00
|
|
|
remove("library_sorting_ascending")
|
2022-05-08 05:48:53 +02:00
|
|
|
}
|
|
|
|
}
|
2022-09-16 04:53:46 +02:00
|
|
|
if (oldVersion < 84) {
|
2022-09-22 14:57:42 +02:00
|
|
|
if (backupPreferences.backupInterval().get() == 0) {
|
|
|
|
backupPreferences.backupInterval().set(12)
|
2023-03-19 22:28:59 +01:00
|
|
|
BackupCreateJob.setupTask(context)
|
2022-09-16 04:53:46 +02:00
|
|
|
}
|
|
|
|
}
|
2022-09-24 16:14:16 +02:00
|
|
|
if (oldVersion < 85) {
|
|
|
|
val preferences = listOf(
|
|
|
|
libraryPreferences.filterChapterByRead(),
|
|
|
|
libraryPreferences.filterChapterByDownloaded(),
|
|
|
|
libraryPreferences.filterChapterByBookmarked(),
|
|
|
|
libraryPreferences.sortChapterBySourceOrNumber(),
|
|
|
|
libraryPreferences.displayChapterByNameOrNumber(),
|
|
|
|
libraryPreferences.sortChapterByAscendingOrDescending(),
|
|
|
|
)
|
|
|
|
|
|
|
|
prefs.edit {
|
|
|
|
preferences.forEach { preference ->
|
|
|
|
val key = preference.key()
|
|
|
|
val value = prefs.getInt(key, Int.MIN_VALUE)
|
|
|
|
if (value == Int.MIN_VALUE) return@forEach
|
|
|
|
remove(key)
|
|
|
|
putLong(key, value.toLong())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-25 16:07:06 +02:00
|
|
|
if (oldVersion < 86) {
|
|
|
|
if (uiPreferences.themeMode().isSet()) {
|
|
|
|
prefs.edit {
|
|
|
|
val themeMode = prefs.getString(uiPreferences.themeMode().key(), null) ?: return@edit
|
|
|
|
putString(uiPreferences.themeMode().key(), themeMode.uppercase())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-02 05:01:24 +01:00
|
|
|
if (oldVersion < 92) {
|
|
|
|
val trackingQueuePref = context.getSharedPreferences("tracking_queue", Context.MODE_PRIVATE)
|
|
|
|
trackingQueuePref.all.forEach {
|
|
|
|
val (_, lastChapterRead) = it.value.toString().split(":")
|
|
|
|
trackingQueuePref.edit {
|
|
|
|
remove(it.key)
|
|
|
|
putFloat(it.key, lastChapterRead.toFloat())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-08 05:22:56 +01:00
|
|
|
if (oldVersion < 96) {
|
2023-02-08 04:37:20 +01:00
|
|
|
LibraryUpdateJob.cancelAllWorks(context)
|
|
|
|
LibraryUpdateJob.setupTask(context)
|
|
|
|
}
|
2023-02-13 04:44:39 +01:00
|
|
|
if (oldVersion < 97) {
|
2023-02-13 05:07:11 +01:00
|
|
|
// Removed background jobs
|
2023-03-19 23:19:40 +01:00
|
|
|
context.workManager.cancelAllWorkByTag("UpdateChecker")
|
|
|
|
context.workManager.cancelAllWorkByTag("ExtensionUpdate")
|
2023-02-13 05:07:11 +01:00
|
|
|
prefs.edit {
|
|
|
|
remove("automatic_ext_updates")
|
|
|
|
}
|
2023-02-13 04:44:39 +01:00
|
|
|
}
|
2023-02-24 22:09:47 +01:00
|
|
|
if (oldVersion < 99) {
|
|
|
|
val prefKeys = listOf(
|
|
|
|
"pref_filter_library_downloaded",
|
|
|
|
"pref_filter_library_unread",
|
|
|
|
"pref_filter_library_started",
|
|
|
|
"pref_filter_library_bookmarked",
|
|
|
|
"pref_filter_library_completed",
|
2023-09-26 05:22:16 +02:00
|
|
|
) + trackerManager.trackers.map { "pref_filter_library_tracked_${it.id}" }
|
2023-02-24 22:09:47 +01:00
|
|
|
|
|
|
|
prefKeys.forEach { key ->
|
|
|
|
val pref = preferenceStore.getInt(key, 0)
|
|
|
|
prefs.edit {
|
|
|
|
remove(key)
|
|
|
|
|
|
|
|
val newValue = when (pref.get()) {
|
2023-07-10 23:25:52 +02:00
|
|
|
1 -> TriState.ENABLED_IS
|
|
|
|
2 -> TriState.ENABLED_NOT
|
|
|
|
else -> TriState.DISABLED
|
2023-02-24 22:09:47 +01:00
|
|
|
}
|
|
|
|
|
2023-07-10 23:25:52 +02:00
|
|
|
preferenceStore.getEnum("${key}_v2", TriState.DISABLED).set(newValue)
|
2023-02-24 22:09:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-06 04:13:54 +02:00
|
|
|
if (oldVersion < 100) {
|
|
|
|
BackupCreateJob.setupTask(context)
|
|
|
|
}
|
2023-08-25 04:25:29 +02:00
|
|
|
if (oldVersion < 105) {
|
|
|
|
val pref = libraryPreferences.autoUpdateDeviceRestrictions()
|
|
|
|
if (pref.isSet() && "battery_not_low" in pref.get()) {
|
|
|
|
pref.getAndSet { it - "battery_not_low" }
|
|
|
|
}
|
|
|
|
}
|
2023-09-24 23:01:26 +02:00
|
|
|
if (oldVersion < 106) {
|
|
|
|
val pref = preferenceStore.getInt("relative_time", 7)
|
|
|
|
if (pref.get() == 0) {
|
|
|
|
uiPreferences.relativeTime().set(false)
|
|
|
|
}
|
|
|
|
}
|
2023-10-08 17:07:42 +02:00
|
|
|
if (oldVersion < 107) {
|
2023-10-29 17:24:02 +01:00
|
|
|
replacePreferences(
|
|
|
|
preferenceStore = preferenceStore,
|
|
|
|
filterPredicate = { it.key.startsWith("pref_mangasync_") || it.key.startsWith("track_token_") },
|
|
|
|
newKey = { Preference.privateKey(it) },
|
|
|
|
)
|
|
|
|
}
|
2023-11-22 04:11:44 +01:00
|
|
|
if (oldVersion < 110) {
|
2023-10-29 17:24:02 +01:00
|
|
|
val prefsToReplace = listOf(
|
|
|
|
"pref_download_only",
|
|
|
|
"incognito_mode",
|
|
|
|
"last_catalogue_source",
|
|
|
|
"trusted_signatures",
|
|
|
|
"last_app_closed",
|
|
|
|
"library_update_last_timestamp",
|
|
|
|
"library_unseen_updates_count",
|
|
|
|
"last_used_category",
|
2023-11-22 04:11:44 +01:00
|
|
|
"last_app_check",
|
|
|
|
"last_ext_check",
|
|
|
|
"last_version_code",
|
2023-10-29 17:24:02 +01:00
|
|
|
)
|
|
|
|
replacePreferences(
|
|
|
|
preferenceStore = preferenceStore,
|
|
|
|
filterPredicate = { it.key in prefsToReplace },
|
|
|
|
newKey = { Preference.appStateKey(it) },
|
|
|
|
)
|
2023-10-08 17:07:42 +02:00
|
|
|
}
|
2020-07-04 20:36:56 +02:00
|
|
|
return true
|
2017-05-21 13:42:06 +02:00
|
|
|
}
|
2020-12-12 17:26:42 +01:00
|
|
|
|
2017-05-21 13:42:06 +02:00
|
|
|
return false
|
|
|
|
}
|
2020-02-27 00:03:34 +01:00
|
|
|
}
|
2023-10-29 17:24:02 +01:00
|
|
|
|
|
|
|
@Suppress("UNCHECKED_CAST")
|
|
|
|
private fun replacePreferences(
|
|
|
|
preferenceStore: PreferenceStore,
|
|
|
|
filterPredicate: (Map.Entry<String, Any?>) -> Boolean,
|
|
|
|
newKey: (String) -> String,
|
|
|
|
) {
|
|
|
|
preferenceStore.getAll()
|
|
|
|
.filter(filterPredicate)
|
|
|
|
.forEach { (key, value) ->
|
|
|
|
when (value) {
|
|
|
|
is Int -> {
|
|
|
|
preferenceStore.getInt(newKey(key)).set(value)
|
|
|
|
preferenceStore.getInt(key).delete()
|
|
|
|
}
|
|
|
|
is Long -> {
|
|
|
|
preferenceStore.getLong(newKey(key)).set(value)
|
|
|
|
preferenceStore.getLong(key).delete()
|
|
|
|
}
|
|
|
|
is Float -> {
|
|
|
|
preferenceStore.getFloat(newKey(key)).set(value)
|
|
|
|
preferenceStore.getFloat(key).delete()
|
|
|
|
}
|
|
|
|
is String -> {
|
|
|
|
preferenceStore.getString(newKey(key)).set(value)
|
|
|
|
preferenceStore.getString(key).delete()
|
|
|
|
}
|
|
|
|
is Boolean -> {
|
|
|
|
preferenceStore.getBoolean(newKey(key)).set(value)
|
|
|
|
preferenceStore.getBoolean(key).delete()
|
|
|
|
}
|
|
|
|
is Set<*> -> (value as? Set<String>)?.let {
|
|
|
|
preferenceStore.getStringSet(newKey(key)).set(value)
|
|
|
|
preferenceStore.getStringSet(key).delete()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|