Skip to content

Commit 8393324

Browse files
Refactored ItemDetailsFragment to implement CollectionItemsGrid for better layout and fixed a bug where the down key event was being consumed before items were populated
- Fixes #270 - Closes #271
1 parent c2da5e6 commit 8393324

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

app/src/main/java/org/jellyfin/androidtv/ui/itemdetail/v2/ItemDetailsFragment.kt

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import androidx.compose.foundation.interaction.collectIsFocusedAsState
2424
import androidx.compose.foundation.layout.Arrangement
2525
import androidx.compose.foundation.layout.Box
2626
import androidx.compose.foundation.layout.Column
27+
import androidx.compose.foundation.layout.ExperimentalLayoutApi
28+
import androidx.compose.foundation.layout.FlowRow
2729
import androidx.compose.foundation.layout.PaddingValues
2830
import androidx.compose.foundation.layout.Row
2931
import androidx.compose.foundation.layout.Spacer
@@ -612,12 +614,12 @@ class ItemDetailsFragment : Fragment() {
612614
if (keyEvent.nativeKeyEvent.action == android.view.KeyEvent.ACTION_DOWN) {
613615
when (keyEvent.key) {
614616
Key.DirectionDown -> {
615-
if (isBoxSet) {
616-
try { collectionFirstItemFocusRequester.requestFocus() } catch (_: Exception) {}
617+
val focused = if (isBoxSet) {
618+
try { collectionFirstItemFocusRequester.requestFocus(); true } catch (_: Exception) { false }
617619
} else {
618-
try { playButtonFocusRequester.requestFocus() } catch (_: Exception) {}
620+
try { playButtonFocusRequester.requestFocus(); true } catch (_: Exception) { false }
619621
}
620-
true
622+
focused
621623
}
622624
else -> false
623625
}
@@ -795,8 +797,7 @@ class ItemDetailsFragment : Fragment() {
795797
// ---- Collection items ----
796798
if (isBoxSet && uiState.collectionItems.isNotEmpty()) {
797799
item {
798-
SectionWithCards(
799-
title = "Items in Collection",
800+
CollectionItemsGrid(
800801
items = uiState.collectionItems,
801802
firstItemFocusRequester = collectionFirstItemFocusRequester,
802803
)
@@ -1385,6 +1386,39 @@ class ItemDetailsFragment : Fragment() {
13851386
}
13861387
}
13871388

1389+
@OptIn(ExperimentalLayoutApi::class)
1390+
@Composable
1391+
private fun CollectionItemsGrid(
1392+
items: List<BaseItemDto>,
1393+
firstItemFocusRequester: FocusRequester? = null,
1394+
) {
1395+
Column {
1396+
SectionHeader(title = "Items in Collection")
1397+
FlowRow(
1398+
modifier = Modifier.focusGroup(),
1399+
horizontalArrangement = Arrangement.spacedBy(16.dp),
1400+
verticalArrangement = Arrangement.spacedBy(16.dp),
1401+
) {
1402+
items.forEachIndexed { index, item ->
1403+
val cardModifier = if (index == 0 && firstItemFocusRequester != null)
1404+
Modifier.focusRequester(firstItemFocusRequester)
1405+
else Modifier
1406+
1407+
SimilarItemCard(
1408+
title = item.name ?: "",
1409+
imageUrl = getPosterUrl(item),
1410+
year = item.productionYear,
1411+
onClick = {
1412+
navigationRepository.navigate(Destinations.itemDetails(item.id, viewModel.serverId))
1413+
},
1414+
modifier = cardModifier,
1415+
item = item,
1416+
)
1417+
}
1418+
}
1419+
}
1420+
}
1421+
13881422
@Composable
13891423
private fun SeasonDetailsContent(uiState: ItemDetailsUiState, contentFocusRequester: FocusRequester, showBackdrop: Boolean = true) {
13901424
val item = uiState.item ?: return

0 commit comments

Comments
 (0)