automatically update downloads to new system

This commit is contained in:
Finnley Somdahl 2024-01-30 20:37:13 -06:00
parent 883c14bf0d
commit 1f98e349dc
3 changed files with 21 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package ani.dantotsu.settings.saving
import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import ani.dantotsu.settings.saving.internal.Compat
import ani.dantotsu.settings.saving.internal.Location
import ani.dantotsu.snackString
@ -26,6 +27,7 @@ object PrefWrapper {
irrelevantPreferences = context.getSharedPreferences(Location.Irrelevant.location, Context.MODE_PRIVATE)
animeDownloadsPreferences = context.getSharedPreferences(Location.AnimeDownloads.location, Context.MODE_PRIVATE)
protectedPreferences = context.getSharedPreferences(Location.Protected.location, Context.MODE_PRIVATE)
Compat.importOldPrefs(context)
}
@Suppress("UNCHECKED_CAST")

View file

@ -44,6 +44,7 @@ enum class PrefName(val data: Pref) {
SomethingSpecial(Pref(Location.Irrelevant, Boolean::class)),
AllowOpeningLinks(Pref(Location.Irrelevant, Boolean::class)),
SearchStyle(Pref(Location.Irrelevant, Int::class)),
HasUpdatedPrefs(Pref(Location.Irrelevant, Boolean::class)),
//Protected
DiscordToken(Pref(Location.Protected, String::class)),

View file

@ -0,0 +1,18 @@
package ani.dantotsu.settings.saving.internal
import android.content.Context
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
class Compat {
companion object {
fun importOldPrefs(context: Context) {
if (PrefWrapper.getVal(PrefName.HasUpdatedPrefs, false)) return
val oldPrefs = context.getSharedPreferences("downloads_pref", Context.MODE_PRIVATE)
val jsonString = oldPrefs.getString("downloads_key", null)
PrefWrapper.setVal(PrefName.DownloadsKeys, jsonString)
oldPrefs.edit().clear().apply()
PrefWrapper.setVal(PrefName.HasUpdatedPrefs, true)
}
}
}