[Android] Fix the audio cards spacings
Nicolas Pomepuy
git at videolan.org
Tue Jan 18 12:23:24 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Nov 22 10:15:23 2021 +0100| [1610f32725643022b19c92d98654adad26dbfa2a] | committer: Nicolas Pomepuy
Fix the audio cards spacings
> https://code.videolan.org/videolan/vlc-android/commit/1610f32725643022b19c92d98654adad26dbfa2a
---
.../org/videolan/television/ui/browser/BaseBrowserTvFragment.kt | 4 ++--
application/vlc-android/res/layout/recycler_section_header.xml | 2 +-
.../vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt | 5 +++--
.../src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt | 3 ++-
.../src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt | 3 ++-
.../videolan/vlc/gui/view/RecyclerSectionItemGridDecoration.kt | 8 ++++----
6 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/application/television/src/main/java/org/videolan/television/ui/browser/BaseBrowserTvFragment.kt b/application/television/src/main/java/org/videolan/television/ui/browser/BaseBrowserTvFragment.kt
index 3d4d9035d..49d598596 100644
--- a/application/television/src/main/java/org/videolan/television/ui/browser/BaseBrowserTvFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/browser/BaseBrowserTvFragment.kt
@@ -158,14 +158,14 @@ abstract class BaseBrowserTvFragment<T> : Fragment(), BrowserFragmentInterface,
binding.imageButtonDisplay.setOnClickListener(displayClick)
spacing = resources.getDimensionPixelSize(R.dimen.kl_small)
- recyclerSectionItemGridDecoration = RecyclerSectionItemGridDecoration(resources.getDimensionPixelSize(R.dimen.recycler_section_header_tv_height), spacing, true, viewModel.nbColumns, viewModel.provider)
+ recyclerSectionItemGridDecoration = RecyclerSectionItemGridDecoration(resources.getDimensionPixelSize(R.dimen.recycler_section_header_tv_height), spacing, spacing, true, viewModel.nbColumns, viewModel.provider)
inGrid = Settings.getInstance(requireActivity()).getBoolean(getDisplayPrefId(), true)
setupDisplayIcon()
setupLayoutManager()
//size of an item
- val itemSize = RecyclerSectionItemGridDecoration.getItemSize(requireActivity().getScreenWidth() - binding.list.paddingLeft - binding.list.paddingRight, viewModel.nbColumns, spacing)
+ val itemSize = RecyclerSectionItemGridDecoration.getItemSize(requireActivity().getScreenWidth() - binding.list.paddingLeft - binding.list.paddingRight, viewModel.nbColumns, spacing, spacing)
adapter = provideAdapter(this, itemSize)
adapter.displaySwitch(inGrid)
diff --git a/application/vlc-android/res/layout/recycler_section_header.xml b/application/vlc-android/res/layout/recycler_section_header.xml
index 79a150672..28c70c8a1 100644
--- a/application/vlc-android/res/layout/recycler_section_header.xml
+++ b/application/vlc-android/res/layout/recycler_section_header.xml
@@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="@dimen/recycler_section_header_height"
android:background="?attr/header_background"
- android:paddingStart="16dp"
+ android:paddingStart="20dp"
android:paddingEnd="28dp"
android:singleLine="true"
android:gravity="center_vertical"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
index 74dc79166..247fd6671 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
@@ -43,6 +43,7 @@ import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.resources.AppContextProvider
import org.videolan.resources.CTX_PLAY_ALL
import org.videolan.tools.Settings
+import org.videolan.tools.dp
import org.videolan.tools.putSingle
import org.videolan.vlc.R
import org.videolan.vlc.databinding.PlaylistsFragmentBinding
@@ -95,7 +96,7 @@ class PlaylistFragment : BaseAudioBrowser<PlaylistsViewModel>(), SwipeRefreshLay
val dimension = resources.getDimension(R.dimen.default_content_width)
val totalWidth = if (dimension > 0) min(requireActivity().getScreenWidth(), dimension.toInt()) else requireActivity().getScreenWidth()
- val itemSize = RecyclerSectionItemGridDecoration.getItemSize(totalWidth - spacing * 2, nbColumns, spacing)
+ val itemSize = RecyclerSectionItemGridDecoration.getItemSize(totalWidth - spacing * 2, nbColumns, spacing, 16.dp)
playlistAdapter = AudioBrowserAdapter(MediaLibraryItem.TYPE_PLAYLIST, this, cardSize = itemSize)
playlistAdapter.onAnyChange { updateEmptyView() }
@@ -168,7 +169,7 @@ class PlaylistFragment : BaseAudioBrowser<PlaylistsViewModel>(), SwipeRefreshLay
when (viewModel.providerInCard) {
true -> {
val screenWidth = (requireActivity() as? INavigator)?.getFragmentWidth(requireActivity()) ?: requireActivity().getScreenWidth()
- adapter?.cardSize = RecyclerSectionItemGridDecoration.getItemSize(screenWidth, nbColumns, spacing)
+ adapter?.cardSize = RecyclerSectionItemGridDecoration.getItemSize(screenWidth, nbColumns, spacing, 16.dp)
adapter?.let { adapter -> displayListInGrid(playlists, adapter, viewModel.provider as MedialibraryProvider<MediaLibraryItem>, spacing) }
}
else -> {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt
index e65e5b49d..ec75d7da7 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt
@@ -38,6 +38,7 @@ import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.resources.CTX_PLAY_ALL
import org.videolan.tools.Settings
+import org.videolan.tools.dp
import org.videolan.tools.putSingle
import org.videolan.vlc.R
import org.videolan.vlc.gui.ContentActivity
@@ -96,7 +97,7 @@ class AudioAlbumsSongsFragment : BaseAudioBrowser<AlbumSongsViewModel>(), SwipeR
super.onViewCreated(view, savedInstanceState)
spacing = resources.getDimension(R.dimen.kl_small).toInt()
- val itemSize = RecyclerSectionItemGridDecoration.getItemSize(requireActivity().getScreenWidth(), nbColumns, spacing)
+ val itemSize = RecyclerSectionItemGridDecoration.getItemSize(requireActivity().getScreenWidth(), nbColumns, spacing, 16.dp)
val albumsList = viewPager.getChildAt(MODE_ALBUM).findViewById(R.id.audio_list) as RecyclerView
val songsList = viewPager.getChildAt(MODE_SONG).findViewById(R.id.audio_list) as RecyclerView
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
index 3aa78a59f..39ab4694c 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
@@ -138,6 +138,7 @@ abstract class BaseAudioBrowser<T : MedialibraryViewModel> : MediaBrowserFragmen
RecyclerSectionItemGridDecoration(
resources.getDimensionPixelSize(R.dimen.recycler_section_header_height),
spacing,
+ 16.dp,
true,
nbColumns,
provider
@@ -175,7 +176,7 @@ abstract class BaseAudioBrowser<T : MedialibraryViewModel> : MediaBrowserFragmen
when (providerInCard) {
true -> {
val screenWidth = (requireActivity() as? INavigator)?.getFragmentWidth(requireActivity()) ?: requireActivity().getScreenWidth()
- val itemSize = RecyclerSectionItemGridDecoration.getItemSize(screenWidth, nbColumns, spacing)
+ val itemSize = RecyclerSectionItemGridDecoration.getItemSize(screenWidth, nbColumns, spacing, 16.dp)
adapter.cardSize = itemSize
displayListInGrid(list, adapter, provider, spacing)
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/view/RecyclerSectionItemGridDecoration.kt b/application/vlc-android/src/org/videolan/vlc/gui/view/RecyclerSectionItemGridDecoration.kt
index a7449ee98..4e07630da 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/view/RecyclerSectionItemGridDecoration.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/view/RecyclerSectionItemGridDecoration.kt
@@ -15,7 +15,7 @@ import org.videolan.vlc.R
private const val TAG = "RecyclerSectionItemDecoration"
@SuppressLint("LongLogTag")
-class RecyclerSectionItemGridDecoration(private val headerOffset: Int, private val space: Int, private val sticky: Boolean, private val nbColumns: Int, private val provider: HeaderProvider) : RecyclerView.ItemDecoration() {
+class RecyclerSectionItemGridDecoration(private val headerOffset: Int, private val space: Int, private val sideSpace: Int, private val sticky: Boolean, private val nbColumns: Int, private val provider: HeaderProvider) : RecyclerView.ItemDecoration() {
private lateinit var headerView: View
private lateinit var header: TextView
@@ -42,8 +42,8 @@ class RecyclerSectionItemGridDecoration(private val headerOffset: Int, private v
val isLastInLine = (pos - positionForSection) % nbColumns == nbColumns - 1
- outRect.left = if (isFirstInLine && Settings.showHeaders) space else space / 2
- outRect.right = if (isLastInLine && Settings.showHeaders) space else space / 2
+ outRect.left = if (isFirstInLine && Settings.showHeaders) sideSpace else space / 2
+ outRect.right = if (isLastInLine && Settings.showHeaders) sideSpace else space / 2
outRect.top = space / 2
outRect.bottom = space / 2
@@ -138,6 +138,6 @@ class RecyclerSectionItemGridDecoration(private val headerOffset: Int, private v
}
companion object {
- fun getItemSize(screenWidth: Int, nbColumns: Int, spacing: Int) = ((screenWidth - (spacing * (nbColumns + 1))).toFloat() / nbColumns).toInt()
+ fun getItemSize(screenWidth: Int, nbColumns: Int, spacing: Int, sideSpacing:Int) = ((screenWidth - (spacing * (nbColumns - 1)) - 2 * sideSpacing).toFloat() / nbColumns).toInt()
}
}
More information about the Android
mailing list