diff --git a/CHANGELOG.md b/CHANGELOG.md index 84bc313..0a958a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Kaleido releases +## 0.8.1 + +- Fix a title page where Down from the buttons did nothing, leaving you stuck at the top. This happened when the Seasons, Cast or another row below had been scrolled away from its first card, for example by reopening a show from Continue Watching. Down now moves to a card in view. + ## 0.8.0 - Replace the two countdowns at the end of an episode with one Up Next screen. When the credits start, the video shrinks into the top-left corner and keeps playing, beside the next episode's artwork, details, rating and synopsis, with the rest of the season and related shows below. Play next episode fills as it counts down, and pressing any button on the remote stops the countdown. Press Left and select the video, or press Back, to return to the credits. diff --git a/app/src/main/java/tv/kaleido/app/BrowseScreens.kt b/app/src/main/java/tv/kaleido/app/BrowseScreens.kt index b594f7e..8b29dc3 100644 --- a/app/src/main/java/tv/kaleido/app/BrowseScreens.kt +++ b/app/src/main/java/tv/kaleido/app/BrowseScreens.kt @@ -111,14 +111,29 @@ import androidx.compose.ui.text.input.TextFieldValue // A reopened episode page resets its selection, but its saved scroll can still // point elsewhere. Compose the entry card before the header sends focus Down. LaunchedEffect(rowId){if(initialItem!=null)row.scrollToItem((initial-1).coerceAtLeast(0))} + val entryIndex=if(entryFocus!=null)rememberRowEntry(row,entry).value else -1 Column { Box(Modifier.padding(horizontal=Cinema.gutter)){SectionHeading(title,subtitle)} LazyRow(state=row,contentPadding=PaddingValues(start=Cinema.gutter,end=Cinema.gutter,top=5.dp,bottom=5.dp),horizontalArrangement=Arrangement.spacedBy(if(landscape)13.dp else 12.dp),modifier=Modifier.focusRestorer(fallback=entryFocus ?: FocusRequester.Default)) { - itemsIndexed(items,key={_,it->it.id}){index,item->MediaTile(vm,item,"$rowId:${item.id}",landscape,modifier=(if(index==entry&&entryFocus!=null)Modifier.focusRequester(entryFocus)else Modifier).then(if(up!=null)Modifier.focusProperties{this.up=up}else Modifier),onMove={anticipateTileMove(vm,items,index,it,0)},episodeTitle=episodeTitles,current=item.id==selectedItem,onFocused=onFocused,onClick=onClick)} + itemsIndexed(items,key={_,it->it.id}){index,item->MediaTile(vm,item,"$rowId:${item.id}",landscape,modifier=(if(index==entryIndex&&entryFocus!=null)Modifier.focusRequester(entryFocus)else Modifier).then(if(up!=null)Modifier.focusProperties{this.up=up}else Modifier),onMove={anticipateTileMove(vm,items,index,it,0)},episodeTitle=episodeTitles,current=item.id==selectedItem,onFocused=onFocused,onClick=onClick)} } } } +/** + * The card a row is entered at from above: [preferred] while it is in view, otherwise the first + * card fully in view. A card scrolled out of a lazy row (e.g. a restored or scrolled Seasons row) + * is not composed, so an explicit focus move to its requester fails and strands focus above. + */ +internal fun rowEntryIndex(preferred:Int,visible:List,viewportStart:Int):Int { + if(visible.isEmpty()||visible.any{it.index==preferred})return preferred + return (visible.firstOrNull{it.offset>=viewportStart} ?: visible.first()).index +} + +/** [rowEntryIndex], updated only when a card enters or leaves the row's view. */ +@Composable internal fun rememberRowEntry(row:LazyListState,preferred:Int):State = + remember(row,preferred){derivedStateOf{row.layoutInfo.let{rowEntryIndex(preferred,it.visibleItemsInfo,it.viewportStartOffset)}}} + internal fun anticipateTileMove(vm:KaleidoViewModel,items:List,index:Int,direction:Key,columns:Int) { val target=when(direction){ Key.DirectionLeft->if(columns==0||index%columns>0)index-1 else -1 diff --git a/app/src/main/java/tv/kaleido/app/TitleDetails.kt b/app/src/main/java/tv/kaleido/app/TitleDetails.kt index 01f7a9c..e82416b 100644 --- a/app/src/main/java/tv/kaleido/app/TitleDetails.kt +++ b/app/src/main/java/tv/kaleido/app/TitleDetails.kt @@ -233,6 +233,7 @@ internal fun nextUp(episodes:List<Title>,watchedPercent:Int)=episodes.firstOrNul @Composable private fun CastRail(vm:KaleidoViewModel,item:Title,actionFocus:FocusRequester,entry:FocusRequester) { val initial=remember(item.id){item.castMembers.indexOfFirst{"cast:${item.id}:${it.id.ifBlank{it.name}}"==vm.focusId}.coerceAtLeast(0)} val row=rememberLazyListState(initialFirstVisibleItemIndex=initial) + val entryIndex by rememberRowEntry(row,0) Column { Text("Cast",color=Accent,fontSize=17.sp,fontWeight=FontWeight.SemiBold,modifier=Modifier.padding(start=Cinema.gutter,bottom=10.dp)) LazyRow(state=row,contentPadding=PaddingValues(horizontal=Cinema.gutter),horizontalArrangement=Arrangement.spacedBy(16.dp),modifier=Modifier.focusRestorer(fallback=entry)) { @@ -241,7 +242,7 @@ internal fun nextUp(episodes:List<Title>,watchedPercent:Int)=episodes.firstOrNul var focused by remember{mutableStateOf(false)} val requester=remember{FocusRequester()} LaunchedEffect(Unit){if(vm.focusId==key){withFrameNanos{};runCatching{requester.requestFocus()}}} - Column(Modifier.width(108.dp).then(if(index==0)Modifier.focusRequester(entry)else Modifier).focusRequester(requester).focusProperties{if(item.type!="collection"&&vm.children.isEmpty())up=actionFocus}.navigationSound().onFocusChanged{ + Column(Modifier.width(108.dp).then(if(index==entryIndex)Modifier.focusRequester(entry)else Modifier).focusRequester(requester).focusProperties{if(item.type!="collection"&&vm.children.isEmpty())up=actionFocus}.navigationSound().onFocusChanged{ focused=it.isFocused;if(it.isFocused)vm.focusId=key }.clickable(enabled=actor.id.isNotBlank()){vm.openActor(actor)}.clearAndSetSemantics{ contentDescription=listOf(actor.name,actor.role).filter{it.isNotBlank()}.joinToString(". ") diff --git a/app/src/test/java/tv/kaleido/app/RowEntryTest.kt b/app/src/test/java/tv/kaleido/app/RowEntryTest.kt new file mode 100644 index 0000000..99f6b48 --- /dev/null +++ b/app/src/test/java/tv/kaleido/app/RowEntryTest.kt @@ -0,0 +1,32 @@ +package tv.kaleido.app + +import androidx.compose.foundation.lazy.LazyListItemInfo +import org.junit.Assert.assertEquals +import org.junit.Test + +class RowEntryTest { + private fun card(index:Int,offset:Int)=object:LazyListItemInfo { + override val index=index + override val key:Any=index + override val offset=offset + override val size=264 + } + // A 264 px card plus 24 px spacing; the row's start padding is 88 px (viewportStart -88). + private fun row(first:Int,firstOffset:Int,count:Int)=List(count){card(first+it,firstOffset+it*288)} + + @Test fun keepsThePreferredCardWhileItIsInView() { + assertEquals(0,rowEntryIndex(0,row(0,0,7),-88)) + assertEquals(3,rowEntryIndex(3,row(1,-100,7),-88)) + } + + @Test fun scrolledAwayRowEntersAtTheFirstFullyVisibleCard() { + // Seasons row restored to its end: Season 6 (index 5) is clipped, Season 7 is the first whole card. + assertEquals(6,rowEntryIndex(0,row(5,-167,7),-88)) + // A card resting in the start padding is still wholly on screen. + assertEquals(4,rowEntryIndex(0,row(4,-60,7),-88)) + } + + @Test fun emptyLayoutKeepsThePreferredCard() { + assertEquals(2,rowEntryIndex(2,emptyList(),-88)) + } +} diff --git a/distribution/Kaleido.apk b/distribution/Kaleido.apk index 6ea5f0f..9ab0990 100644 Binary files a/distribution/Kaleido.apk and b/distribution/Kaleido.apk differ diff --git a/distribution/Kaleido.apk.sha256 b/distribution/Kaleido.apk.sha256 index 56aa617..1b0de83 100644 --- a/distribution/Kaleido.apk.sha256 +++ b/distribution/Kaleido.apk.sha256 @@ -1 +1 @@ -3eaf7ed9d1c9260003993f8c06d3d35c5a9547d157693005f723c7afac743390 Kaleido.apk +2fd832eb90633d1519c15abccc122970a3c5ef51933da35634b8a5b1429d5bc3 Kaleido.apk diff --git a/distribution/latest.json b/distribution/latest.json index 6e8f10a..dcf5c0a 100644 --- a/distribution/latest.json +++ b/distribution/latest.json @@ -1,7 +1,7 @@ { - "version": "0.8.0", - "versionCode": 24, - "url": "https://git.elijahkuntz.com/Elijah/Kaleido/raw/tag/v0.8.0/distribution/Kaleido.apk", - "checksumUrl": "https://git.elijahkuntz.com/Elijah/Kaleido/raw/tag/v0.8.0/distribution/Kaleido.apk.sha256", - "notes": "- Replace the two countdowns at the end of an episode with one Up Next screen. When the credits start, the video shrinks into the top-left corner and keeps playing, beside the next episode's artwork, details, rating and synopsis, with the rest of the season and related shows below. Play next episode fills as it counts down, and pressing any button on the remote stops the countdown. Press Left and select the video, or press Back, to return to the credits.\n- Update Continue Watching as soon as you leave the player, including an episode you have just started.\n- Remove the label above the featured title on Home (\"Recently released\", \"Suggested for you\" and similar), as in Kaleido Desktop." + "version": "0.8.1", + "versionCode": 25, + "url": "https://git.elijahkuntz.com/Elijah/Kaleido/raw/tag/v0.8.1/distribution/Kaleido.apk", + "checksumUrl": "https://git.elijahkuntz.com/Elijah/Kaleido/raw/tag/v0.8.1/distribution/Kaleido.apk.sha256", + "notes": "- Fix a title page where Down from the buttons did nothing, leaving you stuck at the top. This happened when the Seasons, Cast or another row below had been scrolled away from its first card, for example by reopening a show from Continue Watching. Down now moves to a card in view." } diff --git a/version.properties b/version.properties index 7c5ef8c..3068871 100644 --- a/version.properties +++ b/version.properties @@ -1,2 +1,2 @@ -versionName=0.8.0 -versionCode=24 +versionName=0.8.1 +versionCode=25