remove unnecessary context (build failing)
This commit is contained in:
parent
025d31102e
commit
97d062ffc2
11 changed files with 23 additions and 20 deletions
|
@ -97,7 +97,7 @@ class AnilistHomeViewModel : ViewModel() {
|
|||
suspend fun setRecommendation() = recommendation.postValue(Anilist.query.recommendations())
|
||||
|
||||
suspend fun loadMain(context: FragmentActivity) {
|
||||
Anilist.getSavedToken(context)
|
||||
Anilist.getSavedToken()
|
||||
MAL.getSavedToken(context)
|
||||
Discord.getSavedToken(context)
|
||||
if (PrefManager.getVal(PrefName.CheckUpdate)) AppUpdater.check(context)
|
||||
|
|
|
@ -43,7 +43,7 @@ class MediaDetailsViewModel : ViewModel() {
|
|||
|
||||
|
||||
fun loadSelected(media: Media, isDownload: Boolean = false): Selected {
|
||||
val data = PrefManager.getNullableCustomVal<Selected?>("Selected-${media.id}", null)
|
||||
val data = PrefManager.getNullableCustomVal("Selected-${media.id}", null, Selected::class.java)
|
||||
?: Selected().let {
|
||||
it.sourceIndex = 0
|
||||
it.preferDub = PrefManager.getVal(PrefName.SettingsPreferDub)
|
||||
|
|
|
@ -356,7 +356,7 @@ class AnimeWatchAdapter(
|
|||
val episodes = media.anime.episodes!!.keys.toTypedArray()
|
||||
|
||||
val anilistEp = (media.userProgress ?: 0).plus(1)
|
||||
val appEp = PrefManager.getNullableCustomVal<String?>("${media.id}_current_ep", null)?.toIntOrNull() ?: 1
|
||||
val appEp = PrefManager.getCustomVal<String?>("${media.id}_current_ep", "")?.toIntOrNull() ?: 1
|
||||
|
||||
var continueEp = (if (anilistEp > appEp) anilistEp else appEp).toString()
|
||||
if (episodes.contains(continueEp)) {
|
||||
|
|
|
@ -29,8 +29,8 @@ import kotlin.math.ln
|
|||
import kotlin.math.pow
|
||||
|
||||
fun handleProgress(cont: LinearLayout, bar: View, empty: View, mediaId: Int, ep: String) {
|
||||
val curr = PrefManager.getNullableCustomVal("${mediaId}_${ep}", null as Long?)
|
||||
val max = PrefManager.getNullableCustomVal("${mediaId}_${ep}_max", null as Long?)
|
||||
val curr = PrefManager.getNullableCustomVal("${mediaId}_${ep}", null, Long::class.java)
|
||||
val max = PrefManager.getNullableCustomVal("${mediaId}_${ep}_max", null, Long::class.java)
|
||||
if (curr != null && max != null) {
|
||||
cont.visibility = View.VISIBLE
|
||||
val div = curr.toFloat() / max.toFloat()
|
||||
|
|
|
@ -389,7 +389,7 @@ class MangaReadAdapter(
|
|||
if (media.manga?.chapters != null) {
|
||||
val chapters = media.manga.chapters!!.keys.toTypedArray()
|
||||
val anilistEp = (media.userProgress ?: 0).plus(1)
|
||||
val appEp = PrefManager.getNullableCustomVal<String?>("${media.id}_current_chp", null)?.toIntOrNull() ?: 1
|
||||
val appEp = PrefManager.getCustomVal<String?>("${media.id}_current_chp", null)?.toIntOrNull() ?: 1
|
||||
var continueEp = (if (anilistEp > appEp) anilistEp else appEp).toString()
|
||||
val filteredChapters = chapters.filter { chapterKey ->
|
||||
val chapter = media.manga.chapters!![chapterKey]!!
|
||||
|
|
|
@ -181,7 +181,7 @@ abstract class AnimeParser : BaseParser() {
|
|||
override suspend fun loadSavedShowResponse(mediaId: Int): ShowResponse? {
|
||||
checkIfVariablesAreEmpty()
|
||||
val dub = if (isDubAvailableSeparately()) "_${if (selectDub) "dub" else "sub"}" else ""
|
||||
var loaded = PrefManager.getNullableCustomVal<ShowResponse?>("${saveName}${dub}_$mediaId", null)
|
||||
var loaded = PrefManager.getNullableCustomVal("${saveName}${dub}_$mediaId", null, ShowResponse::class.java)
|
||||
if (loaded == null && malSyncBackupName.isNotEmpty())
|
||||
loaded = MalSyncBackup.get(mediaId, malSyncBackupName, selectDub)
|
||||
?.also { saveShowResponse(mediaId, it, true) }
|
||||
|
|
|
@ -134,7 +134,7 @@ abstract class BaseParser {
|
|||
* **/
|
||||
open suspend fun loadSavedShowResponse(mediaId: Int): ShowResponse? {
|
||||
checkIfVariablesAreEmpty()
|
||||
return PrefManager.getNullableCustomVal<ShowResponse?>("${saveName}_$mediaId", null)
|
||||
return PrefManager.getNullableCustomVal("${saveName}_$mediaId", null, ShowResponse::class.java)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -752,7 +752,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
|
|||
if (Anilist.token != null) {
|
||||
binding.settingsAnilistLogin.setText(R.string.logout)
|
||||
binding.settingsAnilistLogin.setOnClickListener {
|
||||
Anilist.removeSavedToken(it.context)
|
||||
Anilist.removeSavedToken()
|
||||
restartMainActivity.isEnabled = true
|
||||
reload()
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ class SettingsDialogFragment : BottomSheetDialogFragment() {
|
|||
if (Anilist.token != null) {
|
||||
binding.settingsLogin.setText(R.string.logout)
|
||||
binding.settingsLogin.setOnClickListener {
|
||||
Anilist.removeSavedToken(it.context)
|
||||
Anilist.removeSavedToken()
|
||||
dismiss()
|
||||
startMainActivity(requireActivity())
|
||||
}
|
||||
|
|
|
@ -125,15 +125,15 @@ object PrefManager {
|
|||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T> getNullableCustomVal(key: String, default: T): T? {
|
||||
fun <T> getNullableCustomVal(key: String, default: T?, clazz: Class<T>): T? {
|
||||
return try {
|
||||
when (default) {
|
||||
is Boolean -> irrelevantPreferences!!.getBoolean(key, default) as T?
|
||||
is Int -> irrelevantPreferences!!.getInt(key, default) as T?
|
||||
is Float -> irrelevantPreferences!!.getFloat(key, default) as T?
|
||||
is Long -> irrelevantPreferences!!.getLong(key, default) as T?
|
||||
is String -> irrelevantPreferences!!.getString(key, default) as T?
|
||||
is Set<*> -> convertFromStringSet(irrelevantPreferences!!.getStringSet(key, null), default) as T?
|
||||
when {
|
||||
clazz.isAssignableFrom(Boolean::class.java) -> irrelevantPreferences!!.getBoolean(key, default as? Boolean ?: false) as T?
|
||||
clazz.isAssignableFrom(Int::class.java) -> irrelevantPreferences!!.getInt(key, default as? Int ?: 0) as T?
|
||||
clazz.isAssignableFrom(Float::class.java) -> irrelevantPreferences!!.getFloat(key, default as? Float ?: 0f) as T?
|
||||
clazz.isAssignableFrom(Long::class.java) -> irrelevantPreferences!!.getLong(key, default as? Long ?: 0L) as T?
|
||||
clazz.isAssignableFrom(String::class.java) -> irrelevantPreferences!!.getString(key, default as? String) as T?
|
||||
clazz.isAssignableFrom(Set::class.java) -> convertFromStringSet(irrelevantPreferences!!.getStringSet(key, null), default) as T?
|
||||
else -> deserializeClass(key, default, Location.Irrelevant)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
@ -141,6 +141,7 @@ object PrefManager {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
fun removeVal(prefName: PrefName) {
|
||||
val pref = getPrefLocation(prefName.data.prefLocation)
|
||||
with(pref.edit()) {
|
||||
|
@ -256,6 +257,7 @@ object PrefManager {
|
|||
fun importAllPrefs(prefs: Map<String, *>, prefLocation: Location) {
|
||||
val pref = getPrefLocation(prefLocation)
|
||||
var hadError = false
|
||||
pref.edit().clear().apply()
|
||||
with(pref.edit()) {
|
||||
prefs.forEach { (key, value) ->
|
||||
when (value) {
|
||||
|
@ -361,6 +363,7 @@ object PrefManager {
|
|||
}
|
||||
} catch (e: Exception) {
|
||||
snackString("Error deserializing preference: ${e.message}")
|
||||
e.printStackTrace()
|
||||
default
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class SubscriptionHelper {
|
|||
isAdult: Boolean,
|
||||
isAnime: Boolean
|
||||
): Selected {
|
||||
val data = PrefManager.getNullableCustomVal<Selected?>("${mediaId}-select", null) ?: Selected().let {
|
||||
val data = PrefManager.getNullableCustomVal("${mediaId}-select", null, Selected::class.java) ?: Selected().let {
|
||||
it.sourceIndex = 0
|
||||
it.preferDub = PrefManager.getVal(PrefName.SettingsPreferDub)
|
||||
it
|
||||
|
@ -124,7 +124,7 @@ class SubscriptionHelper {
|
|||
|
||||
private const val subscriptions = "subscriptions"
|
||||
fun getSubscriptions(): Map<Int, SubscribeMedia> =
|
||||
PrefManager.getNullableCustomVal<Map<Int, SubscribeMedia>?>(subscriptions, null)
|
||||
PrefManager.getNullableCustomVal<Map<Int, SubscribeMedia>>(subscriptions, null, Map::class.java)!!
|
||||
?: mapOf<Int, SubscribeMedia>().also { PrefManager.setCustomVal(subscriptions, it) }
|
||||
|
||||
fun saveSubscription(context: Context, media: Media, subscribed: Boolean) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue