chore: code refactor
This commit is contained in:
parent
8d7b86a667
commit
a2e44da99d
334 changed files with 3550 additions and 3092 deletions
|
@ -6,8 +6,8 @@ import ani.dantotsu.connections.anilist.Anilist
|
|||
import ani.dantotsu.connections.mal.MAL
|
||||
import ani.dantotsu.currContext
|
||||
import ani.dantotsu.media.Media
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.toast
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
|
|
@ -12,7 +12,6 @@ import ani.dantotsu.settings.saving.PrefManager
|
|||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.toast
|
||||
import ani.dantotsu.tryWithSuspend
|
||||
import java.io.File
|
||||
import java.util.Calendar
|
||||
|
||||
object Anilist {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ani.dantotsu.connections.anilist
|
||||
|
||||
import android.app.Activity
|
||||
import android.util.Base64
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.checkGenreTime
|
||||
import ani.dantotsu.checkId
|
||||
|
@ -17,18 +18,17 @@ import ani.dantotsu.media.Character
|
|||
import ani.dantotsu.media.Media
|
||||
import ani.dantotsu.media.Studio
|
||||
import ani.dantotsu.others.MalScraper
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.snackString
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.ObjectInputStream
|
||||
import java.io.ObjectOutputStream
|
||||
import java.io.Serializable
|
||||
import android.util.Base64
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ObjectInputStream
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
class AnilistQueries {
|
||||
|
@ -357,9 +357,9 @@ class AnilistQueries {
|
|||
private suspend fun bannerImage(type: String): String? {
|
||||
//var image = loadData<BannerImage>("banner_$type")
|
||||
val image: BannerImage? = BannerImage(
|
||||
PrefManager.getCustomVal("banner_${type}_url", null),
|
||||
PrefManager.getCustomVal("banner_${type}_time", 0L)
|
||||
)
|
||||
PrefManager.getCustomVal("banner_${type}_url", null),
|
||||
PrefManager.getCustomVal("banner_${type}_time", 0L)
|
||||
)
|
||||
if (image == null || image.checkTime()) {
|
||||
val response =
|
||||
executeQuery<Query.MediaListCollection>("""{ MediaListCollection(userId: ${Anilist.userid}, type: $type, chunk:1,perChunk:25, sort: [SCORE_DESC,UPDATED_TIME_DESC]) { lists { entries{ media { id bannerImage } } } } } """)
|
||||
|
@ -445,14 +445,16 @@ class AnilistQueries {
|
|||
|
||||
|
||||
suspend fun getGenresAndTags(activity: Activity): Boolean {
|
||||
var genres: ArrayList<String>? = PrefManager.getVal<Set<String>>(PrefName.GenresList).toMutableList() as ArrayList<String>?
|
||||
var genres: ArrayList<String>? = PrefManager.getVal<Set<String>>(PrefName.GenresList)
|
||||
.toMutableList() as ArrayList<String>?
|
||||
val adultTags = PrefManager.getVal<Set<String>>(PrefName.TagsListIsAdult).toMutableList()
|
||||
val nonAdultTags = PrefManager.getVal<Set<String>>(PrefName.TagsListNonAdult).toMutableList()
|
||||
val nonAdultTags =
|
||||
PrefManager.getVal<Set<String>>(PrefName.TagsListNonAdult).toMutableList()
|
||||
var tags = if (adultTags.isEmpty() || nonAdultTags.isEmpty()) null else
|
||||
mapOf(
|
||||
true to adultTags,
|
||||
false to nonAdultTags
|
||||
)
|
||||
true to adultTags,
|
||||
false to nonAdultTags
|
||||
)
|
||||
|
||||
if (genres.isNullOrEmpty()) {
|
||||
executeQuery<Query.GenreCollection>(
|
||||
|
@ -530,9 +532,10 @@ class AnilistQueries {
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun getGenreThumbnail(genre: String): Genre? {
|
||||
val genres: MutableMap<String, Genre> = loadSerializableMap<String, Genre>("genre_thumb")?.toMutableMap()
|
||||
?: mutableMapOf()
|
||||
private suspend fun getGenreThumbnail(genre: String): Genre? {
|
||||
val genres: MutableMap<String, Genre> =
|
||||
loadSerializableMap<String, Genre>("genre_thumb")?.toMutableMap()
|
||||
?: mutableMapOf()
|
||||
if (genres.checkGenreTime(genre)) {
|
||||
try {
|
||||
val genreQuery =
|
||||
|
|
|
@ -11,8 +11,8 @@ import ani.dantotsu.connections.discord.Discord
|
|||
import ani.dantotsu.connections.mal.MAL
|
||||
import ani.dantotsu.media.Media
|
||||
import ani.dantotsu.others.AppUpdater
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.snackString
|
||||
import ani.dantotsu.tryWithSuspend
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package ani.dantotsu.connections.anilist
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
@ -14,14 +13,14 @@ import ani.dantotsu.themes.ThemeManager
|
|||
class Login : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
||||
ThemeManager(this).applyTheme()
|
||||
val data: Uri? = intent?.data
|
||||
logger(data.toString())
|
||||
try {
|
||||
Anilist.token =
|
||||
Regex("""(?<=access_token=).+(?=&token_type)""").find(data.toString())!!.value
|
||||
PrefManager.setVal(PrefName.AnilistToken, Anilist.token?:"")
|
||||
PrefManager.setVal(PrefName.AnilistToken, Anilist.token ?: "")
|
||||
} catch (e: Exception) {
|
||||
logError(e)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import ani.dantotsu.themes.ThemeManager
|
|||
class UrlMedia : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
||||
ThemeManager(this).applyTheme()
|
||||
var id: Int? = intent?.extras?.getInt("media", 0) ?: 0
|
||||
var isMAL = false
|
||||
|
|
|
@ -5,8 +5,8 @@ import android.content.Intent
|
|||
import android.widget.TextView
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.others.CustomBottomDialog
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.toast
|
||||
import ani.dantotsu.tryWith
|
||||
import io.noties.markwon.Markwon
|
||||
|
@ -22,7 +22,8 @@ object Discord {
|
|||
|
||||
fun getSavedToken(context: Context): Boolean {
|
||||
token = PrefManager.getVal(
|
||||
PrefName.DiscordToken, null as String?)
|
||||
PrefName.DiscordToken, null as String?
|
||||
)
|
||||
return token != null
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ import ani.dantotsu.R
|
|||
import ani.dantotsu.connections.discord.serializers.Presence
|
||||
import ani.dantotsu.connections.discord.serializers.User
|
||||
import ani.dantotsu.isOnline
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParser
|
||||
|
|
|
@ -19,7 +19,7 @@ class Login : AppCompatActivity() {
|
|||
@SuppressLint("SetJavaScriptEnabled")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
||||
ThemeManager(this).applyTheme()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
val process = getProcessName()
|
||||
|
|
|
@ -9,8 +9,8 @@ import ani.dantotsu.client
|
|||
import ani.dantotsu.connections.mal.MAL.clientId
|
||||
import ani.dantotsu.connections.mal.MAL.saveResponse
|
||||
import ani.dantotsu.logError
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.snackString
|
||||
import ani.dantotsu.startMainActivity
|
||||
import ani.dantotsu.themes.ThemeManager
|
||||
|
@ -21,7 +21,7 @@ import kotlinx.coroutines.launch
|
|||
class Login : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
||||
ThemeManager(this).applyTheme()
|
||||
try {
|
||||
val data: Uri = intent?.data
|
||||
|
|
|
@ -10,8 +10,8 @@ import ani.dantotsu.R
|
|||
import ani.dantotsu.client
|
||||
import ani.dantotsu.currContext
|
||||
import ani.dantotsu.openLinkInBrowser
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.tryWithSuspend
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
@ -66,8 +66,9 @@ object MAL {
|
|||
|
||||
suspend fun getSavedToken(context: FragmentActivity): Boolean {
|
||||
return tryWithSuspend(false) {
|
||||
var res: ResponseToken = PrefManager.getNullableVal<ResponseToken>(PrefName.MALToken, null)
|
||||
?: return@tryWithSuspend false
|
||||
var res: ResponseToken =
|
||||
PrefManager.getNullableVal<ResponseToken>(PrefName.MALToken, null)
|
||||
?: return@tryWithSuspend false
|
||||
if (System.currentTimeMillis() > res.expiresIn)
|
||||
res = refreshToken()
|
||||
?: throw Exception(currContext()?.getString(R.string.refreshing_token_failed))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue