diff --git a/app/src/main/java/ani/dantotsu/Functions.kt b/app/src/main/java/ani/dantotsu/Functions.kt index 5c1f325519..6491c8ab6c 100644 --- a/app/src/main/java/ani/dantotsu/Functions.kt +++ b/app/src/main/java/ani/dantotsu/Functions.kt @@ -154,6 +154,7 @@ import java.io.FileOutputStream import java.io.OutputStream import java.lang.reflect.Field import java.util.Calendar +import java.util.Locale import java.util.TimeZone import java.util.Timer import java.util.TimerTask @@ -1538,4 +1539,27 @@ fun getYoutubeId(url: String): String { val regex = """(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|(?:youtu\.be|youtube\.com)/)([^"&?/\s]{11})|youtube\.com/""".toRegex() val matchResult = regex.find(url) return matchResult?.groupValues?.getOrNull(1) ?: "" -} \ No newline at end of file +} + +fun getLanguageCode(language: String): CharSequence { + val locales = Locale.getAvailableLocales() + for (locale in locales) { + if (locale.displayLanguage.equals(language, ignoreCase = true)) { + val lang: CharSequence = locale.language + return lang + + } + } + val out: CharSequence = "null" + return out +} + +fun getLanguageName(language: String): String? { + val locales = Locale.getAvailableLocales() + for (locale in locales) { + if (locale.language.equals(language, ignoreCase = true)) { + return locale.displayLanguage + } + } + return null +} diff --git a/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt b/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt index 2eab2e349c..594a1d401a 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt @@ -117,6 +117,7 @@ import ani.dantotsu.download.DownloadsManager.Companion.getSubDirectory import ani.dantotsu.download.video.Helper import ani.dantotsu.dp import ani.dantotsu.getCurrentBrightnessValue +import ani.dantotsu.getLanguageCode import ani.dantotsu.hideSystemBars import ani.dantotsu.hideSystemBarsExtendView import ani.dantotsu.isOnline @@ -1396,13 +1397,57 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL val ext = episode.extractors?.find { it.server.name == episode.selectedExtractor } ?: return extractor = ext video = ext.videos.getOrNull(episode.selectedVideo) ?: return + val subLanguages = arrayOf( + "Albanian", + "Arabic", + "Bosnian", + "Bulgarian", + "Chinese", + "Croatian", + "Czech", + "Danish", + "Dutch", + "English", + "Estonian", + "Finnish", + "French", + "Georgian", + "German", + "Greek", + "Hebrew", + "Hindi", + "Indonesian", + "Irish", + "Italian", + "Japanese", + "Korean", + "Lithuanian", + "Luxembourgish", + "Macedonian", + "Mongolian", + "Norwegian", + "Polish", + "Portuguese", + "Punjabi", + "Romanian", + "Russian", + "Serbian", + "Slovak", + "Slovenian", + "Spanish", + "Turkish", + "Ukrainian", + "Urdu", + "Vietnamese", + ) + val lang = subLanguages[PrefManager.getVal(PrefName.SubLanguage)] subtitle = intent.getSerialized("subtitle") ?: when (val subLang: String? = PrefManager.getNullableCustomVal("subLang_${media.id}", null, String::class.java)) { null -> { when (episode.selectedSubtitle) { null -> null - -1 -> ext.subtitles.find { it.language.trim() == "English" || it.language == "en-US" } + -1 -> ext.subtitles.find { it.language.contains( lang, ignoreCase = true ) || it.language.contains( getLanguageCode(lang), ignoreCase = true ) } else -> ext.subtitles.getOrNull(episode.selectedSubtitle!!) } } diff --git a/app/src/main/java/ani/dantotsu/settings/PlayerSettingsActivity.kt b/app/src/main/java/ani/dantotsu/settings/PlayerSettingsActivity.kt index e3999509ba..cf5ec967b1 100644 --- a/app/src/main/java/ani/dantotsu/settings/PlayerSettingsActivity.kt +++ b/app/src/main/java/ani/dantotsu/settings/PlayerSettingsActivity.kt @@ -1,6 +1,7 @@ package ani.dantotsu.settings import android.app.AlertDialog +import android.app.Dialog import android.content.res.Resources import android.graphics.Color import android.os.Build @@ -32,7 +33,6 @@ import ani.dantotsu.util.customAlertDialog import com.google.android.material.slider.Slider.OnChangeListener import kotlin.math.roundToInt - class PlayerSettingsActivity : AppCompatActivity() { lateinit var binding: ActivityPlayerSettingsBinding private val player = "player_settings" @@ -318,6 +318,61 @@ class PlayerSettingsActivity : AppCompatActivity() { toggleSubOptions(isChecked) } toggleSubOptions(binding.subSwitch.isChecked) + val subLanguages = arrayOf( + "Albanian", + "Arabic", + "Bosnian", + "Bulgarian", + "Chinese", + "Croatian", + "Czech", + "Danish", + "Dutch", + "English", + "Estonian", + "Finnish", + "French", + "Georgian", + "German", + "Greek", + "Hebrew", + "Hindi", + "Indonesian", + "Irish", + "Italian", + "Japanese", + "Korean", + "Lithuanian", + "Luxembourgish", + "Macedonian", + "Mongolian", + "Norwegian", + "Polish", + "Portuguese", + "Punjabi", + "Romanian", + "Russian", + "Serbian", + "Slovak", + "Slovenian", + "Spanish", + "Turkish", + "Ukrainian", + "Urdu", + "Vietnamese", + ) + val subLanguageDialog = AlertDialog.Builder(this, R.style.MyPopup) + .setTitle(getString(R.string.subtitle_langauge)) + binding.videoSubLanguage.setOnClickListener { + val dialog = subLanguageDialog.setSingleChoiceItems( + subLanguages, + PrefManager.getVal(PrefName.SubLanguage) + ) { dialog, count -> + PrefManager.setVal(PrefName.SubLanguage, count) + dialog.dismiss() + }.show() + dialog.window?.setDimAmount(0.8f) + } val colorsPrimary = arrayOf( "Black", diff --git a/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt b/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt index fb61242247..b175ababd3 100644 --- a/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt +++ b/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt @@ -92,6 +92,7 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files CursedSpeeds(Pref(Location.Player, Boolean::class, false)), Resize(Pref(Location.Player, Int::class, 0)), Subtitles(Pref(Location.Player, Boolean::class, true)), + SubLanguage(Pref(Location.Player, Int::class, 9)), PrimaryColor(Pref(Location.Player, Int::class, 4)), SecondaryColor(Pref(Location.Player, Int::class, 0)), Outline(Pref(Location.Player, Int::class, 0)), diff --git a/app/src/main/res/layout/activity_player_settings.xml b/app/src/main/res/layout/activity_player_settings.xml index 15efde781a..f7d4e70748 100644 --- a/app/src/main/res/layout/activity_player_settings.xml +++ b/app/src/main/res/layout/activity_player_settings.xml @@ -225,6 +225,25 @@ app:showText="false" app:thumbTint="@color/button_switch_track" /> +