From 36aa6c9aa88495a79f64e0ca221694f4d18596a5 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 3 Mar 2024 00:15:00 +0100 Subject: [PATCH] chore: Lint code --- .editorconfig | 3 ++ .../twitter/patches/hook/json/BaseJsonHook.kt | 2 +- .../twitter/patches/hook/json/JsonHook.kt | 2 +- .../patches/hook/json/JsonHookPatch.kt | 2 +- .../twitter/patches/hook/patch/Hook.kt | 2 +- .../twitter/patches/hook/patch/ads/AdsHook.kt | 3 +- .../patches/hook/patch/dummy/DummyHook.kt | 2 +- .../recommendation/RecommendedUsersHook.kt | 3 +- .../twitter/utils/json/JsonUtils.kt | 2 +- .../twitter/utils/stream/StreamUtils.kt | 2 +- .../revanced/integrations/youtube/Event.kt | 1 - .../PlayerControlsVisibilityObserver.kt | 4 +- .../youtube/shared/PlayerOverlays.kt | 22 +++++------ .../integrations/youtube/shared/PlayerType.kt | 15 ++++--- .../integrations/youtube/shared/VideoState.kt | 9 +++-- .../SwipeControlsConfigurationProvider.kt | 4 +- .../SwipeControlsHostActivity.kt | 39 ++++++++++++------- .../controller/AudioVolumeController.kt | 14 ++++--- .../controller/ScreenBrightnessController.kt | 4 +- .../controller/SwipeZonesController.kt | 16 ++++---- .../controller/VolumeKeysController.kt | 4 +- .../gesture/ClassicSwipeController.kt | 18 ++++++--- .../gesture/PressToSwipeController.kt | 18 ++++++--- .../gesture/core/BaseGestureController.kt | 16 ++++---- .../controller/gesture/core/SwipeDetector.kt | 8 ++-- .../core/VolumeAndBrightnessScroller.kt | 10 ++--- .../youtube/swipecontrols/misc/Point.kt | 2 +- .../youtube/swipecontrols/misc/Rectangle.kt | 3 +- .../misc/ScrollDistanceHelper.kt | 6 +-- .../misc/SwipeControlsOverlay.kt | 2 +- .../swipecontrols/misc/SwipeControlsUtils.kt | 3 +- .../views/SwipeControlsOverlayLayout.kt | 20 +++++----- stub/build.gradle.kts | 2 +- 33 files changed, 150 insertions(+), 113 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..2d6d258f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +[*.{kt,kts}] +ktlint_code_style = intellij_idea +ktlint_standard_no-wildcard-imports = disabled \ No newline at end of file diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/BaseJsonHook.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/BaseJsonHook.kt index 536a43e1..18d5019e 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/BaseJsonHook.kt +++ b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/BaseJsonHook.kt @@ -6,4 +6,4 @@ abstract class BaseJsonHook : JsonHook { abstract fun apply(json: JSONObject) override fun transform(json: JSONObject) = json.apply { apply(json) } -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHook.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHook.kt index 3edfca4e..42751e87 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHook.kt +++ b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHook.kt @@ -12,4 +12,4 @@ interface JsonHook : Hook { fun transform(json: JSONObject): JSONObject override fun hook(type: JSONObject) = transform(type) -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHookPatch.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHookPatch.kt index 6e4067b9..1eb96cfe 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHookPatch.kt +++ b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHookPatch.kt @@ -27,4 +27,4 @@ object JsonHookPatch { return StreamUtils.fromString(jsonObject.toString()) } -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/Hook.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/Hook.kt index d6d163ef..d85bca3e 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/Hook.kt +++ b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/Hook.kt @@ -6,4 +6,4 @@ interface Hook { * @param type The type to hook */ fun hook(type: T): T -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/ads/AdsHook.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/ads/AdsHook.kt index 7c33a5b2..8411f97c 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/ads/AdsHook.kt +++ b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/ads/AdsHook.kt @@ -4,7 +4,6 @@ import app.revanced.integrations.twitter.patches.hook.json.BaseJsonHook import app.revanced.integrations.twitter.patches.hook.twifucker.TwiFucker import org.json.JSONObject - object AdsHook : BaseJsonHook() { /** * Strips JSONObject from promoted ads. @@ -12,4 +11,4 @@ object AdsHook : BaseJsonHook() { * @param json The JSONObject. */ override fun apply(json: JSONObject) = TwiFucker.hidePromotedAds(json) -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/dummy/DummyHook.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/dummy/DummyHook.kt index 1a4f583c..3e1bbaae 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/dummy/DummyHook.kt +++ b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/dummy/DummyHook.kt @@ -11,4 +11,4 @@ object DummyHook : BaseJsonHook() { override fun apply(json: JSONObject) { // Do nothing. } -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/recommendation/RecommendedUsersHook.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/recommendation/RecommendedUsersHook.kt index dfbb1ffb..21b19e7f 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/recommendation/RecommendedUsersHook.kt +++ b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/recommendation/RecommendedUsersHook.kt @@ -4,7 +4,6 @@ import app.revanced.integrations.twitter.patches.hook.json.BaseJsonHook import app.revanced.integrations.twitter.patches.hook.twifucker.TwiFucker import org.json.JSONObject - object RecommendedUsersHook : BaseJsonHook() { /** * Strips JSONObject from recommended users. @@ -12,4 +11,4 @@ object RecommendedUsersHook : BaseJsonHook() { * @param json The JSONObject. */ override fun apply(json: JSONObject) = TwiFucker.hideRecommendedUsers(json) -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/twitter/utils/json/JsonUtils.kt b/app/src/main/java/app/revanced/integrations/twitter/utils/json/JsonUtils.kt index 4b7a5002..80675c80 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/utils/json/JsonUtils.kt +++ b/app/src/main/java/app/revanced/integrations/twitter/utils/json/JsonUtils.kt @@ -10,4 +10,4 @@ object JsonUtils { @JvmStatic @Throws(IOException::class, JSONException::class) fun parseJson(jsonInputStream: InputStream) = JSONObject(StreamUtils.toString(jsonInputStream)) -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/twitter/utils/stream/StreamUtils.kt b/app/src/main/java/app/revanced/integrations/twitter/utils/stream/StreamUtils.kt index 7e008eb8..b7551ebe 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/utils/stream/StreamUtils.kt +++ b/app/src/main/java/app/revanced/integrations/twitter/utils/stream/StreamUtils.kt @@ -21,4 +21,4 @@ object StreamUtils { fun fromString(string: String): InputStream { return ByteArrayInputStream(string.toByteArray()) } -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/youtube/Event.kt b/app/src/main/java/app/revanced/integrations/youtube/Event.kt index 7b25af7f..63e79578 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/Event.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/Event.kt @@ -27,4 +27,3 @@ class Event { observer.invoke(value) } } - diff --git a/app/src/main/java/app/revanced/integrations/youtube/shared/PlayerControlsVisibilityObserver.kt b/app/src/main/java/app/revanced/integrations/youtube/shared/PlayerControlsVisibilityObserver.kt index 912f369e..c31e9d4c 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/shared/PlayerControlsVisibilityObserver.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/shared/PlayerControlsVisibilityObserver.kt @@ -12,7 +12,7 @@ import java.lang.ref.WeakReference * @param activity activity that contains the controls_layout view */ class PlayerControlsVisibilityObserverImpl( - private val activity: Activity + private val activity: Activity, ) : PlayerControlsVisibilityObserver { /** @@ -81,4 +81,4 @@ interface PlayerControlsVisibilityObserver { * is the value of [playerControlsVisibility] equal to [View.VISIBLE]? */ val arePlayerControlsVisible: Boolean -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/youtube/shared/PlayerOverlays.kt b/app/src/main/java/app/revanced/integrations/youtube/shared/PlayerOverlays.kt index 3b15f043..9bce2bc4 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/shared/PlayerOverlays.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/shared/PlayerOverlays.kt @@ -2,8 +2,8 @@ package app.revanced.integrations.youtube.shared import android.view.View import android.view.ViewGroup -import app.revanced.integrations.youtube.swipecontrols.misc.Rectangle import app.revanced.integrations.youtube.Event +import app.revanced.integrations.youtube.swipecontrols.misc.Rectangle /** * hooking class for player overlays @@ -42,8 +42,8 @@ object PlayerOverlays { ChildrenChangeEventArgs( parent, child, - false - ) + false, + ), ) } } @@ -54,8 +54,8 @@ object PlayerOverlays { ChildrenChangeEventArgs( parent, child, - true - ) + true, + ), ) } } @@ -69,15 +69,15 @@ object PlayerOverlays { oldLeft, oldTop, oldRight - oldLeft, - oldBottom - oldTop + oldBottom - oldTop, ), Rectangle( newLeft, newTop, newRight - newLeft, - newBottom - newTop - ) - ) + newBottom - newTop, + ), + ), ) } } @@ -87,11 +87,11 @@ object PlayerOverlays { data class ChildrenChangeEventArgs( val overlaysLayout: ViewGroup, val childView: View, - val wasChildRemoved: Boolean + val wasChildRemoved: Boolean, ) data class LayoutChangeEventArgs( val overlaysLayout: ViewGroup, val oldRect: Rectangle, - val newRect: Rectangle + val newRect: Rectangle, ) diff --git a/app/src/main/java/app/revanced/integrations/youtube/shared/PlayerType.kt b/app/src/main/java/app/revanced/integrations/youtube/shared/PlayerType.kt index 64634ceb..15d1496d 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/shared/PlayerType.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/shared/PlayerType.kt @@ -1,8 +1,8 @@ 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.youtube.Event +import app.revanced.integrations.youtube.patches.VideoInformation /** * Main player type. @@ -12,11 +12,13 @@ enum class PlayerType { * Either no video, or a Short is playing. */ NONE, + /** * A Short is playing. Occurs if a regular video is first opened * and then a Short is opened (without first closing the regular video). */ HIDDEN, + /** * A regular video is minimized. * @@ -28,6 +30,7 @@ enum class PlayerType { WATCH_WHILE_FULLSCREEN, WATCH_WHILE_SLIDING_MAXIMIZED_FULLSCREEN, WATCH_WHILE_SLIDING_MINIMIZED_MAXIMIZED, + /** * Player is either sliding to [HIDDEN] state because a Short was opened while a regular video is on screen. * OR @@ -35,12 +38,14 @@ enum class PlayerType { */ WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED, WATCH_WHILE_SLIDING_FULLSCREEN_DISMISSED, + /** * Home feed video playback. */ INLINE_MINIMAL, VIRTUAL_REALITY_FULLSCREEN, - WATCH_WHILE_PICTURE_IN_PICTURE; + WATCH_WHILE_PICTURE_IN_PICTURE, + ; companion object { @@ -67,6 +72,7 @@ enum class PlayerType { currentPlayerType = value onChange(currentPlayerType) } + @Volatile // value is read/write from different threads private var currentPlayerType = NONE @@ -126,5 +132,4 @@ enum class PlayerType { fun isNoneHiddenOrMinimized(): Boolean { return isNoneHiddenOrSlidingMinimized() || this == WATCH_WHILE_MINIMIZED } - -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/youtube/shared/VideoState.kt b/app/src/main/java/app/revanced/integrations/youtube/shared/VideoState.kt index dfae4133..75db347b 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/shared/VideoState.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/shared/VideoState.kt @@ -12,10 +12,13 @@ enum class VideoState { PAUSED, RECOVERABLE_ERROR, UNRECOVERABLE_ERROR, + /** * @see [VideoInformation.isAtEndOfVideo] */ - ENDED; + ENDED, + + ; companion object { @@ -43,6 +46,6 @@ enum class VideoState { currentVideoState = value } - private var currentVideoState : VideoState? = null + private var currentVideoState: VideoState? = null } -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/SwipeControlsConfigurationProvider.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/SwipeControlsConfigurationProvider.kt index e916186b..0e2d7997 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/SwipeControlsConfigurationProvider.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/SwipeControlsConfigurationProvider.kt @@ -11,7 +11,7 @@ import app.revanced.integrations.youtube.shared.PlayerType * @param context the context to create in */ class SwipeControlsConfigurationProvider( - private val context: Context + private val context: Context, ) { //region swipe enable /** @@ -105,4 +105,4 @@ class SwipeControlsConfigurationProvider( get() = Settings.SWIPE_SAVE_AND_RESTORE_BRIGHTNESS.get() //endregion -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/SwipeControlsHostActivity.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/SwipeControlsHostActivity.kt index 838f6ecb..e6f233e8 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/SwipeControlsHostActivity.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/SwipeControlsHostActivity.kt @@ -6,6 +6,8 @@ import android.os.Bundle import android.view.KeyEvent import android.view.MotionEvent 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.swipecontrols.controller.AudioVolumeController 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.misc.Rectangle 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 /** @@ -80,14 +80,18 @@ class SwipeControlsHostActivity : Activity() { override fun dispatchTouchEvent(ev: MotionEvent?): Boolean { ensureInitialized() - return if ((ev != null) && gesture.submitTouchEvent(ev)) true else { + return if ((ev != null) && gesture.submitTouchEvent(ev)) { + true + } else { super.dispatchTouchEvent(ev) } } override fun dispatchKeyEvent(ev: KeyEvent?): Boolean { ensureInitialized() - return if ((ev != null) && keys.onKeyEvent(ev)) true else { + return if ((ev != null) && keys.onKeyEvent(ev)) { + true + } else { super.dispatchKeyEvent(ev) } } @@ -139,7 +143,7 @@ class SwipeControlsHostActivity : Activity() { contentRoot.x.toInt(), contentRoot.y.toInt(), contentRoot.width, - contentRoot.height + contentRoot.height, ) } @@ -157,7 +161,7 @@ class SwipeControlsHostActivity : Activity() { * (re) attaches swipe overlays */ private fun reAttachOverlays() { - printDebug{ "attaching swipe controls overlay" } + printDebug { "attaching swipe controls overlay" } contentRoot.removeView(overlay) contentRoot.addView(overlay) } @@ -168,7 +172,7 @@ class SwipeControlsHostActivity : Activity() { * @param type the new player type */ private fun onPlayerTypeChanged(type: PlayerType) { - if (config.shouldSaveAndRestoreBrightness) + if (config.shouldSaveAndRestoreBrightness) { when (type) { PlayerType.WATCH_WHILE_FULLSCREEN -> screen?.restore() else -> { @@ -176,29 +180,38 @@ class SwipeControlsHostActivity : Activity() { screen?.restoreDefaultBrightness() } } + } } /** * create the audio volume controller */ private fun createAudioController() = - if (config.enableVolumeControls) - AudioVolumeController(this) else null + if (config.enableVolumeControls) { + AudioVolumeController(this) + } else { + null + } /** * create the screen brightness controller instance */ private fun createScreenController() = - if (config.enableBrightnessControl) - ScreenBrightnessController(this) else null + if (config.enableBrightnessControl) { + ScreenBrightnessController(this) + } else { + null + } /** * create the gesture controller based on settings */ private fun createGestureController() = - if (config.shouldEnablePressToSwipe) + if (config.shouldEnablePressToSwipe) { PressToSwipeController(this) - else ClassicSwipeController(this) + } else { + ClassicSwipeController(this) + } companion object { /** diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/AudioVolumeController.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/AudioVolumeController.kt index ef4bbefb..f607c1fa 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/AudioVolumeController.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/AudioVolumeController.kt @@ -3,8 +3,8 @@ package app.revanced.integrations.youtube.swipecontrols.controller import android.content.Context import android.media.AudioManager import android.os.Build -import app.revanced.integrations.youtube.swipecontrols.misc.clamp import app.revanced.integrations.shared.Logger.printException +import app.revanced.integrations.youtube.swipecontrols.misc.clamp import kotlin.properties.Delegates /** @@ -15,7 +15,7 @@ import kotlin.properties.Delegates */ class AudioVolumeController( context: Context, - private val targetStream: Int = AudioManager.STREAM_MUSIC + private val targetStream: Int = AudioManager.STREAM_MUSIC, ) { /** @@ -34,9 +34,13 @@ class AudioVolumeController( audioManager = mgr maximumVolumeIndex = audioManager.getStreamMaxVolume(targetStream) minimumVolumeIndex = - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) audioManager.getStreamMinVolume( - targetStream - ) else 0 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + audioManager.getStreamMinVolume( + targetStream, + ) + } else { + 0 + } } } diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/ScreenBrightnessController.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/ScreenBrightnessController.kt index 356d9813..1cf282e8 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/ScreenBrightnessController.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/ScreenBrightnessController.kt @@ -10,7 +10,7 @@ import app.revanced.integrations.youtube.swipecontrols.misc.clamp * @param host the host activity of which the brightness is adjusted */ class ScreenBrightnessController( - private val host: Activity + private val host: Activity, ) { /** * screen brightness saved by [save] @@ -68,4 +68,4 @@ class ScreenBrightnessController( attr.screenBrightness = value host.window.attributes = attr } -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/SwipeZonesController.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/SwipeZonesController.kt index 93501bf0..58fddeb5 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/SwipeZonesController.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/SwipeZonesController.kt @@ -3,12 +3,12 @@ package app.revanced.integrations.youtube.swipecontrols.controller import android.app.Activity import android.util.TypedValue 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.applyDimension -import app.revanced.integrations.shared.Utils import kotlin.math.min -/** +/** * Y- Axis: * -------- 0 * ^ @@ -36,7 +36,7 @@ import kotlin.math.min @Suppress("PrivatePropertyName") class SwipeZonesController( private val host: Activity, - private val fallbackScreenRect: () -> Rectangle + private val fallbackScreenRect: () -> Rectangle, ) { /** * 20dp, in pixels @@ -74,7 +74,7 @@ class SwipeZonesController( p.x + _20dp, p.y + _40dp, p.width - _20dp, - p.height - _20dp - _80dp + p.height - _20dp - _80dp, ) } @@ -89,7 +89,7 @@ class SwipeZonesController( eRect.right - zoneWidth, eRect.top, zoneWidth, - eRect.height + eRect.height, ) } @@ -103,7 +103,7 @@ class SwipeZonesController( effectiveSwipeRect.left, effectiveSwipeRect.top, zoneWidth, - effectiveSwipeRect.height + effectiveSwipeRect.height, ) } @@ -137,8 +137,8 @@ class SwipeZonesController( playerView.x.toInt(), playerView.y.toInt(), min(playerView.width, playerWidthWithPadding), - playerView.height + playerView.height, ) } } -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/VolumeKeysController.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/VolumeKeysController.kt index 46c82aac..000634b6 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/VolumeKeysController.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/VolumeKeysController.kt @@ -9,7 +9,7 @@ import app.revanced.integrations.youtube.swipecontrols.SwipeControlsHostActivity * @param controller main controller instance */ class VolumeKeysController( - private val controller: SwipeControlsHostActivity + private val controller: SwipeControlsHostActivity, ) { /** * key event handler @@ -18,7 +18,7 @@ class VolumeKeysController( * @return consume the event? */ fun onKeyEvent(event: KeyEvent): Boolean { - if(!controller.config.overwriteVolumeKeyControls) { + if (!controller.config.overwriteVolumeKeyControls) { return false } diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/ClassicSwipeController.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/ClassicSwipeController.kt index e4cb9cd2..3f1c468f 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/ClassicSwipeController.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/ClassicSwipeController.kt @@ -15,7 +15,7 @@ import app.revanced.integrations.youtube.swipecontrols.misc.toPoint * @param controller reference to the main swipe controller */ class ClassicSwipeController( - private val controller: SwipeControlsHostActivity + private val controller: SwipeControlsHostActivity, ) : BaseGestureController(controller), PlayerControlsVisibilityObserver by PlayerControlsVisibilityObserverImpl(controller) { /** @@ -27,10 +27,16 @@ class ClassicSwipeController( get() = currentSwipe == SwipeDetector.SwipeDirection.VERTICAL override fun isInSwipeZone(motionEvent: MotionEvent): Boolean { - val inVolumeZone = if (controller.config.enableVolumeControls) - (motionEvent.toPoint() in controller.zones.volume) else false - val inBrightnessZone = if (controller.config.enableBrightnessControl) - (motionEvent.toPoint() in controller.zones.brightness) else false + val inVolumeZone = if (controller.config.enableVolumeControls) { + (motionEvent.toPoint() in controller.zones.volume) + } else { + false + } + val inBrightnessZone = if (controller.config.enableBrightnessControl) { + (motionEvent.toPoint() in controller.zones.brightness) + } else { + false + } return inVolumeZone || inBrightnessZone } @@ -92,7 +98,7 @@ class ClassicSwipeController( from: MotionEvent, to: MotionEvent, distanceX: Double, - distanceY: Double + distanceY: Double, ): Boolean { // cancel if not vertical if (currentSwipe != SwipeDetector.SwipeDirection.VERTICAL) return false diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/PressToSwipeController.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/PressToSwipeController.kt index bf391462..84faf385 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/PressToSwipeController.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/PressToSwipeController.kt @@ -13,7 +13,7 @@ import app.revanced.integrations.youtube.swipecontrols.misc.toPoint * @param controller reference to the main swipe controller */ class PressToSwipeController( - private val controller: SwipeControlsHostActivity + private val controller: SwipeControlsHostActivity, ) : BaseGestureController(controller) { /** * 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 isInSwipeZone(motionEvent: MotionEvent): Boolean { - val inVolumeZone = if (controller.config.enableVolumeControls) - (motionEvent.toPoint() in controller.zones.volume) else false - val inBrightnessZone = if (controller.config.enableBrightnessControl) - (motionEvent.toPoint() in controller.zones.brightness) else false + val inVolumeZone = if (controller.config.enableVolumeControls) { + (motionEvent.toPoint() in controller.zones.volume) + } else { + false + } + val inBrightnessZone = if (controller.config.enableBrightnessControl) { + (motionEvent.toPoint() in controller.zones.brightness) + } else { + false + } return inVolumeZone || inBrightnessZone } @@ -53,7 +59,7 @@ class PressToSwipeController( from: MotionEvent, to: MotionEvent, distanceX: Double, - distanceY: Double + distanceY: Double, ): Boolean { // cancel if not in swipe session or vertical if (!isInSwipeSession || currentSwipe != SwipeDetector.SwipeDirection.VERTICAL) return false diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/BaseGestureController.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/BaseGestureController.kt index b3c54e44..fb5a1b04 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/BaseGestureController.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/BaseGestureController.kt @@ -11,11 +11,11 @@ import app.revanced.integrations.youtube.swipecontrols.SwipeControlsHostActivity * @param controller reference to the main swipe controller */ abstract class BaseGestureController( - private val controller: SwipeControlsHostActivity + private val controller: SwipeControlsHostActivity, ) : GestureController, GestureDetector.SimpleOnGestureListener(), SwipeDetector by SwipeDetectorImpl( - controller.config.swipeMagnitudeThreshold.toDouble() + controller.config.swipeMagnitudeThreshold.toDouble(), ), VolumeAndBrightnessScroller by VolumeAndBrightnessScrollerImpl( controller, @@ -23,7 +23,7 @@ abstract class BaseGestureController( controller.screen, controller.overlay, 10, - 1 + 1, ) { /** @@ -85,7 +85,7 @@ abstract class BaseGestureController( from: MotionEvent, to: MotionEvent, distanceX: Float, - distanceY: Float + distanceY: Float, ): Boolean { // submit to swipe detector submitForSwipe(from, to, distanceX, distanceY) @@ -96,7 +96,7 @@ abstract class BaseGestureController( from, to, distanceX.toDouble(), - distanceY.toDouble() + distanceY.toDouble(), ) // if the swipe was consumed, cancel downstream events once @@ -110,7 +110,9 @@ abstract class BaseGestureController( } consumed - } else false + } else { + false + } } /** @@ -149,6 +151,6 @@ abstract class BaseGestureController( from: MotionEvent, to: MotionEvent, distanceX: Double, - distanceY: Double + distanceY: Double, ): Boolean } diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/SwipeDetector.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/SwipeDetector.kt index 078acfce..3dc5cc42 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/SwipeDetector.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/SwipeDetector.kt @@ -25,7 +25,7 @@ interface SwipeDetector { from: MotionEvent, to: MotionEvent, distanceX: Float, - distanceY: Float + distanceY: Float, ) /** @@ -50,7 +50,7 @@ interface SwipeDetector { /** * swipe along the Y- Axes */ - VERTICAL + VERTICAL, } } @@ -60,7 +60,7 @@ interface SwipeDetector { * @param swipeMagnitudeThreshold minimum magnitude before a swipe is detected as such */ class SwipeDetectorImpl( - private val swipeMagnitudeThreshold: Double + private val swipeMagnitudeThreshold: Double, ) : SwipeDetector { override var currentSwipe = SwipeDetector.SwipeDirection.NONE @@ -68,7 +68,7 @@ class SwipeDetectorImpl( from: MotionEvent, to: MotionEvent, distanceX: Float, - distanceY: Float + distanceY: Float, ) { if (currentSwipe == SwipeDetector.SwipeDirection.NONE) { // no swipe direction was detected yet, try to detect one diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/VolumeAndBrightnessScroller.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/VolumeAndBrightnessScroller.kt index 758e584a..dec14b81 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/VolumeAndBrightnessScroller.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/VolumeAndBrightnessScroller.kt @@ -48,7 +48,7 @@ class VolumeAndBrightnessScrollerImpl( private val screenController: ScreenBrightnessController?, private val overlayController: SwipeControlsOverlay, volumeDistance: Int = 10, - brightnessDistance: Int = 1 + brightnessDistance: Int = 1, ) : VolumeAndBrightnessScroller { // region volume @@ -56,8 +56,8 @@ class VolumeAndBrightnessScrollerImpl( ScrollDistanceHelper( volumeDistance.applyDimension( context, - TypedValue.COMPLEX_UNIT_DIP - ) + TypedValue.COMPLEX_UNIT_DIP, + ), ) { _, _, direction -> volumeController?.run { volume += direction @@ -73,8 +73,8 @@ class VolumeAndBrightnessScrollerImpl( ScrollDistanceHelper( brightnessDistance.applyDimension( context, - TypedValue.COMPLEX_UNIT_DIP - ) + TypedValue.COMPLEX_UNIT_DIP, + ), ) { _, _, direction -> screenController?.run { if (screenBrightness > 0 || direction > 0) { diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/Point.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/Point.kt index eaca3270..f3d8a966 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/Point.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/Point.kt @@ -7,7 +7,7 @@ import android.view.MotionEvent */ data class Point( val x: Int, - val y: Int + val y: Int, ) /** diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/Rectangle.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/Rectangle.kt index 5a3255e7..3195251d 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/Rectangle.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/Rectangle.kt @@ -7,7 +7,7 @@ data class Rectangle( val x: Int, val y: Int, val width: Int, - val height: Int + val height: Int, ) { val left = x val right = x + width @@ -15,7 +15,6 @@ data class Rectangle( val bottom = y + height } - /** * is the point within this rectangle? */ diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/ScrollDistanceHelper.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/ScrollDistanceHelper.kt index eb7082ce..a85dbac8 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/ScrollDistanceHelper.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/ScrollDistanceHelper.kt @@ -11,7 +11,7 @@ import kotlin.math.sign */ class ScrollDistanceHelper( 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( oldDistance, scrolledDistance, - sign(scrolledDistance).toInt() + sign(scrolledDistance).toInt(), ) } } @@ -53,4 +53,4 @@ class ScrollDistanceHelper( private fun subtractUnitDistance() { scrolledDistance -= (unitDistance * sign(scrolledDistance)) } -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/SwipeControlsOverlay.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/SwipeControlsOverlay.kt index b4155ccf..644cb23f 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/SwipeControlsOverlay.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/SwipeControlsOverlay.kt @@ -23,4 +23,4 @@ interface SwipeControlsOverlay { * called when a new swipe- session has started */ fun onEnterSwipeSession() -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/SwipeControlsUtils.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/SwipeControlsUtils.kt index a197c510..141dc222 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/SwipeControlsUtils.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/misc/SwipeControlsUtils.kt @@ -20,7 +20,6 @@ fun Int.applyDimension(context: Context, unit: Int): Int { return TypedValue.applyDimension( unit, this.toFloat(), - context.resources.displayMetrics + context.resources.displayMetrics, ).roundToInt() } - diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/views/SwipeControlsOverlayLayout.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/views/SwipeControlsOverlayLayout.kt index d5f0c25a..dbe2434f 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/views/SwipeControlsOverlayLayout.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/views/SwipeControlsOverlayLayout.kt @@ -11,10 +11,10 @@ import android.view.View import android.view.ViewGroup import android.widget.RelativeLayout import android.widget.TextView +import app.revanced.integrations.shared.Utils import app.revanced.integrations.youtube.swipecontrols.SwipeControlsConfigurationProvider import app.revanced.integrations.youtube.swipecontrols.misc.SwipeControlsOverlay import app.revanced.integrations.youtube.swipecontrols.misc.applyDimension -import app.revanced.integrations.shared.Utils import kotlin.math.round /** @@ -24,7 +24,7 @@ import kotlin.math.round */ class SwipeControlsOverlayLayout( context: Context, - private val config: SwipeControlsConfigurationProvider + private val config: SwipeControlsConfigurationProvider, ) : RelativeLayout(context), SwipeControlsOverlay { /** * DO NOT use this, for tools only @@ -40,14 +40,14 @@ class SwipeControlsOverlayLayout( private fun getDrawable(name: String, width: Int, height: Int): Drawable { return resources.getDrawable( Utils.getResourceIdentifier(context, name, "drawable"), - context.theme + context.theme, ).apply { setTint(config.overlayForegroundColor) setBounds( 0, 0, width, - height + height, ) } } @@ -59,14 +59,14 @@ class SwipeControlsOverlayLayout( feedbackTextView = TextView(context).apply { layoutParams = LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT + ViewGroup.LayoutParams.WRAP_CONTENT, ).apply { addRule(CENTER_IN_PARENT, TRUE) setPadding( feedbackTextViewPadding, feedbackTextViewPadding, feedbackTextViewPadding, - feedbackTextViewPadding + feedbackTextViewPadding, ) } background = GradientDrawable().apply { @@ -108,7 +108,7 @@ class SwipeControlsOverlayLayout( icon, null, null, - null + null, ) visibility = VISIBLE } @@ -117,7 +117,7 @@ class SwipeControlsOverlayLayout( override fun onVolumeChanged(newVolume: Int, maximumVolume: Int) { showFeedbackView( "$newVolume", - if (newVolume > 0) normalVolumeIcon else mutedVolumeIcon + if (newVolume > 0) normalVolumeIcon else mutedVolumeIcon, ) } @@ -134,8 +134,8 @@ class SwipeControlsOverlayLayout( @Suppress("DEPRECATION") performHapticFeedback( HapticFeedbackConstants.LONG_PRESS, - HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING + HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING, ) } } -} \ No newline at end of file +} diff --git a/stub/build.gradle.kts b/stub/build.gradle.kts index d16c19b7..c874e310 100644 --- a/stub/build.gradle.kts +++ b/stub/build.gradle.kts @@ -16,7 +16,7 @@ android { isMinifyEnabled = false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" + "proguard-rules.pro", ) } }