From 373d0136baa96915075792acfb83b17c17d9da30 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 2 Jun 2023 16:24:47 +0200 Subject: [PATCH] Don't rely on Locale#getDefault for the currently set locale --- .../java/com/github/libretube/extensions/FormatShort.kt | 3 ++- .../java/com/github/libretube/helpers/LocaleHelper.kt | 9 ++++++--- .../com/github/libretube/ui/adapters/VideosAdapter.kt | 2 -- .../com/github/libretube/ui/fragments/PlayerFragment.kt | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/github/libretube/extensions/FormatShort.kt b/app/src/main/java/com/github/libretube/extensions/FormatShort.kt index 4b6c45f4d..621b1339c 100644 --- a/app/src/main/java/com/github/libretube/extensions/FormatShort.kt +++ b/app/src/main/java/com/github/libretube/extensions/FormatShort.kt @@ -2,6 +2,7 @@ package com.github.libretube.extensions import android.icu.text.CompactDecimalFormat import android.os.Build +import com.github.libretube.helpers.LocaleHelper import java.util.* import kotlin.math.pow @@ -9,7 +10,7 @@ fun Long?.formatShort(): String { val value = this ?: 0 return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { CompactDecimalFormat - .getInstance(Locale.getDefault(), CompactDecimalFormat.CompactStyle.SHORT) + .getInstance(LocaleHelper.getAppLocale(), CompactDecimalFormat.CompactStyle.SHORT) .format(value) } else { val units = arrayOf("", "K", "M", "B", "T") diff --git a/app/src/main/java/com/github/libretube/helpers/LocaleHelper.kt b/app/src/main/java/com/github/libretube/helpers/LocaleHelper.kt index dac686890..bdeef6dc0 100644 --- a/app/src/main/java/com/github/libretube/helpers/LocaleHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/LocaleHelper.kt @@ -11,10 +11,9 @@ import com.github.libretube.obj.Country import java.util.* object LocaleHelper { - - fun updateLanguage(context: Context) { + fun getAppLocale(): Locale { val languageName = PreferenceHelper.getString(PreferenceKeys.LANGUAGE, "sys") - val locale = when { + return when { languageName == "sys" -> Locale.getDefault() languageName.contains("-") -> { val languageParts = languageName.split("-") @@ -25,6 +24,10 @@ object LocaleHelper { } else -> Locale(languageName) } + } + + fun updateLanguage(context: Context) { + val locale = getAppLocale() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) updateResources(context, locale) updateResourcesLegacy(context, locale) } diff --git a/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt index 8d195cc97..5e3593e34 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt @@ -170,8 +170,6 @@ class VideosAdapter( channelContainer.setOnClickListener { NavigationHelper.navigateChannel(root.context, video.uploaderUrl) } - } else { - videoInfo.maxLines = 2 } root.setOnClickListener { diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 4dd9c2271..4b22a91af 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -79,6 +79,7 @@ import com.github.libretube.helpers.BackgroundHelper import com.github.libretube.helpers.DashHelper import com.github.libretube.helpers.DisplayHelper import com.github.libretube.helpers.ImageHelper +import com.github.libretube.helpers.LocaleHelper import com.github.libretube.helpers.NavigationHelper import com.github.libretube.helpers.PlayerHelper import com.github.libretube.helpers.PlayerHelper.checkForSegments @@ -1360,7 +1361,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { trackSelector.updateParameters { setPreferredAudioLanguage( - Locale.getDefault().language.lowercase().substring(0, 2), + LocaleHelper.getAppLocale().language.lowercase().substring(0, 2), ) }