Commit 367b428b authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Geoffrey Métais
Browse files

Header for multi disc in Album view

Fixes #1025
parent 421af442
......@@ -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)
......
......@@ -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)
}
}
......
......@@ -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)
......
......@@ -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()
......
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