Skip to content

Commit

Permalink
feat(YouTube): Reorganize settings menu
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios committed Feb 17, 2024
1 parent b5caab6 commit 13105ba
Show file tree
Hide file tree
Showing 59 changed files with 176 additions and 190 deletions.
9 changes: 5 additions & 4 deletions api/revanced-patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,6 @@ public abstract class app/revanced/patches/shared/misc/settings/preference/BaseP
public class app/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen : app/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$BasePreferenceCollection {
public fun <init> (Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Set;Ljava/util/Set;)V
public synthetic fun <init> (Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Set;Ljava/util/Set;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen;Ljava/lang/String;Ljava/util/Set;Ljava/util/Set;)V
public synthetic fun <init> (Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen;Ljava/lang/String;Ljava/util/Set;Ljava/util/Set;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun addPreferences ([Lapp/revanced/patches/shared/misc/settings/preference/BasePreference;)V
public final fun getCategories ()Ljava/util/Set;
public synthetic fun transform ()Lapp/revanced/patches/shared/misc/settings/preference/BasePreference;
Expand Down Expand Up @@ -1601,9 +1599,12 @@ public final class app/revanced/patches/youtube/misc/settings/SettingsPatch$Pref
public static final field INSTANCE Lapp/revanced/patches/youtube/misc/settings/SettingsPatch$PreferenceScreen;
public fun commit (Lapp/revanced/patches/shared/misc/settings/preference/PreferenceScreen;)V
public final fun getADS ()Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen;
public final fun getINTERACTIONS ()Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen;
public final fun getLAYOUT ()Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen;
public final fun getLAYOUT_FEED ()Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen;
public final fun getLAYOUT_OTHER ()Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen;
public final fun getLAYOUT_PLAYER ()Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen;
public final fun getMISC ()Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen;
public final fun getSEEKBAR ()Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen;
public final fun getSHORTS ()Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen;
public final fun getVIDEO ()Lapp/revanced/patches/shared/misc/settings/preference/BasePreferenceScreen$Screen;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,23 @@ abstract class BaseSettingsResourcePatch(
}

override fun close() {
fun Node.addPreference(preference: BasePreference) {
preference.serialize(ownerDocument) { resource ->
fun Node.addPreference(preference: BasePreference, addFirst: Boolean = false) {
val node = preference.serialize(ownerDocument) { resource ->
// TODO: Currently, resources can only be added to "values", which may not be the correct place.
// It may be necessary to ask for the desired resourceValue in the future.
AddResourcesPatch("values", resource)
}.let(this::appendChild)
}
if (addFirst && firstChild != null) {
insertBefore(node, firstChild)
} else {
appendChild(node)
}
}

// Add the root preference to an existing fragment if needed.
rootPreference?.let { (intentPreference, fragment) ->
context.xmlEditor["res/xml/$fragment.xml"].use {
it.getNode("PreferenceScreen").addPreference(intentPreference)
it.getNode("PreferenceScreen").addPreference(intentPreference, true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ abstract class BasePreferenceScreen(
val categories: MutableSet<Category> = mutableSetOf()
) : BasePreferenceCollection(key, titleKey, preferences) {

/**
* Initialize using title and summary keys with suffix "_title" and "_summary".
*/
constructor(
key: String? = null,
preferences: MutableSet<BasePreference> = mutableSetOf(),
categories: MutableSet<Category> = mutableSetOf()
) : this(key, key + "_title", key + "_summary", preferences, categories)

override fun transform(): PreferenceScreen {
return PreferenceScreen(
key,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
package app.revanced.patches.shared.misc.settings.preference

import app.revanced.patches.shared.misc.settings.preference.IntentPreference.Intent
import app.revanced.util.resource.BaseResource
import org.w3c.dom.Document

/**
* A preference that opens an intent.
*
* @param key The preference key. If null, other parameters must be specified.
* @param key Optional preference key.
* @param titleKey The preference title key.
* @param summaryKey The preference summary key.
* @param tag The preference tag.
* @param intent The intent to open.
*
* @see Intent
*/
class IntentPreference(
key: String? = null,
titleKey: String = "${key}_title",
summaryKey: String? = "${key}_summary",
tag: String = "Preference",
val intent: Intent,
) : BasePreference(null, titleKey, summaryKey, tag) {
) : BasePreference(key, titleKey, summaryKey, tag) {

override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit) =
super.serialize(ownerDocument, resourceCallback).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
]
)
@Suppress("unused")
object HideAdsPatch : BytecodePatch() {
object HideAdsPatch : BytecodePatch(emptySet()) {
override fun execute(context: BytecodeContext) {
context.classes.forEach { classDef ->
classDef.methods.forEach { method ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import app.revanced.patches.youtube.video.information.VideoInformationPatch
]
)
@Suppress("unused")
object CopyVideoUrlBytecodePatch : BytecodePatch() {
object CopyVideoUrlBytecodePatch : BytecodePatch(emptySet()) {
private const val INTEGRATIONS_PLAYER_PACKAGE = "Lapp/revanced/integrations/youtube/videoplayer"
private val BUTTONS_DESCRIPTORS = listOf(
"$INTEGRATIONS_PLAYER_PACKAGE/CopyVideoUrlButton;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal object CopyVideoUrlResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.INTERACTIONS.addPreferences(
SettingsPatch.PreferenceScreen.LAYOUT_PLAYER.addPreferences(
PreferenceScreen(
"revanced_copy_video_url_preference_screen",
preferences = setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ object RemoveViewerDiscretionDialogPatch : BytecodePatch(
override fun execute(context: BytecodeContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.INTERACTIONS.addPreferences(SwitchPreference("revanced_remove_viewer_discretion_dialog"))
SettingsPatch.PreferenceScreen.LAYOUT_PLAYER.addPreferences(
SwitchPreference("revanced_remove_viewer_discretion_dialog")
)

CreateDialogFingerprint.result?.mutableMethod?.apply {
val showDialogIndex = implementation!!.instructions.lastIndex - 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import app.revanced.patches.youtube.video.information.VideoInformationPatch
]
)
@Suppress("unused")
object ExternalDownloadsBytecodePatch : BytecodePatch() {
object ExternalDownloadsBytecodePatch : BytecodePatch(emptySet()) {
private const val BUTTON_DESCRIPTOR = "Lapp/revanced/integrations/youtube/videoplayer/ExternalDownloadButton;"

override fun execute(context: BytecodeContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal object ExternalDownloadsResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.INTERACTIONS.addPreferences(
SettingsPatch.PreferenceScreen.LAYOUT_PLAYER.addPreferences(
PreferenceScreen(
"revanced_external_downloader_preference_screen",
preferences = setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object DisablePreciseSeekingGesturePatch : BytecodePatch(
override fun execute(context: BytecodeContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.INTERACTIONS.addPreferences(
SettingsPatch.PreferenceScreen.SEEKBAR.addPreferences(
SwitchPreference("revanced_disable_precise_seeking_gesture")
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object EnableSeekbarTappingPatch : BytecodePatch(
override fun execute(context: BytecodeContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.INTERACTIONS.addPreferences(SwitchPreference("revanced_seekbar_tapping"))
SettingsPatch.PreferenceScreen.SEEKBAR.addPreferences(SwitchPreference("revanced_seekbar_tapping"))

// Find the required methods to tap the seekbar.
val seekbarTappingMethods = OnTouchEventHandlerFingerprint.result?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object EnableSlideToSeekPatch : BytecodePatch(
override fun execute(context: BytecodeContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.INTERACTIONS.addPreferences(SwitchPreference("revanced_slide_to_seek"))
SettingsPatch.PreferenceScreen.SEEKBAR.addPreferences(SwitchPreference("revanced_slide_to_seek"))

arrayOf(
// Restore the behaviour to slide to seek.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal object SwipeControlsResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.INTERACTIONS.addPreferences(
SettingsPatch.PreferenceScreen.LAYOUT_PLAYER.addPreferences(
PreferenceScreen(
key = "revanced_swipe_controls_preference_screen",
preferences = setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object AutoCaptionsPatch : BytecodePatch(
override fun execute(context: BytecodeContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(SwitchPreference("revanced_auto_captions"))
SettingsPatch.PreferenceScreen.LAYOUT_PLAYER.addPreferences(SwitchPreference("revanced_auto_captions"))

mapOf(
StartVideoInformerFingerprint to 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ object ChangeHeaderPatch : ResourcePatch() {
}

/**
* A function that overwrites both header variants from [from] to [to] in the target resource directories.
* A function that overwrites both header variants in the target resource directories.
*/
val overwriteFromTo: (String, String) -> Unit = { from: String, to: String ->
targetResourceDirectories.forEach { directory ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object HideButtonsPatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SettingsPatch.PreferenceScreen.LAYOUT_PLAYER.addPreferences(
PreferenceScreen(
"revanced_hide_buttons_preference_screen",
preferences = setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object HideAutoplayButtonPatch : BytecodePatch(
override fun execute(context: BytecodeContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(SwitchPreference("revanced_hide_autoplay_button"))
SettingsPatch.PreferenceScreen.LAYOUT_PLAYER.addPreferences(SwitchPreference("revanced_hide_autoplay_button"))

LayoutConstructorFingerprint.result?.mutableMethod?.apply {
val layoutGenMethodInstructions = implementation!!.instructions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object HideCaptionsButtonPatch : BytecodePatch(
override fun execute(context: BytecodeContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(SwitchPreference("revanced_hide_captions_button"))
SettingsPatch.PreferenceScreen.LAYOUT_PLAYER.addPreferences(SwitchPreference("revanced_hide_captions_button"))

val subtitleButtonControllerMethod = SubtitleButtonControllerFingerprint.result!!.mutableMethod

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import app.revanced.patches.youtube.misc.settings.SettingsPatch
CompatiblePackage("com.google.android.youtube")
]
)
object HideCastButtonPatch : BytecodePatch() {
object HideCastButtonPatch : BytecodePatch(emptySet()) {
override fun execute(context: BytecodeContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(SwitchPreference("revanced_hide_cast_button"))
SettingsPatch.PreferenceScreen.LAYOUT_PLAYER.addPreferences(SwitchPreference("revanced_hide_cast_button"))

val buttonClass = context.findClass("MediaRouteButton")
?: throw PatchException("MediaRouteButton class not found.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object NavigationButtonsPatch : BytecodePatch(
override fun execute(context: BytecodeContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SettingsPatch.PreferenceScreen.LAYOUT_OTHER.addPreferences(
PreferenceScreen(
key = "revanced_navigation_buttons_preference_screen",
preferences = setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object HidePlayerButtonsPatch : BytecodePatch(
override fun execute(context: BytecodeContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(SwitchPreference("revanced_hide_player_buttons"))
SettingsPatch.PreferenceScreen.LAYOUT_PLAYER.addPreferences(SwitchPreference("revanced_hide_player_buttons"))

PlayerControlsVisibilityModelFingerprint.result?.apply {
val callIndex = scanResult.patternScanResult!!.endIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal object AlbumCardsResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(SwitchPreference("revanced_hide_album_cards"))
SettingsPatch.PreferenceScreen.LAYOUT_FEED.addPreferences(SwitchPreference("revanced_hide_album_cards"))

albumCardId = ResourceMappingPatch.resourceMappings.single {
it.type == "layout" && it.name == "album_card"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal object BreakingNewsResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(SwitchPreference("revanced_hide_breaking_news"))
SettingsPatch.PreferenceScreen.LAYOUT_FEED.addPreferences(SwitchPreference("revanced_hide_breaking_news"))

horizontalCardListId = ResourceMappingPatch.resourceMappings.single {
it.type == "layout" && it.name == "horizontal_card_list"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object CommentsPatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SettingsPatch.PreferenceScreen.LAYOUT_PLAYER.addPreferences(
PreferenceScreen(
"revanced_comments_preference_screen",
preferences = setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal object CrowdfundingBoxResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(SwitchPreference("revanced_hide_crowdfunding_box"))
SettingsPatch.PreferenceScreen.LAYOUT_FEED.addPreferences(SwitchPreference("revanced_hide_crowdfunding_box"))

crowdfundingBoxId = ResourceMappingPatch.resourceMappings.single {
it.type == "layout" && it.name == "donation_companion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal object HideEndscreenCardsResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(SwitchPreference("revanced_hide_endscreen_cards"))
SettingsPatch.PreferenceScreen.LAYOUT_PLAYER.addPreferences(SwitchPreference("revanced_hide_endscreen_cards"))

fun findEndscreenResourceId(name: String) = ResourceMappingPatch.resourceMappings.single {
it.type == "layout" && it.name == "endscreen_element_layout_$name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal object HideFilterBarResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SettingsPatch.PreferenceScreen.LAYOUT_FEED.addPreferences(
PreferenceScreen(
key = "revanced_hide_filter_bar_preference",
preferences = setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal object HideFloatingMicrophoneButtonResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(SwitchPreference("revanced_hide_floating_microphone_button"))
SettingsPatch.PreferenceScreen.LAYOUT_OTHER.addPreferences(SwitchPreference("revanced_hide_floating_microphone_button"))

fabButtonId = ResourceMappingPatch.resourceMappings.find { it.type == "id" && it.name == "fab" }?.id
?: throw PatchException("Can not find required fab button resource id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object DisableFullscreenAmbientModePatch : BytecodePatch(
override fun execute(context: BytecodeContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SettingsPatch.PreferenceScreen.LAYOUT_PLAYER.addPreferences(
SwitchPreference("revanced_disable_fullscreen_ambient_mode")
)

Expand Down
Loading

0 comments on commit 13105ba

Please sign in to comment.