[Android] Fix cards spacing

Nicolas Pomepuy git at videolan.org
Fri Jul 5 12:24:20 CEST 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Fri Jul  5 09:13:32 2019 +0200| [95bc7328dc71d17208ff67b6273ac08d3d44497a] | committer: Geoffrey Métais

Fix cards spacing

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

 .../src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt |  2 +-
 .../videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt   |  2 +-
 .../vlc/gui/view/RecyclerSectionItemGridDecoration.kt      | 14 +++++++++-----
 3 files changed, 11 insertions(+), 7 deletions(-)

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 2dc2280fe..d0d5643c5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
@@ -88,7 +88,7 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>(), SwipeRef
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
-        spacing = requireActivity().resources.getDimension(R.dimen.kl_half).toInt()
+        spacing = requireActivity().resources.getDimension(R.dimen.kl_small).toInt()
 
 
         if (!::settings.isInitialized) settings = Settings.getInstance(requireContext())
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt
index 5936856db..a762edde8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt
@@ -135,7 +135,7 @@ abstract class BaseBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEv
             override fun requestChildRectangleOnScreen(parent: RecyclerView, child: View, rect: Rect, immediate: Boolean, focusedChildVisible: Boolean) = false
         }
 
-        spacing = resources.getDimensionPixelSize(R.dimen.kl_half)
+        spacing = resources.getDimensionPixelSize(R.dimen.kl_small)
 
         //size of an item
         val itemSize = RecyclerSectionItemGridDecoration.getItemSize(requireActivity().getScreenWidth() - list.paddingLeft - list.paddingRight, viewModel.nbColumns, spacing)
diff --git a/vlc-android/src/org/videolan/vlc/gui/view/RecyclerSectionItemGridDecoration.kt b/vlc-android/src/org/videolan/vlc/gui/view/RecyclerSectionItemGridDecoration.kt
index 13b769cb4..86cfb3b67 100644
--- a/vlc-android/src/org/videolan/vlc/gui/view/RecyclerSectionItemGridDecoration.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/view/RecyclerSectionItemGridDecoration.kt
@@ -12,6 +12,7 @@ import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.R
 import org.videolan.vlc.providers.HeaderProvider
 import org.videolan.vlc.util.Settings
+import kotlin.math.floor
 
 private const val TAG = "RecyclerSectionItemDecoration"
 
@@ -26,11 +27,14 @@ class RecyclerSectionItemGridDecoration(private val headerOffset: Int, private v
 
         val pos = parent.getChildAdapterPosition(view)
         val positionForSection = provider.getPositionForSection(pos)
+        val isFirstInLine = positionForSection == pos || (pos - positionForSection) % nbColumns == 0
+        val isLastInLine = (pos - positionForSection) % nbColumns == nbColumns - 1
 
-        outRect.left = space
-        outRect.right = space
-        outRect.top = space
-        outRect.bottom = space
+
+        outRect.left = if (isFirstInLine) space else space / 2
+        outRect.right = if (isLastInLine) space else space / 2
+        outRect.top = space / 2
+        outRect.bottom = space / 2
 
         for (i in 0 until nbColumns) {
             if ((pos - i) >= 0 && provider.isFirstInSection(pos - i)) {
@@ -125,6 +129,6 @@ class RecyclerSectionItemGridDecoration(private val headerOffset: Int, private v
     }
 
     companion object {
-        fun getItemSize(screenWidth: Int, nbColumns: Int, spacing: Int) = (screenWidth - (spacing * nbColumns)) / nbColumns
+        fun getItemSize(screenWidth: Int, nbColumns: Int, spacing: Int) = ((screenWidth - (spacing * (nbColumns + 1))).toFloat() / nbColumns).toInt()
     }
 }



More information about the Android mailing list