[Android] Header for multi disc in Album view
Nicolas Pomepuy
git at videolan.org
Mon Sep 23 16:03:41 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Mon Sep 23 10:04:22 2019 +0200| [367b428bab3a2e8203679b1cf83ea40022b3d09d] | committer: Geoffrey Métais
Header for multi disc in Album view
Fixes #1025
> https://code.videolan.org/videolan/vlc-android/commit/367b428bab3a2e8203679b1cf83ea40022b3d09d
---
vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt | 3 +++
.../vlc/providers/medialibrary/MedialibraryProvider.kt | 3 ++-
.../videolan/vlc/providers/medialibrary/TracksProvider.kt | 5 +++++
vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt | 14 ++++++++++++--
4 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
index dc12d213c..4ab50356d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
@@ -66,6 +66,7 @@ import org.videolan.vlc.gui.helpers.SwipeDragItemTouchHelperCallback
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.helpers.UiTools.snackerConfirm
import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.getWritePermission
+import org.videolan.vlc.gui.view.RecyclerSectionItemDecoration
import org.videolan.vlc.interfaces.IEventsHandler
import org.videolan.vlc.interfaces.IListEventsHandler
import org.videolan.vlc.media.MediaUtils
@@ -122,6 +123,8 @@ open class PlaylistActivity : AudioPlayerContainerActivity(), IEventsHandler, IL
if (isPlaylist) {
itemTouchHelper = ItemTouchHelper(SwipeDragItemTouchHelperCallback(audioBrowserAdapter))
itemTouchHelper!!.attachToRecyclerView(binding.songs)
+ } else {
+ binding.songs.addItemDecoration(RecyclerSectionItemDecoration(resources.getDimensionPixelSize(R.dimen.recycler_section_header_height), true, viewModel.tracksProvider))
}
binding.songs.layoutManager = LinearLayoutManager(this)
diff --git a/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt b/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt
index 3cca1729b..ac265255a 100644
--- a/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/medialibrary/MedialibraryProvider.kt
@@ -65,6 +65,7 @@ abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context,
abstract fun getTotalCount(): Int
abstract fun getPage(loadSize: Int, startposition: Int): Array<T>
abstract fun getAll(): Array<T>
+ open fun isByDisc(): Boolean = false
override fun sort(sort: Int) {
if (canSortBy(sort)) {
@@ -101,7 +102,7 @@ abstract class MedialibraryProvider<T : MediaLibraryItem>(val context: Context,
startposition > 0 -> pagedList.value?.getOrNull(startposition + position - 1)
else -> null
}
- ModelsHelper.getHeader(context, sort, item, previous)?.let {
+ ModelsHelper.getHeader(context, sort, item, previous, isByDisc())?.let {
privateHeaders.put(startposition + position, it)
}
}
diff --git a/vlc-android/src/org/videolan/vlc/providers/medialibrary/TracksProvider.kt b/vlc-android/src/org/videolan/vlc/providers/medialibrary/TracksProvider.kt
index 7479edbd5..41e5a15e7 100644
--- a/vlc-android/src/org/videolan/vlc/providers/medialibrary/TracksProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/medialibrary/TracksProvider.kt
@@ -24,6 +24,7 @@ import android.content.Context
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.videolan.medialibrary.interfaces.AbstractMedialibrary
import org.videolan.medialibrary.interfaces.media.*
+import org.videolan.medialibrary.media.Album
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.util.Settings
import org.videolan.vlc.viewmodels.SortableModel
@@ -37,6 +38,10 @@ class TracksProvider(val parent : MediaLibraryItem?, context: Context, scope: So
override fun canSortByAlbum() = parent !== null
override fun canSortByLastModified() = true
+ override fun isByDisc(): Boolean {
+ return parent is Album
+ }
+
init {
sort = Settings.getInstance(context).getInt(sortKey, AbstractMedialibrary.SORT_DEFAULT)
desc = Settings.getInstance(context).getBoolean("${sortKey}_desc", parent is AbstractArtist)
diff --git a/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt b/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
index 98239f470..68dada04c 100644
--- a/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
+++ b/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
@@ -12,6 +12,7 @@ import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.medialibrary.interfaces.media.AbstractPlaylist
import org.videolan.medialibrary.media.DummyItem
import org.videolan.medialibrary.media.MediaLibraryItem
+import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.PlaybackService
import org.videolan.vlc.R
import kotlin.math.floor
@@ -109,7 +110,16 @@ object ModelsHelper {
return if (title.isEmpty() || !Character.isLetter(title[0]) || isSpecialItem()) "#" else title.substring(0, 1).toUpperCase()
}
- fun getHeader(context: Context?, sort: Int, item: MediaLibraryItem?, aboveItem: MediaLibraryItem?) = if (context !== null && item != null) when (sort) {
+ private fun MediaLibraryItem.getDiscNumber(): String? = if (this is MediaWrapper && this.discNumber != 0) "Disc ${this.discNumber}" else null
+
+ fun getHeader(context: Context?, sort: Int, item: MediaLibraryItem?, aboveItem: MediaLibraryItem?, forceByDiscs: Boolean = false) = if (context !== null && item != null) if (forceByDiscs) {
+ val disc = item.getDiscNumber()
+ if (aboveItem == null) disc
+ else {
+ val previousDisc = aboveItem.getDiscNumber()
+ disc.takeIf { it != previousDisc }
+ }
+ } else when (sort) {
SORT_DEFAULT,
SORT_FILENAME,
SORT_ALPHA -> {
@@ -122,7 +132,7 @@ object ModelsHelper {
}
SORT_DURATION -> {
val length = item.getLength()
- val lengthCategory = length.toLong().lengthToCategory()
+ val lengthCategory = length.lengthToCategory()
if (aboveItem == null) lengthCategory
else {
val previous = aboveItem.getLength().lengthToCategory()
More information about the Android
mailing list