mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #3894 from Bnyro/master
Don't rely on Locale#getDefault for the currently set locale
This commit is contained in:
commit
26647f3c2a
@ -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")
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -170,8 +170,6 @@ class VideosAdapter(
|
||||
channelContainer.setOnClickListener {
|
||||
NavigationHelper.navigateChannel(root.context, video.uploaderUrl)
|
||||
}
|
||||
} else {
|
||||
videoInfo.maxLines = 2
|
||||
}
|
||||
|
||||
root.setOnClickListener {
|
||||
|
@ -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),
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user