mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Fix jumping to a letter for many grids (#687)
## Description On any grid that wasn't showing movies, tv shows, or videos, the jump to letter functionality did not work correctly. This PR fixes jumping for other media types, eg collections or episodes. Additionally, the jump now also takes filters into account, so if filtering Movies, it will jump to the right place now within the available movies. ### Related issues Fixes #683
This commit is contained in:
parent
80670c3e0f
commit
5cb3662995
1 changed files with 73 additions and 61 deletions
|
|
@ -304,50 +304,14 @@ class CollectionFolderViewModel
|
|||
recursive: Boolean,
|
||||
filter: GetItemsFilter,
|
||||
useSeriesForPrimary: Boolean,
|
||||
): ApiRequestPager<out Any> {
|
||||
val item = item.value
|
||||
return when (filter.override) {
|
||||
): ApiRequestPager<out Any> =
|
||||
when (filter.override) {
|
||||
GetItemsFilterOverride.NONE -> {
|
||||
val includeItemTypes =
|
||||
item
|
||||
?.data
|
||||
?.collectionType
|
||||
?.baseItemKinds
|
||||
.orEmpty()
|
||||
val request =
|
||||
filter.applyTo(
|
||||
GetItemsRequest(
|
||||
parentId = item?.id,
|
||||
enableImageTypes = listOf(ImageType.PRIMARY, ImageType.THUMB),
|
||||
includeItemTypes = includeItemTypes,
|
||||
recursive = recursive,
|
||||
excludeItemIds = item?.let { listOf(item.id) },
|
||||
sortBy =
|
||||
buildList {
|
||||
if (sortAndDirection.sort != ItemSortBy.DEFAULT) {
|
||||
add(sortAndDirection.sort)
|
||||
if (sortAndDirection.sort != ItemSortBy.SORT_NAME) {
|
||||
add(ItemSortBy.SORT_NAME)
|
||||
}
|
||||
if (item?.data?.collectionType == CollectionType.MOVIES) {
|
||||
add(ItemSortBy.PRODUCTION_YEAR)
|
||||
}
|
||||
}
|
||||
},
|
||||
sortOrder =
|
||||
buildList {
|
||||
if (sortAndDirection.sort != ItemSortBy.DEFAULT) {
|
||||
add(sortAndDirection.direction)
|
||||
if (sortAndDirection.sort != ItemSortBy.SORT_NAME) {
|
||||
add(SortOrder.ASCENDING)
|
||||
}
|
||||
if (item?.data?.collectionType == CollectionType.MOVIES) {
|
||||
add(SortOrder.ASCENDING)
|
||||
}
|
||||
}
|
||||
},
|
||||
fields = SlimItemFields,
|
||||
),
|
||||
createGetItemsRequest(
|
||||
sortAndDirection = sortAndDirection,
|
||||
recursive = recursive,
|
||||
filter = filter,
|
||||
)
|
||||
val newPager =
|
||||
ApiRequestPager(
|
||||
|
|
@ -378,6 +342,55 @@ class CollectionFolderViewModel
|
|||
newPager
|
||||
}
|
||||
}
|
||||
|
||||
private fun createGetItemsRequest(
|
||||
sortAndDirection: SortAndDirection,
|
||||
recursive: Boolean,
|
||||
filter: GetItemsFilter,
|
||||
): GetItemsRequest {
|
||||
val item = item.value
|
||||
val includeItemTypes =
|
||||
item
|
||||
?.data
|
||||
?.collectionType
|
||||
?.baseItemKinds
|
||||
.orEmpty()
|
||||
val request =
|
||||
filter.applyTo(
|
||||
GetItemsRequest(
|
||||
parentId = item?.id,
|
||||
enableImageTypes = listOf(ImageType.PRIMARY, ImageType.THUMB),
|
||||
includeItemTypes = includeItemTypes,
|
||||
recursive = recursive,
|
||||
excludeItemIds = item?.let { listOf(item.id) },
|
||||
sortBy =
|
||||
buildList {
|
||||
if (sortAndDirection.sort != ItemSortBy.DEFAULT) {
|
||||
add(sortAndDirection.sort)
|
||||
if (sortAndDirection.sort != ItemSortBy.SORT_NAME) {
|
||||
add(ItemSortBy.SORT_NAME)
|
||||
}
|
||||
if (item?.data?.collectionType == CollectionType.MOVIES) {
|
||||
add(ItemSortBy.PRODUCTION_YEAR)
|
||||
}
|
||||
}
|
||||
},
|
||||
sortOrder =
|
||||
buildList {
|
||||
if (sortAndDirection.sort != ItemSortBy.DEFAULT) {
|
||||
add(sortAndDirection.direction)
|
||||
if (sortAndDirection.sort != ItemSortBy.SORT_NAME) {
|
||||
add(SortOrder.ASCENDING)
|
||||
}
|
||||
if (item?.data?.collectionType == CollectionType.MOVIES) {
|
||||
add(SortOrder.ASCENDING)
|
||||
}
|
||||
}
|
||||
},
|
||||
fields = SlimItemFields,
|
||||
),
|
||||
)
|
||||
return request
|
||||
}
|
||||
|
||||
suspend fun getFilterOptionValues(filterOption: ItemFilterBy<*>): List<FilterValueOption> =
|
||||
|
|
@ -457,26 +470,25 @@ class CollectionFolderViewModel
|
|||
|
||||
suspend fun positionOfLetter(letter: Char): Int? =
|
||||
withContext(Dispatchers.IO) {
|
||||
item.value?.let { item ->
|
||||
val includeItemTypes =
|
||||
when (item.data.collectionType) {
|
||||
CollectionType.MOVIES -> listOf(BaseItemKind.MOVIE)
|
||||
CollectionType.TVSHOWS -> listOf(BaseItemKind.SERIES)
|
||||
CollectionType.HOMEVIDEOS -> listOf(BaseItemKind.VIDEO)
|
||||
else -> listOf()
|
||||
}
|
||||
val request =
|
||||
GetItemsRequest(
|
||||
parentId = item.id,
|
||||
includeItemTypes = includeItemTypes,
|
||||
nameLessThan = letter.toString(),
|
||||
limit = 0,
|
||||
enableTotalRecordCount = true,
|
||||
recursive = true,
|
||||
)
|
||||
val result by GetItemsRequestHandler.execute(api, request)
|
||||
result.totalRecordCount
|
||||
val sort = sortAndDirection.value
|
||||
val filter = filter.value
|
||||
if (sort == null || filter == null) {
|
||||
return@withContext null
|
||||
}
|
||||
val request =
|
||||
createGetItemsRequest(
|
||||
sortAndDirection = sort,
|
||||
recursive = recursive,
|
||||
filter = filter,
|
||||
).copy(
|
||||
enableImageTypes = null,
|
||||
fields = null,
|
||||
nameLessThan = letter.toString(),
|
||||
limit = 0,
|
||||
enableTotalRecordCount = true,
|
||||
)
|
||||
val result by GetItemsRequestHandler.execute(api, request)
|
||||
result.totalRecordCount
|
||||
}
|
||||
|
||||
fun setWatched(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue