Add ability to sort and filter items in a playlist (#818)

## Description
Add ability to sort and filter items in a playlist. There's a new button
for each added to the playlist details page. Starting playback will run
in the order selected.

The sort and filter are persisted locally per playlist, so returning to
the playlist will remember the previous settings.

Note: playlist playback is still limited to 100 items (#42)

### Related issues
Closes #285

### Testing
Emulator & nvidia shield

## Screenshots
![playlist_sort_filter
Large](https://github.com/user-attachments/assets/9880021b-a1c3-4d8d-ace2-83737f3f772a)

## AI or LLM usage
None
This commit is contained in:
Ray 2026-02-03 15:11:37 -05:00 committed by GitHub
parent ae5035703f
commit 045b689994
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 497 additions and 246 deletions

View file

@ -17,7 +17,6 @@ import com.github.damontecres.wholphin.ui.toServerString
import com.github.damontecres.wholphin.util.ApiRequestPager
import com.github.damontecres.wholphin.util.GetEpisodesRequestHandler
import com.github.damontecres.wholphin.util.GetItemsRequestHandler
import com.github.damontecres.wholphin.util.GetPlaylistItemsRequestHandler
import com.github.damontecres.wholphin.util.TransformList
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.CoroutineScope
@ -34,7 +33,6 @@ import org.jellyfin.sdk.model.api.PlaylistUserPermissions
import org.jellyfin.sdk.model.api.SortOrder
import org.jellyfin.sdk.model.api.request.GetEpisodesRequest
import org.jellyfin.sdk.model.api.request.GetItemsRequest
import org.jellyfin.sdk.model.api.request.GetPlaylistItemsRequest
import org.jellyfin.sdk.model.serializer.toUUIDOrNull
import java.util.UUID
import javax.inject.Inject
@ -79,19 +77,22 @@ class PlaylistCreator
suspend fun createFromPlaylistId(
playlistId: UUID,
startIndex: Int?,
shuffled: Boolean,
sortAndDirection: SortAndDirection,
filter: GetItemsFilter,
): Playlist {
val request =
GetPlaylistItemsRequest(
playlistId = playlistId,
fields = DefaultItemFields,
startIndex = startIndex,
limit = Playlist.MAX_SIZE,
filter.applyTo(
GetItemsRequest(
userId = serverRepository.currentUser.value?.id,
parentId = playlistId,
fields = DefaultItemFields,
startIndex = startIndex,
limit = Playlist.MAX_SIZE,
sortBy = listOf(sortAndDirection.sort),
sortOrder = listOf(sortAndDirection.direction),
),
)
var items = GetPlaylistItemsRequestHandler.execute(api, request).content.items
if (shuffled) {
items = items.shuffled()
}
val items = GetItemsRequestHandler.execute(api, request).content.items
return Playlist(items.convertAndAddParts(), 0)
}
@ -206,9 +207,18 @@ class PlaylistCreator
BaseItemKind.PLAYLIST -> {
PlaylistCreationResult.Success(
createFromPlaylistId(
item.id,
startIndex,
shuffled,
playlistId = item.id,
startIndex = startIndex,
sortAndDirection =
if (shuffled) {
SortAndDirection(ItemSortBy.RANDOM, SortOrder.ASCENDING)
} else {
sortAndDirection ?: SortAndDirection(
ItemSortBy.DEFAULT,
SortOrder.ASCENDING,
)
},
filter = filter,
),
)
}