Commit 88edbaab authored by Nicolas Pomepuy's avatar Nicolas Pomepuy
Browse files

Fix FAB visibility for audio and video fragments

Fixes #1570
parent 812c2585
Pipeline #46419 passed with stage
in 2 minutes and 26 seconds
......@@ -2,6 +2,7 @@ package org.videolan.vlc.gui
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.View
import androidx.appcompat.app.AppCompatActivity
......@@ -18,6 +19,7 @@ import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.resources.AndroidDevices
import org.videolan.resources.TAG_ITEM
import org.videolan.tools.retrieveParent
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
import org.videolan.vlc.gui.browser.KEY_MEDIA
import org.videolan.vlc.gui.helpers.FloatingActionButtonBehavior
......@@ -102,6 +104,7 @@ abstract class BaseFragment : Fragment(), ActionMode.Callback {
protected open fun hasFAB() = ::swipeRefreshLayout.isInitialized
open fun setFabPlayVisibility(enable: Boolean) {
if (BuildConfig.DEBUG) Log.d("FAB", "setFabPlayVisibility $enable", NullPointerException())
fabPlay?.run {
if (enable) show() else hide()
}
......
......@@ -200,6 +200,7 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
lists[index].scrollToPosition(it)
restorePositions.delete(index)
}
setFabPlayShuffleAllVisibility(items.isNotEmpty())
})
provider.loading.observe(viewLifecycleOwner, { loading ->
if (loading == null || currentTab != index) return@observe
......@@ -272,8 +273,8 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
MediaUtils.playAll(activity, viewModel.tracksProvider, 0, true)
}
private fun setFabPlayShuffleAllVisibility() {
setFabPlayVisibility(songsAdapter.itemCount > 2)
private fun setFabPlayShuffleAllVisibility(force: Boolean = false) {
setFabPlayVisibility(force || songsAdapter.itemCount > 2)
}
override fun getTitle(): String = getString(R.string.audio)
......@@ -282,7 +283,6 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
private fun updateEmptyView() {
empty_loading.state = if (viewModel.providers[currentTab].loading.value == true && empty) EmptyLoadingState.LOADING else if (empty) EmptyLoadingState.EMPTY else EmptyLoadingState.NONE
setFabPlayShuffleAllVisibility()
}
override fun onPageSelected(position: Int) {
......
......@@ -122,12 +122,12 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
updateEmptyView()
restoreMultiSelectHelper()
if (activity?.isFinishing == false && viewModel.group != null && it.size < 2) requireActivity().finish()
setFabPlayVisibility(true)
})
viewModel.provider.loading.observe(this, { loading ->
setRefreshing(loading) { refresh ->
if (!refresh) {
setFabPlayVisibility(true)
menu?.let { UiTools.updateSortTitles(it, viewModel.provider) }
restoreMultiSelectHelper()
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment