[Android] Prevent FAB locked hidden when the view pager hosts different fragment types

Nicolas Pomepuy git at videolan.org
Tue Nov 15 10:33:23 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Nov 14 14:18:17 2022 +0100| [44ed2f7908c8e38d1982ce1c6738100486fdc1b5] | committer: Duncan McNamara

Prevent FAB locked hidden when the view pager hosts different fragment types

Fixes #2732

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

 application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt | 8 +++++++-
 .../vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt     | 2 ++
 .../src/org/videolan/vlc/gui/video/VideoBrowserFragment.kt       | 9 ++++++++-
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.kt          | 3 +++
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt
index e51d1f2f5e..e5b41dcc5f 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt
@@ -54,6 +54,8 @@ abstract class BaseFragment : Fragment(), ActionMode.Callback {
     val menu: Menu?
         get() = (activity as? AudioPlayerContainerActivity)?.menu
 
+    open val isMainNavigationPoint = true
+
     abstract fun getTitle(): String
     open fun onFabPlayClick(view: View) {}
 
@@ -72,9 +74,13 @@ abstract class BaseFragment : Fragment(), ActionMode.Callback {
             it.setColorSchemeColors(color)
             it.setProgressBackgroundColorSchemeColor(bColor)
         }
+        if (isMainNavigationPoint) manageFabNeverShow()
+        if (hasFAB()) updateFabPlayView()
+    }
+
+    fun manageFabNeverShow() {
         val fab = requireActivity().findViewById<FloatingActionButton?>(R.id.fab)
         ((fab?.layoutParams as? CoordinatorLayout.LayoutParams)?.behavior as? FloatingActionButtonBehavior)?.shouldNeverShow = !hasFAB() && requireActivity() is MainActivity
-        if (hasFAB()) updateFabPlayView()
     }
 
     override fun onStart() {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
index dab040a244..3cb4a1054c 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
@@ -67,6 +67,8 @@ class PlaylistFragment : BaseAudioBrowser<PlaylistsViewModel>(), SwipeRefreshLay
     private lateinit var playlistAdapter: AudioBrowserAdapter
     private lateinit var fastScroller: FastScroller
     override val isChild = true
+    override val isMainNavigationPoint = false
+    
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         val type = arguments?.getInt(PLAYLIST_TYPE, 0) ?: 0
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoBrowserFragment.kt
index 14e404cefd..b71cf88923 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoBrowserFragment.kt
@@ -146,7 +146,10 @@ class VideoBrowserFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListene
         tcl.onPageScrollStateChanged(state)
     }
 
-    override fun onPageSelected(position: Int) {}
+    override fun onPageSelected(position: Int) {
+        if (position == 0) setFabPlayVisibility(true)
+        manageFabNeverShow()
+    }
 
     private fun setupTabLayout() {
         if (tabLayout == null || !::viewPager.isInitialized) return
@@ -157,6 +160,10 @@ class VideoBrowserFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListene
         viewPager.addOnPageChangeListener(this)
     }
 
+    override fun hasFAB(): Boolean {
+        return !::viewPager.isInitialized || viewPager.currentItem == 0
+    }
+
     private fun unSetTabLayout() {
         if (tabLayout != null || !::viewPager.isInitialized) return
         viewPager.removeOnPageChangeListener(layoutOnPageChangeListener)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
index c14b4735cd..45c812b892 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
@@ -89,6 +89,9 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
     private var gridItemDecoration: RecyclerView.ItemDecoration? = null
     private lateinit var settings: SharedPreferences
     override val isChild = true
+    //in case of fragment being hosted by other fragments, it's useful to prevent the
+    //FAB visibility to be locked hidden
+    override val isMainNavigationPoint = false
 
     private fun FragmentActivity.open(item: MediaLibraryItem) {
         val i = Intent(activity, SecondaryActivity::class.java)



More information about the Android mailing list