From 0bd1bb37bd68366bb01b805592ff2f136a944cf4 Mon Sep 17 00:00:00 2001 From: Samfun75 <38332931+Samfun75@users.noreply.github.com> Date: Tue, 6 Feb 2024 01:32:57 +0300 Subject: [PATCH] fix: Better locale detection and avoid launching null intents (#1382) --- app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt | 4 ++-- .../java/eu/kanade/tachiyomi/ui/player/ExternalIntents.kt | 4 ++-- .../main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt | 2 +- .../main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index bc0dd3e492..e6529948eb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -580,8 +580,8 @@ class MainActivity : BaseActivity() { } catch (e: Exception) { logcat(LogPriority.ERROR, e) withUIContext { Injekt.get().toast(e.message) } - return - } + null + } ?: return externalPlayerResult?.launch(intent) ?: return } else { context.startActivity( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/ExternalIntents.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/ExternalIntents.kt index 1de599edbe..46fe22b9e5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/ExternalIntents.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/ExternalIntents.kt @@ -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 { @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt index 79dc77c9b3..30cf5ffc46 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt @@ -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 -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt index aaf8b0fc58..eb27028d04 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/LocaleHelper.kt @@ -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 } }