mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-08-30 11:05:15 +02:00
chore: Lint code
This commit is contained in:
parent
e5aa30ebe5
commit
36aa6c9aa8
3
.editorconfig
Normal file
3
.editorconfig
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[*.{kt,kts}]
|
||||||
|
ktlint_code_style = intellij_idea
|
||||||
|
ktlint_standard_no-wildcard-imports = disabled
|
@ -4,7 +4,6 @@ import app.revanced.integrations.twitter.patches.hook.json.BaseJsonHook
|
|||||||
import app.revanced.integrations.twitter.patches.hook.twifucker.TwiFucker
|
import app.revanced.integrations.twitter.patches.hook.twifucker.TwiFucker
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
|
||||||
object AdsHook : BaseJsonHook() {
|
object AdsHook : BaseJsonHook() {
|
||||||
/**
|
/**
|
||||||
* Strips JSONObject from promoted ads.
|
* Strips JSONObject from promoted ads.
|
||||||
|
@ -4,7 +4,6 @@ import app.revanced.integrations.twitter.patches.hook.json.BaseJsonHook
|
|||||||
import app.revanced.integrations.twitter.patches.hook.twifucker.TwiFucker
|
import app.revanced.integrations.twitter.patches.hook.twifucker.TwiFucker
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
|
||||||
object RecommendedUsersHook : BaseJsonHook() {
|
object RecommendedUsersHook : BaseJsonHook() {
|
||||||
/**
|
/**
|
||||||
* Strips JSONObject from recommended users.
|
* Strips JSONObject from recommended users.
|
||||||
|
@ -27,4 +27,3 @@ class Event<T> {
|
|||||||
observer.invoke(value)
|
observer.invoke(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import java.lang.ref.WeakReference
|
|||||||
* @param activity activity that contains the controls_layout view
|
* @param activity activity that contains the controls_layout view
|
||||||
*/
|
*/
|
||||||
class PlayerControlsVisibilityObserverImpl(
|
class PlayerControlsVisibilityObserverImpl(
|
||||||
private val activity: Activity
|
private val activity: Activity,
|
||||||
) : PlayerControlsVisibilityObserver {
|
) : PlayerControlsVisibilityObserver {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,8 +2,8 @@ package app.revanced.integrations.youtube.shared
|
|||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import app.revanced.integrations.youtube.swipecontrols.misc.Rectangle
|
|
||||||
import app.revanced.integrations.youtube.Event
|
import app.revanced.integrations.youtube.Event
|
||||||
|
import app.revanced.integrations.youtube.swipecontrols.misc.Rectangle
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hooking class for player overlays
|
* hooking class for player overlays
|
||||||
@ -42,8 +42,8 @@ object PlayerOverlays {
|
|||||||
ChildrenChangeEventArgs(
|
ChildrenChangeEventArgs(
|
||||||
parent,
|
parent,
|
||||||
child,
|
child,
|
||||||
false
|
false,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,8 +54,8 @@ object PlayerOverlays {
|
|||||||
ChildrenChangeEventArgs(
|
ChildrenChangeEventArgs(
|
||||||
parent,
|
parent,
|
||||||
child,
|
child,
|
||||||
true
|
true,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,15 +69,15 @@ object PlayerOverlays {
|
|||||||
oldLeft,
|
oldLeft,
|
||||||
oldTop,
|
oldTop,
|
||||||
oldRight - oldLeft,
|
oldRight - oldLeft,
|
||||||
oldBottom - oldTop
|
oldBottom - oldTop,
|
||||||
),
|
),
|
||||||
Rectangle(
|
Rectangle(
|
||||||
newLeft,
|
newLeft,
|
||||||
newTop,
|
newTop,
|
||||||
newRight - newLeft,
|
newRight - newLeft,
|
||||||
newBottom - newTop
|
newBottom - newTop,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,11 +87,11 @@ object PlayerOverlays {
|
|||||||
data class ChildrenChangeEventArgs(
|
data class ChildrenChangeEventArgs(
|
||||||
val overlaysLayout: ViewGroup,
|
val overlaysLayout: ViewGroup,
|
||||||
val childView: View,
|
val childView: View,
|
||||||
val wasChildRemoved: Boolean
|
val wasChildRemoved: Boolean,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class LayoutChangeEventArgs(
|
data class LayoutChangeEventArgs(
|
||||||
val overlaysLayout: ViewGroup,
|
val overlaysLayout: ViewGroup,
|
||||||
val oldRect: Rectangle,
|
val oldRect: Rectangle,
|
||||||
val newRect: Rectangle
|
val newRect: Rectangle,
|
||||||
)
|
)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package app.revanced.integrations.youtube.shared
|
package app.revanced.integrations.youtube.shared
|
||||||
|
|
||||||
import app.revanced.integrations.youtube.patches.VideoInformation
|
|
||||||
import app.revanced.integrations.youtube.Event
|
|
||||||
import app.revanced.integrations.shared.Logger
|
import app.revanced.integrations.shared.Logger
|
||||||
|
import app.revanced.integrations.youtube.Event
|
||||||
|
import app.revanced.integrations.youtube.patches.VideoInformation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main player type.
|
* Main player type.
|
||||||
@ -12,11 +12,13 @@ enum class PlayerType {
|
|||||||
* Either no video, or a Short is playing.
|
* Either no video, or a Short is playing.
|
||||||
*/
|
*/
|
||||||
NONE,
|
NONE,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Short is playing. Occurs if a regular video is first opened
|
* A Short is playing. Occurs if a regular video is first opened
|
||||||
* and then a Short is opened (without first closing the regular video).
|
* and then a Short is opened (without first closing the regular video).
|
||||||
*/
|
*/
|
||||||
HIDDEN,
|
HIDDEN,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A regular video is minimized.
|
* A regular video is minimized.
|
||||||
*
|
*
|
||||||
@ -28,6 +30,7 @@ enum class PlayerType {
|
|||||||
WATCH_WHILE_FULLSCREEN,
|
WATCH_WHILE_FULLSCREEN,
|
||||||
WATCH_WHILE_SLIDING_MAXIMIZED_FULLSCREEN,
|
WATCH_WHILE_SLIDING_MAXIMIZED_FULLSCREEN,
|
||||||
WATCH_WHILE_SLIDING_MINIMIZED_MAXIMIZED,
|
WATCH_WHILE_SLIDING_MINIMIZED_MAXIMIZED,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Player is either sliding to [HIDDEN] state because a Short was opened while a regular video is on screen.
|
* Player is either sliding to [HIDDEN] state because a Short was opened while a regular video is on screen.
|
||||||
* OR
|
* OR
|
||||||
@ -35,12 +38,14 @@ enum class PlayerType {
|
|||||||
*/
|
*/
|
||||||
WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED,
|
WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED,
|
||||||
WATCH_WHILE_SLIDING_FULLSCREEN_DISMISSED,
|
WATCH_WHILE_SLIDING_FULLSCREEN_DISMISSED,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Home feed video playback.
|
* Home feed video playback.
|
||||||
*/
|
*/
|
||||||
INLINE_MINIMAL,
|
INLINE_MINIMAL,
|
||||||
VIRTUAL_REALITY_FULLSCREEN,
|
VIRTUAL_REALITY_FULLSCREEN,
|
||||||
WATCH_WHILE_PICTURE_IN_PICTURE;
|
WATCH_WHILE_PICTURE_IN_PICTURE,
|
||||||
|
;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
@ -67,6 +72,7 @@ enum class PlayerType {
|
|||||||
currentPlayerType = value
|
currentPlayerType = value
|
||||||
onChange(currentPlayerType)
|
onChange(currentPlayerType)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Volatile // value is read/write from different threads
|
@Volatile // value is read/write from different threads
|
||||||
private var currentPlayerType = NONE
|
private var currentPlayerType = NONE
|
||||||
|
|
||||||
@ -126,5 +132,4 @@ enum class PlayerType {
|
|||||||
fun isNoneHiddenOrMinimized(): Boolean {
|
fun isNoneHiddenOrMinimized(): Boolean {
|
||||||
return isNoneHiddenOrSlidingMinimized() || this == WATCH_WHILE_MINIMIZED
|
return isNoneHiddenOrSlidingMinimized() || this == WATCH_WHILE_MINIMIZED
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -12,10 +12,13 @@ enum class VideoState {
|
|||||||
PAUSED,
|
PAUSED,
|
||||||
RECOVERABLE_ERROR,
|
RECOVERABLE_ERROR,
|
||||||
UNRECOVERABLE_ERROR,
|
UNRECOVERABLE_ERROR,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see [VideoInformation.isAtEndOfVideo]
|
* @see [VideoInformation.isAtEndOfVideo]
|
||||||
*/
|
*/
|
||||||
ENDED;
|
ENDED,
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import app.revanced.integrations.youtube.shared.PlayerType
|
|||||||
* @param context the context to create in
|
* @param context the context to create in
|
||||||
*/
|
*/
|
||||||
class SwipeControlsConfigurationProvider(
|
class SwipeControlsConfigurationProvider(
|
||||||
private val context: Context
|
private val context: Context,
|
||||||
) {
|
) {
|
||||||
//region swipe enable
|
//region swipe enable
|
||||||
/**
|
/**
|
||||||
|
@ -6,6 +6,8 @@ import android.os.Bundle
|
|||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import app.revanced.integrations.shared.Logger.printDebug
|
||||||
|
import app.revanced.integrations.shared.Logger.printException
|
||||||
import app.revanced.integrations.youtube.shared.PlayerType
|
import app.revanced.integrations.youtube.shared.PlayerType
|
||||||
import app.revanced.integrations.youtube.swipecontrols.controller.AudioVolumeController
|
import app.revanced.integrations.youtube.swipecontrols.controller.AudioVolumeController
|
||||||
import app.revanced.integrations.youtube.swipecontrols.controller.ScreenBrightnessController
|
import app.revanced.integrations.youtube.swipecontrols.controller.ScreenBrightnessController
|
||||||
@ -16,8 +18,6 @@ import app.revanced.integrations.youtube.swipecontrols.controller.gesture.PressT
|
|||||||
import app.revanced.integrations.youtube.swipecontrols.controller.gesture.core.GestureController
|
import app.revanced.integrations.youtube.swipecontrols.controller.gesture.core.GestureController
|
||||||
import app.revanced.integrations.youtube.swipecontrols.misc.Rectangle
|
import app.revanced.integrations.youtube.swipecontrols.misc.Rectangle
|
||||||
import app.revanced.integrations.youtube.swipecontrols.views.SwipeControlsOverlayLayout
|
import app.revanced.integrations.youtube.swipecontrols.views.SwipeControlsOverlayLayout
|
||||||
import app.revanced.integrations.shared.Logger.printDebug
|
|
||||||
import app.revanced.integrations.shared.Logger.printException
|
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,14 +80,18 @@ class SwipeControlsHostActivity : Activity() {
|
|||||||
|
|
||||||
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
|
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
|
||||||
ensureInitialized()
|
ensureInitialized()
|
||||||
return if ((ev != null) && gesture.submitTouchEvent(ev)) true else {
|
return if ((ev != null) && gesture.submitTouchEvent(ev)) {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
super.dispatchTouchEvent(ev)
|
super.dispatchTouchEvent(ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispatchKeyEvent(ev: KeyEvent?): Boolean {
|
override fun dispatchKeyEvent(ev: KeyEvent?): Boolean {
|
||||||
ensureInitialized()
|
ensureInitialized()
|
||||||
return if ((ev != null) && keys.onKeyEvent(ev)) true else {
|
return if ((ev != null) && keys.onKeyEvent(ev)) {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
super.dispatchKeyEvent(ev)
|
super.dispatchKeyEvent(ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,7 +143,7 @@ class SwipeControlsHostActivity : Activity() {
|
|||||||
contentRoot.x.toInt(),
|
contentRoot.x.toInt(),
|
||||||
contentRoot.y.toInt(),
|
contentRoot.y.toInt(),
|
||||||
contentRoot.width,
|
contentRoot.width,
|
||||||
contentRoot.height
|
contentRoot.height,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +172,7 @@ class SwipeControlsHostActivity : Activity() {
|
|||||||
* @param type the new player type
|
* @param type the new player type
|
||||||
*/
|
*/
|
||||||
private fun onPlayerTypeChanged(type: PlayerType) {
|
private fun onPlayerTypeChanged(type: PlayerType) {
|
||||||
if (config.shouldSaveAndRestoreBrightness)
|
if (config.shouldSaveAndRestoreBrightness) {
|
||||||
when (type) {
|
when (type) {
|
||||||
PlayerType.WATCH_WHILE_FULLSCREEN -> screen?.restore()
|
PlayerType.WATCH_WHILE_FULLSCREEN -> screen?.restore()
|
||||||
else -> {
|
else -> {
|
||||||
@ -177,28 +181,37 @@ class SwipeControlsHostActivity : Activity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create the audio volume controller
|
* create the audio volume controller
|
||||||
*/
|
*/
|
||||||
private fun createAudioController() =
|
private fun createAudioController() =
|
||||||
if (config.enableVolumeControls)
|
if (config.enableVolumeControls) {
|
||||||
AudioVolumeController(this) else null
|
AudioVolumeController(this)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create the screen brightness controller instance
|
* create the screen brightness controller instance
|
||||||
*/
|
*/
|
||||||
private fun createScreenController() =
|
private fun createScreenController() =
|
||||||
if (config.enableBrightnessControl)
|
if (config.enableBrightnessControl) {
|
||||||
ScreenBrightnessController(this) else null
|
ScreenBrightnessController(this)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create the gesture controller based on settings
|
* create the gesture controller based on settings
|
||||||
*/
|
*/
|
||||||
private fun createGestureController() =
|
private fun createGestureController() =
|
||||||
if (config.shouldEnablePressToSwipe)
|
if (config.shouldEnablePressToSwipe) {
|
||||||
PressToSwipeController(this)
|
PressToSwipeController(this)
|
||||||
else ClassicSwipeController(this)
|
} else {
|
||||||
|
ClassicSwipeController(this)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
|
@ -3,8 +3,8 @@ package app.revanced.integrations.youtube.swipecontrols.controller
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import app.revanced.integrations.youtube.swipecontrols.misc.clamp
|
|
||||||
import app.revanced.integrations.shared.Logger.printException
|
import app.revanced.integrations.shared.Logger.printException
|
||||||
|
import app.revanced.integrations.youtube.swipecontrols.misc.clamp
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,7 +15,7 @@ import kotlin.properties.Delegates
|
|||||||
*/
|
*/
|
||||||
class AudioVolumeController(
|
class AudioVolumeController(
|
||||||
context: Context,
|
context: Context,
|
||||||
private val targetStream: Int = AudioManager.STREAM_MUSIC
|
private val targetStream: Int = AudioManager.STREAM_MUSIC,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,9 +34,13 @@ class AudioVolumeController(
|
|||||||
audioManager = mgr
|
audioManager = mgr
|
||||||
maximumVolumeIndex = audioManager.getStreamMaxVolume(targetStream)
|
maximumVolumeIndex = audioManager.getStreamMaxVolume(targetStream)
|
||||||
minimumVolumeIndex =
|
minimumVolumeIndex =
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) audioManager.getStreamMinVolume(
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
targetStream
|
audioManager.getStreamMinVolume(
|
||||||
) else 0
|
targetStream,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import app.revanced.integrations.youtube.swipecontrols.misc.clamp
|
|||||||
* @param host the host activity of which the brightness is adjusted
|
* @param host the host activity of which the brightness is adjusted
|
||||||
*/
|
*/
|
||||||
class ScreenBrightnessController(
|
class ScreenBrightnessController(
|
||||||
private val host: Activity
|
private val host: Activity,
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* screen brightness saved by [save]
|
* screen brightness saved by [save]
|
||||||
|
@ -3,9 +3,9 @@ package app.revanced.integrations.youtube.swipecontrols.controller
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import app.revanced.integrations.shared.Utils
|
||||||
import app.revanced.integrations.youtube.swipecontrols.misc.Rectangle
|
import app.revanced.integrations.youtube.swipecontrols.misc.Rectangle
|
||||||
import app.revanced.integrations.youtube.swipecontrols.misc.applyDimension
|
import app.revanced.integrations.youtube.swipecontrols.misc.applyDimension
|
||||||
import app.revanced.integrations.shared.Utils
|
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,7 +36,7 @@ import kotlin.math.min
|
|||||||
@Suppress("PrivatePropertyName")
|
@Suppress("PrivatePropertyName")
|
||||||
class SwipeZonesController(
|
class SwipeZonesController(
|
||||||
private val host: Activity,
|
private val host: Activity,
|
||||||
private val fallbackScreenRect: () -> Rectangle
|
private val fallbackScreenRect: () -> Rectangle,
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* 20dp, in pixels
|
* 20dp, in pixels
|
||||||
@ -74,7 +74,7 @@ class SwipeZonesController(
|
|||||||
p.x + _20dp,
|
p.x + _20dp,
|
||||||
p.y + _40dp,
|
p.y + _40dp,
|
||||||
p.width - _20dp,
|
p.width - _20dp,
|
||||||
p.height - _20dp - _80dp
|
p.height - _20dp - _80dp,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ class SwipeZonesController(
|
|||||||
eRect.right - zoneWidth,
|
eRect.right - zoneWidth,
|
||||||
eRect.top,
|
eRect.top,
|
||||||
zoneWidth,
|
zoneWidth,
|
||||||
eRect.height
|
eRect.height,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ class SwipeZonesController(
|
|||||||
effectiveSwipeRect.left,
|
effectiveSwipeRect.left,
|
||||||
effectiveSwipeRect.top,
|
effectiveSwipeRect.top,
|
||||||
zoneWidth,
|
zoneWidth,
|
||||||
effectiveSwipeRect.height
|
effectiveSwipeRect.height,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ class SwipeZonesController(
|
|||||||
playerView.x.toInt(),
|
playerView.x.toInt(),
|
||||||
playerView.y.toInt(),
|
playerView.y.toInt(),
|
||||||
min(playerView.width, playerWidthWithPadding),
|
min(playerView.width, playerWidthWithPadding),
|
||||||
playerView.height
|
playerView.height,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import app.revanced.integrations.youtube.swipecontrols.SwipeControlsHostActivity
|
|||||||
* @param controller main controller instance
|
* @param controller main controller instance
|
||||||
*/
|
*/
|
||||||
class VolumeKeysController(
|
class VolumeKeysController(
|
||||||
private val controller: SwipeControlsHostActivity
|
private val controller: SwipeControlsHostActivity,
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* key event handler
|
* key event handler
|
||||||
|
@ -15,7 +15,7 @@ import app.revanced.integrations.youtube.swipecontrols.misc.toPoint
|
|||||||
* @param controller reference to the main swipe controller
|
* @param controller reference to the main swipe controller
|
||||||
*/
|
*/
|
||||||
class ClassicSwipeController(
|
class ClassicSwipeController(
|
||||||
private val controller: SwipeControlsHostActivity
|
private val controller: SwipeControlsHostActivity,
|
||||||
) : BaseGestureController(controller),
|
) : BaseGestureController(controller),
|
||||||
PlayerControlsVisibilityObserver by PlayerControlsVisibilityObserverImpl(controller) {
|
PlayerControlsVisibilityObserver by PlayerControlsVisibilityObserverImpl(controller) {
|
||||||
/**
|
/**
|
||||||
@ -27,10 +27,16 @@ class ClassicSwipeController(
|
|||||||
get() = currentSwipe == SwipeDetector.SwipeDirection.VERTICAL
|
get() = currentSwipe == SwipeDetector.SwipeDirection.VERTICAL
|
||||||
|
|
||||||
override fun isInSwipeZone(motionEvent: MotionEvent): Boolean {
|
override fun isInSwipeZone(motionEvent: MotionEvent): Boolean {
|
||||||
val inVolumeZone = if (controller.config.enableVolumeControls)
|
val inVolumeZone = if (controller.config.enableVolumeControls) {
|
||||||
(motionEvent.toPoint() in controller.zones.volume) else false
|
(motionEvent.toPoint() in controller.zones.volume)
|
||||||
val inBrightnessZone = if (controller.config.enableBrightnessControl)
|
} else {
|
||||||
(motionEvent.toPoint() in controller.zones.brightness) else false
|
false
|
||||||
|
}
|
||||||
|
val inBrightnessZone = if (controller.config.enableBrightnessControl) {
|
||||||
|
(motionEvent.toPoint() in controller.zones.brightness)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
return inVolumeZone || inBrightnessZone
|
return inVolumeZone || inBrightnessZone
|
||||||
}
|
}
|
||||||
@ -92,7 +98,7 @@ class ClassicSwipeController(
|
|||||||
from: MotionEvent,
|
from: MotionEvent,
|
||||||
to: MotionEvent,
|
to: MotionEvent,
|
||||||
distanceX: Double,
|
distanceX: Double,
|
||||||
distanceY: Double
|
distanceY: Double,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
// cancel if not vertical
|
// cancel if not vertical
|
||||||
if (currentSwipe != SwipeDetector.SwipeDirection.VERTICAL) return false
|
if (currentSwipe != SwipeDetector.SwipeDirection.VERTICAL) return false
|
||||||
|
@ -13,7 +13,7 @@ import app.revanced.integrations.youtube.swipecontrols.misc.toPoint
|
|||||||
* @param controller reference to the main swipe controller
|
* @param controller reference to the main swipe controller
|
||||||
*/
|
*/
|
||||||
class PressToSwipeController(
|
class PressToSwipeController(
|
||||||
private val controller: SwipeControlsHostActivity
|
private val controller: SwipeControlsHostActivity,
|
||||||
) : BaseGestureController(controller) {
|
) : BaseGestureController(controller) {
|
||||||
/**
|
/**
|
||||||
* monitors if the user is currently in a swipe session.
|
* monitors if the user is currently in a swipe session.
|
||||||
@ -26,10 +26,16 @@ class PressToSwipeController(
|
|||||||
override fun shouldDropMotion(motionEvent: MotionEvent): Boolean = false
|
override fun shouldDropMotion(motionEvent: MotionEvent): Boolean = false
|
||||||
|
|
||||||
override fun isInSwipeZone(motionEvent: MotionEvent): Boolean {
|
override fun isInSwipeZone(motionEvent: MotionEvent): Boolean {
|
||||||
val inVolumeZone = if (controller.config.enableVolumeControls)
|
val inVolumeZone = if (controller.config.enableVolumeControls) {
|
||||||
(motionEvent.toPoint() in controller.zones.volume) else false
|
(motionEvent.toPoint() in controller.zones.volume)
|
||||||
val inBrightnessZone = if (controller.config.enableBrightnessControl)
|
} else {
|
||||||
(motionEvent.toPoint() in controller.zones.brightness) else false
|
false
|
||||||
|
}
|
||||||
|
val inBrightnessZone = if (controller.config.enableBrightnessControl) {
|
||||||
|
(motionEvent.toPoint() in controller.zones.brightness)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
return inVolumeZone || inBrightnessZone
|
return inVolumeZone || inBrightnessZone
|
||||||
}
|
}
|
||||||
@ -53,7 +59,7 @@ class PressToSwipeController(
|
|||||||
from: MotionEvent,
|
from: MotionEvent,
|
||||||
to: MotionEvent,
|
to: MotionEvent,
|
||||||
distanceX: Double,
|
distanceX: Double,
|
||||||
distanceY: Double
|
distanceY: Double,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
// cancel if not in swipe session or vertical
|
// cancel if not in swipe session or vertical
|
||||||
if (!isInSwipeSession || currentSwipe != SwipeDetector.SwipeDirection.VERTICAL) return false
|
if (!isInSwipeSession || currentSwipe != SwipeDetector.SwipeDirection.VERTICAL) return false
|
||||||
|
@ -11,11 +11,11 @@ import app.revanced.integrations.youtube.swipecontrols.SwipeControlsHostActivity
|
|||||||
* @param controller reference to the main swipe controller
|
* @param controller reference to the main swipe controller
|
||||||
*/
|
*/
|
||||||
abstract class BaseGestureController(
|
abstract class BaseGestureController(
|
||||||
private val controller: SwipeControlsHostActivity
|
private val controller: SwipeControlsHostActivity,
|
||||||
) : GestureController,
|
) : GestureController,
|
||||||
GestureDetector.SimpleOnGestureListener(),
|
GestureDetector.SimpleOnGestureListener(),
|
||||||
SwipeDetector by SwipeDetectorImpl(
|
SwipeDetector by SwipeDetectorImpl(
|
||||||
controller.config.swipeMagnitudeThreshold.toDouble()
|
controller.config.swipeMagnitudeThreshold.toDouble(),
|
||||||
),
|
),
|
||||||
VolumeAndBrightnessScroller by VolumeAndBrightnessScrollerImpl(
|
VolumeAndBrightnessScroller by VolumeAndBrightnessScrollerImpl(
|
||||||
controller,
|
controller,
|
||||||
@ -23,7 +23,7 @@ abstract class BaseGestureController(
|
|||||||
controller.screen,
|
controller.screen,
|
||||||
controller.overlay,
|
controller.overlay,
|
||||||
10,
|
10,
|
||||||
1
|
1,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,7 +85,7 @@ abstract class BaseGestureController(
|
|||||||
from: MotionEvent,
|
from: MotionEvent,
|
||||||
to: MotionEvent,
|
to: MotionEvent,
|
||||||
distanceX: Float,
|
distanceX: Float,
|
||||||
distanceY: Float
|
distanceY: Float,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
// submit to swipe detector
|
// submit to swipe detector
|
||||||
submitForSwipe(from, to, distanceX, distanceY)
|
submitForSwipe(from, to, distanceX, distanceY)
|
||||||
@ -96,7 +96,7 @@ abstract class BaseGestureController(
|
|||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
distanceX.toDouble(),
|
distanceX.toDouble(),
|
||||||
distanceY.toDouble()
|
distanceY.toDouble(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// if the swipe was consumed, cancel downstream events once
|
// if the swipe was consumed, cancel downstream events once
|
||||||
@ -110,7 +110,9 @@ abstract class BaseGestureController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
consumed
|
consumed
|
||||||
} else false
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,6 +151,6 @@ abstract class BaseGestureController(
|
|||||||
from: MotionEvent,
|
from: MotionEvent,
|
||||||
to: MotionEvent,
|
to: MotionEvent,
|
||||||
distanceX: Double,
|
distanceX: Double,
|
||||||
distanceY: Double
|
distanceY: Double,
|
||||||
): Boolean
|
): Boolean
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ interface SwipeDetector {
|
|||||||
from: MotionEvent,
|
from: MotionEvent,
|
||||||
to: MotionEvent,
|
to: MotionEvent,
|
||||||
distanceX: Float,
|
distanceX: Float,
|
||||||
distanceY: Float
|
distanceY: Float,
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,7 +50,7 @@ interface SwipeDetector {
|
|||||||
/**
|
/**
|
||||||
* swipe along the Y- Axes
|
* swipe along the Y- Axes
|
||||||
*/
|
*/
|
||||||
VERTICAL
|
VERTICAL,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ interface SwipeDetector {
|
|||||||
* @param swipeMagnitudeThreshold minimum magnitude before a swipe is detected as such
|
* @param swipeMagnitudeThreshold minimum magnitude before a swipe is detected as such
|
||||||
*/
|
*/
|
||||||
class SwipeDetectorImpl(
|
class SwipeDetectorImpl(
|
||||||
private val swipeMagnitudeThreshold: Double
|
private val swipeMagnitudeThreshold: Double,
|
||||||
) : SwipeDetector {
|
) : SwipeDetector {
|
||||||
override var currentSwipe = SwipeDetector.SwipeDirection.NONE
|
override var currentSwipe = SwipeDetector.SwipeDirection.NONE
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ class SwipeDetectorImpl(
|
|||||||
from: MotionEvent,
|
from: MotionEvent,
|
||||||
to: MotionEvent,
|
to: MotionEvent,
|
||||||
distanceX: Float,
|
distanceX: Float,
|
||||||
distanceY: Float
|
distanceY: Float,
|
||||||
) {
|
) {
|
||||||
if (currentSwipe == SwipeDetector.SwipeDirection.NONE) {
|
if (currentSwipe == SwipeDetector.SwipeDirection.NONE) {
|
||||||
// no swipe direction was detected yet, try to detect one
|
// no swipe direction was detected yet, try to detect one
|
||||||
|
@ -48,7 +48,7 @@ class VolumeAndBrightnessScrollerImpl(
|
|||||||
private val screenController: ScreenBrightnessController?,
|
private val screenController: ScreenBrightnessController?,
|
||||||
private val overlayController: SwipeControlsOverlay,
|
private val overlayController: SwipeControlsOverlay,
|
||||||
volumeDistance: Int = 10,
|
volumeDistance: Int = 10,
|
||||||
brightnessDistance: Int = 1
|
brightnessDistance: Int = 1,
|
||||||
) : VolumeAndBrightnessScroller {
|
) : VolumeAndBrightnessScroller {
|
||||||
|
|
||||||
// region volume
|
// region volume
|
||||||
@ -56,8 +56,8 @@ class VolumeAndBrightnessScrollerImpl(
|
|||||||
ScrollDistanceHelper(
|
ScrollDistanceHelper(
|
||||||
volumeDistance.applyDimension(
|
volumeDistance.applyDimension(
|
||||||
context,
|
context,
|
||||||
TypedValue.COMPLEX_UNIT_DIP
|
TypedValue.COMPLEX_UNIT_DIP,
|
||||||
)
|
),
|
||||||
) { _, _, direction ->
|
) { _, _, direction ->
|
||||||
volumeController?.run {
|
volumeController?.run {
|
||||||
volume += direction
|
volume += direction
|
||||||
@ -73,8 +73,8 @@ class VolumeAndBrightnessScrollerImpl(
|
|||||||
ScrollDistanceHelper(
|
ScrollDistanceHelper(
|
||||||
brightnessDistance.applyDimension(
|
brightnessDistance.applyDimension(
|
||||||
context,
|
context,
|
||||||
TypedValue.COMPLEX_UNIT_DIP
|
TypedValue.COMPLEX_UNIT_DIP,
|
||||||
)
|
),
|
||||||
) { _, _, direction ->
|
) { _, _, direction ->
|
||||||
screenController?.run {
|
screenController?.run {
|
||||||
if (screenBrightness > 0 || direction > 0) {
|
if (screenBrightness > 0 || direction > 0) {
|
||||||
|
@ -7,7 +7,7 @@ import android.view.MotionEvent
|
|||||||
*/
|
*/
|
||||||
data class Point(
|
data class Point(
|
||||||
val x: Int,
|
val x: Int,
|
||||||
val y: Int
|
val y: Int,
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,7 +7,7 @@ data class Rectangle(
|
|||||||
val x: Int,
|
val x: Int,
|
||||||
val y: Int,
|
val y: Int,
|
||||||
val width: Int,
|
val width: Int,
|
||||||
val height: Int
|
val height: Int,
|
||||||
) {
|
) {
|
||||||
val left = x
|
val left = x
|
||||||
val right = x + width
|
val right = x + width
|
||||||
@ -15,7 +15,6 @@ data class Rectangle(
|
|||||||
val bottom = y + height
|
val bottom = y + height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* is the point within this rectangle?
|
* is the point within this rectangle?
|
||||||
*/
|
*/
|
||||||
|
@ -11,7 +11,7 @@ import kotlin.math.sign
|
|||||||
*/
|
*/
|
||||||
class ScrollDistanceHelper(
|
class ScrollDistanceHelper(
|
||||||
private val unitDistance: Int,
|
private val unitDistance: Int,
|
||||||
private val callback: (oldDistance: Double, newDistance: Double, direction: Int) -> Unit
|
private val callback: (oldDistance: Double, newDistance: Double, direction: Int) -> Unit,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,7 +35,7 @@ class ScrollDistanceHelper(
|
|||||||
callback.invoke(
|
callback.invoke(
|
||||||
oldDistance,
|
oldDistance,
|
||||||
scrolledDistance,
|
scrolledDistance,
|
||||||
sign(scrolledDistance).toInt()
|
sign(scrolledDistance).toInt(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ fun Int.applyDimension(context: Context, unit: Int): Int {
|
|||||||
return TypedValue.applyDimension(
|
return TypedValue.applyDimension(
|
||||||
unit,
|
unit,
|
||||||
this.toFloat(),
|
this.toFloat(),
|
||||||
context.resources.displayMetrics
|
context.resources.displayMetrics,
|
||||||
).roundToInt()
|
).roundToInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,10 +11,10 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import app.revanced.integrations.shared.Utils
|
||||||
import app.revanced.integrations.youtube.swipecontrols.SwipeControlsConfigurationProvider
|
import app.revanced.integrations.youtube.swipecontrols.SwipeControlsConfigurationProvider
|
||||||
import app.revanced.integrations.youtube.swipecontrols.misc.SwipeControlsOverlay
|
import app.revanced.integrations.youtube.swipecontrols.misc.SwipeControlsOverlay
|
||||||
import app.revanced.integrations.youtube.swipecontrols.misc.applyDimension
|
import app.revanced.integrations.youtube.swipecontrols.misc.applyDimension
|
||||||
import app.revanced.integrations.shared.Utils
|
|
||||||
import kotlin.math.round
|
import kotlin.math.round
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,7 +24,7 @@ import kotlin.math.round
|
|||||||
*/
|
*/
|
||||||
class SwipeControlsOverlayLayout(
|
class SwipeControlsOverlayLayout(
|
||||||
context: Context,
|
context: Context,
|
||||||
private val config: SwipeControlsConfigurationProvider
|
private val config: SwipeControlsConfigurationProvider,
|
||||||
) : RelativeLayout(context), SwipeControlsOverlay {
|
) : RelativeLayout(context), SwipeControlsOverlay {
|
||||||
/**
|
/**
|
||||||
* DO NOT use this, for tools only
|
* DO NOT use this, for tools only
|
||||||
@ -40,14 +40,14 @@ class SwipeControlsOverlayLayout(
|
|||||||
private fun getDrawable(name: String, width: Int, height: Int): Drawable {
|
private fun getDrawable(name: String, width: Int, height: Int): Drawable {
|
||||||
return resources.getDrawable(
|
return resources.getDrawable(
|
||||||
Utils.getResourceIdentifier(context, name, "drawable"),
|
Utils.getResourceIdentifier(context, name, "drawable"),
|
||||||
context.theme
|
context.theme,
|
||||||
).apply {
|
).apply {
|
||||||
setTint(config.overlayForegroundColor)
|
setTint(config.overlayForegroundColor)
|
||||||
setBounds(
|
setBounds(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
width,
|
width,
|
||||||
height
|
height,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,14 +59,14 @@ class SwipeControlsOverlayLayout(
|
|||||||
feedbackTextView = TextView(context).apply {
|
feedbackTextView = TextView(context).apply {
|
||||||
layoutParams = LayoutParams(
|
layoutParams = LayoutParams(
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
).apply {
|
).apply {
|
||||||
addRule(CENTER_IN_PARENT, TRUE)
|
addRule(CENTER_IN_PARENT, TRUE)
|
||||||
setPadding(
|
setPadding(
|
||||||
feedbackTextViewPadding,
|
feedbackTextViewPadding,
|
||||||
feedbackTextViewPadding,
|
feedbackTextViewPadding,
|
||||||
feedbackTextViewPadding,
|
feedbackTextViewPadding,
|
||||||
feedbackTextViewPadding
|
feedbackTextViewPadding,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
background = GradientDrawable().apply {
|
background = GradientDrawable().apply {
|
||||||
@ -108,7 +108,7 @@ class SwipeControlsOverlayLayout(
|
|||||||
icon,
|
icon,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null
|
null,
|
||||||
)
|
)
|
||||||
visibility = VISIBLE
|
visibility = VISIBLE
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ class SwipeControlsOverlayLayout(
|
|||||||
override fun onVolumeChanged(newVolume: Int, maximumVolume: Int) {
|
override fun onVolumeChanged(newVolume: Int, maximumVolume: Int) {
|
||||||
showFeedbackView(
|
showFeedbackView(
|
||||||
"$newVolume",
|
"$newVolume",
|
||||||
if (newVolume > 0) normalVolumeIcon else mutedVolumeIcon
|
if (newVolume > 0) normalVolumeIcon else mutedVolumeIcon,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ class SwipeControlsOverlayLayout(
|
|||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
performHapticFeedback(
|
performHapticFeedback(
|
||||||
HapticFeedbackConstants.LONG_PRESS,
|
HapticFeedbackConstants.LONG_PRESS,
|
||||||
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING
|
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ android {
|
|||||||
isMinifyEnabled = false
|
isMinifyEnabled = false
|
||||||
proguardFiles(
|
proguardFiles(
|
||||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
"proguard-rules.pro"
|
"proguard-rules.pro",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user