-
-
Notifications
You must be signed in to change notification settings - Fork 518
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
Add "ask to skip" media segment action #4068
Merged
nielsvanvelzen
merged 1 commit into
jellyfin:master
from
nielsvanvelzen:media-segments-ask-to-skip
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / Android Lint
Unknown nullness Note