From 6fe27427705255dbbf394c121ee492b28e571d4c Mon Sep 17 00:00:00 2001 From: Blatzar <46196380+Blatzar@users.noreply.github.com> Date: Wed, 8 Jun 2022 20:15:24 +0200 Subject: [PATCH] Added keyboard shortcuts (O or NUMPAD_8) to open online subtitle searcher :) --- .../com/lagradost/cloudstream3/CommonActivity.kt | 4 ++++ .../cloudstream3/ui/player/FullScreenPlayer.kt | 14 ++++++++++++++ .../cloudstream3/ui/player/GeneratorPlayer.kt | 11 ++++++----- .../lagradost/cloudstream3/ui/player/IPlayer.kt | 1 + 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt index 0854a7bb..58d36b1a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/CommonActivity.kt @@ -282,6 +282,10 @@ object CommonActivity { KeyEvent.KEYCODE_S, KeyEvent.KEYCODE_NUMPAD_9 -> { PlayerEventType.ShowMirrors } + // OpenSubtitles shortcut + KeyEvent.KEYCODE_O, KeyEvent.KEYCODE_NUMPAD_8 -> { + PlayerEventType.SearchSubtitlesOnline + } KeyEvent.KEYCODE_E, KeyEvent.KEYCODE_NUMPAD_3 -> { PlayerEventType.ShowSpeed } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt index 66a7e6fb..a5e6a416 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/FullScreenPlayer.kt @@ -38,6 +38,7 @@ import com.lagradost.cloudstream3.CommonActivity.keyEventListener import com.lagradost.cloudstream3.CommonActivity.playerEventListener import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.mvvm.logError +import com.lagradost.cloudstream3.ui.player.GeneratorPlayer.Companion.subsProvidersIsActive import com.lagradost.cloudstream3.utils.Qualities import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute @@ -138,6 +139,14 @@ open class FullScreenPlayer : AbstractPlayerFragment() { throw NotImplementedError() } + open fun openOnlineSubPicker( + context: Context, + imdbId: Long?, + dismissCallback: (() -> Unit) + ) { + throw NotImplementedError() + } + /** Returns false if the touch is on the status bar or navigation bar*/ private fun isValidTouch(rawX: Float, rawY: Float): Boolean { val statusHeight = statusBarHeight ?: 0 @@ -1070,6 +1079,11 @@ open class FullScreenPlayer : AbstractPlayerFragment() { PlayerEventType.ShowMirrors -> { showMirrorsDialogue() } + PlayerEventType.SearchSubtitlesOnline -> { + if (subsProvidersIsActive) { + openOnlineSubPicker(view.context, null) {} + } + } } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index ba4532e7..528a9b95 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -65,12 +65,13 @@ class GeneratorPlayer : FullScreenPlayer() { putSerializable("syncData", syncData) } } + + val subsProviders + get() = subtitleProviders.filter { !it.requiresLogin || it.loginInfo() != null } + val subsProvidersIsActive + get() = subsProviders.isNotEmpty() } - private val subsProviders - get() = subtitleProviders.filter { !it.requiresLogin || it.loginInfo() != null } - private val subsProvidersIsActive - get() = subsProviders.isNotEmpty() private var titleRez = 3 private var limitTitle = 0 @@ -209,7 +210,7 @@ class GeneratorPlayer : FullScreenPlayer() { return meta } - private fun openOnlineSubPicker( + override fun openOnlineSubPicker( context: Context, imdbId: Long?, dismissCallback: (() -> Unit) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/IPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/IPlayer.kt index f703a0c3..0f7cea4f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/IPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/IPlayer.kt @@ -22,6 +22,7 @@ enum class PlayerEventType(val value: Int) { ShowSpeed(11), ShowMirrors(12), Resize(13), + SearchSubtitlesOnline(14), } enum class CSPlayerEvent(val value: Int) {