diff --git a/app/src/main/java/ani/dantotsu/connections/anilist/Anilist.kt b/app/src/main/java/ani/dantotsu/connections/anilist/Anilist.kt index 77325d0b76..b0f2ba81d4 100644 --- a/app/src/main/java/ani/dantotsu/connections/anilist/Anilist.kt +++ b/app/src/main/java/ani/dantotsu/connections/anilist/Anilist.kt @@ -8,6 +8,8 @@ import ani.dantotsu.R import ani.dantotsu.client import ani.dantotsu.currContext import ani.dantotsu.openLinkInBrowser +import ani.dantotsu.settings.saving.PrefManager +import ani.dantotsu.settings.saving.PrefName import ani.dantotsu.tryWithSuspend import java.io.File import java.util.Calendar @@ -94,15 +96,12 @@ object Anilist { } } - fun getSavedToken(context: Context): Boolean { - if ("anilistToken" in context.fileList()) { - token = File(context.filesDir, "anilistToken").readText() - return true - } - return false + fun getSavedToken(): Boolean { + token = PrefManager.getVal(PrefName.AnilistToken, null as String?) + return !token.isNullOrEmpty() } - fun removeSavedToken(context: Context) { + fun removeSavedToken() { token = null username = null adult = false @@ -111,9 +110,7 @@ object Anilist { bg = null episodesWatched = null chapterRead = null - if ("anilistToken" in context.fileList()) { - File(context.filesDir, "anilistToken").delete() - } + PrefManager.removeVal(PrefName.AnilistToken) } suspend inline fun executeQuery( diff --git a/app/src/main/java/ani/dantotsu/connections/anilist/Login.kt b/app/src/main/java/ani/dantotsu/connections/anilist/Login.kt index 497ca01fbc..caf61f258a 100644 --- a/app/src/main/java/ani/dantotsu/connections/anilist/Login.kt +++ b/app/src/main/java/ani/dantotsu/connections/anilist/Login.kt @@ -6,6 +6,8 @@ import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import ani.dantotsu.logError import ani.dantotsu.logger +import ani.dantotsu.settings.saving.PrefManager +import ani.dantotsu.settings.saving.PrefName import ani.dantotsu.startMainActivity import ani.dantotsu.themes.ThemeManager @@ -19,10 +21,7 @@ class Login : AppCompatActivity() { try { Anilist.token = Regex("""(?<=access_token=).+(?=&token_type)""").find(data.toString())!!.value - val filename = "anilistToken" - this.openFileOutput(filename, Context.MODE_PRIVATE).use { - it.write(Anilist.token!!.toByteArray()) - } + PrefManager.setVal(PrefName.AnilistToken, Anilist.token?:"") } catch (e: Exception) { logError(e) } diff --git a/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt b/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt index 2e7b3ff18f..802aaab0d8 100644 --- a/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt +++ b/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt @@ -147,6 +147,7 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files DiscordId(Pref(Location.Protected, String::class, "")), DiscordUserName(Pref(Location.Protected, String::class, "")), DiscordAvatar(Pref(Location.Protected, String::class, "")), + AnilistToken(Pref(Location.Protected, String::class, "")), AnilistUserName(Pref(Location.Protected, String::class, "")), MALCodeChallenge(Pref(Location.Protected, String::class, "")), MALToken(Pref(Location.Protected, MAL.ResponseToken::class, "")), diff --git a/app/src/main/java/ani/dantotsu/settings/saving/internal/PreferenceInternal.kt b/app/src/main/java/ani/dantotsu/settings/saving/internal/PreferenceInternal.kt index 6e9fcbb3fd..1f1d2052ce 100644 --- a/app/src/main/java/ani/dantotsu/settings/saving/internal/PreferenceInternal.kt +++ b/app/src/main/java/ani/dantotsu/settings/saving/internal/PreferenceInternal.kt @@ -18,5 +18,5 @@ enum class Location(val location: String, val exportable: Boolean) { NovelReader("ani.dantotsu.novelReader", true), Irrelevant("ani.dantotsu.irrelevant", false), AnimeDownloads("animeDownloads", false), //different for legacy reasons - Protected("ani.dantotsu.protected", false), + Protected("ani.dantotsu.protected", true), }