Skip to content

Commit

Permalink
automatically update downloads to new system
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Jan 31, 2024
1 parent 883c14b commit 1f98e34
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/ani/dantotsu/settings/saving/PrefWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/ani/dantotsu/settings/saving/internal/Compat.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 1f98e34

Please sign in to comment.