Skip to content

Commit

Permalink
fix(gestures): use safe gestures insets
Browse files Browse the repository at this point in the history
 * hide systemui automatically
  • Loading branch information
abdallahmehiz committed Aug 1, 2024
1 parent 6c50703 commit 84e0025
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.ui.layout.boundsInWindow
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.lifecycleScope
import androidx.media.AudioAttributesCompat
Expand Down Expand Up @@ -157,6 +158,8 @@ class PlayerActivity : AppCompatActivity() {
setPictureInPictureParams(createPipParams())
}
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
windowInsetsController.hide(WindowInsetsCompat.Type.navigationBars())
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
super.onStart()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import androidx.compose.foundation.indication
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.PressInteraction
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.safeGestures
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.material.ripple.LocalRippleTheme
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -49,7 +52,7 @@ import live.mehiz.mpvkt.ui.player.controls.components.DoubleTapSeekSecondsView
import live.mehiz.mpvkt.ui.theme.PlayerRippleTheme
import org.koin.compose.koinInject

@Suppress("CyclomaticComplexMethod")
@Suppress("CyclomaticComplexMethod", "MultipleEmitters")
@Composable
fun GestureHandler(modifier: Modifier = Modifier) {
val viewModel = koinInject<PlayerViewModel>()
Expand Down Expand Up @@ -102,8 +105,9 @@ fun GestureHandler(modifier: Modifier = Modifier) {
val currentBrightness by viewModel.currentBrightness.collectAsState()
val haptics = LocalHapticFeedback.current
Box(
modifier = modifier
modifier = Modifier
.fillMaxSize()
.windowInsetsPadding(WindowInsets.safeGestures)
.pointerInput(Unit) {
detectTapGestures(
onTap = {
Expand Down Expand Up @@ -217,6 +221,9 @@ fun GestureHandler(modifier: Modifier = Modifier) {
}
}
},
)
Box(
modifier = modifier.fillMaxSize(),
contentAlignment = if (isSeekingForwards) Alignment.CenterEnd else Alignment.CenterStart,
) {
CompositionLocalProvider(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package live.mehiz.mpvkt.ui.player.controls.components.sheets.subtitles

import androidx.annotation.StringRes
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.BorderColor
import androidx.compose.material.icons.filled.FormatColorFill
Expand Down Expand Up @@ -68,12 +69,15 @@ fun SubtitleSettingsColorsCard(
Column {
var currentColorType by remember { mutableStateOf(SubColorType.Text) }
var currentColor by remember { mutableIntStateOf(preferences.textColor.get()) }
LazyRow(
Row(
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(start = 4.dp, end = 16.dp),
modifier = Modifier
.fillMaxWidth()
.horizontalScroll(rememberScrollState())
.padding(start = 4.dp, end = 16.dp),
) {
items(SubColorType.entries) { type ->
SubColorType.entries.forEach { type ->
IconToggleButton(
checked = currentColorType == type,
onCheckedChange = {
Expand All @@ -95,14 +99,12 @@ fun SubtitleSettingsColorsCard(
)
}
}
item { Text(stringResource(currentColorType.titleRes)) }
item {
Spacer(Modifier.weight(1f))
TextButton(onClick = { resetColors(preferences) }) {
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
Icon(Icons.Default.FormatColorReset, null)
Text(stringResource(R.string.generic_reset))
}
Text(stringResource(currentColorType.titleRes))
Spacer(Modifier.weight(1f))
TextButton(onClick = { resetColors(preferences) }) {
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
Icon(Icons.Default.FormatColorReset, null)
Text(stringResource(R.string.generic_reset))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.pager.HorizontalPager
Expand Down Expand Up @@ -53,11 +52,7 @@ fun SubtitleSettingsSheet(

val orientation = LocalConfiguration.current.orientation

ConstraintLayout(
modifier = modifier
.fillMaxSize()
.windowInsetsPadding(WindowInsets.systemBars),
) {
ConstraintLayout(modifier = modifier.fillMaxSize()) {
val vposSlider = createRef()
val subSettingsCards = createRef()
val cards: @Composable (Int) -> Unit = {
Expand Down Expand Up @@ -154,7 +149,7 @@ val CARDS_MAX_WIDTH = 420.dp
val SubtitleSettingsCardColors: @Composable () -> CardColors = {
val colors = CardDefaults.cardColors()
colors.copy(
containerColor = colors.containerColor.copy(0.8f),
disabledContainerColor = colors.disabledContainerColor.copy(0.8f),
containerColor = colors.containerColor.copy(0.6f),
disabledContainerColor = colors.disabledContainerColor.copy(0.6f),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package live.mehiz.mpvkt.ui.player.controls.components.sheets.subtitles

import android.annotation.SuppressLint
import android.net.Uri
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.BorderColor
import androidx.compose.material.icons.filled.FormatBold
Expand Down Expand Up @@ -102,41 +103,40 @@ fun SubtitleSettingsTypographyCard(
val isBold by preferences.bold.collectAsState()
val isItalic by preferences.italic.collectAsState()
val justify by preferences.justification.collectAsState()
LazyRow(
Modifier.padding(start = 4.dp, end = 16.dp),
Row(
Modifier
.fillMaxWidth()
.horizontalScroll(rememberScrollState())
.padding(start = 4.dp, end = 16.dp),
verticalAlignment = Alignment.CenterVertically,
) {
item {
IconToggleButton(
checked = isBold,
onCheckedChange = {
preferences.bold.set(it)
MPVLib.setPropertyBoolean("sub-bold", it)
},
) {
Icon(
Icons.Default.FormatBold,
null,
modifier = Modifier.size(32.dp),
)
}
IconToggleButton(
checked = isBold,
onCheckedChange = {
preferences.bold.set(it)
MPVLib.setPropertyBoolean("sub-bold", it)
},
) {
Icon(
Icons.Default.FormatBold,
null,
modifier = Modifier.size(32.dp),
)
}
item {
IconToggleButton(
checked = isItalic,
onCheckedChange = {
preferences.italic.set(it)
MPVLib.setPropertyBoolean("sub-italic", it)
},
) {
Icon(
Icons.Default.FormatItalic,
null,
modifier = Modifier.size(32.dp),
)
}
IconToggleButton(
checked = isItalic,
onCheckedChange = {
preferences.italic.set(it)
MPVLib.setPropertyBoolean("sub-italic", it)
},
) {
Icon(
Icons.Default.FormatItalic,
null,
modifier = Modifier.size(32.dp),
)
}
items(SubtitleJustification.entries.minus(SubtitleJustification.Auto)) { justification ->
SubtitleJustification.entries.minus(SubtitleJustification.Auto).forEach { justification ->
IconToggleButton(
checked = justify.value == justification.value,
onCheckedChange = {
Expand All @@ -152,13 +152,11 @@ fun SubtitleSettingsTypographyCard(
Icon(justification.icon, null)
}
}
item {
Spacer(Modifier.weight(1f))
TextButton(onClick = { resetTypography(preferences) }) {
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
Icon(Icons.Default.FormatClear, null)
Text(stringResource(R.string.generic_reset))
}
Spacer(Modifier.weight(1f))
TextButton(onClick = { resetTypography(preferences) }) {
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
Icon(Icons.Default.FormatClear, null)
Text(stringResource(R.string.generic_reset))
}
}
}
Expand Down

0 comments on commit 84e0025

Please sign in to comment.