From c15ff1c5640b7b5cea0506319972f26f000a4c1c Mon Sep 17 00:00:00 2001
From: Quickdesh <36792807+Quickdesh@users.noreply.github.com>
Date: Wed, 6 Apr 2022 20:39:43 +0900
Subject: [PATCH] Add option to lock controls in mpv player (#491)
---
.../eu/kanade/tachiyomi/ui/player/Gestures.kt | 2 ++
.../tachiyomi/ui/player/PlayerActivity.kt | 16 ++++++++++++++-
app/src/main/res/layout/player_activity.xml | 20 ++++++++++++++++++-
3 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/Gestures.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/Gestures.kt
index ef54578eec..028c48f485 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/Gestures.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/Gestures.kt
@@ -44,6 +44,7 @@ class Gestures(
}
override fun onDoubleTap(e: MotionEvent): Boolean {
+ if (activity.isLocked) return false
if (e.y < height * 0.05F || e.y > height * 0.95F) return false
val interval = preferences.skipLengthPreference()
when {
@@ -60,6 +61,7 @@ class Gestures(
distanceX: Float,
distanceY: Float
): Boolean {
+ if (activity.isLocked) return false
if (e1.y < height * 0.05F || e1.y > height * 0.95F) return false
val dx = e1.x - e2.x
val dy = e1.y - e2.y
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt
index 77341d47e4..aedefa7ecf 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt
@@ -80,6 +80,8 @@ class PlayerActivity :
private var width = 0
private var height = 0
+ internal var isLocked = false
+
private var audioFocusRestore: () -> Unit = {}
private val audioFocusChangeListener = AudioManager.OnAudioFocusChangeListener { type ->
@@ -247,6 +249,12 @@ class PlayerActivity :
gestures.onTouch(v, event)
mDetector.onTouchEvent(event)
}
+
+ // Lock and Unlock controls
+ binding.lockControls.setOnClickListener { isLocked = true; toggleControls() }
+ binding.unlockControls.setOnClickListener { isLocked = false; toggleControls() }
+
+ // Cycle, Long click controls
binding.cycleAudioBtn.setOnLongClickListener { pickAudio(); true }
binding.cycleSpeedBtn.setOnLongClickListener { pickSpeed(); true }
binding.cycleSubsBtn.setOnLongClickListener { pickSub(); true }
@@ -271,7 +279,13 @@ class PlayerActivity :
}
fun toggleControls() {
- binding.controls.isVisible = !binding.controls.isVisible
+ if (isLocked) {
+ binding.unlockControls.isVisible = !binding.unlockControls.isVisible
+ binding.controls.isVisible = false
+ } else {
+ binding.unlockControls.isVisible = false
+ binding.controls.isVisible = !binding.controls.isVisible
+ }
}
private fun pickAudio() {
diff --git a/app/src/main/res/layout/player_activity.xml b/app/src/main/res/layout/player_activity.xml
index 44b0a93d50..451a01ba43 100644
--- a/app/src/main/res/layout/player_activity.xml
+++ b/app/src/main/res/layout/player_activity.xml
@@ -13,6 +13,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
+
+
-
+