Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
chore: Lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Mar 2, 2024
1 parent e5aa30e commit 36aa6c9
Show file tree
Hide file tree
Showing 33 changed files with 150 additions and 113 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.{kt,kts}]
ktlint_code_style = intellij_idea
ktlint_standard_no-wildcard-imports = disabled
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ abstract class BaseJsonHook : JsonHook {
abstract fun apply(json: JSONObject)

override fun transform(json: JSONObject) = json.apply { apply(json) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ interface JsonHook : Hook<JSONObject> {
fun transform(json: JSONObject): JSONObject

override fun hook(type: JSONObject) = transform(type)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ object JsonHookPatch {

return StreamUtils.fromString(jsonObject.toString())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ interface Hook<T> {
* @param type The type to hook
*/
fun hook(type: T): T
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ 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.
*
* @param json The JSONObject.
*/
override fun apply(json: JSONObject) = TwiFucker.hidePromotedAds(json)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ object DummyHook : BaseJsonHook() {
override fun apply(json: JSONObject) {
// Do nothing.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ 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.
*
* @param json The JSONObject.
*/
override fun apply(json: JSONObject) = TwiFucker.hideRecommendedUsers(json)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ object JsonUtils {
@JvmStatic
@Throws(IOException::class, JSONException::class)
fun parseJson(jsonInputStream: InputStream) = JSONObject(StreamUtils.toString(jsonInputStream))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ object StreamUtils {
fun fromString(string: String): InputStream {
return ByteArrayInputStream(string.toByteArray())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ class Event<T> {
observer.invoke(value)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down Expand Up @@ -81,4 +81,4 @@ interface PlayerControlsVisibilityObserver {
* is the value of [playerControlsVisibility] equal to [View.VISIBLE]?
*/
val arePlayerControlsVisible: Boolean
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,8 +42,8 @@ object PlayerOverlays {
ChildrenChangeEventArgs(
parent,
child,
false
)
false,
),
)
}
}
Expand All @@ -54,8 +54,8 @@ object PlayerOverlays {
ChildrenChangeEventArgs(
parent,
child,
true
)
true,
),
)
}
}
Expand All @@ -69,15 +69,15 @@ object PlayerOverlays {
oldLeft,
oldTop,
oldRight - oldLeft,
oldBottom - oldTop
oldBottom - oldTop,
),
Rectangle(
newLeft,
newTop,
newRight - newLeft,
newBottom - newTop
)
)
newBottom - newTop,
),
),
)
}
}
Expand All @@ -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,
)
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
*
Expand All @@ -28,19 +30,22 @@ 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
* The user has swiped a minimized player away to be closed (and no Short is being opened).
*/
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 {

Expand All @@ -67,6 +72,7 @@ enum class PlayerType {
currentPlayerType = value
onChange(currentPlayerType)
}

@Volatile // value is read/write from different threads
private var currentPlayerType = NONE

Expand Down Expand Up @@ -126,5 +132,4 @@ enum class PlayerType {
fun isNoneHiddenOrMinimized(): Boolean {
return isNoneHiddenOrSlidingMinimized() || this == WATCH_WHILE_MINIMIZED
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ enum class VideoState {
PAUSED,
RECOVERABLE_ERROR,
UNRECOVERABLE_ERROR,

/**
* @see [VideoInformation.isAtEndOfVideo]
*/
ENDED;
ENDED,

;

companion object {

Expand Down Expand Up @@ -43,6 +46,6 @@ enum class VideoState {
currentVideoState = value
}

private var currentVideoState : VideoState? = null
private var currentVideoState: VideoState? = null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down Expand Up @@ -105,4 +105,4 @@ class SwipeControlsConfigurationProvider(
get() = Settings.SWIPE_SAVE_AND_RESTORE_BRIGHTNESS.get()

//endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

/**
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -139,7 +143,7 @@ class SwipeControlsHostActivity : Activity() {
contentRoot.x.toInt(),
contentRoot.y.toInt(),
contentRoot.width,
contentRoot.height
contentRoot.height,
)
}

Expand All @@ -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)
}
Expand All @@ -168,37 +172,46 @@ 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 -> {
screen?.save()
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 {
/**
Expand Down
Loading

0 comments on commit 36aa6c9

Please sign in to comment.