Skip to content

Commit

Permalink
fix no tv start option, fix crash on tv when clicking cast button, ad…
Browse files Browse the repository at this point in the history
…ded volume slider on desktop
  • Loading branch information
DatL4g committed Dec 17, 2023
1 parent b204d4d commit 7829595
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 56 deletions.
4 changes: 3 additions & 1 deletion app/android/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:banner="@mipmap/tv_banner"
android:supportsRtl="true"
android:theme="@style/SplashScreenTheme"
android:name=".App"
Expand All @@ -40,6 +41,7 @@
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>

Expand All @@ -49,7 +51,7 @@

<receiver
android:name="androidx.mediarouter.media.MediaTransferReceiver"
android:exported="true"></receiver>
android:exported="true" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ actual fun SystemProvider(content: @Composable () -> Unit) {
}

@Composable
actual fun isTv(): Boolean {
actual fun rememberIsTv(): Boolean {
val context = LocalContext.current
return remember { context.isTv() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import dev.datlag.burningseries.shared.common.findWindow
import dev.datlag.burningseries.shared.common.lifecycle.collectAsStateWithLifecycle
import dev.datlag.burningseries.shared.common.withIOContext
import dev.datlag.burningseries.shared.common.withMainContext
import dev.datlag.burningseries.shared.rememberIsTv
import dev.datlag.burningseries.shared.ui.*
import dev.datlag.kast.ConnectionState
import dev.datlag.kast.Kast
Expand Down Expand Up @@ -324,6 +325,7 @@ actual fun VideoScreen(component: VideoComponent) {

val progressColor = MaterialTheme.colorScheme.primary.toArgb()
val episode by component.episode.collectAsStateWithLifecycle()
val isTv = rememberIsTv()

AndroidView(
modifier = Modifier.fillMaxSize().background(Color.Black),
Expand Down Expand Up @@ -354,6 +356,12 @@ actual fun VideoScreen(component: VideoComponent) {
usingPlayer.pause()
component.selectCast()
}
mediaRouteButton.visibility = if (isTv) {
View.GONE
} else {
View.VISIBLE
}
mediaRouteButton.isEnabled = !isTv

subtitleButton.setOnClickListener {
playerView.player?.pause()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ actual fun CastDialog(component: CastComponent) {
icon = {
Icon(
imageVector = Icons.Default.Cast,
contentDescription = null
contentDescription = stringResource(SharedRes.strings.casting)
)
},
title = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ fun App(
expect fun SystemProvider(content: @Composable () -> Unit)

@Composable
expect fun isTv(): Boolean
expect fun rememberIsTv(): Boolean
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package dev.datlag.burningseries.shared.common

import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.focusable
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.waitForUpOrCancellation
Expand All @@ -16,13 +12,11 @@ import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridItemScope
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.material3.ColorScheme
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.vector.PathBuilder
import androidx.compose.ui.input.pointer.pointerInput
Expand Down Expand Up @@ -112,13 +106,13 @@ fun LazyListState.OnBottomReached(enabled: Boolean = true, buffer: Int = 0, bloc
}
}

@Composable
fun Modifier.isFocused(
hoverable: Boolean = true,
focusable: Boolean = true,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
builder: Modifier.() -> Modifier
): Modifier = composed {
val interactionSource = remember { MutableInteractionSource() }

val isHovered by interactionSource.collectIsHoveredAsState()
val isFocused by interactionSource.collectIsFocusedAsState()

Expand All @@ -133,14 +127,42 @@ fun Modifier.isFocused(
)
}

@Composable
fun Modifier.onFocusChanged(
hoverable: Boolean = true,
focusable: Boolean = true,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
onChanged: (Boolean) -> Unit
): Modifier = composed {
val isHovered by interactionSource.collectIsHoveredAsState()
val isFocused by interactionSource.collectIsFocusedAsState()

val latestValue = remember(isHovered, isFocused) { isHovered || isFocused }

LaunchedEffect(latestValue) {
onChanged(latestValue)
}

this.hoverable(
interactionSource = interactionSource,
enabled = hoverable
).focusable(
interactionSource = interactionSource,
enabled = focusable
)
}

@Composable
fun Modifier.focusScale(
scale: Float = 1.1F,
hoverable: Boolean = true,
focusable: Boolean = true
focusable: Boolean = true,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }
) = composed {
isFocused(
hoverable,
focusable
focusable,
interactionSource
) {
graphicsLayer {
scaleX = scale
Expand All @@ -149,32 +171,6 @@ fun Modifier.focusScale(
}
}

@Composable
fun ColorScheme.animate(spec: AnimationSpec<Color> = spring(stiffness = Spring.StiffnessLow)): ColorScheme {
return this.copy(
primary = animateColorAsState(this.primary, spec).value,
onPrimary = animateColorAsState(this.onPrimary, spec).value,
primaryContainer = animateColorAsState(this.primaryContainer, spec).value,
onPrimaryContainer = animateColorAsState(this.onPrimaryContainer, spec).value,
secondary = animateColorAsState(this.secondary, spec).value,
onSecondary = animateColorAsState(this.onSecondary, spec).value,
secondaryContainer = animateColorAsState(this.secondaryContainer, spec).value,
onSecondaryContainer = animateColorAsState(this.onSecondaryContainer, spec).value,
tertiary = animateColorAsState(this.tertiary, spec).value,
onTertiary = animateColorAsState(this.onTertiary, spec).value,
tertiaryContainer = animateColorAsState(this.tertiaryContainer, spec).value,
onTertiaryContainer = animateColorAsState(this.onTertiaryContainer, spec).value,
background = animateColorAsState(this.background, spec).value,
onBackground = animateColorAsState(this.onBackground, spec).value,
surface = animateColorAsState(this.surface, spec).value,
onSurface = animateColorAsState(this.onSurface, spec).value,
error = animateColorAsState(this.error, spec).value,
onError = animateColorAsState(this.onError, spec).value,
errorContainer = animateColorAsState(this.errorContainer, spec).value,
onErrorContainer = animateColorAsState(this.onErrorContainer, spec).value
)
}

fun PathBuilder.drawPathFromSvgData(data: String) {
val pathCommands = data.split("(?=[a-zA-Z])".toRegex()).filterNot { it.isBlank() }
val numberRegex = "[-+]?\\d*\\.?\\d+".toRegex()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.extensions.compose.jetbrains.pages.Pages
import com.moriatsushi.insetsx.ExperimentalSoftwareKeyboardApi
import dev.datlag.burningseries.shared.common.lifecycle.collectAsStateWithLifecycle
import dev.datlag.burningseries.shared.isTv
import dev.datlag.burningseries.shared.rememberIsTv
import dev.datlag.burningseries.shared.ui.custom.ExpandedPages
import dev.icerock.moko.resources.compose.stringResource

Expand All @@ -29,7 +29,7 @@ fun InitialScreen(component: InitialComponent) {
WindowWidthSizeClass.Compact -> CompactScreen(component)
WindowWidthSizeClass.Medium -> MediumScreen(component)
WindowWidthSizeClass.Expanded -> {
if (isTv()) {
if (rememberIsTv()) {
MediumScreen(component)
} else {
ExpandedScreen(component)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import dev.datlag.burningseries.shared.SharedRes
import dev.datlag.burningseries.shared.common.header
import dev.datlag.burningseries.shared.common.lifecycle.collectAsStateWithLifecycle
import dev.datlag.burningseries.shared.common.onClick
import dev.datlag.burningseries.shared.isTv
import dev.datlag.burningseries.shared.rememberIsTv
import dev.datlag.burningseries.shared.ui.custom.VerticalScrollbar
import dev.datlag.burningseries.shared.ui.custom.rememberScrollbarAdapter
import dev.datlag.burningseries.shared.ui.screen.initial.home.component.SeriesItem
Expand All @@ -37,7 +37,7 @@ import dev.icerock.moko.resources.compose.stringResource
fun FavoriteScreen(component: FavoriteComponent) {
when (calculateWindowSizeClass().widthSizeClass) {
WindowWidthSizeClass.Expanded -> {
if (isTv()) {
if (rememberIsTv()) {
DefaultView(component)
} else {
ExpandedView(component)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.material.icons.Icons
import androidx.compose.material3.*
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
Expand All @@ -23,8 +22,8 @@ import dev.datlag.burningseries.model.state.HomeState
import dev.datlag.burningseries.shared.SharedRes
import dev.datlag.burningseries.shared.common.header
import dev.datlag.burningseries.shared.common.lifecycle.collectAsStateWithLifecycle
import dev.datlag.burningseries.shared.isTv
import dev.datlag.burningseries.shared.other.StateSaver
import dev.datlag.burningseries.shared.rememberIsTv
import dev.datlag.burningseries.shared.ui.custom.VerticalScrollbar
import dev.datlag.burningseries.shared.ui.custom.rememberScrollbarAdapter
import dev.datlag.burningseries.shared.ui.custom.state.ErrorState
Expand Down Expand Up @@ -53,7 +52,7 @@ fun HomeScreen(component: HomeComponent) {
is HomeState.Success -> {
when (calculateWindowSizeClass().widthSizeClass) {
WindowWidthSizeClass.Expanded -> {
if (isTv()) {
if (rememberIsTv()) {
DefaultView(currentState.home, component)
} else {
ExpandedView(currentState.home, component)
Expand Down Expand Up @@ -142,7 +141,7 @@ private fun MainView(home: Home, component: HomeComponent, modifier: Modifier =
) {
Icon(
imageVector = MaterialSymbols.rememberDeployedCodeAlert(),
contentDescription = null
contentDescription = stringResource(SharedRes.strings.sekret_unavailable_title)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import dev.datlag.burningseries.shared.SharedRes
import dev.datlag.burningseries.shared.common.OnBottomReached
import dev.datlag.burningseries.shared.common.lifecycle.collectAsStateWithLifecycle
import dev.datlag.burningseries.shared.common.onClick
import dev.datlag.burningseries.shared.isTv
import dev.datlag.burningseries.shared.rememberIsTv
import dev.datlag.burningseries.shared.ui.custom.VerticalScrollbar
import dev.datlag.burningseries.shared.ui.custom.rememberScrollbarAdapter
import dev.datlag.burningseries.shared.ui.custom.state.ErrorState
Expand All @@ -54,7 +54,7 @@ fun SearchScreen(component: SearchComponent) {
is SearchState.Success -> {
when (calculateWindowSizeClass().widthSizeClass) {
WindowWidthSizeClass.Expanded -> {
if (isTv()) {
if (rememberIsTv()) {
DefaultView(component)
} else {
ExpandedView(component)
Expand Down
2 changes: 2 additions & 0 deletions app/shared/src/commonMain/resources/MR/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@
<string name="github">GitHub</string>
<string name="sekret_unavailable_title">Sekret unavailable</string>
<string name="sekret_unavailable_text">Some features do not work currently.\nYou should restart the app and check if this issue persists.</string>
<string name="muted">Muted</string>
<string name="unmuted">Unmuted</string>
</resources>
4 changes: 4 additions & 0 deletions app/shared/src/commonMain/resources/MR/de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@
<string name="release_available_title">Neue Version verfügbar</string>
<string name="release_available_text">Eine neue Version ist verfügbar "%s".\nDas solltest du dir ansehen!</string>
<string name="github">GitHub</string>
<string name="sekret_unavailable_title">Sekret nicht verfügbar</string>
<string name="sekret_unavailable_text">Einige Funktionen sind momentan nicht verfügbar.\nDu solltest die App neu starten und prüfen, ob das Problem bestehen bleibt.</string>
<string name="muted">Stumm</string>
<string name="unmuted">Nicht stumm</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import androidx.compose.foundation.LocalContextMenuRepresentation
import androidx.compose.foundation.text.LocalTextContextMenu
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.awt.ComposeWindow
import com.dzirbel.contextmenu.ContextMenuColors
Expand Down Expand Up @@ -35,6 +37,6 @@ fun ContextMenuColors(scheme: ColorScheme = MaterialTheme.colorScheme) = Context
)

@Composable
actual fun isTv(): Boolean {
actual fun rememberIsTv(): Boolean {
return false
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package dev.datlag.burningseries.shared.ui.screen.video

import androidx.compose.runtime.MutableFloatState
import androidx.compose.runtime.MutableLongState
import androidx.compose.runtime.MutableState

interface MediaPlayer {
val isPlaying: MutableState<Boolean>
val time: MutableLongState
val length: MutableLongState
val isMuted: MutableState<Boolean>
val volume: MutableFloatState
fun play()
fun pause()
fun rewind()
fun forward()
fun seekTo(millis: Long)
fun mute()
fun unmute()
fun setVolume(volume: Float)
}
Loading

0 comments on commit 7829595

Please sign in to comment.