Skip to content

Commit

Permalink
feat: implement forward/rewind clickable component
Browse files Browse the repository at this point in the history
Closes #15
  • Loading branch information
Thalys Matias Carrara committed Jun 7, 2023
1 parent 0a7cd07 commit 3c4e1b7
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.profusion.androidenhancedvideoplayer.components.playerOverlay

import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.profusion.androidenhancedvideoplayer.R

@Composable
fun SeekClickableArea(
modifier: Modifier = Modifier,
scaleAnimation: Float,
seekState: Boolean,
onSeekSingleTap: () -> Unit,
onSeekDoubleTap: () -> Unit,
toggleIsControlsVisible: () -> Unit,
getSeekTime: () -> Int,
seekIcon: @Composable (modifier: Modifier) -> Unit
) {
Box(
modifier = modifier
.fillMaxHeight()
.pointerInput(seekState) {
detectTapGestures(
onTap = when (seekState) {
true -> { _ -> onSeekSingleTap() }
false -> { _ -> toggleIsControlsVisible() }
},
onDoubleTap = when (seekState) {
true -> null
false -> { _ -> onSeekDoubleTap() }
}
)
}.testTag("SeekClickableArea"),
contentAlignment = Alignment.Center
) {
val timeLabel = getSeekTime()
val timeUnit = stringResource(id = R.string.controls_time_unit)
if (seekState) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
seekIcon(modifier = Modifier.scale(scaleAnimation))
Spacer(modifier = Modifier.height(20.dp))
Text(
text = "$timeLabel $timeUnit",
maxLines = 2
)
}
}
}
}

0 comments on commit 3c4e1b7

Please sign in to comment.