[Android] Fix mini player UI in NoStatus activities
Nicolas Pomepuy
git at videolan.org
Tue Mar 8 13:43:48 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Mar 8 10:30:40 2022 +0100| [49456b7552617ce49c7cb8d0ead2064c363597fa] | committer: Duncan McNamara
Fix mini player UI in NoStatus activities
Fixes #2289
> https://code.videolan.org/videolan/vlc-android/commit/49456b7552617ce49c7cb8d0ead2064c363597fa
---
.../vlc/gui/AudioPlayerContainerActivity.kt | 32 +++++++++++++++++++---
.../src/org/videolan/vlc/gui/InfoActivity.kt | 1 +
.../src/org/videolan/vlc/gui/PlaylistActivity.kt | 6 +---
3 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
index f80e918be..28661e6b4 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
@@ -36,10 +36,11 @@ import androidx.appcompat.widget.Toolbar
import androidx.appcompat.widget.ViewStubCompat
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.net.toUri
-import androidx.core.view.isVisible
+import androidx.core.view.*
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.google.android.material.appbar.AppBarLayout
+import com.google.android.material.appbar.CollapsingToolbarLayout
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.bottomsheet.BottomSheetBehavior.*
import com.google.android.material.navigationrail.NavigationRailView
@@ -66,6 +67,7 @@ import org.videolan.vlc.media.PlaylistManager
import kotlin.math.max
import kotlin.math.min
+
private const val TAG = "VLC/APCActivity"
private const val ACTION_DISPLAY_PROGRESSBAR = 1339
@@ -94,14 +96,13 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener {
private var scanProgressText: TextView? = null
private var scanProgressBar: ProgressBar? = null
private lateinit var resumeCard: Snackbar
-
private var preventRescan = false
+
private var playerShown = false
val tipsDelegate: AudioTipsDelegate by lazy(LazyThreadSafetyMode.NONE) { AudioTipsDelegate(this) }
val playlistTipsDelegate: AudioPlaylistTipsDelegate by lazy(LazyThreadSafetyMode.NONE) { AudioPlaylistTipsDelegate(this) }
private val playerKeyListenerDelegate: PlayerKeyListenerDelegate by lazy(LazyThreadSafetyMode.NONE) { PlayerKeyListenerDelegate(this at AudioPlayerContainerActivity) }
val shownTips = ArrayList<Int>()
-
protected val currentFragment: Fragment?
get() = supportFragmentManager.findFragmentById(R.id.fragment_placeholder)
@@ -111,6 +112,8 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener {
@Suppress("LeakingThis")
protected val handler: Handler = ProgressHandler(this)
+ private var topInset: Int = 0
+
val isAudioPlayerReady: Boolean
get() = ::audioPlayer.isInitialized
@@ -118,6 +121,7 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener {
get() = isAudioPlayerReady && playerBehavior.state == STATE_EXPANDED
var bottomIsHiddden: Boolean = false
+ open val managePlayerTopMargin = false
override fun getSnackAnchorView(overAudioPlayer:Boolean): View? {
return if (::audioPlayerContainer.isInitialized && audioPlayerContainer.visibility != View.GONE && ::playerBehavior.isInitialized && playerBehavior.state == STATE_COLLAPSED)
@@ -134,6 +138,20 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener {
super.onCreate(savedInstanceState)
volumeControlStream = AudioManager.STREAM_MUSIC
registerLiveData()
+ if (managePlayerTopMargin) {
+ WindowCompat.setDecorFitsSystemWindows(window, false)
+ ViewCompat.setOnApplyWindowInsetsListener(findViewById(android.R.id.content)) { view, windowInsets ->
+ val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
+ view.updateLayoutParams<ViewGroup.MarginLayoutParams>{
+ leftMargin = insets.left
+ rightMargin = insets.right
+ bottomMargin = insets.bottom
+ (findViewById<Toolbar>(R.id.main_toolbar).layoutParams as CollapsingToolbarLayout.LayoutParams).topMargin = insets.top
+ }
+
+ WindowInsetsCompat.CONSUMED
+ }
+ }
}
protected open fun initAudioPlayerContainerActivity() {
@@ -187,7 +205,7 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener {
val translationpercent = min(1f, max(0f, slideOffset))
bottomBehavior?.let { bottomBehavior ->
bottomBar?.let { bottomBar ->
- val translation = min((translationpercent * audioPlayerContainer.height / 2), bottomBar.height.toFloat())
+ val translation = min((translationpercent * audioPlayerContainer.height / 2), bottomBar.height.toFloat()) - if (managePlayerTopMargin) topInset else 0
bottomBehavior.translate(bottomBar, translation)
}
}
@@ -195,6 +213,12 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener {
override fun onStateChanged(bottomSheet: View, newState: Int) {
onPlayerStateChanged(bottomSheet, newState)
+ if (managePlayerTopMargin) {
+ WindowInsetsControllerCompat(window, window.decorView).apply {
+ systemBarsBehavior = if (newState == STATE_EXPANDED) WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE else WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_TOUCH
+ if (newState == STATE_EXPANDED) hide( WindowInsetsCompat.Type.statusBars()) else show( WindowInsetsCompat.Type.statusBars())
+ }
+ }
audioPlayer.onStateChanged(newState)
if (newState == STATE_COLLAPSED || newState == STATE_HIDDEN) removeTipViewIfDisplayed()
updateFragmentMargins(newState)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt
index 428a587ac..729086c56 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt
@@ -63,6 +63,7 @@ class InfoActivity : AudioPlayerContainerActivity(), View.OnClickListener, PathA
private lateinit var model: InfoModel
internal lateinit var binding: InfoActivityBinding
+ override val managePlayerTopMargin = true
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
index d3764ee24..a91231825 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
@@ -50,7 +50,6 @@ import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.medialibrary.interfaces.media.Playlist
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.resources.*
-import org.videolan.resources.util.isExternalStorageManager
import org.videolan.tools.copy
import org.videolan.tools.isStarted
import org.videolan.vlc.BuildConfig
@@ -65,8 +64,6 @@ import org.videolan.vlc.gui.helpers.FloatingActionButtonBehavior
import org.videolan.vlc.gui.helpers.SwipeDragItemTouchHelperCallback
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.helpers.UiTools.addToPlaylist
-import org.videolan.vlc.gui.helpers.UiTools.snackerConfirm
-import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.getWritePermission
import org.videolan.vlc.gui.view.RecyclerSectionItemDecoration
import org.videolan.vlc.interfaces.IEventsHandler
import org.videolan.vlc.interfaces.IListEventsHandler
@@ -75,9 +72,7 @@ import org.videolan.vlc.media.PlaylistManager
import org.videolan.vlc.util.*
import org.videolan.vlc.viewmodels.mobile.PlaylistViewModel
import org.videolan.vlc.viewmodels.mobile.getViewModel
-import java.lang.Runnable
import java.util.*
-import kotlin.collections.ArrayList
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
@@ -91,6 +86,7 @@ open class PlaylistActivity : AudioPlayerContainerActivity(), IEventsHandler<Med
private var isPlaylist: Boolean = false
private lateinit var viewModel: PlaylistViewModel
private var itemTouchHelper: ItemTouchHelper? = null
+ override val managePlayerTopMargin = true
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
More information about the Android
mailing list