Skip to content

Commit

Permalink
move anilist to protected
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Feb 2, 2024
1 parent cd96b6a commit 025d311
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
17 changes: 7 additions & 10 deletions app/src/main/java/ani/dantotsu/connections/anilist/Anilist.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/ani/dantotsu/connections/anilist/Login.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

0 comments on commit 025d311

Please sign in to comment.