From dace8af0a098678080a235de050ebe2a4f857a91 Mon Sep 17 00:00:00 2001
From: Anil Kumar Beesetti <66936649+anilbeesetti@users.noreply.github.com>
Date: Mon, 21 Aug 2023 11:40:25 +0530
Subject: [PATCH] Feat: Add zoom gesture preference (#521)
* feat: add zoom gesture preference
* refactor: change toggle gesture functions signatures
---
.../core/model/PlayerPreferences.kt | 1 +
.../core/ui/designsystem/NextIcons.kt | 2 ++
core/ui/src/main/res/values/strings.xml | 2 ++
.../player/utils/PlayerGestureHelper.kt | 1 +
.../screens/player/PlayerPreferencesScreen.kt | 21 ++++++++++++++--
.../player/PlayerPreferencesViewModel.kt | 24 +++++++++----------
6 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/PlayerPreferences.kt b/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/PlayerPreferences.kt
index 47972b326..6a316cb7e 100644
--- a/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/PlayerPreferences.kt
+++ b/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/PlayerPreferences.kt
@@ -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,
diff --git a/core/ui/src/main/java/dev/anilbeesetti/nextplayer/core/ui/designsystem/NextIcons.kt b/core/ui/src/main/java/dev/anilbeesetti/nextplayer/core/ui/designsystem/NextIcons.kt
index 8d5b827f5..a563b89b8 100644
--- a/core/ui/src/main/java/dev/anilbeesetti/nextplayer/core/ui/designsystem/NextIcons.kt
+++ b/core/ui/src/main/java/dev/anilbeesetti/nextplayer/core/ui/designsystem/NextIcons.kt
@@ -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
@@ -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
diff --git a/core/ui/src/main/res/values/strings.xml b/core/ui/src/main/res/values/strings.xml
index 78f0cef85..9daa60793 100644
--- a/core/ui/src/main/res/values/strings.xml
+++ b/core/ui/src/main/res/values/strings.xml
@@ -147,4 +147,6 @@
Stretch
Crop
100%
+ Zoom gesture
+ Pinch to zoom the video
\ No newline at end of file
diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/utils/PlayerGestureHelper.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/utils/PlayerGestureHelper.kt
index a5bac6c11..5c7d72629 100644
--- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/utils/PlayerGestureHelper.kt
+++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/utils/PlayerGestureHelper.kt
@@ -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) {
diff --git a/feature/settings/src/main/java/dev/anilbeesetti/nextplayer/settings/screens/player/PlayerPreferencesScreen.kt b/feature/settings/src/main/java/dev/anilbeesetti/nextplayer/settings/screens/player/PlayerPreferencesScreen.kt
index c8d72e2c1..f9d22b20f 100644
--- a/feature/settings/src/main/java/dev/anilbeesetti/nextplayer/settings/screens/player/PlayerPreferencesScreen.kt
+++ b/feature/settings/src/main/java/dev/anilbeesetti/nextplayer/settings/screens/player/PlayerPreferencesScreen.kt
@@ -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),
@@ -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,
diff --git a/feature/settings/src/main/java/dev/anilbeesetti/nextplayer/settings/screens/player/PlayerPreferencesViewModel.kt b/feature/settings/src/main/java/dev/anilbeesetti/nextplayer/settings/screens/player/PlayerPreferencesViewModel.kt
index 58c77d28c..7ac8681e9 100644
--- a/feature/settings/src/main/java/dev/anilbeesetti/nextplayer/settings/screens/player/PlayerPreferencesViewModel.kt
+++ b/feature/settings/src/main/java/dev/anilbeesetti/nextplayer/settings/screens/player/PlayerPreferencesViewModel.kt
@@ -110,7 +110,7 @@ class PlayerPreferencesViewModel @Inject constructor(
}
}
- fun toggleSwipeControls() {
+ fun toggleUseSwipeControls() {
viewModelScope.launch {
preferencesRepository.updatePlayerPreferences {
it.copy(useSwipeControls = !it.useSwipeControls)
@@ -118,35 +118,33 @@ class PlayerPreferencesViewModel @Inject constructor(
}
}
- 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) }
}
}