[Android] Fix audio item selection with action mode

Nicolas Pomepuy git at videolan.org
Tue May 7 12:58:11 CEST 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Tue May  7 10:12:21 2019 +0200| [f34eba1974f17dc4ef0bf8e01249ac74fc19ac4a] | committer: Geoffrey Métais

Fix audio item selection with action mode

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

 .../src/org/videolan/vlc/gui/PlaylistFragment.kt       |  2 +-
 .../org/videolan/vlc/gui/audio/AudioBrowserFragment.kt | 10 +++++++---
 .../src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt | 18 +++++++++++-------
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt b/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
index 090ae2951..747cc958a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
@@ -106,7 +106,7 @@ class PlaylistFragment : BaseAudioBrowser(), SwipeRefreshLayout.OnRefreshListene
         val itemSize = requireActivity().getScreenWidth() / nbColumns - spacing * 2
 
         playlistAdapter = AudioBrowserAdapter(MediaLibraryItem.TYPE_PLAYLIST, this, itemSize)
-        currentAdapter = playlistAdapter
+        adapter = playlistAdapter
 
         playlists.layoutManager = gridLayoutManager
         playlists.adapter = playlistAdapter
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
index 62600b80b..44970fe7d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
@@ -234,8 +234,8 @@ class AudioBrowserFragment : BaseAudioBrowser(), SwipeRefreshLayout.OnRefreshLis
     }
 
     private fun updateEmptyView() {
-        emptyView.visibility = if (currentAdapter != null && currentAdapter!!.isEmpty) View.VISIBLE else View.GONE
-        medialibrarySettingsBtn.visibility = if (currentAdapter != null && currentAdapter!!.isEmpty) View.VISIBLE else View.GONE
+        emptyView.visibility = if (getCurrentAdapter() != null && getCurrentAdapter()!!.isEmpty) View.VISIBLE else View.GONE
+        medialibrarySettingsBtn.visibility = if (getCurrentAdapter() != null && getCurrentAdapter()!!.isEmpty) View.VISIBLE else View.GONE
         setFabPlayShuffleAllVisibility()
     }
 
@@ -292,7 +292,7 @@ class AudioBrowserFragment : BaseAudioBrowser(), SwipeRefreshLayout.OnRefreshLis
 
     override fun onUpdateFinished(adapter: RecyclerView.Adapter<*>) {
         super.onUpdateFinished(adapter)
-        if (currentAdapter != null && adapter === currentAdapter) {
+        if (getCurrentAdapter() != null && adapter === getCurrentAdapter()) {
             swipeRefreshLayout?.isEnabled = (getCurrentRV().layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() <= 0
             updateEmptyView()
             fastScroller.setRecyclerView(getCurrentRV(), viewModel)
@@ -306,6 +306,10 @@ class AudioBrowserFragment : BaseAudioBrowser(), SwipeRefreshLayout.OnRefreshLis
         return lists[viewPager!!.currentItem]!!
     }
 
+    override fun getCurrentAdapter(): AudioBrowserAdapter? {
+        return adapters[viewPager!!.currentItem]
+    }
+
     private class AudioBrowserHandler internal constructor(owner: AudioBrowserFragment) : WeakHandler<AudioBrowserFragment>(owner) {
 
         override fun handleMessage(msg: Message) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt b/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
index 782237030..3a3129da4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
@@ -63,7 +63,11 @@ abstract class BaseAudioBrowser : MediaBrowserFragment<MLPagedModel<*>>(), IEven
     private val tcl = TabLayout.TabLayoutOnPageChangeListener(tabLayout)
 
     protected abstract fun getCurrentRV(): RecyclerView
-    protected var currentAdapter: AudioBrowserAdapter? = null
+    protected var adapter: AudioBrowserAdapter? = null
+
+    open fun getCurrentAdapter(): AudioBrowserAdapter? {
+        return adapter
+    }
 
     private lateinit var layoutOnPageChangeListener: TabLayout.TabLayoutOnPageChangeListener
 
@@ -151,7 +155,7 @@ abstract class BaseAudioBrowser : MediaBrowserFragment<MLPagedModel<*>>(), IEven
     }
 
     override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
-        val selection = currentAdapter?.multiSelectHelper?.getSelection()
+        val selection = getCurrentAdapter()?.multiSelectHelper?.getSelection()
         val count = selection?.size
         if (count == 0) {
             stopActionMode()
@@ -165,7 +169,7 @@ abstract class BaseAudioBrowser : MediaBrowserFragment<MLPagedModel<*>>(), IEven
     }
 
     override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
-        val list = currentAdapter?.multiSelectHelper?.getSelection()
+        val list = getCurrentAdapter()?.multiSelectHelper?.getSelection()
         stopActionMode()
         if (list != null && list.isNotEmpty())
             runIO(Runnable {
@@ -186,7 +190,7 @@ abstract class BaseAudioBrowser : MediaBrowserFragment<MLPagedModel<*>>(), IEven
     }
 
     override fun onDestroyActionMode(actionMode: ActionMode) {
-        onDestroyActionMode(currentAdapter)
+        onDestroyActionMode(getCurrentAdapter())
     }
 
     internal fun onDestroyActionMode(adapter: AudioBrowserAdapter?) {
@@ -204,14 +208,14 @@ abstract class BaseAudioBrowser : MediaBrowserFragment<MLPagedModel<*>>(), IEven
 
     override fun onClick(v: View, position: Int, item: MediaLibraryItem) {
         if (actionMode != null) {
-            currentAdapter?.multiSelectHelper?.toggleSelection(position)
+            getCurrentAdapter()?.multiSelectHelper?.toggleSelection(position)
             invalidateActionMode()
         }
     }
 
     override fun onLongClick(v: View, position: Int, item: MediaLibraryItem): Boolean {
         if (actionMode != null) return false
-        currentAdapter?.multiSelectHelper?.toggleSelection(position)
+        getCurrentAdapter()?.multiSelectHelper?.toggleSelection(position)
         startActionMode()
         return true
     }
@@ -247,7 +251,7 @@ abstract class BaseAudioBrowser : MediaBrowserFragment<MLPagedModel<*>>(), IEven
     }
 
     override fun onCtxAction(position: Int, option: Int) {
-        val adapter = currentAdapter
+        val adapter = getCurrentAdapter()
         if (position >= adapter?.itemCount ?: 0) return
         val media = adapter?.getItem(position) ?: return
         when (option) {



More information about the Android mailing list