[Android] Adapters: abort binding when job is cancelled

Geoffrey Métais git at videolan.org
Wed Oct 30 11:29:43 CET 2019


vlc-android | branch: 3.2.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Oct 30 11:26:49 2019 +0100| [43c7d93f1734215ca5081744a532f42014fb12ab] | committer: Geoffrey Métais

Adapters: abort binding when job is cancelled

(cherry picked from commit 4b8ff286fda296413522e5c8e1a4be05d955dd7b)

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

 vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt | 3 ++-
 vlc-android/src/org/videolan/vlc/gui/folders/FoldersAdapter.kt        | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt
index 01b728181..e39e85eb8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt
@@ -58,6 +58,7 @@ internal class StorageBrowserAdapter(fragment: StorageBrowserFragment) : BaseBro
             if (!storagePath.endsWith("/")) storagePath += "/"
             vh.binding.item = storage
             updateJob?.join()
+            if (updateJob?.isCancelled == true) return at launch
             val hasContextMenu = customDirsLocation.contains(storagePath)
             val checked = (fragment as StorageBrowserFragment).scannedDirectory || mediaDirsLocation.containsPath(storagePath)
             vh.binding.hasContextMenu = hasContextMenu
@@ -87,7 +88,7 @@ internal class StorageBrowserAdapter(fragment: StorageBrowserFragment) : BaseBro
     suspend fun updateListState(context: Context) {
         updateMediaDirs(context)
         updateJob?.join()
-        notifyItemRangeChanged(0, itemCount)
+        if (updateJob?.isCancelled == false) notifyItemRangeChanged(0, itemCount)
     }
 
     fun updateMediaDirs(context: Context) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/folders/FoldersAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/folders/FoldersAdapter.kt
index f2db1d1b4..8596dba4a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/folders/FoldersAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/folders/FoldersAdapter.kt
@@ -24,7 +24,6 @@ class FoldersAdapter(val actor: SendChannel<FolderAction>) : PagedListAdapter<Ab
 
     val multiSelectHelper = MultiSelectHelper(this, UPDATE_SELECTION)
 
-
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
         if (!this::inflater.isInitialized) inflater = LayoutInflater.from(parent.context)
         return ViewHolder(FolderItemBinding.inflate(inflater, parent, false))
@@ -54,7 +53,7 @@ class FoldersAdapter(val actor: SendChannel<FolderAction>) : PagedListAdapter<Ab
     }
 
     override fun onViewRecycled(holder: ViewHolder) {
-        holder.job?. cancel()
+        holder.job?.cancel()
         holder.job = null
         super.onViewRecycled(holder)
     }



More information about the Android mailing list