[Android] Fix language change

Nicolas Pomepuy git at videolan.org
Mon Jul 29 14:25:22 CEST 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Fri Jul 26 14:14:20 2019 +0200| [826eaf5f4cb7a09a3309f152630d86664fee5fc5] | committer: Nicolas Pomepuy

Fix language change

> https://code.videolan.org/videolan/vlc-android/commit/826eaf5f4cb7a09a3309f152630d86664fee5fc5
---

 vlc-android/src/org/videolan/vlc/VLCApplication.kt               | 9 ++++-----
 vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt             | 2 ++
 vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt          | 8 +++-----
 .../src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.kt        | 2 +-
 4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.kt b/vlc-android/src/org/videolan/vlc/VLCApplication.kt
index a3fbb49d1..11193562b 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.kt
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.kt
@@ -44,7 +44,10 @@ import org.videolan.vlc.gui.helpers.AudioUtil
 import org.videolan.vlc.gui.helpers.BitmapCache
 import org.videolan.vlc.gui.helpers.NotificationHelper
 import org.videolan.vlc.gui.helpers.UiTools
-import org.videolan.vlc.util.*
+import org.videolan.vlc.util.Settings
+import org.videolan.vlc.util.Util
+import org.videolan.vlc.util.VLCInstance
+import org.videolan.vlc.util.runIO
 import java.lang.ref.WeakReference
 import java.lang.reflect.InvocationTargetException
 
@@ -96,10 +99,6 @@ class VLCApplication : MultiDexApplication() {
         //Initiate Kotlinx Dispatchers in a thread to prevent ANR
         Thread(Runnable {
             locale = Settings.getInstance(instance).getString("set_locale", "")
-            runOnMainThread(Runnable {
-                // Set the locale for API < 24 and set application resources and direction for API >=24
-                UiTools.setLocale(appContext)
-            })
 
             runIO(Runnable {
                 if (AndroidUtil.isOOrLater)
diff --git a/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt b/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt
index a93f8d29d..f7a31841d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt
@@ -8,6 +8,7 @@ import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.MainScope
 import kotlinx.coroutines.cancel
 import org.videolan.tools.KeyHelper
+import org.videolan.vlc.gui.helpers.UiTools
 import org.videolan.vlc.gui.helpers.applyTheme
 import org.videolan.vlc.util.Settings
 
@@ -16,6 +17,7 @@ open class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope() {
     lateinit var settings: SharedPreferences
 
     override fun onCreate(savedInstanceState: Bundle?) {
+        UiTools.setLocale(this)
         settings = Settings.getInstance(this)
         /* Theme must be applied before super.onCreate */
         applyTheme()
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
index 09bfe5261..3f71abcc8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
@@ -30,7 +30,7 @@ import android.content.Context
 import android.content.DialogInterface
 import android.content.Intent
 import android.content.res.Configuration
-import android.graphics.*
+import android.graphics.Bitmap
 import android.graphics.drawable.BitmapDrawable
 import android.media.MediaRouter
 import android.net.Uri
@@ -481,10 +481,8 @@ object UiTools {
     }
 
     fun setLocale(context: Context) {
-        // Are we using advanced debugging - locale?
-        val p = VLCApplication.locale
-        if (p != "") {
-            val locale = getLocaleFromString(p!!)
+        if (!VLCApplication.locale.isNullOrEmpty()) {
+            val locale = getLocaleFromString(VLCApplication.locale!!)
             Locale.setDefault(locale)
             val config = Configuration()
             config.locale = locale
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.kt
index e5baf6f89..42160d325 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.kt
@@ -34,7 +34,6 @@ import android.widget.TextView
 import androidx.fragment.app.FragmentActivity
 import androidx.lifecycle.Observer
 import kotlinx.coroutines.*
-import org.videolan.medialibrary.Medialibrary
 import org.videolan.medialibrary.interfaces.AbstractMedialibrary
 import org.videolan.tools.KeyHelper
 import org.videolan.vlc.*
@@ -58,6 +57,7 @@ abstract class BaseTvActivity : FragmentActivity(), CoroutineScope by MainScope(
 
     override fun onCreate(savedInstanceState: Bundle?) {
         //Init Medialibrary if KO
+        UiTools.setLocale(this)
         if (savedInstanceState != null) startMedialibrary(firstRun = false, upgrade = false, parse = true)
         super.onCreate(savedInstanceState)
         mediaLibrary = AbstractMedialibrary.getInstance()



More information about the Android mailing list