mirror of
https://github.com/rebelonion/Dantotsu.git
synced 2026-01-26 02:11:02 +00:00
Added sub language preference option
This commit is contained in:
@@ -96,6 +96,7 @@ import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
|
||||
import ani.dantotsu.databinding.ItemCountDownBinding
|
||||
import ani.dantotsu.media.Media
|
||||
import ani.dantotsu.notifications.IncognitoNotificationClickReceiver
|
||||
import ani.dantotsu.others.LanguageMapper
|
||||
import ani.dantotsu.others.SpoilerPlugin
|
||||
import ani.dantotsu.parsers.ShowResponse
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
@@ -149,6 +150,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
|
||||
@@ -1467,3 +1469,26 @@ fun buildMarkwon(
|
||||
.build()
|
||||
return markwon
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -116,6 +116,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
|
||||
@@ -1382,13 +1383,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!!)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -31,7 +32,6 @@ import ani.dantotsu.toast
|
||||
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",
|
||||
|
||||
@@ -88,6 +88,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)),
|
||||
|
||||
@@ -225,6 +225,25 @@
|
||||
app:showText="false"
|
||||
app:thumbTint="@color/button_switch_track" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/videoSubLanguage"
|
||||
style="@style/Widget.Material3.Button.TextButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:insetTop="0dp"
|
||||
android:insetBottom="0dp"
|
||||
android:paddingHorizontal="32dp"
|
||||
android:text="@string/subtitle_langauge"
|
||||
android:textAlignment="viewStart"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@color/bg_opp"
|
||||
app:cornerRadius="0dp"
|
||||
app:icon="@drawable/ic_round_subtitles_24"
|
||||
app:iconPadding="16dp"
|
||||
app:iconSize="24dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/videoSubColorPrimary"
|
||||
style="@style/Widget.Material3.Button.TextButton"
|
||||
|
||||
@@ -995,4 +995,5 @@ Non quae tempore quo provident laudantium qui illo dolor vel quia dolor et exerc
|
||||
<string name="view_subscriptions_desc">View and edit all your subscriptions</string>
|
||||
<string name="subscriptions">Subscriptions</string>
|
||||
<string name="subscription_deleted">Subscription Deleted</string>
|
||||
<string name="subtitle_langauge">Subtitle Langauge</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user