[Android] Handle OnDismiss event on option dialogs

Sébastien Toque git at videolan.org
Tue Jun 11 09:42:03 CEST 2019


vlc-android | branch: master | Sébastien Toque <xilasz at gmail.com> | Tue Jun 11 09:42:02 2019 +0200| [f258985caf4bc39d1799f691e07952bbf57b5d41] | committer: Geoffrey Métais

Handle OnDismiss event on option dialogs

This fixes the status bar not dimmed when an option dialog is closed.

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

 .../org/videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt  | 6 ++++++
 .../src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt     | 8 ++++----
 vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt | 3 ++-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt
index fc9744336..aa04a5457 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/VLCBottomSheetDialogFragment.kt
@@ -1,5 +1,6 @@
 package org.videolan.vlc.gui.dialogs
 
+import android.content.DialogInterface
 import android.content.res.Configuration
 import android.os.Bundle
 import android.view.ContextThemeWrapper
@@ -19,6 +20,7 @@ import org.videolan.vlc.util.Settings
 
 abstract class VLCBottomSheetDialogFragment : BottomSheetDialogFragment() {
 
+    var onDismissListener: DialogInterface.OnDismissListener? = null
 
     fun inflate(inflater: LayoutInflater, container: ViewGroup?, @LayoutRes layout: Int): View? {
         if (Settings.showTvUi) {
@@ -46,6 +48,10 @@ abstract class VLCBottomSheetDialogFragment : BottomSheetDialogFragment() {
 
     }
 
+    override fun onDismiss(dialog: DialogInterface?) {
+        super.onDismiss(dialog)
+        onDismissListener?.onDismiss(dialog)
+    }
 
     override fun onResume() {
         super.onResume()
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
index ffab71241..9a5ffbc90 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
 import android.app.AlarmManager
 import android.app.PendingIntent
 import android.content.Context
+import android.content.DialogInterface
 import android.content.Intent
 import android.support.v4.media.session.PlaybackStateCompat
 import android.text.format.DateFormat
@@ -29,10 +30,7 @@ import org.videolan.vlc.VLCApplication
 import org.videolan.vlc.databinding.PlayerOptionItemBinding
 import org.videolan.vlc.gui.DiffUtilAdapter
 import org.videolan.vlc.gui.audio.EqualizerFragment
-import org.videolan.vlc.gui.dialogs.JumpToTimeDialog
-import org.videolan.vlc.gui.dialogs.PlaybackSpeedDialog
-import org.videolan.vlc.gui.dialogs.SelectChapterDialog
-import org.videolan.vlc.gui.dialogs.SleepTimerDialog
+import org.videolan.vlc.gui.dialogs.*
 import org.videolan.vlc.gui.video.VideoPlayerActivity
 import org.videolan.vlc.interfaces.IPlaybackSettingsController
 import org.videolan.vlc.media.ABRepeat
@@ -243,6 +241,8 @@ class PlayerOptionsDelegate(val activity: AppCompatActivity, val service: Playba
             }
             else -> return
         }
+        if (newFragment is VLCBottomSheetDialogFragment && activity is VideoPlayerActivity)
+            newFragment.onDismissListener = DialogInterface.OnDismissListener { activity.dimStatusBar(true) }
         newFragment.show(activity.supportFragmentManager, tag)
         hide()
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index e9e298eb3..0e78c34e6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -1853,6 +1853,7 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
                         listener.onTrackSelected(trackID)
                         dialog.dismiss()
                     }
+                    .setOnDismissListener { this.dimStatusBar(true) }
                     .create()
             alertDialog!!.setCanceledOnTouchOutside(true)
             alertDialog!!.ownerActivity = this at VideoPlayerActivity
@@ -2242,7 +2243,7 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
      * Hide it on Android 4.0 and later
      */
     @TargetApi(Build.VERSION_CODES.KITKAT)
-    private fun dimStatusBar(dim: Boolean) {
+    public fun dimStatusBar(dim: Boolean) {
         if (isNavMenu) return
         if (dim || isLocked)
             actionBar.hide()



More information about the Android mailing list