mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 16:11:20 +02:00
Show button for trailers instead of card row (#618)
## Description On both movie & series detail pages, show a button to play trailers instead of the row of cards below. The button works like this: - If no trailers, the button shows "No trailers" and is disabled/non-clickable - If only a single trailer, the button shows "Play trailer" and clicking it plays the trailer - Otherwise, shows "Trailers" and clicking displays a dialog to choose one Local trailers are shown first in the list. Then there is an attempt to sort the trailers for the dialog so that names with "Official Trailer" or "Official Theatrical Trailer" are listed first and "Teaser" is listed last. This isn't perfect and doesn't work for non-English, but there's no other metadata to use. ### Related issues Closes #408
This commit is contained in:
parent
b8e8a1d913
commit
0fe8e5d988
12 changed files with 218 additions and 170 deletions
|
|
@ -22,31 +22,53 @@ class TrailerService
|
|||
@param:ApplicationContext private val context: Context,
|
||||
private val api: ApiClient,
|
||||
) {
|
||||
suspend fun getTrailers(item: BaseItem): List<Trailer> {
|
||||
val remoteTrailers =
|
||||
item.data.remoteTrailers
|
||||
?.mapNotNull { t ->
|
||||
t.url?.let { url ->
|
||||
val name =
|
||||
t.name
|
||||
// TODO would be nice to clean up the trailer name
|
||||
fun getRemoteTrailers(item: BaseItem): List<Trailer> =
|
||||
item.data.remoteTrailers
|
||||
?.mapNotNull { t ->
|
||||
t.url?.let { url ->
|
||||
val name =
|
||||
t.name
|
||||
// TODO would be nice to clean up the trailer name
|
||||
// ?.replace(item.name ?: "", "")
|
||||
// ?.removePrefix(" - ")
|
||||
?: context.getString(R.string.trailer)
|
||||
RemoteTrailer(name, url)
|
||||
}
|
||||
}.orEmpty()
|
||||
.sortedBy { it.name }
|
||||
val localTrailerCount = item.data.localTrailerCount ?: 0
|
||||
?: context.getString(R.string.trailer)
|
||||
val subtitle =
|
||||
when (url.toUri().host) {
|
||||
"youtube.com", "www.youtube.com" -> "YouTube"
|
||||
else -> null
|
||||
}
|
||||
RemoteTrailer(name, url, subtitle)
|
||||
}
|
||||
}.orEmpty()
|
||||
.sortedWith(
|
||||
compareBy(
|
||||
{
|
||||
// Try to show official trailers first & teasers last
|
||||
when {
|
||||
it.name.contains("Official Trailer", true) -> 0
|
||||
it.name.contains("Official Theatrical Trailer", true) -> 0
|
||||
it.name.contains("Teaser", true) -> 10
|
||||
it.name.contains("Trailer", true) -> 1
|
||||
else -> 5
|
||||
}
|
||||
},
|
||||
{
|
||||
it.name
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
suspend fun getLocalTrailers(item: BaseItem): List<Trailer> {
|
||||
val localTrailerCount = item.data.localTrailerCount ?: return emptyList()
|
||||
val localTrailers =
|
||||
if (localTrailerCount > 0) {
|
||||
api.userLibraryApi.getLocalTrailers(item.id).content.map {
|
||||
LocalTrailer(BaseItem.Companion.from(it, api))
|
||||
LocalTrailer(BaseItem.from(it, api))
|
||||
}
|
||||
} else {
|
||||
listOf()
|
||||
}
|
||||
return localTrailers + remoteTrailers
|
||||
return localTrailers
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue