mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-08-05 02:50:44 +00:00
feat(library): add Rating and Release Date sorting options
This commit is contained in:
parent
cfa49a2cda
commit
6d54ff1698
2 changed files with 36 additions and 0 deletions
|
|
@ -20,6 +20,10 @@ enum class LibrarySortOption {
|
|||
ADDED_ASC,
|
||||
TITLE_ASC,
|
||||
TITLE_DESC,
|
||||
RATING_DESC,
|
||||
RATING_ASC,
|
||||
RELEASE_DATE_DESC,
|
||||
RELEASE_DATE_ASC,
|
||||
}
|
||||
|
||||
data class LibraryDisplaySettingsUiState(
|
||||
|
|
@ -131,6 +135,26 @@ internal fun sortLibraryItems(
|
|||
compareByDescending<LibraryItem> { libraryTitleSortKey(it) }
|
||||
.thenBy { it.id },
|
||||
)
|
||||
LibrarySortOption.RATING_DESC -> items.sortedWith(
|
||||
compareByDescending<LibraryItem> { it.imdbRating?.toFloatOrNull() ?: 0f }
|
||||
.thenBy { libraryTitleTieBreakKey(it) }
|
||||
.thenBy { it.id },
|
||||
)
|
||||
LibrarySortOption.RATING_ASC -> items.sortedWith(
|
||||
compareBy<LibraryItem> { it.imdbRating?.toFloatOrNull() ?: Float.MAX_VALUE }
|
||||
.thenBy { libraryTitleTieBreakKey(it) }
|
||||
.thenBy { it.id },
|
||||
)
|
||||
LibrarySortOption.RELEASE_DATE_DESC -> items.sortedWith(
|
||||
compareByDescending<LibraryItem> { releaseDateSortKey(it) }
|
||||
.thenBy { libraryTitleTieBreakKey(it) }
|
||||
.thenBy { it.id },
|
||||
)
|
||||
LibrarySortOption.RELEASE_DATE_ASC -> items.sortedWith(
|
||||
compareBy<LibraryItem> { releaseDateSortKey(it) }
|
||||
.thenBy { libraryTitleTieBreakKey(it) }
|
||||
.thenBy { it.id },
|
||||
)
|
||||
}
|
||||
|
||||
internal fun sortLibrarySections(
|
||||
|
|
@ -235,6 +259,14 @@ private fun libraryTitleTieBreakKey(item: LibraryItem): String =
|
|||
.ifBlank { item.id }
|
||||
.lowercase()
|
||||
|
||||
private val IsoDateRegex = Regex("\\b\\d{4}(-\\d{2})?(-\\d{2})?\\b")
|
||||
|
||||
private fun releaseDateSortKey(item: LibraryItem): String {
|
||||
val info = item.releaseInfo.orEmpty().trim()
|
||||
if (info.isBlank()) return ""
|
||||
return IsoDateRegex.find(info)?.value ?: info.lowercase()
|
||||
}
|
||||
|
||||
private fun libraryDisplayItemKey(item: LibraryItem): String =
|
||||
"${item.type.normalizedLibraryType()}:${item.id.trim()}"
|
||||
|
||||
|
|
|
|||
|
|
@ -163,6 +163,10 @@ private fun librarySortOptionLabel(option: LibrarySortOption): String =
|
|||
LibrarySortOption.ADDED_ASC -> stringResource(Res.string.library_sort_added_asc)
|
||||
LibrarySortOption.TITLE_ASC -> stringResource(Res.string.library_sort_title_asc)
|
||||
LibrarySortOption.TITLE_DESC -> stringResource(Res.string.library_sort_title_desc)
|
||||
LibrarySortOption.RATING_DESC -> "Rating (Highest)"
|
||||
LibrarySortOption.RATING_ASC -> "Rating (Lowest)"
|
||||
LibrarySortOption.RELEASE_DATE_DESC -> "Release Date (Newest)"
|
||||
LibrarySortOption.RELEASE_DATE_ASC -> "Release Date (Oldest)"
|
||||
}
|
||||
|
||||
private fun List<LibraryVerticalEntry>.findEntry(preview: MetaPreview): LibraryVerticalEntry? =
|
||||
|
|
|
|||
Loading…
Reference in a new issue