Commit 436dce3e authored by Nicolas Pomepuy's avatar Nicolas Pomepuy
Browse files

Fix grid item size calculation

parent f3263566
......@@ -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
......
......@@ -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@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)
}
}
......
......@@ -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
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment