ui: Visible drawer focus + subscriptions row on Home
Menu items now flip to white/dark on focus (before, focus moved invisibly so navigation looked broken) with explicit UP/DOWN key handling. Home gains a 'New from your subscriptions' row (first page, refreshed with the rest after playback).
This commit is contained in:
parent
60ef94c52e
commit
694467b038
2 changed files with 60 additions and 2 deletions
|
|
@ -55,10 +55,18 @@ class HomeRowsViewModel(private val repository: PeerTubeRepository) : ViewModel(
|
||||||
private set
|
private set
|
||||||
var continueLoading by mutableStateOf(true)
|
var continueLoading by mutableStateOf(true)
|
||||||
private set
|
private set
|
||||||
|
var subItems by mutableStateOf<List<VideoDto>>(emptyList())
|
||||||
|
private set
|
||||||
private var loaded = false
|
private var loaded = false
|
||||||
|
|
||||||
val recent = RecentVideosViewModel(repository)
|
val recent = RecentVideosViewModel(repository)
|
||||||
|
|
||||||
|
private fun fetchSubs() {
|
||||||
|
viewModelScope.launch {
|
||||||
|
subItems = repository.subscriptionVideos(0, 12).getOrNull()?.data ?: emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** History's newest entries + resume positions from the video detail endpoint. */
|
/** History's newest entries + resume positions from the video detail endpoint. */
|
||||||
fun load() {
|
fun load() {
|
||||||
if (loaded) return
|
if (loaded) return
|
||||||
|
|
@ -71,10 +79,12 @@ class HomeRowsViewModel(private val repository: PeerTubeRepository) : ViewModel(
|
||||||
continueItems = emptyList()
|
continueItems = emptyList()
|
||||||
loaded = true
|
loaded = true
|
||||||
fetchContinue()
|
fetchContinue()
|
||||||
|
fetchSubs()
|
||||||
recent.refresh()
|
recent.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchContinue() {
|
private fun fetchContinue() {
|
||||||
|
fetchSubs()
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
continueLoading = true
|
continueLoading = true
|
||||||
val history = repository.history(0, 12).getOrNull()?.takeIf { it.isNotEmpty() }
|
val history = repository.history(0, 12).getOrNull()?.takeIf { it.isNotEmpty() }
|
||||||
|
|
@ -199,6 +209,24 @@ fun HomeRowsScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (viewModel.subItems.isNotEmpty()) {
|
||||||
|
item {
|
||||||
|
Text(
|
||||||
|
text = "New from your subscriptions",
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
color = Color.White,
|
||||||
|
modifier = Modifier.padding(start = 16.dp, top = 16.dp, bottom = 4.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
item {
|
||||||
|
FocusScrollRow(
|
||||||
|
videos = viewModel.subItems,
|
||||||
|
progressOf = { null },
|
||||||
|
onOpenVideo = onOpenVideo,
|
||||||
|
onLeftAtStart = { },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,12 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.focus.onFocusChanged
|
||||||
|
import androidx.compose.ui.input.key.Key
|
||||||
|
import androidx.compose.ui.input.key.key
|
||||||
|
import androidx.compose.ui.input.key.KeyEventType
|
||||||
|
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||||
|
import androidx.compose.ui.input.key.type
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
|
|
@ -327,12 +333,36 @@ private fun MenuDrawerItem(
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
val labelColor = if (selected) Color(0xFFE0E0E0) else Color(0xFFB0B0B0)
|
val focusManager = androidx.compose.ui.platform.LocalFocusManager.current
|
||||||
|
var focused by remember { mutableStateOf(false) }
|
||||||
|
val labelColor = when {
|
||||||
|
focused -> Color(0xFF101010)
|
||||||
|
selected -> Color(0xFFE0E0E0)
|
||||||
|
else -> Color(0xFFB0B0B0)
|
||||||
|
}
|
||||||
Row(
|
Row(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.then(if (selected) Modifier.background(Color(0x33CE2B2B)) else Modifier)
|
.onFocusChanged { focused = it.isFocused }
|
||||||
|
.background(
|
||||||
|
when {
|
||||||
|
focused -> Color.White
|
||||||
|
selected -> Color(0x33CE2B2B)
|
||||||
|
else -> Color.Transparent
|
||||||
|
}
|
||||||
|
)
|
||||||
.focusable()
|
.focusable()
|
||||||
|
.onPreviewKeyEvent { ke ->
|
||||||
|
when (ke.key) {
|
||||||
|
androidx.compose.ui.input.key.Key.DirectionDown -> {
|
||||||
|
focusManager?.moveFocus(androidx.compose.ui.focus.FocusDirection.Down); true
|
||||||
|
}
|
||||||
|
androidx.compose.ui.input.key.Key.DirectionUp -> {
|
||||||
|
focusManager?.moveFocus(androidx.compose.ui.focus.FocusDirection.Up); true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
.clickable(onClick = onClick)
|
.clickable(onClick = onClick)
|
||||||
.padding(horizontal = 24.dp, vertical = 14.dp),
|
.padding(horizontal = 24.dp, vertical = 14.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue