[Android] Fix layout issue in video grid when coming back from a group

Nicolas Pomepuy git at videolan.org
Thu Sep 16 04:04:08 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Sep 14 08:41:15 2021 +0200| [fffb3a1d9d17bd19a7634ff73a675c1dc1164b01] | committer: Nicolas Pomepuy

Fix layout issue in video grid when coming back from a group

Fixes #2174

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

 .../src/org/videolan/vlc/gui/video/VideoGridFragment.kt      |  3 +--
 .../src/org/videolan/vlc/gui/video/VideoListAdapter.kt       | 12 ++++++------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
index 940f0aefa..66e5684d4 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
@@ -285,14 +285,13 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
             val margin = binding.videoGrid.paddingStart + binding.videoGrid.paddingEnd
             val columnWidth = binding.videoGrid.getPerfectColumnWidth(thumbnailWidth, margin) - res.getDimensionPixelSize(R.dimen.left_right_1610_margin) * 2
             binding.videoGrid.columnWidth = columnWidth
-            videoListAdapter.setGridCardWidth(binding.videoGrid.columnWidth)
             binding.videoGrid.addItemDecoration(gridItemDecoration!!)
             binding.videoGrid.setPadding(4.dp, 4.dp, 4.dp, 4.dp)
         } else {
             binding.videoGrid.setPadding(0, 0, 0, 0)
         }
         binding.videoGrid.setNumColumns(if (listMode) 1 else -1)
-        if (videoListAdapter.isListMode != listMode) videoListAdapter.isListMode = listMode
+        videoListAdapter.isListMode = listMode
     }
 
     override fun onFabPlayClick(view: View) {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt
index c5d1b6b6f..d22ac31ea 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt
@@ -23,6 +23,7 @@ package org.videolan.vlc.gui.video
 import android.annotation.SuppressLint
 import android.annotation.TargetApi
 import android.os.Build
+import android.util.Log
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
@@ -66,7 +67,6 @@ class VideoListAdapter(private var isSeenMediaMarkerVisible: Boolean
 
     var isListMode = false
     var dataType = VideoGroupingType.NONE
-    private var gridCardWidth = 0
     val showFilename = ObservableBoolean(false)
 
     val multiSelectHelper = MultiSelectHelper(this, UPDATE_SELECTION)
@@ -90,9 +90,13 @@ class VideoListAdapter(private var isSeenMediaMarkerVisible: Boolean
     val all: List<MediaLibraryItem>
         get() = currentList?.snapshot() ?: emptyList()
 
+    override fun getItemViewType(position: Int): Int {
+        return if (isListMode) 0 else 1
+    }
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
         val inflater = LayoutInflater.from(parent.context)
-        val binding = DataBindingUtil.inflate<ViewDataBinding>(inflater, if (isListMode) R.layout.video_list_card else R.layout.video_grid_card, parent, false)
+        val binding = DataBindingUtil.inflate<ViewDataBinding>(inflater, if (viewType == 0) R.layout.video_list_card else R.layout.video_grid_card, parent, false)
+        if (BuildConfig.DEBUG) Log.d(this::class.java.simpleName, "Creating View Holder with list: $isListMode")
         return ViewHolder(binding)
     }
 
@@ -187,10 +191,6 @@ class VideoListAdapter(private var isSeenMediaMarkerVisible: Boolean
     }
 
 
-    fun setGridCardWidth(gridCardWidth: Int) {
-        this.gridCardWidth = gridCardWidth
-    }
-
     override fun getItemId(position: Int) = 0L
 
     @TargetApi(Build.VERSION_CODES.M)



More information about the Android mailing list