[Android] Fix grid item size calculation
Nicolas Pomepuy
git at videolan.org
Tue Jul 2 14:13:38 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Tue Jul 2 12:59:02 2019 +0200| [436dce3ecfd3847aae7552700451c39a12618628] | committer: Nicolas Pomepuy
Fix grid item size calculation
> https://code.videolan.org/videolan/vlc-android/commit/436dce3ecfd3847aae7552700451c39a12618628
---
vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt | 2 +-
.../org/videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt | 6 +-----
.../vlc/gui/view/RecyclerSectionItemGridDecoration.kt | 11 ++++-------
3 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt b/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
index 566deaea5..3b7d1ff03 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<PlaylistsViewModel>(), SwipeRefreshLay
//size of an item
val spacing = resources.getDimension(R.dimen.kl_half).toInt()
- val itemSize = RecyclerSectionItemGridDecoration.getItemSize(requireActivity().getScreenWidth(), nbColumns, spacing)
+ val itemSize = RecyclerSectionItemGridDecoration.getItemSize(requireActivity().getScreenWidth() - spacing * 2, nbColumns, spacing)
playlistAdapter = AudioBrowserAdapter(MediaLibraryItem.TYPE_PLAYLIST, this, itemSize)
adapter = playlistAdapter
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 d2dcbce0f..7cbec95d8 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
@@ -138,7 +138,7 @@ abstract class BaseBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEv
spacing = resources.getDimensionPixelSize(R.dimen.kl_half)
//size of an item
- val itemSize = RecyclerSectionItemGridDecoration.getItemSize(requireActivity().getScreenWidth(), viewModel.nbColumns, spacing)
+ val itemSize = RecyclerSectionItemGridDecoration.getItemSize(requireActivity().getScreenWidth() - list.paddingLeft - list.paddingRight, viewModel.nbColumns, spacing)
gridLayoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
@@ -192,7 +192,6 @@ abstract class BaseBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEv
viewModel.nbColumns = getColumnNumber()
}
-
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
@@ -219,14 +218,12 @@ abstract class BaseBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEv
return true
}
-
override fun onCtxClick(v: View, position: Int, item: MediaLibraryItem) {}
override fun onUpdateFinished(adapter: RecyclerView.Adapter<*>) {}
override fun onImageClick(v: View, position: Int, item: MediaLibraryItem) {}
-
override fun onItemFocused(v: View, item: MediaLibraryItem) {
(item as? MediaLibraryItem)?.run {
if (currentArt == artworkMrl) return at run
@@ -350,7 +347,6 @@ abstract class BaseBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEv
animationDelegate.setVisibility(imageButtonHeader, if (viewModel.provider.headers.isEmpty) View.GONE else View.VISIBLE)
animationDelegate.setVisibility(headerButton, if (viewModel.provider.headers.isEmpty) View.GONE else View.VISIBLE)
animationDelegate.setVisibility(headerDescription, if (viewModel.provider.headers.isEmpty) View.GONE else View.VISIBLE)
-
}
}
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 e833d841c..13b769cb4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/view/RecyclerSectionItemGridDecoration.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/view/RecyclerSectionItemGridDecoration.kt
@@ -26,18 +26,15 @@ 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
- if (BuildConfig.DEBUG) Log.d(TAG, "Item $pos first: $isFirstInLine last: $isLastInLine")
- outRect.left = if (isFirstInLine) space * 2 else space
- outRect.right = if (isLastInLine) space * 2 else space
+ outRect.left = space
+ outRect.right = space
outRect.top = space
outRect.bottom = space
for (i in 0 until nbColumns) {
if ((pos - i) >= 0 && provider.isFirstInSection(pos - i)) {
- if (BuildConfig.DEBUG) Log.d(TAG, "Adding offset for $pos");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Adding offset for $pos")
outRect.top = headerOffset + space
}
}
@@ -128,6 +125,6 @@ class RecyclerSectionItemGridDecoration(private val headerOffset: Int, private v
}
companion object {
- fun getItemSize(screenWidth: Int, nbColumns: Int, spacing: Int) = ((screenWidth - spacing * 2) / nbColumns) - (spacing * nbColumns)
+ fun getItemSize(screenWidth: Int, nbColumns: Int, spacing: Int) = (screenWidth - (spacing * nbColumns)) / nbColumns
}
}
More information about the Android
mailing list