-
-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "ask to skip" media segment action
- Loading branch information
1 parent
4f23ad4
commit 0537a20
Showing
9 changed files
with
213 additions
and
5 deletions.
There are no files selected for viewing
10 changes: 8 additions & 2 deletions
10
app/src/main/java/org/jellyfin/androidtv/ui/composable/overscan.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
package org.jellyfin.androidtv.ui.composable | ||
|
||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
|
||
/** | ||
* Apply a [padding] with the default overscan values of 48 horizontal and 27 vertical display pixels. | ||
* Default overscan values of 48 horizontal and 27 vertical display pixels. | ||
*/ | ||
fun Modifier.overscan(): Modifier = then(padding(48.dp, 27.dp)) | ||
val overscanPaddingValues = PaddingValues(48.dp, 27.dp) | ||
|
||
/** | ||
* Apply a [padding] with [overscanPaddingValues]. | ||
*/ | ||
fun Modifier.overscan(): Modifier = padding(overscanPaddingValues) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
app/src/main/java/org/jellyfin/androidtv/ui/playback/overlay/SkipOverlayView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package org.jellyfin.androidtv.ui.playback.overlay | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import androidx.compose.animation.AnimatedVisibility | ||
import androidx.compose.animation.fadeIn | ||
import androidx.compose.animation.fadeOut | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.padding | ||
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.derivedStateOf | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.platform.AbstractComposeView | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.tv.material3.Text | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import org.jellyfin.androidtv.R | ||
import org.jellyfin.androidtv.ui.playback.segment.MediaSegmentRepository | ||
import kotlin.time.Duration | ||
import kotlin.time.Duration.Companion.milliseconds | ||
|
||
@Composable | ||
fun SkipOverlayComposable( | ||
visible: Boolean, | ||
) { | ||
Box( | ||
contentAlignment = Alignment.BottomEnd, | ||
modifier = Modifier | ||
.padding(48.dp, 48.dp) | ||
) { | ||
AnimatedVisibility(visible, enter = fadeIn(), exit = fadeOut()) { | ||
Row( | ||
modifier = Modifier | ||
.clip(RoundedCornerShape(6.dp)) | ||
.background(colorResource(R.color.popup_menu_background).copy(alpha = 0.6f)) | ||
.padding(10.dp), | ||
horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
Image( | ||
painter = painterResource(R.drawable.ic_control_select), | ||
contentDescription = null, | ||
) | ||
|
||
Text( | ||
text = stringResource(R.string.segment_action_skip), | ||
color = colorResource(R.color.button_default_normal_text), | ||
fontSize = 18.sp, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
class SkipOverlayView @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyle: Int = 0 | ||
) : AbstractComposeView(context, attrs, defStyle) { | ||
private val _currentPosition = MutableStateFlow(Duration.ZERO) | ||
private val _targetPosition = MutableStateFlow<Duration?>(null) | ||
private val _skipUiEnabled = MutableStateFlow(true) | ||
|
||
var currentPosition: Duration | ||
get() = _currentPosition.value | ||
set(value) { | ||
_currentPosition.value = value | ||
} | ||
|
||
var currentPositionMs: Long | ||
get() = _currentPosition.value.inWholeMilliseconds | ||
set(value) { | ||
_currentPosition.value = value.milliseconds | ||
} | ||
|
||
var targetPosition: Duration? | ||
get() = _targetPosition.value | ||
set(value) { | ||
_targetPosition.value = value | ||
} | ||
|
||
var targetPositionMs: Long? | ||
get() = _targetPosition.value?.inWholeMilliseconds | ||
set(value) { | ||
_targetPosition.value = value?.milliseconds | ||
} | ||
|
||
var skipUiEnabled: Boolean | ||
get() = _skipUiEnabled.value | ||
set(value) { | ||
_skipUiEnabled.value = value | ||
} | ||
|
||
val visible: Boolean | ||
get() { | ||
val enabled = _skipUiEnabled.value | ||
val targetPosition = _targetPosition.value | ||
val currentPosition = _currentPosition.value | ||
|
||
return enabled && targetPosition != null && currentPosition <= (targetPosition - MediaSegmentRepository.SkipMinDuration) | ||
} | ||
|
||
@Composable | ||
override fun Content() { | ||
val skipUiEnabled by _skipUiEnabled.collectAsState() | ||
val currentPosition by _currentPosition.collectAsState() | ||
val targetPosition by _targetPosition.collectAsState() | ||
|
||
val visible by remember(skipUiEnabled, currentPosition, targetPosition) { | ||
derivedStateOf { visible } | ||
} | ||
|
||
// Auto hide | ||
LaunchedEffect(skipUiEnabled, targetPosition) { | ||
delay(MediaSegmentRepository.AskToSkipAutoHideDuration) | ||
_targetPosition.value = null | ||
} | ||
|
||
SkipOverlayComposable(visible) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters