Skip to content

Commit

Permalink
refactor: add simplified Preference constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios committed Dec 31, 2023
1 parent e2984fd commit 1ece93b
Show file tree
Hide file tree
Showing 99 changed files with 504 additions and 1,325 deletions.
26 changes: 15 additions & 11 deletions api/revanced-patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ public final class app/revanced/patches/music/misc/gms/GmsCoreSupportPatch : app
public static final field INSTANCE Lapp/revanced/patches/music/misc/gms/GmsCoreSupportPatch;
}

public final class app/revanced/patches/music/misc/gms/YTMusicGmsCoreSupportResourcePatch : app/revanced/patches/shared/misc/gms/AbstractGmsCoreSupportResourcePatch {
public static final field INSTANCE Lapp/revanced/patches/music/misc/gms/YTMusicGmsCoreSupportResourcePatch;
public final class app/revanced/patches/music/misc/gms/GmsCoreSupportResourcePatch : app/revanced/patches/shared/misc/gms/AbstractGmsCoreSupportResourcePatch {
public static final field INSTANCE Lapp/revanced/patches/music/misc/gms/GmsCoreSupportResourcePatch;
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V
}
Expand Down Expand Up @@ -659,8 +659,8 @@ public final class app/revanced/patches/shared/settings/preference/impl/InputTyp
}

public final class app/revanced/patches/shared/settings/preference/impl/ListPreference : app/revanced/patches/shared/settings/preference/DefaultBasePreference {
public fun <init> (Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patches/shared/settings/preference/impl/ArrayResource;Lapp/revanced/patches/shared/settings/preference/impl/ArrayResource;Ljava/lang/String;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patches/shared/settings/preference/impl/ArrayResource;Lapp/revanced/patches/shared/settings/preference/impl/ArrayResource;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patches/shared/settings/preference/impl/ArrayResource;Lapp/revanced/patches/shared/settings/preference/impl/ArrayResource;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patches/shared/settings/preference/impl/ArrayResource;Lapp/revanced/patches/shared/settings/preference/impl/ArrayResource;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getEntries ()Lapp/revanced/patches/shared/settings/preference/impl/ArrayResource;
public final fun getEntryValues ()Lapp/revanced/patches/shared/settings/preference/impl/ArrayResource;
public fun serialize (Lorg/w3c/dom/Document;)Lorg/w3c/dom/Element;
Expand Down Expand Up @@ -693,8 +693,9 @@ public class app/revanced/patches/shared/settings/preference/impl/PreferenceCate
}

public class app/revanced/patches/shared/settings/preference/impl/PreferenceScreen : app/revanced/patches/shared/settings/preference/BasePreference {
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/util/List;)V
public final fun getPreferences ()Ljava/util/List;
public fun serialize (Lorg/w3c/dom/Document;)Lorg/w3c/dom/Element;
public final fun setPreferences (Ljava/util/List;)V
Expand All @@ -703,12 +704,14 @@ public class app/revanced/patches/shared/settings/preference/impl/PreferenceScre
public final class app/revanced/patches/shared/settings/preference/impl/SwitchPreference : app/revanced/patches/shared/settings/preference/DefaultBasePreference {
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getSummaryOffKey ()Ljava/lang/String;
public final fun getSummaryOnKey ()Ljava/lang/String;
public fun <init> (Ljava/lang/String;Z)V
public synthetic fun <init> (Ljava/lang/String;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun serialize (Lorg/w3c/dom/Document;)Lorg/w3c/dom/Element;
}

public final class app/revanced/patches/shared/settings/preference/impl/TextPreference : app/revanced/patches/shared/settings/preference/DefaultBasePreference {
public fun <init> (Ljava/lang/String;Lapp/revanced/patches/shared/settings/preference/impl/InputType;Ljava/lang/String;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;Lapp/revanced/patches/shared/settings/preference/impl/InputType;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patches/shared/settings/preference/impl/InputType;Ljava/lang/String;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patches/shared/settings/preference/impl/InputType;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getInputType ()Lapp/revanced/patches/shared/settings/preference/impl/InputType;
Expand All @@ -735,9 +738,10 @@ public abstract class app/revanced/patches/shared/settings/util/AbstractPreferen
public class app/revanced/patches/shared/settings/util/AbstractPreferenceScreen$Screen : app/revanced/patches/shared/settings/util/AbstractPreferenceScreen$BasePreferenceCollection {
public fun <init> (Lapp/revanced/patches/shared/settings/util/AbstractPreferenceScreen;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/List;)V
public synthetic fun <init> (Lapp/revanced/patches/shared/settings/util/AbstractPreferenceScreen;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lapp/revanced/patches/shared/settings/util/AbstractPreferenceScreen;Ljava/lang/String;Ljava/util/List;Ljava/util/List;)V
public synthetic fun <init> (Lapp/revanced/patches/shared/settings/util/AbstractPreferenceScreen;Ljava/lang/String;Ljava/util/List;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun addPreferences ([Lapp/revanced/patches/shared/settings/preference/BasePreference;)V
public final fun getCategories ()Ljava/util/List;
public final fun getSummaryKey ()Ljava/lang/String;
public synthetic fun transform ()Lapp/revanced/patches/shared/settings/preference/BasePreference;
public fun transform ()Lapp/revanced/patches/shared/settings/preference/impl/PreferenceScreen;
}
Expand Down Expand Up @@ -1451,8 +1455,8 @@ public final class app/revanced/patches/youtube/misc/gms/GmsCoreSupportPatch : a
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/youtube/misc/gms/YouTubeGmsCoreSupportResourcePatch : app/revanced/patches/shared/misc/gms/AbstractGmsCoreSupportResourcePatch {
public static final field INSTANCE Lapp/revanced/patches/youtube/misc/gms/YouTubeGmsCoreSupportResourcePatch;
public final class app/revanced/patches/youtube/misc/gms/GmsCoreSupportResourcePatch : app/revanced/patches/shared/misc/gms/AbstractGmsCoreSupportResourcePatch {
public static final field INSTANCE Lapp/revanced/patches/youtube/misc/gms/GmsCoreSupportResourcePatch;
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.reddit.ad.comments.fingerprints.HideCommentAdsFingerprint

@Patch(description = "Removes ads in the comments.",)
@Patch(description = "Removes ads in the comments.")
object HideCommentAdsPatch : BytecodePatch(
setOf(HideCommentAdsFingerprint)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.reddit.customclients.syncforreddit.detection.piracy.fingerprints.PiracyDetectionFingerprint

@Patch(description = "Disables detection of modified versions.",)
@Patch(description = "Disables detection of modified versions.")
object DisablePiracyDetectionPatch : BytecodePatch(setOf(PiracyDetectionFingerprint)) {
override fun execute(context: BytecodeContext) {
// Do not throw an error if the fingerprint is not resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import org.w3c.dom.Document
class ListPreference(
key: String,
titleKey: String,
summaryKey: String?,
val entries: ArrayResource?,
val entryValues: ArrayResource?,
summaryKey: String? = null,
default: String? = null,
) : DefaultBasePreference<String>(key, titleKey, summaryKey, "ListPreference", default) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ import org.w3c.dom.Document
open class PreferenceScreen(
key: String,
titleKey: String,
var preferences: List<BasePreference>,
summaryKey: String? = null
summaryKey: String? = null,
var preferences: List<BasePreference>
) : BasePreference(key, titleKey, summaryKey, "PreferenceScreen") {

/**
* Initialize using title and summary keys with suffix "_title" and "_summary".
*/
constructor(
key: String, preferences: List<BasePreference>
) : this(key, "${key}_title", "${key}_summary", preferences)

override fun serialize(ownerDocument: Document) =
super.serialize(ownerDocument).apply {
addSummary(summaryKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ import org.w3c.dom.Element
class SwitchPreference(
key: String,
titleKey: String,
val summaryOnKey: String,
val summaryOffKey: String,
private val summaryOnKey: String,
private val summaryOffKey: String,
default: Boolean = false,
) : DefaultBasePreference<Boolean>( key, titleKey, null, "SwitchPreference", default) {

/**
* Initialize using title and summary keys with the suffix "_title", "_summary_on", "_summary_off"
*/
constructor(key: String, default: Boolean = false) : this(key, "${key}_title",
"${key}_summary_on", "${key}_summary_off", default)

override fun serialize(ownerDocument: Document): Element {
return super.serialize(ownerDocument).apply {
addSummary(summaryOnKey, SummaryType.ON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ class TextPreference(
tag: String = "app.revanced.integrations.settingsmenu.ResettableEditTextPreference"
) : DefaultBasePreference<String>(key, titleKey, summaryKey, tag, default) {

/**
* Initialize using title and summary keys with the suffix "_title", "_summary_on", "_summary_off"
*/
constructor(
key: String, inputType: InputType = InputType.TEXT, default: String? = null,
tag: String = "app.revanced.integrations.settingsmenu.ResettableEditTextPreference"
) : this(key, "${key}_title", "${key}_summary", inputType, default, tag)


override fun serialize(ownerDocument: Document) =
super.serialize(ownerDocument).apply {
setAttribute("android:inputType", inputType.type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,26 @@ abstract class AbstractPreferenceScreen(
open inner class Screen(
key: String,
titleKey: String,
val summaryKey: String? = null,
private val summaryKey: String? = null,
preferences: MutableList<BasePreference> = mutableListOf(),
val categories: MutableList<Category> = mutableListOf()
) : BasePreferenceCollection(key, titleKey, preferences) {

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

override fun transform(): PreferenceScreen {
return PreferenceScreen(
key,
titleKey,
summaryKey,
// Screens and preferences are sorted at runtime by integrations code,
// so they appear in alphabetical order for the localized language in use.
preferences + categories.map { it.transform() },
summaryKey
preferences + categories.map { it.transform() }
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package app.revanced.patches.tiktok.interaction.speed.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

internal object SpeedControlParentFingerprint : MethodFingerprint(
strings = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ object AudioAdsPatch : BytecodePatch(
SettingsPatch.PreferenceScreen.ADS.CLIENT_SIDE.addPreferences(
SwitchPreference(
"revanced_block_audio_ads",
"revanced_block_audio_ads",
"revanced_block_audio_ads_on",
"revanced_block_audio_ads_off",
default = true,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ object EmbeddedAdsPatch : BytecodePatch(
StringsPatch.includePatchStrings("EmbeddedAds")
SettingsPatch.PreferenceScreen.ADS.SURESTREAM.addPreferences(
ListPreference(
"revanced_block_embedded_ads",
"revanced_block_embedded_ads",
ArrayResource(
key = "revanced_block_embedded_ads",
titleKey = "revanced_block_embedded_ads",
summaryKey = null,
entries = ArrayResource(
"revanced_hls_proxies",
listOf(
"revanced_proxy_disabled",
"revanced_proxy_luminous",
"revanced_proxy_purpleadblock",
)
),
ArrayResource(
entryValues = ArrayResource(
"revanced_hls_proxies_values",
listOf(
"disabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ object VideoAdsPatch : AbstractAdPatch(
SettingsPatch.PreferenceScreen.ADS.CLIENT_SIDE.addPreferences(
SwitchPreference(
"revanced_block_video_ads",
"revanced_block_video_ads",
"revanced_block_video_ads_on",
"revanced_block_video_ads_off",
default = true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@ object ShowDeletedMessagesPatch : BytecodePatch(
StringsPatch.includePatchStrings("ShowDeletedMessages")
SettingsPatch.PreferenceScreen.CHAT.GENERAL.addPreferences(
ListPreference(
"revanced_show_deleted_messages",
"revanced_show_deleted_messages_title",
ArrayResource(
key = "revanced_show_deleted_messages",
titleKey = "revanced_show_deleted_messages_title",
summaryKey = null,
entries = ArrayResource(
"revanced_deleted_messages_entries",
listOf(
"revanced_deleted_messages_entry_hide",
"revanced_deleted_messages_entry_spoiler",
"revanced_deleted_messages_entry_cross_out",
)
),
ArrayResource(
entryValues = ArrayResource(
"revanced_deleted_messages_values",
listOf(
"hide",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ object AutoClaimChannelPointPatch : BytecodePatch(
SettingsPatch.PreferenceScreen.CHAT.GENERAL.addPreferences(
SwitchPreference(
"revanced_auto_claim_channel_points",
"revanced_auto_claim_channel_points",
"revanced_auto_claim_channel_points_on",
"revanced_auto_claim_channel_points_off",
default = true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ object DebugModePatch : BytecodePatch(
SettingsPatch.PreferenceScreen.MISC.OTHER.addPreferences(
SwitchPreference(
"revanced_debug_mode",
"revanced_debug_mode_title",
"revanced_debug_mode_on",
"revanced_debug_mode_off",
default = false,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,60 +26,15 @@ object HideAdsResourcePatch : ResourcePatch() {
override fun execute(context: ResourceContext) {
StringsPatch.includePatchStrings("HideAds")
PreferenceScreen.ADS.addPreferences(
SwitchPreference(
"revanced_hide_general_ads",
"revanced_hide_general_ads_title",
"revanced_hide_general_ads_summary_on",
"revanced_hide_general_ads_summary_off"
),
SwitchPreference(
"revanced_hide_fullscreen_ads",
"revanced_hide_fullscreen_ads_title",
"revanced_hide_fullscreen_ads_summary_on",
"revanced_hide_fullscreen_ads_summary_off"
),
SwitchPreference(
"revanced_hide_buttoned_ads",
"revanced_hide_buttoned_ads_title",
"revanced_hide_buttoned_ads_summary_on",
"revanced_hide_buttoned_ads_summary_off"
),
SwitchPreference(
"revanced_hide_paid_content_ads",
"revanced_hide_paid_content_ads_title",
"revanced_hide_paid_content_ads_summary_on",
"revanced_hide_paid_content_ads_summary_off"
),
SwitchPreference(
"revanced_hide_self_sponsor_ads",
"revanced_hide_self_sponsor_ads_title",
"revanced_hide_self_sponsor_ads_summary_on",
"revanced_hide_self_sponsor_ads_summary_off"
),
SwitchPreference(
"revanced_hide_products_banner",
"revanced_hide_products_banner_title",
"revanced_hide_products_banner_summary_on",
"revanced_hide_products_banner_summary_off"
),
SwitchPreference(
"revanced_hide_shopping_links",
"revanced_hide_shopping_links_title",
"revanced_hide_shopping_links_summary_on",
"revanced_hide_shopping_links_summary_off",
),
SwitchPreference(
"revanced_hide_web_search_results",
"revanced_hide_web_search_results_title",
"revanced_hide_web_search_results_summary_on",
"revanced_hide_web_search_results_summary_off",
),
SwitchPreference(
"revanced_hide_merchandise_banners",
"revanced_hide_merchandise_banners_title",
"revanced_hide_merchandise_banners_summary_on",
"revanced_hide_merchandise_banners_summary_off",
)
SwitchPreference("revanced_hide_general_ads"),
SwitchPreference("revanced_hide_fullscreen_ads"),
SwitchPreference("revanced_hide_buttoned_ads"),
SwitchPreference("revanced_hide_paid_content_ads"),
SwitchPreference("revanced_hide_self_sponsor_ads"),
SwitchPreference("revanced_hide_products_banner"),
SwitchPreference("revanced_hide_shopping_links"),
SwitchPreference("revanced_hide_web_search_results"),
SwitchPreference("revanced_hide_merchandise_banners")
)

LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
Expand Down
Loading

0 comments on commit 1ece93b

Please sign in to comment.