Release Kaleido 0.1.9 with responsive navigation and clearer show details
All checks were successful
Validate and publish Kaleido / android (push) Successful in 2m25s
All checks were successful
Validate and publish Kaleido / android (push) Successful in 2m25s
This commit is contained in:
parent
5199bb0928
commit
784921dba9
20 changed files with 271 additions and 49 deletions
|
|
@ -11,6 +11,26 @@ import kotlinx.coroutines.runBlocking
|
|||
class BrowsePolicyTest {
|
||||
private fun title(id:String,type:String="movie")=Title.parse(JSONObject("""{"ratingKey":"$id","type":"$type","art":"/art/$id","title":"Title $id","originallyAvailableAt":"2026-10-01"}"""))
|
||||
|
||||
@Test fun recentSeasonsGroupByPlexShowIdentityAndPreserveRecency()=runBlocking {
|
||||
val latest=title("s3","season").copy(parentId="show-a",parentTitle="Same name",title="Season 3")
|
||||
val single=title("s1","season").copy(parentId="show-b",parentTitle="Same name",title="Season 1")
|
||||
val older=title("s2","season").copy(parentId="show-a",parentTitle="Same name",title="Season 2")
|
||||
val show=title("show-a","show");val loaded=mutableListOf<String>()
|
||||
val result=groupRecentSeasons(listOf(latest,single,older,latest)){id->loaded+=id;show}
|
||||
assertEquals(listOf("show-a","s1"),result.map{it.id})
|
||||
assertEquals(show,result.first()) // Real show metadata, artwork, counts and navigation.
|
||||
assertEquals("Same name · Season 1",result.last().title)
|
||||
assertEquals(listOf("show-a"),loaded)
|
||||
}
|
||||
@Test fun recentSeasonsKeepUnknownParentsSeparateAndLimitAfterGrouping()=runBlocking {
|
||||
val unknown=listOf(title("unknown1","season"),title("unknown2","season"))
|
||||
val seasons=(1..24).map{title("s$it","season").copy(parentId="p$it")}
|
||||
val result=groupRecentSeasons(unknown+seasons){error("Single seasons need no show request")}
|
||||
assertEquals(18,result.size)
|
||||
assertEquals(listOf("unknown1","unknown2","s1"),result.take(3).map{it.id})
|
||||
assertTrue(groupRecentSeasons(emptyList()){error("Empty row")}.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun partiallyWatchedShowUsesEpisodeCountsEvenWithViewCount() {
|
||||
val show=Title.parse(JSONObject("""{"type":"show","viewCount":12,"leafCount":30,"viewedLeafCount":10}"""))
|
||||
assertFalse(show.fullyWatched);assertEquals(20,show.remainingEpisodes)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@ class LivePlexTest {
|
|||
@Test fun liveGeneratedPreviewAndNewSeasons()=runBlocking {
|
||||
val showSection=api.sections().first{it.type=="show"}
|
||||
val seasons=api.recentSeasons(showSection.id)
|
||||
assertTrue(seasons.isNotEmpty());assertTrue(seasons.all{it.type=="season"&&it.parentTitle.isNotBlank()})
|
||||
assertTrue(seasons.isNotEmpty());assertTrue(seasons.all{it.type=="show"||it.type=="season"&&it.parentTitle.isNotBlank()})
|
||||
assertEquals(seasons.size,seasons.map{if(it.type=="show")it.id else it.parentId.ifBlank{it.id}}.distinct().size)
|
||||
val episode=api.details("7599") // Known live test episode with generated preview indexes.
|
||||
assertTrue(episode.chapters.isNotEmpty())
|
||||
val preview=api.previewPath(episode,90000) ?: error("No server preview path")
|
||||
|
|
@ -60,7 +61,7 @@ class LivePlexTest {
|
|||
}
|
||||
@Test fun liveDirectStreamCopiesSupportedVideo()=runBlocking {
|
||||
val episode=api.details("7599") // HEVC test episode supported by this onn.
|
||||
val decision=api.container("/video/:/transcode/universal/decision",api.transcodeParams(episode,"kaleido-remux-regression",1,90000,20000))
|
||||
val decision=api.container("/video/:/transcode/universal/decision",api.transcodeParams(episode,"kaleido-remux-regression",1,90000,StreamQuality.Original))
|
||||
val streams=decision.optJSONArray("Metadata").objects().flatMap{it.optJSONArray("Media").objects()}.flatMap{it.optJSONArray("Part").objects()}.flatMap{it.optJSONArray("Stream").objects()}
|
||||
assertEquals("copy",streams.first{it.optInt("streamType")==1}.optString("decision"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,22 +44,39 @@ import kotlinx.coroutines.delay
|
|||
@Composable fun TopBar(vm:KaleidoViewModel,navigation:DiscoveryNavigation?=null) {
|
||||
val initialFocus by remember{derivedStateOf{vm.focusId.isBlank()}}
|
||||
val scope=rememberCoroutineScope();val pendingTab=remember{arrayOfNulls<Job>(1)}
|
||||
val focusedTab=remember{arrayOf(vm.page.kind)}
|
||||
// Let the focus highlight draw before the new section composes in its long frame,
|
||||
// so the press responds at once. A quick second move replaces the pending switch.
|
||||
fun activate(kind:String){pendingTab[0]?.cancel();pendingTab[0]=scope.launch{withFrameNanos{};withFrameNanos{};if(vm.page.kind!=kind)vm.tab(kind)}}
|
||||
fun select(kind:String){vm.tab(kind);vm.focusId="tab:$kind"}
|
||||
fun activate(kind:String){pendingTab[0]?.cancel();pendingTab[0]=scope.launch{withFrameNanos{};withFrameNanos{};if(vm.page.kind!=kind)select(kind)}}
|
||||
val immersive=vm.page.kind=="home"||(vm.page.kind in listOf("movies","tv")&&!vm.allTitles)
|
||||
// Extend the scrim beyond the controls so it dissolves into the scene without a hard edge.
|
||||
Box(Modifier.fillMaxWidth().height(62.dp).drawBehind {
|
||||
Box(Modifier.fillMaxWidth().height(62.dp).onPreviewKeyEvent {
|
||||
// There is no destination above the header. Letting repeated Up events run
|
||||
// Compose's default search measures offscreen lazy rows looking for one.
|
||||
it.type==KeyEventType.KeyDown&&it.key==Key.DirectionUp
|
||||
}.drawBehind {
|
||||
val depth=if(immersive)size.height*1.8f else size.height
|
||||
val colors=if(!immersive)listOf(Ink,Ink)else if(navigation?.scrolled==true)listOf(Color.Black.copy(alpha=.93f),Color.Black.copy(alpha=.66f),Color.Black.copy(alpha=.18f),Color.Transparent)else listOf(Color.Black.copy(alpha=.64f),Color.Black.copy(alpha=.22f),Color.Transparent)
|
||||
drawRect(Brush.verticalGradient(colors,endY=depth),size=Size(size.width,depth))
|
||||
}.padding(horizontal=Cinema.gutter)) {
|
||||
Box(Modifier.align(Alignment.CenterStart)){Brand()}
|
||||
Row(Modifier.align(Alignment.Center).onPreviewKeyEvent{
|
||||
if(navigation!=null&&it.type==KeyEventType.KeyDown&&it.key==Key.DirectionDown){navigation.enter?.invoke();true}else false
|
||||
if(navigation!=null&&it.type==KeyEventType.KeyDown&&it.key==Key.DirectionDown){
|
||||
pendingTab[0]?.cancel()
|
||||
val target=focusedTab[0]
|
||||
if(vm.page.kind!=target){navigation.pendingEntry=target;vm.tab(target);vm.focusId=if(target=="home")"home-feature"else "discovery-entry"}else navigation.enter?.invoke()
|
||||
true
|
||||
}else false
|
||||
}.focusProperties{if(navigation!=null)down=navigation.entry},horizontalArrangement=Arrangement.spacedBy(16.dp),verticalAlignment=Alignment.CenterVertically) {
|
||||
listOf("home" to "Home","movies" to "Movies","tv" to "TV Shows").forEach{(kind,label)->
|
||||
NavigationLabel(label,vm.page.kind==kind,modifier=if(navigation!=null&&vm.page.kind==kind)Modifier.focusRequester(navigation.top)else Modifier,initialFocus=vm.page.kind==kind&&initialFocus,onFocused={if(vm.page.kind!=kind)activate(kind)}){pendingTab[0]?.cancel();if(vm.page.kind!=kind)vm.tab(kind)}
|
||||
NavigationLabel(label,vm.page.kind==kind,modifier=if(navigation!=null&&vm.page.kind==kind)Modifier.focusRequester(navigation.top)else Modifier,initialFocus=vm.page.kind==kind&&initialFocus,onFocused={
|
||||
focusedTab[0]=kind
|
||||
// A tab already has focus. Don't schedule its delayed initial-focus
|
||||
// request again when the section changes: it can steal the next press.
|
||||
vm.focusId="tab:$kind"
|
||||
if(vm.page.kind!=kind)activate(kind)
|
||||
}){pendingTab[0]?.cancel();if(vm.page.kind!=kind)select(kind)}
|
||||
}
|
||||
}
|
||||
Row(Modifier.align(Alignment.CenterEnd),verticalAlignment=Alignment.CenterVertically,horizontalArrangement=Arrangement.spacedBy(9.dp)) {
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ class DiscoveryNavigation {
|
|||
val section=FocusRequester()
|
||||
val top=FocusRequester()
|
||||
var scrolled by mutableStateOf(false)
|
||||
var pendingEntry by mutableStateOf<String?>(null)
|
||||
var enter:(()->Unit)?=null
|
||||
}
|
||||
/** Preserve server-supplied recommendations, but give each destination an editorial purpose. */
|
||||
|
|
|
|||
|
|
@ -73,9 +73,13 @@ private suspend fun LazyListState.animateBrowseTo(index:Int) {
|
|||
repeat(45){withFrameNanos{}}
|
||||
if(!list.isScrollInProgress&&list.firstVisibleItemIndex==0&&list.firstVisibleItemScrollOffset==1)list.scrollBy(-1f)
|
||||
}
|
||||
val rowStates=remember(hubs){List(hubs.size){row->LazyListState(firstVisibleItemIndex=if(restore?.first==row)restore.second else 0)}}
|
||||
val rowStates=remember(hubs){List(hubs.size){row->LazyListState(
|
||||
cacheWindow=LazyLayoutCacheWindow(aheadFraction=1f,behindFraction=.5f),
|
||||
firstVisibleItemIndex=if(restore?.first==row)restore.second else 0)}}
|
||||
val requesters=remember(hubs){mutableMapOf<Pair<Int,Int>,FocusRequester>()}
|
||||
val columns=remember(hubs){mutableMapOf<Int,Int>()}
|
||||
val pendingColumns=remember(hubs){mutableMapOf<Int,Int>()}
|
||||
val horizontalTimes=remember(hubs){mutableMapOf<Int,Long>()}
|
||||
val navigationJob=remember{arrayOfNulls<Job>(1)}
|
||||
val scope=rememberCoroutineScope()
|
||||
val density=LocalDensity.current
|
||||
|
|
@ -105,11 +109,15 @@ private suspend fun LazyListState.animateBrowseTo(index:Int) {
|
|||
val rowOffset=if(home)1 else 0
|
||||
suspend fun moveToRow(row:Int,column:Int)=coroutineScope {
|
||||
val state=rowStates.getOrNull(row) ?: return@coroutineScope
|
||||
val visible=list.layoutInfo.visibleItemsInfo.any{it.index==row+rowOffset}&&state.layoutInfo.visibleItemsInfo.any{it.index==column}
|
||||
val focused=visible&&runCatching{requesters[row to column]?.requestFocus()==true}.getOrDefault(false)
|
||||
val scrolling=launch{list.animateBrowseTo(row+rowOffset)}
|
||||
state.scrollToItem(column)
|
||||
snapshotFlow{list.layoutInfo.visibleItemsInfo.any{it.index==row+rowOffset}&&state.layoutInfo.visibleItemsInfo.any{it.index==column}}.first{it}
|
||||
withFrameNanos{}
|
||||
runCatching{requesters.getOrPut(row to column){FocusRequester()}.requestFocus()}
|
||||
if(!state.layoutInfo.visibleItemsInfo.any{it.index==column})state.requestScrollToItem(column)
|
||||
if(!focused) {
|
||||
snapshotFlow{list.layoutInfo.visibleItemsInfo.any{it.index==row+rowOffset}&&state.layoutInfo.visibleItemsInfo.any{it.index==column}}.first{it}
|
||||
withFrameNanos{}
|
||||
runCatching{requesters.getOrPut(row to column){FocusRequester()}.requestFocus()}
|
||||
}
|
||||
scrolling.join()
|
||||
}
|
||||
suspend fun moveToHero()=coroutineScope {
|
||||
|
|
@ -120,9 +128,23 @@ private suspend fun LazyListState.animateBrowseTo(index:Int) {
|
|||
LaunchedEffect(home,features.isNotEmpty()){if(home&&vm.focusId=="home-feature"){list.scrollToItem(0);withFrameNanos{};runCatching{heroFocus.requestFocus()}}}
|
||||
DisposableEffect(navigation,list,hubs){
|
||||
navigation.scrolled=false
|
||||
navigation.enter={(if(home)activeFeature.value else hubs.firstOrNull()?.items?.firstOrNull())?.let{vm.anticipate(it,cinematic=home)};navigationJob[0]?.cancel();navigationJob[0]=scope.launch{list.animateBrowseTo(0);rowStates.firstOrNull()?.scrollToItem(0);withFrameNanos{};runCatching{(if(home)heroFocus else navigation.section).requestFocus()}}}
|
||||
navigation.enter={
|
||||
navigationJob[0]?.cancel()
|
||||
// Discover is fixed above the catalog. Enter it immediately, without resetting
|
||||
// or waiting for two lazy lists to lay out. The next Down explicitly enters row 0.
|
||||
if(!home)runCatching{navigation.section.requestFocus()}
|
||||
else {
|
||||
val visible=list.layoutInfo.visibleItemsInfo.any{it.index==0}
|
||||
if(visible)runCatching{heroFocus.requestFocus()}
|
||||
navigationJob[0]=scope.launch{if(visible)list.animateBrowseTo(0)else moveToHero()}
|
||||
activeFeature.value?.let{vm.anticipate(it,cinematic=true)}
|
||||
}
|
||||
}
|
||||
onDispose{navigation.enter=null}
|
||||
}
|
||||
LaunchedEffect(navigation.pendingEntry,destination) {
|
||||
if(navigation.pendingEntry==destination){navigation.pendingEntry=null;navigation.enter?.invoke()}
|
||||
}
|
||||
val title=when(destination){"movies"->"Movies";"tv"->"TV Shows";else->"Home"}
|
||||
BoxWithConstraints(Modifier.fillMaxSize()) {
|
||||
val heroHeight=maxHeight*.80f-62.dp
|
||||
|
|
@ -133,7 +155,12 @@ private suspend fun LazyListState.animateBrowseTo(index:Int) {
|
|||
Row(Modifier.fillMaxWidth().height(39.dp).padding(horizontal=Cinema.gutter),verticalAlignment=Alignment.CenterVertically) {
|
||||
Text(title,color=Accent,fontSize=19.sp,fontWeight=FontWeight.SemiBold,modifier=Modifier.padding(end=20.dp))
|
||||
if(!home) {
|
||||
NavigationLabel("Discover",true,modifier=Modifier.focusRequester(navigation.section).focusProperties{up=navigation.top;down=navigation.entry},initialFocus=sectionEntry){}
|
||||
NavigationLabel("Discover",true,modifier=Modifier.focusRequester(navigation.section).focusProperties{up=navigation.top;down=navigation.entry}.onPreviewKeyEvent {
|
||||
if(it.type==KeyEventType.KeyDown&&it.key==Key.DirectionDown){
|
||||
hubs.firstOrNull()?.items?.firstOrNull()?.let{item->vm.anticipate(item)}
|
||||
navigationJob[0]?.cancel();navigationJob[0]=scope.launch{moveToRow(0,0)};true
|
||||
}else false
|
||||
},initialFocus=sectionEntry){}
|
||||
// Nothing sits right of Library; an unbounded search would open Home from the top bar.
|
||||
NavigationLabel("Library",false,modifier=Modifier.focusProperties{up=navigation.top;down=navigation.entry;right=FocusRequester.Cancel}){vm.setAll(true)}
|
||||
}
|
||||
|
|
@ -182,20 +209,39 @@ private suspend fun LazyListState.animateBrowseTo(index:Int) {
|
|||
BrowseCard(vm,item,"${hub.id}:${item.id}",poster,wideEpisode,if(row==0&&column==0)navigation.entry else null,requester,staging,
|
||||
Modifier.onPreviewKeyEvent{event->
|
||||
if(event.type==KeyEventType.KeyDown&&event.key in listOf(Key.DirectionLeft,Key.DirectionRight)) {
|
||||
val target=column+if(event.key==Key.DirectionLeft)-1 else 1
|
||||
val target=(pendingColumns[row] ?: column)+if(event.key==Key.DirectionLeft)-1 else 1
|
||||
if(target in hub.items.indices) {
|
||||
vm.anticipate(hub.items[target],cinematic=home)
|
||||
val now=event.nativeKeyEvent.eventTime
|
||||
val rapid=now-(horizontalTimes[row] ?: 0L)<160L
|
||||
horizontalTimes[row]=now
|
||||
pendingColumns[row]=target
|
||||
navigationJob[0]?.cancel()
|
||||
val state=rowStates[row]
|
||||
val visible=state.layoutInfo.visibleItemsInfo.any{it.index==target}
|
||||
if(visible)runCatching{requesters.getOrPut(row to target){FocusRequester()}.requestFocus()}
|
||||
navigationJob[0]=scope.launch {
|
||||
// KeyDown/KeyUp can arrive between frames. Commit focus once
|
||||
// on the next frame, so accessibility doesn't force an extra
|
||||
// catalog layout between those events. Bursts keep the latest
|
||||
// logical column instead of dropping a move while awaiting layout.
|
||||
withFrameNanos{}
|
||||
if(!rapid)vm.anticipate(hub.items[target],cinematic=home)
|
||||
val visible=state.layoutInfo.visibleItemsInfo.any{it.index==target}
|
||||
val anchor=(target-1).coerceAtLeast(0)
|
||||
if(visible) {
|
||||
if(visible&&!rapid) {
|
||||
runCatching{requesters.getOrPut(row to target){FocusRequester()}.requestFocus()}
|
||||
val pitch=with(density){(if(poster)130.dp else if(wideEpisode)274.dp else 224.dp).toPx()}
|
||||
val delta=(anchor-state.firstVisibleItemIndex)*pitch-state.firstVisibleItemScrollOffset
|
||||
if(kotlin.math.abs(delta)>1)state.animateScrollBy(delta,tween(140))
|
||||
}else{state.scrollToItem(anchor);withFrameNanos{};runCatching{requesters.getOrPut(row to target){FocusRequester()}.requestFocus()}}
|
||||
}else{
|
||||
// Schedule one layout for the next frame instead of forcing
|
||||
// synchronous composition between rapid remote events.
|
||||
state.requestScrollToItem(anchor)
|
||||
snapshotFlow{state.layoutInfo.visibleItemsInfo.any{it.index==target}}.first{it}
|
||||
withFrameNanos{};runCatching{requesters.getOrPut(row to target){FocusRequester()}.requestFocus()}
|
||||
}
|
||||
// A held direction snaps to the latest anchor. Repeatedly
|
||||
// cancelling pixel animations and decoding transient backdrops
|
||||
// costs more than the focus move; predict only after it settles.
|
||||
if(rapid){delay(70);vm.anticipate(hub.items[target],cinematic=home)}
|
||||
}
|
||||
}
|
||||
true
|
||||
|
|
@ -216,7 +262,7 @@ private suspend fun LazyListState.animateBrowseTo(index:Int) {
|
|||
}
|
||||
true
|
||||
}else false
|
||||
},onHovered={columns[row]=column;hovered.value=it;heroActive=false})
|
||||
},onHovered={columns[row]=column;pendingColumns[row]=column;hovered.value=it;heroActive=false})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -264,12 +310,13 @@ private suspend fun LazyListState.animateBrowseTo(index:Int) {
|
|||
/**
|
||||
* A newly shown section composed every visible card in one 100–200 ms frame. While it is
|
||||
* entering, each card first lays out at its fixed size and fills in its artwork and titles a
|
||||
* few cards per frame, under the page's fade-in. Cards composed later fill in at once.
|
||||
* few cards per frame, under the page's fade-in. Later offscreen cards spread their
|
||||
* artwork/text work over three frames too, keeping lazy-layout work short during input.
|
||||
*/
|
||||
private class CardStaging {
|
||||
var entering=true
|
||||
private var count=0
|
||||
fun frames()=if(entering)count++/3 else -1
|
||||
fun frames()=if(entering)count++/3 else count++%3
|
||||
}
|
||||
|
||||
@Composable private fun BrowseCard(vm:KaleidoViewModel,item:Title,focusKey:String,poster:Boolean,wideEpisode:Boolean,entry:FocusRequester?,requester:FocusRequester,staging:CardStaging,modifier:Modifier,onHovered:(Title)->Unit) {
|
||||
|
|
|
|||
|
|
@ -65,9 +65,9 @@ class PlexApi(val clientId: String) {
|
|||
suspend fun hubs(section: String? = null): List<Hub> = withContext(Dispatchers.Default){container(if(section==null) "/hubs" else "/hubs/sections/$section", mapOf("count" to "18","includeExternalMetadata" to "1")).optJSONArray("Hub").objects().map { Hub(it.optString("hubIdentifier",it.optString("key",it.optString("title"))),it.optString("title"),it.optJSONArray("Metadata").objects().map(Title::parse)) }.filter { it.items.isNotEmpty() && it.items.first().type in listOf("movie","show","episode","season","collection") }}
|
||||
suspend fun onDeck(): List<Title> = container("/library/onDeck",mapOf("X-Plex-Container-Size" to "30")).optJSONArray("Metadata").objects().map(Title::parse)
|
||||
suspend fun recentSeasons(section:String):List<Title> = withContext(Dispatchers.Default){
|
||||
container("/library/sections/$section/all",mapOf("type" to "3","sort" to "addedAt:desc","X-Plex-Container-Size" to "18")).optJSONArray("Metadata").objects().map{j->
|
||||
Title.parse(j).let{it.copy(title=listOf(it.parentTitle,it.title).filter{v->v.isNotBlank()}.joinToString(" · "))}
|
||||
}
|
||||
// Fetch beyond the display limit so one large series import doesn't fill the row.
|
||||
val seasons=container("/library/sections/$section/all",mapOf("type" to "3","sort" to "addedAt:desc","X-Plex-Container-Size" to "100")).optJSONArray("Metadata").objects().map(Title::parse)
|
||||
groupRecentSeasons(seasons,::details)
|
||||
}
|
||||
suspend fun library(section: String, start: Int = 0, sort: String = "titleSort:asc", genre: String = "", unwatched: Boolean = false): LibraryPage = withContext(Dispatchers.Default){
|
||||
val p=mutableMapOf("X-Plex-Container-Start" to start.toString(),"X-Plex-Container-Size" to "100","sort" to sort)
|
||||
|
|
|
|||
14
app/src/main/java/tv/kaleido/app/RecentSeasons.kt
Normal file
14
app/src/main/java/tv/kaleido/app/RecentSeasons.kt
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package tv.kaleido.app
|
||||
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
|
||||
/** Preserve newest-first order. A multi-season addition opens the real show's season list. */
|
||||
internal suspend fun groupRecentSeasons(seasons:List<Title>,loadShow:suspend (String)->Title):List<Title> = coroutineScope {
|
||||
seasons.distinctBy{it.id}.groupBy{it.parentId.ifBlank{"season:${it.id}"}}.values.take(18).map { group->async {
|
||||
val season=group.first()
|
||||
if(group.size>1&&season.parentId.isNotBlank())loadShow(season.parentId)
|
||||
else season.copy(title=listOf(season.parentTitle,season.title).filter{it.isNotBlank()}.joinToString(" · "))
|
||||
}}.awaitAll()
|
||||
}
|
||||
|
|
@ -5,9 +5,11 @@ import androidx.compose.foundation.*
|
|||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.*
|
||||
import androidx.compose.foundation.gestures.BringIntoViewSpec
|
||||
import androidx.compose.foundation.gestures.animateScrollBy
|
||||
import androidx.compose.foundation.gestures.LocalBringIntoViewSpec
|
||||
import androidx.compose.foundation.lazy.grid.*
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.outlined.ArrowBack
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
|
|
@ -18,19 +20,25 @@ import androidx.compose.ui.Alignment
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.focus.*
|
||||
import androidx.compose.ui.input.key.*
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shadow
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.semantics.*
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import coil.compose.AsyncImage
|
||||
import coil.request.ImageRequest
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable fun DetailsScreen(vm:KaleidoViewModel) {
|
||||
val item=vm.detail ?: return
|
||||
|
|
@ -39,6 +47,7 @@ import coil.request.ImageRequest
|
|||
val restoreFocus=remember(item.id){vm.focusId}
|
||||
val restoreRow=remember(item.id){listOf("cast:","children:","related:").any{restoreFocus.startsWith("$it${item.id}:")}}
|
||||
val list=rememberLazyListState()
|
||||
val backdropFadeDistance=with(LocalDensity.current){180.dp.toPx()}
|
||||
LaunchedEffect(item.id,vm.children.isNotEmpty(),vm.detailRelated.isNotEmpty()) {
|
||||
val castCount=if(item.castMembers.isNotEmpty())1 else 0
|
||||
val target=when {
|
||||
|
|
@ -53,14 +62,17 @@ import coil.request.ImageRequest
|
|||
}
|
||||
Box(Modifier.fillMaxSize().background(Ink)) {
|
||||
if(item.type=="show") {
|
||||
BrowseBackdrop(vm.api,item.art.ifBlank{item.thumb},Modifier.fillMaxSize(),cinematic=true)
|
||||
// Keep long descriptions and provider badges legible across bright artwork.
|
||||
Box(Modifier.fillMaxSize().background(Brush.verticalGradient(0f to Ink.copy(alpha=.4f),.48f to Ink.copy(alpha=.4f),.75f to Color.Transparent)))
|
||||
BrowseBackdrop(vm.api,item.art.ifBlank{item.thumb},Modifier.fillMaxSize().graphicsLayer {
|
||||
alpha=if(list.firstVisibleItemIndex>0)0f else (1f-list.firstVisibleItemScrollOffset/backdropFadeDistance).coerceIn(0f,1f)
|
||||
},cinematic=true)
|
||||
// Keep the scene in the header; rows and captions sit on near-black. Read scroll
|
||||
// in the layer so scrolling doesn't recompose the details and cast hierarchy.
|
||||
Box(Modifier.fillMaxSize().background(Brush.verticalGradient(0f to Ink.copy(alpha=.4f),.35f to Ink.copy(alpha=.5f),.62f to Ink.copy(alpha=.96f),.8f to Ink)))
|
||||
}
|
||||
CompositionLocalProvider(LocalBringIntoViewSpec provides DetailsScroll) {
|
||||
LazyColumn(state=list,contentPadding=PaddingValues(bottom=30.dp),verticalArrangement=Arrangement.spacedBy(18.dp),modifier=Modifier.fillMaxSize()) {
|
||||
item(key="details-${item.id}") {
|
||||
Box(Modifier.fillMaxWidth().height(if(item.type in listOf("movie","episode"))322.dp else 286.dp)) {
|
||||
Box(Modifier.fillMaxWidth().then(if(item.type=="show")Modifier.heightIn(min=248.dp)else Modifier.height(if(item.type in listOf("movie","episode"))322.dp else 286.dp))) {
|
||||
if(item.type!="show") {
|
||||
Artwork(vm.api,item.art,Modifier.fillMaxSize(),1920,1080)
|
||||
Box(Modifier.fillMaxSize().background(Brush.horizontalGradient(listOf(Ink.copy(alpha=.98f),Ink.copy(alpha=.8f),Color.Transparent))))
|
||||
|
|
@ -68,9 +80,9 @@ import coil.request.ImageRequest
|
|||
}
|
||||
IconControl(Icons.AutoMirrored.Outlined.ArrowBack,"Back",modifier=Modifier.padding(start=36.dp,top=14.dp)){vm.back()}
|
||||
if(item.type=="show") {
|
||||
Row(Modifier.fillMaxWidth().padding(start=Cinema.gutter,end=Cinema.gutter,top=68.dp),horizontalArrangement=Arrangement.spacedBy(24.dp),verticalAlignment=Alignment.Top) {
|
||||
Row(Modifier.fillMaxWidth().padding(start=Cinema.gutter,end=Cinema.gutter,top=56.dp),horizontalArrangement=Arrangement.spacedBy(24.dp),verticalAlignment=Alignment.Top) {
|
||||
Artwork(vm.api,item.poster.ifBlank{item.thumb},Modifier.width(128.dp).height(192.dp).clip(androidx.compose.foundation.shape.RoundedCornerShape(6.dp)),384,576,animate=false,contentScale=ContentScale.Fit)
|
||||
TitleInformation(vm,item,actionFocus,childFocus,!restoreRow,Modifier.weight(1f))
|
||||
TitleInformation(vm,item,actionFocus,childFocus,!restoreRow,Modifier.weight(1f,fill=false).widthIn(max=560.dp))
|
||||
}
|
||||
}else TitleInformation(vm,item,actionFocus,childFocus,!restoreRow,Modifier.align(Alignment.CenterStart).padding(start=Cinema.gutter,top=30.dp).width(560.dp))
|
||||
}
|
||||
|
|
@ -94,6 +106,8 @@ private object DetailsScroll:BringIntoViewSpec {
|
|||
|
||||
@Composable private fun TitleInformation(vm:KaleidoViewModel,item:Title,actionFocus:FocusRequester,childFocus:FocusRequester,initialFocus:Boolean,modifier:Modifier) {
|
||||
val actionNavigation=Modifier.focusProperties{if(vm.children.isNotEmpty())down=childFocus}
|
||||
var summaryOverflow by remember(item.id){mutableStateOf(false)}
|
||||
var showSynopsis by remember(item.id){mutableStateOf(false)}
|
||||
Column(modifier) {
|
||||
CompositionLocalProvider(LocalTextStyle provides LocalTextStyle.current.copy(shadow=Shadow(Color.Black.copy(alpha=.95f),Offset(0f,2f),6f))) {
|
||||
if(item.type=="episode")Text(item.grandparentTitle,color=Cinema.secondary,fontSize=11.sp)
|
||||
|
|
@ -102,7 +116,7 @@ private object DetailsScroll:BringIntoViewSpec {
|
|||
Text(listOf(item.subtitle,item.contentRating).filter{it.isNotBlank()}.joinToString(" · "),color=Muted,fontSize=10.5.sp,lineHeight=16.sp,maxLines=1,overflow=TextOverflow.Ellipsis,modifier=Modifier.weight(1f,fill=false))
|
||||
AudienceRatings(item,Modifier.padding(start=12.dp))
|
||||
}
|
||||
Text(item.summary,color=Cinema.secondary,fontSize=12.sp,lineHeight=18.sp,maxLines=3,overflow=TextOverflow.Ellipsis,modifier=Modifier.padding(top=10.dp,bottom=17.dp))
|
||||
Text(item.summary,color=Cinema.secondary,fontSize=12.sp,lineHeight=18.sp,maxLines=3,overflow=TextOverflow.Ellipsis,onTextLayout={summaryOverflow=it.hasVisualOverflow},modifier=Modifier.padding(top=10.dp,bottom=17.dp))
|
||||
}
|
||||
if(item.type!="collection")Row(horizontalArrangement=Arrangement.spacedBy(9.dp),verticalAlignment=Alignment.CenterVertically) {
|
||||
ActionButton(if(item.offset>0)"Resume · ${item.offset/60000} min"else if(item.type=="show")"Watch next"else "Play",Icons.Filled.PlayArrow,modifier=actionNavigation.focusRequester(actionFocus),primary=true,initialFocus=initialFocus){vm.play(item)}
|
||||
|
|
@ -111,9 +125,41 @@ private object DetailsScroll:BringIntoViewSpec {
|
|||
val watched=item.isWatched(vm.watchedPercent)
|
||||
ActionButton(if(vm.markingId==item.id)"Updating…"else if(watched)"Mark unwatched"else "Mark watched",if(watched)Icons.Outlined.CheckCircle else Icons.Outlined.Check,modifier=actionNavigation){vm.mark(item)}
|
||||
}
|
||||
if(item.type=="show"&&summaryOverflow)ActionButton("Synopsis",Icons.Outlined.Description,modifier=actionNavigation){showSynopsis=true}
|
||||
}
|
||||
if(item.type!="show")item.media.firstOrNull()?.let{media->Text(listOf(media.resolution.uppercase(),media.videoCodec.uppercase(),media.audioCodec.uppercase()).filter{it.isNotBlank()}.joinToString(" · "),color=Cinema.quiet,fontSize=9.sp,modifier=Modifier.padding(top=12.dp))}
|
||||
}
|
||||
if(showSynopsis)SynopsisDialog(vm.api,item){showSynopsis=false}
|
||||
}
|
||||
|
||||
@Composable private fun SynopsisDialog(api:PlexApi,item:Title,onDismiss:()->Unit) {
|
||||
val scroll=rememberScrollState()
|
||||
val scope=rememberCoroutineScope()
|
||||
val step=with(LocalDensity.current){100.dp.toPx()}
|
||||
Dialog(onDismissRequest=onDismiss,properties=DialogProperties(usePlatformDefaultWidth=false,decorFitsSystemWindows=false)) {
|
||||
Box(Modifier.fillMaxSize().background(Color.Black.copy(alpha=.42f)).padding(Cinema.gutter),contentAlignment=Alignment.Center) {
|
||||
Row(Modifier.width(760.dp).heightIn(max=420.dp).clip(RoundedCornerShape(Cinema.radius)).background(Ink).border(1.dp,Accent.copy(alpha=.12f),RoundedCornerShape(Cinema.radius)).padding(28.dp).onPreviewKeyEvent {
|
||||
if(it.type==KeyEventType.KeyDown&&it.key in listOf(Key.DirectionUp,Key.DirectionDown)) {
|
||||
scope.launch{scroll.animateScrollBy(if(it.key==Key.DirectionUp)-step else step)};true
|
||||
}else false
|
||||
},horizontalArrangement=Arrangement.spacedBy(28.dp),verticalAlignment=Alignment.Top) {
|
||||
Artwork(api,item.poster.ifBlank{item.thumb},Modifier.padding(top=4.dp).width(128.dp).height(192.dp).clip(RoundedCornerShape(Cinema.radius)),384,576,animate=false,contentScale=ContentScale.Fit)
|
||||
Column(Modifier.weight(1f)) {
|
||||
Row(Modifier.fillMaxWidth(),horizontalArrangement=Arrangement.spacedBy(18.dp),verticalAlignment=Alignment.Top) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
Eyebrow("Synopsis")
|
||||
Text(item.title,color=Accent,fontSize=26.sp,lineHeight=32.sp,fontWeight=FontWeight.SemiBold,maxLines=2,overflow=TextOverflow.Ellipsis,modifier=Modifier.padding(top=6.dp))
|
||||
Text(listOf(item.year,item.contentRating).filter{it.isNotBlank()}.joinToString(" · "),color=Muted,fontSize=10.sp,lineHeight=14.sp,modifier=Modifier.padding(top=6.dp))
|
||||
}
|
||||
IconControl(Icons.Outlined.Close,"Close",initialFocus=true,onClick=onDismiss)
|
||||
}
|
||||
Box(Modifier.padding(top=18.dp,bottom=16.dp).fillMaxWidth().height(1.dp).background(Accent.copy(alpha=.1f)))
|
||||
Text(item.summary,color=Cinema.secondary,fontSize=12.5.sp,lineHeight=20.sp,modifier=Modifier.weight(1f,fill=false).verticalScroll(scroll))
|
||||
Text(if(scroll.maxValue>0)"↑ ↓ Scroll · Back to close"else "Back to close",color=Cinema.quiet,fontSize=9.sp,lineHeight=13.sp,modifier=Modifier.padding(top=20.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable private fun CastRail(vm:KaleidoViewModel,item:Title,actionFocus:FocusRequester) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue