Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnimeUI: Extension moved and preferred subtitle language #3045

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'AnimeUI'
extClass = '.AnimeUI'
extVersionCode = 1
extVersionCode = 2
}

apply from: "$rootDir/common.gradle"
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand All @@ -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)!!
Expand All @@ -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 ==============================

Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Binary file removed src/en/animeui/res/web_hi_res_512.png
Binary file not shown.