[Android] AudioBrowserFragment: use the new empty view and visibility fixes
Nicolas Pomepuy
git at videolan.org
Tue Mar 14 11:59:20 UTC 2023
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Feb 21 09:40:54 2023 +0100| [37f7bb2ee33109943ad98cb2830bf91eabea9994] | committer: Nicolas Pomepuy
AudioBrowserFragment: use the new empty view and visibility fixes
> https://code.videolan.org/videolan/vlc-android/commit/37f7bb2ee33109943ad98cb2830bf91eabea9994
---
.../src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt | 11 ++++++++---
.../src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt | 2 ++
.../src/org/videolan/vlc/viewmodels/MedialibraryViewModel.kt | 2 ++
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
index 41f09a044e..f8dd531398 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
@@ -61,6 +61,7 @@ import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
import org.videolan.vlc.util.Permissions
import org.videolan.vlc.util.isTalkbackIsEnabled
+import org.videolan.vlc.util.onAnyChange
import org.videolan.vlc.viewmodels.mobile.AudioBrowserViewModel
import org.videolan.vlc.viewmodels.mobile.getViewModel
@@ -146,6 +147,9 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
activity?.invalidateOptionsMenu()
}
})
+ adapters.forEach {
+ it.onAnyChange { updateEmptyView() }
+ }
}
override fun onDisplaySettingChanged(key: String, value: Any) {
@@ -319,12 +323,13 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
private fun updateEmptyView() {
swipeRefreshLayout.visibility = if (Medialibrary.getInstance().isInitiated) View.VISIBLE else View.GONE
- emptyView.emptyText = viewModel.filterQuery?.let { getString(R.string.empty_search, it) } ?: getString(R.string.nomedia)
+ emptyView.emptyText = viewModel.filterQuery?.let { getString(R.string.empty_search, it) } ?: if (viewModel.providers[currentTab].onlyFavorites) getString(R.string.nofav) else getString(R.string.nomedia)
emptyView.state = when {
!Permissions.canReadStorage(requireActivity()) && empty -> EmptyLoadingState.MISSING_PERMISSION
viewModel.providers[currentTab].loading.value == true && empty -> EmptyLoadingState.LOADING
- empty && viewModel.filterQuery?.isNotEmpty() == true -> EmptyLoadingState.EMPTY_SEARCH
- empty -> EmptyLoadingState.EMPTY
+ emptyAt(currentTab) && viewModel.filterQuery?.isNotEmpty() == true -> EmptyLoadingState.EMPTY_SEARCH
+ emptyAt(currentTab) && viewModel.providers[currentTab].onlyFavorites -> EmptyLoadingState.EMPTY_FAVORITES
+ emptyAt(currentTab) -> EmptyLoadingState.EMPTY
else -> EmptyLoadingState.NONE
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
index 87f8a7b095..f527d5bfb4 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
@@ -436,6 +436,8 @@ abstract class BaseAudioBrowser<T : MedialibraryViewModel> : MediaBrowserFragmen
protected val empty: Boolean
get() = viewModel.isEmpty() && getCurrentAdapter()?.isEmpty != false
+ fun emptyAt(index:Int): Boolean = viewModel.isEmptyAt(index) && getCurrentAdapter()?.isEmpty != false
+
@Suppress("UNCHECKED_CAST")
override fun getMultiHelper(): MultiSelectHelper<T>? = getCurrentAdapter()?.multiSelectHelper as? MultiSelectHelper<T>
}
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/MedialibraryViewModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/MedialibraryViewModel.kt
index 6ce1e98e81..6f67dd091d 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/MedialibraryViewModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/MedialibraryViewModel.kt
@@ -27,6 +27,8 @@ abstract class MedialibraryViewModel(context: Context) : SortableModel(context),
fun isEmpty() = providers.all { it.isEmpty() }
+ fun isEmptyAt(index:Int) = providers[index].isEmpty()
+
override fun restore() {
if (filterQuery !== null) filter(null)
}
More information about the Android
mailing list