Skip to content

Commit

Permalink
Feat: Add zoom gesture preference (#521)
Browse files Browse the repository at this point in the history
* feat: add zoom gesture preference

* refactor: change toggle gesture functions signatures
  • Loading branch information
anilbeesetti authored Aug 21, 2023
1 parent c63353e commit dace8af
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ data class PlayerPreferences(
val minDurationForFastSeek: Long = 120000L,
val useSwipeControls: Boolean = true,
val useSeekControls: Boolean = true,
val useZoomControls: Boolean = true,
val rememberSelections: Boolean = true,
val preferredAudioLanguage: String = "",
val playerScreenOrientation: ScreenOrientation = ScreenOrientation.VIDEO_ORIENTATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.material.icons.rounded.Link
import androidx.compose.material.icons.rounded.LocalMovies
import androidx.compose.material.icons.rounded.LocationOn
import androidx.compose.material.icons.rounded.Palette
import androidx.compose.material.icons.rounded.Pinch
import androidx.compose.material.icons.rounded.PlayCircle
import androidx.compose.material.icons.rounded.PriorityHigh
import androidx.compose.material.icons.rounded.Replay10
Expand Down Expand Up @@ -74,6 +75,7 @@ object NextIcons {
val Link = Icons.Rounded.Link
val Location = Icons.Rounded.LocationOn
val Movie = Icons.Rounded.LocalMovies
val Pinch = Icons.Rounded.Pinch
val Player = Icons.Rounded.PlayCircle
val Priority = Icons.Rounded.PriorityHigh
val Replay = Icons.Rounded.Replay10
Expand Down
2 changes: 2 additions & 0 deletions core/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,6 @@
<string name="stretch">Stretch</string>
<string name="crop">Crop</string>
<string name="hundred_percent">100%</string>
<string name="zoom_gesture">Zoom gesture</string>
<string name="zoom_gesture_description">Pinch to zoom the video</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class PlayerGestureHelper(
private val SCALE_RANGE = 0.25f..4.0f

override fun onScale(detector: ScaleGestureDetector): Boolean {
if (!prefs.useZoomControls) return false
if (activity.isControlsLocked) return false

if (currentGestureAction == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ fun PlayerPreferencesScreen(
}
seekGestureSetting(
isChecked = preferences.useSeekControls,
onClick = viewModel::toggleSeekControls
onClick = viewModel::toggleUseSeekControls
)
swipeGestureSetting(
isChecked = preferences.useSwipeControls,
onClick = viewModel::toggleSwipeControls
onClick = viewModel::toggleUseSwipeControls
)
zoomGestureSetting(
isChecked = preferences.useZoomControls,
onClick = viewModel::toggleUseZoomControls
)
doubleTapGestureSetting(
isChecked = (preferences.doubleTapGesture != DoubleTapGesture.NONE),
Expand Down Expand Up @@ -357,6 +361,19 @@ fun LazyListScope.swipeGestureSetting(
)
}

fun LazyListScope.zoomGestureSetting(
isChecked: Boolean,
onClick: () -> Unit
) = item {
PreferenceSwitch(
title = stringResource(id = R.string.zoom_gesture),
description = stringResource(id = R.string.zoom_gesture_description),
icon = NextIcons.Pinch,
isChecked = isChecked,
onClick = onClick
)
}

fun LazyListScope.doubleTapGestureSetting(
isChecked: Boolean,
onChecked: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,43 +110,41 @@ class PlayerPreferencesViewModel @Inject constructor(
}
}

fun toggleSwipeControls() {
fun toggleUseSwipeControls() {
viewModelScope.launch {
preferencesRepository.updatePlayerPreferences {
it.copy(useSwipeControls = !it.useSwipeControls)
}
}
}

fun toggleRememberSelections() {
fun toggleUseSeekControls() {
viewModelScope.launch {
preferencesRepository.updatePlayerPreferences {
it.copy(rememberSelections = !it.rememberSelections)
it.copy(useSeekControls = !it.useSeekControls)
}
}
}

fun toggleSeekControls() {
fun toggleUseZoomControls() {
viewModelScope.launch {
preferencesRepository.updatePlayerPreferences {
it.copy(useSeekControls = !it.useSeekControls)
it.copy(useZoomControls = !it.useZoomControls)
}
}
}

fun updateAudioLanguage(value: String) {
fun toggleRememberSelections() {
viewModelScope.launch {
preferencesRepository.updatePlayerPreferences { it.copy(preferredAudioLanguage = value) }
preferencesRepository.updatePlayerPreferences {
it.copy(rememberSelections = !it.rememberSelections)
}
}
}

fun updateSubtitleLanguage(value: String) {
fun updateAudioLanguage(value: String) {
viewModelScope.launch {
preferencesRepository.updatePlayerPreferences {
it.copy(
preferredSubtitleLanguage = value
)
}
preferencesRepository.updatePlayerPreferences { it.copy(preferredAudioLanguage = value) }
}
}

Expand Down

0 comments on commit dace8af

Please sign in to comment.