mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-11-06 02:40:58 +01:00
Improvements to "Add to playlist" dialog (#1706)
## Description Fixes & improves the "Add to playlist" dialog: - Added searching by name - Playlists are sorted by recently updated - No longer filters by media type - Filters based on user's permission for the playlists The behavior is now consistent with the web UI's list except for the sort ### Related issues Should fix #1124 ### Testing Emulator testing ## Screenshots N/A ## AI or LLM usage None
This commit is contained in:
parent
39c030c1d5
commit
a350fa2017
16 changed files with 211 additions and 76 deletions
|
|
@ -15,13 +15,11 @@ import com.github.damontecres.wholphin.ui.gt
|
|||
import com.github.damontecres.wholphin.ui.indexOfFirstOrNull
|
||||
import com.github.damontecres.wholphin.ui.playback.playable
|
||||
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.TransformList
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import org.jellyfin.sdk.api.client.ApiClient
|
||||
import org.jellyfin.sdk.api.client.exception.InvalidStatusException
|
||||
import org.jellyfin.sdk.api.client.extensions.playlistsApi
|
||||
import org.jellyfin.sdk.api.client.extensions.tvShowsApi
|
||||
import org.jellyfin.sdk.api.client.extensions.videosApi
|
||||
|
|
@ -344,26 +342,49 @@ class PlaylistCreator
|
|||
* Get the playlists on the server for a given media type
|
||||
*/
|
||||
suspend fun getServerPlaylists(
|
||||
query: String,
|
||||
mediaType: MediaType?,
|
||||
scope: CoroutineScope,
|
||||
): List<PlaylistInfo?> {
|
||||
): List<PlaylistInfo> {
|
||||
val userId =
|
||||
serverRepository.currentUser?.id ?: throw IllegalStateException("No user found")
|
||||
val request =
|
||||
GetItemsRequest(
|
||||
searchTerm = query.takeIf { it.isNotBlank() },
|
||||
includeItemTypes = listOf(BaseItemKind.PLAYLIST),
|
||||
mediaTypes = mediaType?.let { listOf(mediaType) },
|
||||
recursive = true,
|
||||
limit = 25,
|
||||
sortBy = listOf(ItemSortBy.DATE_LAST_CONTENT_ADDED),
|
||||
sortOrder = listOf(SortOrder.DESCENDING),
|
||||
)
|
||||
val pager = ApiRequestPager(api, request, GetItemsRequestHandler, scope).init()
|
||||
return TransformList(pager) {
|
||||
it?.let {
|
||||
PlaylistInfo(
|
||||
id = it.id,
|
||||
name = it.name ?: context.getString(R.string.unknown),
|
||||
count = it.data.childCount ?: 0,
|
||||
mediaType = it.data.mediaType,
|
||||
)
|
||||
val playlists = GetItemsRequestHandler.execute(api, request).content.items
|
||||
return playlists
|
||||
.mapNotNull { playlist ->
|
||||
try {
|
||||
val response = api.playlistsApi.getPlaylistUser(playlist.id, userId).content
|
||||
if (response.canEdit) {
|
||||
PlaylistInfo(
|
||||
id = playlist.id,
|
||||
name = playlist.name ?: context.getString(R.string.unknown),
|
||||
count = playlist.childCount ?: 0,
|
||||
mediaType = playlist.mediaType,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} catch (ex: InvalidStatusException) {
|
||||
if (ex.status == 404) {
|
||||
null
|
||||
} else {
|
||||
throw ex
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// .sortedWith(
|
||||
// compareBy<PlaylistInfo> {
|
||||
// SearchRelevance.score(it.name, BaseItemKind.PLAYLIST, query)
|
||||
// }.thenBy { it.name },
|
||||
// )
|
||||
}
|
||||
|
||||
suspend fun createServerPlaylist(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue