Update HiAnime.kt

This commit is contained in:
Arkai1 2025-04-17 10:20:56 +05:30 committed by GitHub
parent 85cfd67d11
commit ea6de1273f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,6 +11,9 @@ import eu.kanade.tachiyomi.multisrc.zorotheme.ZoroTheme
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import okhttp3.Request import okhttp3.Request
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import android.content.SharedPreferences
class HiAnime : ZoroTheme( class HiAnime : ZoroTheme(
"en", "en",
@ -26,6 +29,10 @@ class HiAnime : ZoroTheme(
override val ajaxRoute = "/v2" override val ajaxRoute = "/v2"
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
private val streamtapeExtractor by lazy { StreamTapeExtractor(client) } private val streamtapeExtractor by lazy { StreamTapeExtractor(client) }
private val megaCloudExtractor by lazy { MegaCloudExtractor(client, headers, preferences) } private val megaCloudExtractor by lazy { MegaCloudExtractor(client, headers, preferences) }
@ -66,20 +73,15 @@ class HiAnime : ZoroTheme(
ListPreference(screen.context).apply { ListPreference(screen.context).apply {
key = PREF_DOMAIN_KEY key = PREF_DOMAIN_KEY
title = "Preferred domain" title = "Preferred domain"
entries = arrayOf("hianimez.to", "hianimez.is", "hianime.to", "hianime.nz", "hianime.pe") entries = PREF_DOMAIN_ENTRIES
entryValues = arrayOf("https://hianimez.to", "https://hianimez.is", "https://hianime.to", "https://hianime.nz", "https://hianime.pe") entryValues = PREF_DOMAIN_ENTRY_VALUES
setDefaultValue(PREF_DOMAIN_DEFAULT) setDefaultValue(PREF_DOMAIN_DEFAULT)
summary = "%s" summary = "%s"
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
val selected = newValue as String val selectedDomain = newValue as String
val index = findIndexOfValue(selected) preferences.edit().putString(PREF_DOMAIN_KEY, selectedDomain).commit()
if (index == -1) {
Toast.makeText(screen.context, "Invalid selection. Please try again.", Toast.LENGTH_LONG).show()
return@setOnPreferenceChangeListener false
}
val entry = entryValues[index] as String
preferences.edit().putString(PREF_DOMAIN_KEY, entry).commit()
Toast.makeText( Toast.makeText(
screen.context, screen.context,
"Restart Aniyomi to apply changes", "Restart Aniyomi to apply changes",
@ -92,27 +94,16 @@ class HiAnime : ZoroTheme(
} }
companion object { companion object {
private const val PREF_DOMAIN_KEY = "preferred_domain" private const val PREF_DOMAIN_KEY = "preferred_domain"
private const val PREF_DOMAIN_DEFAULT = "https://hianimez.to" private const val PREF_DOMAIN_DEFAULT = "https://hianimez.to"
// Updated property name to follow screaming snake case private val PREF_DOMAIN_ENTRIES = arrayOf("hianimez.to", "hianime.to", "hianimez.is", "hianime.nz", "hianime.pe")
private val ALLOWED_DOMAINS = listOf( private val PREF_DOMAIN_ENTRY_VALUES = arrayOf("https://hianimez.to", "https://hianime.to", "https://hianimez.is", "https://hianime.nz", "https://hianime.pe")
"https://hianimez.to",
"https://hianimez.is",
"https://hianime.to",
"https://hianime.nz",
"https://hianime.pe",
)
// Initialize custom SharedPreferences for the extension // Dynamically fetch the preferred domain
fun getPreferredDomain(preferences: SharedPreferences): String { fun getPreferredDomain(): String {
// Fetch the saved domain from SharedPreferences val preferences = Injekt.get<Application>().getSharedPreferences("source_${HiAnime::class.java.simpleName}", 0x0000)
val domain = preferences.getString(PREF_DOMAIN_KEY, PREF_DOMAIN_DEFAULT) ?: PREF_DOMAIN_DEFAULT return preferences.getString(PREF_DOMAIN_KEY, PREF_DOMAIN_DEFAULT) ?: PREF_DOMAIN_DEFAULT
// Validate the domain against the allowed list }
return if (ALLOWED_DOMAINS.contains(domain)) domain else PREF_DOMAIN_DEFAULT
}
fun createPreferences(context: Context): SharedPreferences {
return context.getSharedPreferences("source_${this::class.java.simpleName}", Context.MODE_PRIVATE)
} }
} }