Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix focus issues on older Android versions #4376

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions app/src/main/java/org/jellyfin/androidtv/ui/NowPlayingView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -50,7 +51,9 @@
import org.koin.compose.koinInject

@Composable
fun NowPlayingComposable() {
fun NowPlayingComposable(

Check warning

Code scanning / detekt

One method should have one responsibility. Long methods tend to handle many things at once. Prefer smaller methods to make them easier to understand. Warning

The function NowPlayingComposable is too long (88). The maximum length is 60.
onFocusableChange: (focusable: Boolean) -> Unit,
) {
val playbackManager = koinInject<PlaybackManager>()
val navigationRepository = koinInject<NavigationRepository>()
val imageHelper = koinInject<ImageHelper>()
Expand All @@ -59,6 +62,8 @@
val item = entry?.run { baseItemFlow.collectAsState(baseItem) }?.value
val progress = rememberPlayerProgress(playbackManager)

LaunchedEffect(item == null) { onFocusableChange(item != null) }

AnimatedVisibility(
visible = item != null,
enter = fadeIn(),
Expand Down Expand Up @@ -153,5 +158,11 @@
defStyle: Int = 0
) : AbstractComposeView(context, attrs, defStyle) {
@Composable
override fun Content() = NowPlayingComposable()
override fun Content() = NowPlayingComposable(
// Workaround for older Android versions unable to find focus in our toolbar view when the NowPlayingView is added but inactive
onFocusableChange = { focusable ->
isFocusable = focusable
descendantFocusability = if (focusable) FOCUS_AFTER_DESCENDANTS else FOCUS_BLOCK_DESCENDANTS
}
)
}
4 changes: 3 additions & 1 deletion app/src/main/res/layout/fragment_select_server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
<androidx.compose.ui.platform.ComposeView
android:id="@+id/notifications"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:focusable="false" />

<LinearLayout
android:layout_width="match_parent"
Expand Down
Loading