Skip to content

Commit

Permalink
Add option to lock controls in mpv player (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
quickdesh authored Apr 6, 2022
1 parent 895e822 commit c15ff1c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/eu/kanade/tachiyomi/ui/player/Gestures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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 }
Expand All @@ -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() {
Expand Down
20 changes: 19 additions & 1 deletion app/src/main/res/layout/player_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />

<ImageButton
android:layout_marginHorizontal="5dp"
android:id="@+id/unlockControls"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/ic_lock_open_24dp"
android:visibility="gone"
android:background="?attr/selectableItemBackgroundBorderless"
app:tint="?attr/colorOnPrimarySurface" />

<!-- This LinearLayout only exists to prevent clipping -->
<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -180,7 +190,15 @@
android:gravity="center"
android:orientation="horizontal">


<ImageButton
android:layout_marginHorizontal="5dp"
android:id="@+id/lockControls"
android:layout_width="48dp"
android:layout_height="match_parent"
android:onClick="cycleAudio"
android:src="@drawable/ic_lock_24dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:tint="?attr/colorOnPrimarySurface" />

<ImageButton
android:layout_marginHorizontal="5dp"
Expand Down

0 comments on commit c15ff1c

Please sign in to comment.