feat(all/animeui): Move extension + add sub language preference (#3045)

Co-authored-by: jmir1 <jhmiramon@gmail.com>
This commit is contained in:
imper1aldev 2024-03-13 04:16:39 -06:00 committed by GitHub
parent c61a4478cc
commit 3219273e30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 49 additions and 7 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'AnimeUI'
extClass = '.AnimeUI'
extVersionCode = 1
extVersionCode = 2
}
apply from: "$rootDir/common.gradle"

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -1,4 +1,4 @@
package eu.kanade.tachiyomi.animeextension.en.animeui
package eu.kanade.tachiyomi.animeextension.all.animeui
import android.app.Application
import android.content.SharedPreferences
@ -30,12 +30,14 @@ class AnimeUI : ConfigurableAnimeSource, AnimeHttpSource() {
override val baseUrl = "https://animeui.com"
override val lang = "en"
override val lang = "all"
override val supportsLatest = true
private val json: Json by injectLazy()
override val id: Long = 7372747480486811746L
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
@ -135,7 +137,7 @@ class AnimeUI : ConfigurableAnimeSource, AnimeHttpSource() {
val subtitleList = parsed.subtitlesJson?.let {
json.decodeFromString<List<SubtitleObject>>(it).map { s ->
Track("$baseUrl/api${s.url}", s.subtitle_name)
}
}.sortSubs()
} ?: emptyList()
val cid = parsed.episode.cid
@ -154,7 +156,17 @@ class AnimeUI : ConfigurableAnimeSource, AnimeHttpSource() {
}
}
// ============================= Utilities ==============================
// ============================= Utilities ==============================.
private fun Iterable<Track>.sortSubs(): List<Track> {
val sub = preferences.getString(PREF_SUB_LANG_KEY, PREF_SUB_LANG_DEFAULT)!!
return this.sortedWith(
compareBy<Track>(
{ it.lang.startsWith(sub, true) },
{ it.lang.contains(sub, true) },
).thenByDescending { it.lang },
).reversed()
}
override fun List<Video>.sort(): List<Video> {
val server = preferences.getString(PREF_SERVER_KEY, PREF_SERVER_DEFAULT)!!
@ -173,6 +185,20 @@ class AnimeUI : ConfigurableAnimeSource, AnimeHttpSource() {
"Tokyo", "Kyoto", "Nagoya", "Sendai", "Sagara",
"Nara", "Osaka", "Web", "Noshiro",
)
private const val PREF_SUB_LANG_KEY = "preferred_sub_lang"
private const val PREF_SUB_LANG_DEFAULT = "English"
private val LOCALE_LIST = arrayOf(
"English",
"Spanish",
"European Spanish",
"Portuguese",
"Deutsch",
"French",
"Italian",
"Russian",
"Arabic",
)
}
// ============================== Settings ==============================
@ -194,6 +220,22 @@ class AnimeUI : ConfigurableAnimeSource, AnimeHttpSource() {
}
}.also(screen::addPreference)
ListPreference(screen.context).apply {
key = PREF_SUB_LANG_KEY
title = "Preferred subtitle language"
entries = LOCALE_LIST
entryValues = LOCALE_LIST
setDefaultValue(PREF_SUB_LANG_DEFAULT)
summary = "%s"
setOnPreferenceChangeListener { _, newValue ->
val selected = newValue as String
val index = findIndexOfValue(selected)
val entry = entryValues[index] as String
preferences.edit().putString(key, entry).commit()
}
}.also(screen::addPreference)
ListPreference(screen.context).apply {
key = PREF_SERVER_KEY
title = "Preferred server"

View File

@ -1,4 +1,4 @@
package eu.kanade.tachiyomi.animeextension.en.animeui
package eu.kanade.tachiyomi.animeextension.all.animeui
import eu.kanade.tachiyomi.animesource.model.SAnime
import eu.kanade.tachiyomi.animesource.model.SEpisode

View File

@ -1,4 +1,4 @@
package eu.kanade.tachiyomi.animeextension.en.animeui
package eu.kanade.tachiyomi.animeextension.all.animeui
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList

Binary file not shown.

Before

Width:  |  Height:  |  Size: 109 KiB