move anilist to protected

This commit is contained in:
Finnley Somdahl 2024-02-02 09:50:06 -06:00
parent cd96b6ab06
commit 025d31102e
4 changed files with 12 additions and 15 deletions

View file

@ -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 <reified T : Any> executeQuery(

View file

@ -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)
}

View file

@ -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, "")),

View file

@ -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),
}