[Android] Fix MIUI file picker dialog flickering issue

Nicolas Pomepuy git at videolan.org
Tue May 25 12:03:50 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue May 25 10:11:56 2021 +0200| [218398baa113711437ba825db197780822fa0501] | committer: Nicolas Pomepuy

Fix MIUI file picker dialog flickering issue

Fixes #1990

> https://code.videolan.org/videolan/vlc-android/commit/218398baa113711437ba825db197780822fa0501
---

 .../src/org/videolan/vlc/gui/BaseActivity.kt        |  1 +
 .../videolan/vlc/gui/browser/FilePickerActivity.kt  | 21 ++++++++++++---------
 .../src/org/videolan/vlc/gui/helpers/UiTools.kt     |  4 ++++
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt
index dc9b8bd03..e54445dca 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt
@@ -25,6 +25,7 @@ abstract class BaseActivity : AppCompatActivity() {
     lateinit var settings: SharedPreferences
 
     open val displayTitle = false
+    open fun forcedTheme():Int? = null
     abstract fun getSnackAnchorView(): View?
     private var baseContextWrappingDelegate: AppCompatDelegate? = null
 
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerActivity.kt
index edc4702ee..4005b7e77 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerActivity.kt
@@ -23,30 +23,33 @@
 
 package org.videolan.vlc.gui.browser
 
+import android.content.res.Configuration
 import android.os.Bundle
 import android.view.Gravity
 import android.view.View
-import androidx.appcompat.app.AppCompatActivity
-import androidx.appcompat.app.AppCompatDelegate
 import androidx.core.os.bundleOf
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.ObsoleteCoroutinesApi
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
-import org.videolan.tools.KEY_APP_THEME
-import org.videolan.tools.Settings
 import org.videolan.vlc.R
+import org.videolan.vlc.gui.BaseActivity
 import org.videolan.vlc.gui.video.VideoPlayerActivity
 import kotlin.reflect.jvm.jvmName
 
 @ObsoleteCoroutinesApi
 @ExperimentalCoroutinesApi
-class FilePickerActivity : AppCompatActivity() {
+class FilePickerActivity : BaseActivity() {
+    override fun getSnackAnchorView(): View? = findViewById(android.R.id.content)
+
+    /**
+     * Forces the dark theme if the dialog is opened from the VideoPlayerActivity
+     */
+    override fun forcedTheme() =
+        if (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_NO && callingActivity?.className == VideoPlayerActivity::class.jvmName)
+            R.style.Theme_VLC_PickerDialog_Dark
+        else null
 
     public override fun onCreate(savedInstanceState: Bundle?) {
-        if (callingActivity?.className != VideoPlayerActivity::class.jvmName)
-            AppCompatDelegate.setDefaultNightMode(Integer.valueOf(Settings.getInstance(this).getString(KEY_APP_THEME, "-1")!!))
-        else
-            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
         super.onCreate(savedInstanceState)
         setContentView(R.layout.file_picker_activity)
         val ft = supportFragmentManager.beginTransaction()
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
index 445814efb..7951cf92c 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
@@ -691,6 +691,10 @@ fun isSelected(v: View, isSelected: Boolean?) {
 }
 
 fun BaseActivity.applyTheme() {
+    forcedTheme()?.let {
+        setTheme(it)
+        return
+    }
     if (Settings.showTvUi) {
         AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
         setTheme(R.style.Theme_VLC_Black)



More information about the Android mailing list