Yomiroll: fix settings screen stuck on mi devices (#1506)

This commit is contained in:
Samfun75
2023-04-26 00:00:43 +03:00
committed by GitHub
parent 4a03ca00bd
commit f096727573
2 changed files with 31 additions and 22 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Yomiroll' extName = 'Yomiroll'
pkgNameSuffix = 'all.kamyroll' pkgNameSuffix = 'all.kamyroll'
extClass = '.Yomiroll' extClass = '.Yomiroll'
extVersionCode = 21 extVersionCode = 22
libVersion = '13' libVersion = '13'
} }

View File

@ -63,19 +63,6 @@ class Yomiroll : ConfigurableAnimeSource, AnimeHttpSource() {
override val client: OkHttpClient = OkHttpClient().newBuilder() override val client: OkHttpClient = OkHttpClient().newBuilder()
.addInterceptor(tokenInterceptor).build() .addInterceptor(tokenInterceptor).build()
companion object {
private val DateFormatter by lazy {
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH)
}
private const val PREF_QLT = "preferred_quality"
private const val PREF_AUD = "preferred_audio"
private const val PREF_SUB = "preferred_sub"
private const val PREF_SUB_TYPE = "preferred_sub_type"
private const val PREF_USE_LOCAL_Token = "preferred_local_Token"
}
// ============================== Popular =============================== // ============================== Popular ===============================
override fun popularAnimeRequest(page: Int): Request { override fun popularAnimeRequest(page: Int): Request {
@ -191,9 +178,10 @@ class Yomiroll : ConfigurableAnimeSource, AnimeHttpSource() {
override fun episodeListParse(response: Response): List<SEpisode> { override fun episodeListParse(response: Response): List<SEpisode> {
val seasons = json.decodeFromString<SeasonResult>(response.body.string()) val seasons = json.decodeFromString<SeasonResult>(response.body.string())
val series = response.request.url.encodedPath.contains("series/") val series = response.request.url.encodedPath.contains("series/")
val chunkSize = if (preferences.getBoolean(PREF_DISABLE_SEASON_PARALLEL_MAP, false)) 1 else 6
return if (series) { return if (series) {
seasons.data.sortedBy { it.season_number }.chunked(6).map { chunk -> seasons.data.sortedBy { it.season_number }.chunked(chunkSize).map { chunk ->
chunk.parallelMap { seasonData -> chunk.parallelMap { seasonData ->
runCatching { runCatching {
val episodeResp = val episodeResp =
@ -407,7 +395,7 @@ class Yomiroll : ConfigurableAnimeSource, AnimeHttpSource() {
} }
) + ) +
( (
if (this@toSAnime.series_metadata?.audio_locales?.any() == true || if ((this@toSAnime.series_metadata?.audio_locales?.size ?: 0) > 1 ||
this@toSAnime.movie_metadata?.is_dubbed == true this@toSAnime.movie_metadata?.is_dubbed == true
) { ) {
" Dub" " Dub"
@ -517,10 +505,20 @@ class Yomiroll : ConfigurableAnimeSource, AnimeHttpSource() {
} }
} }
val disableParallelEpMap = SwitchPreferenceCompat(screen.context).apply {
key = PREF_DISABLE_SEASON_PARALLEL_MAP
title = "Disable Parallel Requests for Seasons"
setDefaultValue(false)
setOnPreferenceChangeListener { _, newValue ->
preferences.edit().putBoolean(key, newValue as Boolean).commit()
}
}
screen.addPreference(videoQualityPref) screen.addPreference(videoQualityPref)
screen.addPreference(audLocalePref) screen.addPreference(audLocalePref)
screen.addPreference(subLocalePref) screen.addPreference(subLocalePref)
screen.addPreference(subTypePref) screen.addPreference(subTypePref)
screen.addPreference(disableParallelEpMap)
screen.addPreference(localSubsPreference(screen)) screen.addPreference(localSubsPreference(screen))
} }
@ -536,18 +534,16 @@ class Yomiroll : ConfigurableAnimeSource, AnimeHttpSource() {
this.apply { this.apply {
key = PREF_USE_LOCAL_Token key = PREF_USE_LOCAL_Token
title = "Use Local Token (Don't Spam this please!)" title = "Use Local Token (Don't Spam this please!)"
runBlocking { summary = runBlocking {
withContext(Dispatchers.IO) { summary = getTokenDetail() } withContext(Dispatchers.IO) { getTokenDetail() }
} }
setDefaultValue(false) setDefaultValue(false)
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
val new = newValue as Boolean val new = newValue as Boolean
preferences.edit().putBoolean(key, new).commit().also { preferences.edit().putBoolean(key, new).commit().also {
Thread { Thread {
runBlocking { summary = runBlocking {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) { getTokenDetail(true) }
summary = getTokenDetail(true)
}
} }
}.start() }.start()
} }
@ -575,4 +571,17 @@ class Yomiroll : ConfigurableAnimeSource, AnimeHttpSource() {
"Error: ${e.localizedMessage ?: "Something Went Wrong"}" "Error: ${e.localizedMessage ?: "Something Went Wrong"}"
} }
} }
companion object {
private val DateFormatter by lazy {
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH)
}
private const val PREF_QLT = "preferred_quality"
private const val PREF_AUD = "preferred_audio"
private const val PREF_SUB = "preferred_sub"
private const val PREF_SUB_TYPE = "preferred_sub_type"
private const val PREF_DISABLE_SEASON_PARALLEL_MAP = "preferred_disable_parallelMap"
private const val PREF_USE_LOCAL_Token = "preferred_local_Token"
}
} }