Skip to content

Commit

Permalink
fix: Better locale detection and avoid launching null intents (#1382)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samfun75 authored Feb 5, 2024
1 parent 8979594 commit 0bd1bb3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,8 @@ class MainActivity : BaseActivity() {
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
withUIContext { Injekt.get<Application>().toast(e.message) }
return
}
null
} ?: return
externalPlayerResult?.launch(intent) ?: return
} else {
context.startActivity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class ExternalIntents {

val localLangName = LocaleHelper.getSimpleLocaleDisplayName()
video.subtitleTracks.firstOrNull {
it.lang.contains(localLangName)
it.lang.contains(localLangName, true)
}?.let {
putExtra("subtitle", it.url)
} ?: video.subtitleTracks.firstOrNull()?.let {
Expand Down Expand Up @@ -225,7 +225,7 @@ class ExternalIntents {

val localLangName = LocaleHelper.getSimpleLocaleDisplayName()
val langIndex = video.subtitleTracks.indexOfFirst {
it.lang.contains(localLangName)
it.lang.contains(localLangName, true)
}
val requestedLanguage = if (langIndex == -1) 0 else langIndex
val requestedUrl = video.subtitleTracks.getOrNull(requestedLanguage)?.url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ class PlayerActivity : BaseActivity() {
currentVideoList?.getOrNull(streams.quality.index)
?.subtitleTracks?.let { tracks ->
val langIndex = tracks.indexOfFirst {
it.lang.contains(localLangName)
it.lang.contains(localLangName, true)
}
val requestedLanguage = if (langIndex == -1) 0 else langIndex
tracks.getOrNull(requestedLanguage)?.let { sub ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ object LocaleHelper {
* Return English display string from string language code
*/
fun getSimpleLocaleDisplayName(): String {
val sp = Locale.getDefault().language.split("_", "-")
return Locale(sp[0]).getDisplayLanguage(LocaleListCompat.getDefault()[0]!!)
return LocaleListCompat.getDefault()[0]!!.displayLanguage
}
}

Expand Down

0 comments on commit 0bd1bb3

Please sign in to comment.