[Android] Prevent FAb to be displayed on fragments having no FAB action
Nicolas Pomepuy
git at videolan.org
Wed Aug 5 14:25:24 CEST 2020
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Aug 4 11:31:57 2020 +0200| [e1b9724c39625a6afdafc54c0c2f81b3a64da6a0] | committer: Nicolas Pomepuy
Prevent FAb to be displayed on fragments having no FAB action
Fixes #1438
> https://code.videolan.org/videolan/vlc-android/commit/e1b9724c39625a6afdafc54c0c2f81b3a64da6a0
---
application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt | 9 ++++++---
.../org/videolan/vlc/gui/helpers/FloatingActionButtonBehavior.kt | 5 +++++
2 files changed, 11 insertions(+), 3 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 16421e3a4..ae64f7892 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt
@@ -6,6 +6,7 @@ import android.view.Menu
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ActionMode
+import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.google.android.material.floatingactionbutton.FloatingActionButton
@@ -15,6 +16,7 @@ import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.resources.AndroidDevices
import org.videolan.resources.TAG_ITEM
import org.videolan.vlc.R
+import org.videolan.vlc.gui.helpers.FloatingActionButtonBehavior
import org.videolan.vlc.gui.view.SwipeRefreshLayout
abstract class BaseFragment : Fragment(), ActionMode.Callback {
@@ -48,7 +50,9 @@ abstract class BaseFragment : Fragment(), ActionMode.Callback {
swipeRefreshLayout = it
it.setColorSchemeResources(R.color.orange700)
}
- if (hasFAB()) fabPlay = requireActivity().findViewById(R.id.fab)
+ val fab = requireActivity().findViewById<FloatingActionButton>(R.id.fab)
+ ((fab.layoutParams as? CoordinatorLayout.LayoutParams)?.behavior as? FloatingActionButtonBehavior)?.shouldNeverShow = !hasFAB()
+ if (hasFAB()) fabPlay = fab
}
override fun onStart() {
@@ -83,8 +87,7 @@ abstract class BaseFragment : Fragment(), ActionMode.Callback {
open fun setFabPlayVisibility(enable: Boolean) {
fabPlay?.run {
- if (enable) show()
- else hide()
+ if (enable) show() else hide()
}
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/FloatingActionButtonBehavior.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/FloatingActionButtonBehavior.kt
index 532a2ade9..08432cac7 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/FloatingActionButtonBehavior.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/FloatingActionButtonBehavior.kt
@@ -51,6 +51,7 @@ class FloatingActionButtonBehavior(context: Context, attrs: AttributeSet?) : Flo
get() {
return ((player?.layoutParams as? CoordinatorLayout.LayoutParams)?.behavior as? PlayerBehavior)
}
+ var shouldNeverShow = false
init {
onVisibilityChangedListener = object : FloatingActionButton.OnVisibilityChangedListener() {
@@ -94,6 +95,10 @@ class FloatingActionButtonBehavior(context: Context, attrs: AttributeSet?) : Flo
override fun onNestedScroll(coordinatorLayout: CoordinatorLayout, child: FloatingActionButton, target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int) {
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type)
+ if (shouldNeverShow) {
+ child.hide(onVisibilityChangedListener)
+ return
+ }
// When target is a NestedScrollView, use dyUnconsumed as dyConsumed is always 0
val dy = if (target is NestedScrollView) dyUnconsumed else dyConsumed
if (dy > 0 && child.visibility == View.VISIBLE)
More information about the Android
mailing list