remove unnecessary context (build failing)

This commit is contained in:
Finnley Somdahl 2024-02-02 14:49:19 -06:00
parent 025d31102e
commit 97d062ffc2
11 changed files with 23 additions and 20 deletions

View file

@ -97,7 +97,7 @@ class AnilistHomeViewModel : ViewModel() {
suspend fun setRecommendation() = recommendation.postValue(Anilist.query.recommendations()) suspend fun setRecommendation() = recommendation.postValue(Anilist.query.recommendations())
suspend fun loadMain(context: FragmentActivity) { suspend fun loadMain(context: FragmentActivity) {
Anilist.getSavedToken(context) Anilist.getSavedToken()
MAL.getSavedToken(context) MAL.getSavedToken(context)
Discord.getSavedToken(context) Discord.getSavedToken(context)
if (PrefManager.getVal(PrefName.CheckUpdate)) AppUpdater.check(context) if (PrefManager.getVal(PrefName.CheckUpdate)) AppUpdater.check(context)

View file

@ -43,7 +43,7 @@ class MediaDetailsViewModel : ViewModel() {
fun loadSelected(media: Media, isDownload: Boolean = false): Selected { 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 { ?: Selected().let {
it.sourceIndex = 0 it.sourceIndex = 0
it.preferDub = PrefManager.getVal(PrefName.SettingsPreferDub) it.preferDub = PrefManager.getVal(PrefName.SettingsPreferDub)

View file

@ -356,7 +356,7 @@ class AnimeWatchAdapter(
val episodes = media.anime.episodes!!.keys.toTypedArray() val episodes = media.anime.episodes!!.keys.toTypedArray()
val anilistEp = (media.userProgress ?: 0).plus(1) 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() var continueEp = (if (anilistEp > appEp) anilistEp else appEp).toString()
if (episodes.contains(continueEp)) { if (episodes.contains(continueEp)) {

View file

@ -29,8 +29,8 @@ import kotlin.math.ln
import kotlin.math.pow import kotlin.math.pow
fun handleProgress(cont: LinearLayout, bar: View, empty: View, mediaId: Int, ep: String) { fun handleProgress(cont: LinearLayout, bar: View, empty: View, mediaId: Int, ep: String) {
val curr = PrefManager.getNullableCustomVal("${mediaId}_${ep}", null as Long?) val curr = PrefManager.getNullableCustomVal("${mediaId}_${ep}", null, Long::class.java)
val max = PrefManager.getNullableCustomVal("${mediaId}_${ep}_max", null as Long?) val max = PrefManager.getNullableCustomVal("${mediaId}_${ep}_max", null, Long::class.java)
if (curr != null && max != null) { if (curr != null && max != null) {
cont.visibility = View.VISIBLE cont.visibility = View.VISIBLE
val div = curr.toFloat() / max.toFloat() val div = curr.toFloat() / max.toFloat()

View file

@ -389,7 +389,7 @@ class MangaReadAdapter(
if (media.manga?.chapters != null) { if (media.manga?.chapters != null) {
val chapters = media.manga.chapters!!.keys.toTypedArray() val chapters = media.manga.chapters!!.keys.toTypedArray()
val anilistEp = (media.userProgress ?: 0).plus(1) 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() var continueEp = (if (anilistEp > appEp) anilistEp else appEp).toString()
val filteredChapters = chapters.filter { chapterKey -> val filteredChapters = chapters.filter { chapterKey ->
val chapter = media.manga.chapters!![chapterKey]!! val chapter = media.manga.chapters!![chapterKey]!!

View file

@ -181,7 +181,7 @@ abstract class AnimeParser : BaseParser() {
override suspend fun loadSavedShowResponse(mediaId: Int): ShowResponse? { override suspend fun loadSavedShowResponse(mediaId: Int): ShowResponse? {
checkIfVariablesAreEmpty() checkIfVariablesAreEmpty()
val dub = if (isDubAvailableSeparately()) "_${if (selectDub) "dub" else "sub"}" else "" 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()) if (loaded == null && malSyncBackupName.isNotEmpty())
loaded = MalSyncBackup.get(mediaId, malSyncBackupName, selectDub) loaded = MalSyncBackup.get(mediaId, malSyncBackupName, selectDub)
?.also { saveShowResponse(mediaId, it, true) } ?.also { saveShowResponse(mediaId, it, true) }

View file

@ -134,7 +134,7 @@ abstract class BaseParser {
* **/ * **/
open suspend fun loadSavedShowResponse(mediaId: Int): ShowResponse? { open suspend fun loadSavedShowResponse(mediaId: Int): ShowResponse? {
checkIfVariablesAreEmpty() checkIfVariablesAreEmpty()
return PrefManager.getNullableCustomVal<ShowResponse?>("${saveName}_$mediaId", null) return PrefManager.getNullableCustomVal("${saveName}_$mediaId", null, ShowResponse::class.java)
} }
/** /**

View file

@ -752,7 +752,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
if (Anilist.token != null) { if (Anilist.token != null) {
binding.settingsAnilistLogin.setText(R.string.logout) binding.settingsAnilistLogin.setText(R.string.logout)
binding.settingsAnilistLogin.setOnClickListener { binding.settingsAnilistLogin.setOnClickListener {
Anilist.removeSavedToken(it.context) Anilist.removeSavedToken()
restartMainActivity.isEnabled = true restartMainActivity.isEnabled = true
reload() reload()
} }

View file

@ -60,7 +60,7 @@ class SettingsDialogFragment : BottomSheetDialogFragment() {
if (Anilist.token != null) { if (Anilist.token != null) {
binding.settingsLogin.setText(R.string.logout) binding.settingsLogin.setText(R.string.logout)
binding.settingsLogin.setOnClickListener { binding.settingsLogin.setOnClickListener {
Anilist.removeSavedToken(it.context) Anilist.removeSavedToken()
dismiss() dismiss()
startMainActivity(requireActivity()) startMainActivity(requireActivity())
} }

View file

@ -125,15 +125,15 @@ object PrefManager {
} }
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
fun <T> getNullableCustomVal(key: String, default: T): T? { fun <T> getNullableCustomVal(key: String, default: T?, clazz: Class<T>): T? {
return try { return try {
when (default) { when {
is Boolean -> irrelevantPreferences!!.getBoolean(key, default) as T? clazz.isAssignableFrom(Boolean::class.java) -> irrelevantPreferences!!.getBoolean(key, default as? Boolean ?: false) as T?
is Int -> irrelevantPreferences!!.getInt(key, default) as T? clazz.isAssignableFrom(Int::class.java) -> irrelevantPreferences!!.getInt(key, default as? Int ?: 0) as T?
is Float -> irrelevantPreferences!!.getFloat(key, default) as T? clazz.isAssignableFrom(Float::class.java) -> irrelevantPreferences!!.getFloat(key, default as? Float ?: 0f) as T?
is Long -> irrelevantPreferences!!.getLong(key, default) as T? clazz.isAssignableFrom(Long::class.java) -> irrelevantPreferences!!.getLong(key, default as? Long ?: 0L) as T?
is String -> irrelevantPreferences!!.getString(key, default) as T? clazz.isAssignableFrom(String::class.java) -> irrelevantPreferences!!.getString(key, default as? String) as T?
is Set<*> -> convertFromStringSet(irrelevantPreferences!!.getStringSet(key, null), default) as T? clazz.isAssignableFrom(Set::class.java) -> convertFromStringSet(irrelevantPreferences!!.getStringSet(key, null), default) as T?
else -> deserializeClass(key, default, Location.Irrelevant) else -> deserializeClass(key, default, Location.Irrelevant)
} }
} catch (e: Exception) { } catch (e: Exception) {
@ -141,6 +141,7 @@ object PrefManager {
} }
} }
fun removeVal(prefName: PrefName) { fun removeVal(prefName: PrefName) {
val pref = getPrefLocation(prefName.data.prefLocation) val pref = getPrefLocation(prefName.data.prefLocation)
with(pref.edit()) { with(pref.edit()) {
@ -256,6 +257,7 @@ object PrefManager {
fun importAllPrefs(prefs: Map<String, *>, prefLocation: Location) { fun importAllPrefs(prefs: Map<String, *>, prefLocation: Location) {
val pref = getPrefLocation(prefLocation) val pref = getPrefLocation(prefLocation)
var hadError = false var hadError = false
pref.edit().clear().apply()
with(pref.edit()) { with(pref.edit()) {
prefs.forEach { (key, value) -> prefs.forEach { (key, value) ->
when (value) { when (value) {
@ -361,6 +363,7 @@ object PrefManager {
} }
} catch (e: Exception) { } catch (e: Exception) {
snackString("Error deserializing preference: ${e.message}") snackString("Error deserializing preference: ${e.message}")
e.printStackTrace()
default default
} }
} }

View file

@ -27,7 +27,7 @@ class SubscriptionHelper {
isAdult: Boolean, isAdult: Boolean,
isAnime: Boolean isAnime: Boolean
): Selected { ): 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.sourceIndex = 0
it.preferDub = PrefManager.getVal(PrefName.SettingsPreferDub) it.preferDub = PrefManager.getVal(PrefName.SettingsPreferDub)
it it
@ -124,7 +124,7 @@ class SubscriptionHelper {
private const val subscriptions = "subscriptions" private const val subscriptions = "subscriptions"
fun getSubscriptions(): Map<Int, SubscribeMedia> = 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) } ?: mapOf<Int, SubscribeMedia>().also { PrefManager.setCustomVal(subscriptions, it) }
fun saveSubscription(context: Context, media: Media, subscribed: Boolean) { fun saveSubscription(context: Context, media: Media, subscribed: Boolean) {