Merge pull request #3894 from Bnyro/master

Don't rely on Locale#getDefault for the currently set locale
This commit is contained in:
Bnyro 2023-06-02 16:24:36 +02:00 committed by GitHub
commit 26647f3c2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 7 deletions

View File

@ -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")

View File

@ -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)
}

View File

@ -170,8 +170,6 @@ class VideosAdapter(
channelContainer.setOnClickListener {
NavigationHelper.navigateChannel(root.context, video.uploaderUrl)
}
} else {
videoInfo.maxLines = 2
}
root.setOnClickListener {

View File

@ -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),
)
}