refactor: Fix package and code structure (#2541)
BREAKING CHANGE: Various public APIs have changed names and packages or were removed entirely
This commit is contained in:
@ -11,9 +11,27 @@ import com.android.tools.smali.dexlib2.iface.ClassDef
|
||||
import com.android.tools.smali.dexlib2.iface.Method
|
||||
|
||||
abstract class AbstractIntegrationsPatch(
|
||||
private val integrationsDescriptor: String,
|
||||
private val hooks: Set<IntegrationsFingerprint>
|
||||
) : BytecodePatch(hooks) {
|
||||
|
||||
@Deprecated(
|
||||
"Use the constructor without the integrationsDescriptor parameter",
|
||||
ReplaceWith("AbstractIntegrationsPatch(hooks)")
|
||||
)
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
constructor(
|
||||
integrationsDescriptor: String,
|
||||
hooks: Set<IntegrationsFingerprint>
|
||||
) : this(hooks)
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
if (context.findClass(INTEGRATIONS_CLASS_DESCRIPTOR) == null) throw PatchException(
|
||||
"Integrations have not been merged yet. This patch can not succeed without merging the integrations."
|
||||
)
|
||||
|
||||
for (hook in hooks) hook.invoke(INTEGRATIONS_CLASS_DESCRIPTOR)
|
||||
}
|
||||
|
||||
/**
|
||||
* [MethodFingerprint] for integrations.
|
||||
*
|
||||
@ -53,11 +71,7 @@ abstract class AbstractIntegrationsPatch(
|
||||
}
|
||||
}
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
if (context.findClass(integrationsDescriptor) == null) throw PatchException(
|
||||
"Integrations have not been merged yet. This patch can not succeed without merging the integrations."
|
||||
)
|
||||
|
||||
for (hook in hooks) hook.invoke(integrationsDescriptor)
|
||||
private companion object {
|
||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/shared/Utils;"
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import app.revanced.patches.shared.settings.preference.impl.ArrayResource
|
||||
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
||||
import app.revanced.util.ResourceGroup
|
||||
import app.revanced.util.copyResources
|
||||
import app.revanced.util.mergeStrings
|
||||
import org.w3c.dom.Node
|
||||
import java.io.Closeable
|
||||
|
||||
@ -37,6 +38,8 @@ abstract class AbstractSettingsResourcePatch(
|
||||
stringsEditor = context.xmlEditor["res/values/strings.xml"]
|
||||
arraysEditor = context.xmlEditor["res/values/arrays.xml"]
|
||||
revancedPreferencesEditor = context.xmlEditor["res/xml/$preferenceFileName.xml"]
|
||||
|
||||
context.mergeStrings("settings/host/values/strings.xml")
|
||||
}
|
||||
|
||||
internal companion object {
|
||||
|
@ -1,32 +0,0 @@
|
||||
package app.revanced.patches.shared.settings.preference
|
||||
|
||||
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
||||
import org.w3c.dom.Document
|
||||
|
||||
/**
|
||||
* Base preference class that also has a default value.
|
||||
*
|
||||
* @param key The key of the preference.
|
||||
* @param title The title of the preference.
|
||||
* @param tag The tag of the preference.
|
||||
* @param summary The summary of the preference.
|
||||
* @param default The default value of the preference.
|
||||
*/
|
||||
abstract class DefaultBasePreference<T>(
|
||||
key: String?,
|
||||
title: StringResource,
|
||||
summary: StringResource? = null,
|
||||
tag: String,
|
||||
val default: T? = null,
|
||||
) : BasePreference(key, title, summary, tag) {
|
||||
|
||||
/**
|
||||
* Serialize preference element to XML.
|
||||
* Overriding methods should invoke super and operate on its return value.
|
||||
* @param ownerDocument Target document to create elements from.
|
||||
* @param resourceCallback Called when a resource has been processed.
|
||||
* @return The serialized element.
|
||||
*/
|
||||
override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit) =
|
||||
super.serialize(ownerDocument, resourceCallback).apply { addDefault(default) }
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package app.revanced.patches.shared.settings.preference.impl
|
||||
|
||||
import app.revanced.patches.shared.settings.preference.BasePreference
|
||||
import app.revanced.patches.shared.settings.preference.BaseResource
|
||||
import app.revanced.patches.shared.settings.preference.DefaultBasePreference
|
||||
import app.revanced.patches.shared.settings.preference.addSummary
|
||||
import org.w3c.dom.Document
|
||||
|
||||
@ -13,16 +13,14 @@ import org.w3c.dom.Document
|
||||
* @param entries The human-readable entries of the list preference.
|
||||
* @param entryValues The entry values of the list preference.
|
||||
* @param summary The summary of the list preference.
|
||||
* @param default The default entry value of the list preference.
|
||||
*/
|
||||
class ListPreference(
|
||||
key: String,
|
||||
title: StringResource,
|
||||
val entries: ArrayResource,
|
||||
val entryValues: ArrayResource,
|
||||
summary: StringResource? = null,
|
||||
default: String? = null,
|
||||
) : DefaultBasePreference<String>(key, title, summary, "ListPreference", default) {
|
||||
private val entries: ArrayResource,
|
||||
private val entryValues: ArrayResource,
|
||||
summary: StringResource? = null
|
||||
) : BasePreference(key, title, summary, "ListPreference") {
|
||||
override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit) =
|
||||
super.serialize(ownerDocument, resourceCallback).apply {
|
||||
setAttribute("android:entries", "@array/${entries.also { resourceCallback.invoke(it) }.name}")
|
||||
|
@ -1,10 +1,10 @@
|
||||
package app.revanced.patches.shared.settings.preference.impl
|
||||
|
||||
import app.revanced.patches.shared.settings.AbstractSettingsResourcePatch.Companion.include
|
||||
import app.revanced.patches.shared.settings.preference.BasePreference
|
||||
import app.revanced.patches.shared.settings.preference.BaseResource
|
||||
import app.revanced.patches.shared.settings.preference.DefaultBasePreference
|
||||
import app.revanced.patches.shared.settings.preference.SummaryType
|
||||
import app.revanced.patches.shared.settings.preference.addSummary
|
||||
import app.revanced.patches.shared.settings.AbstractSettingsResourcePatch.Companion.include
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Element
|
||||
|
||||
@ -16,15 +16,13 @@ import org.w3c.dom.Element
|
||||
* @param summaryOn The summary to show when the preference is enabled.
|
||||
* @param summaryOff The summary to show when the preference is disabled.
|
||||
* @param userDialogMessage The message to show in a dialog when the user toggles the preference.
|
||||
* @param default The default value of the switch.
|
||||
*/
|
||||
class SwitchPreference(
|
||||
key: String, title: StringResource,
|
||||
val summaryOn: StringResource,
|
||||
val summaryOff: StringResource,
|
||||
val userDialogMessage: StringResource? = null,
|
||||
default: Boolean = false,
|
||||
) : DefaultBasePreference<Boolean>( key, title, null, "SwitchPreference", default) {
|
||||
) : BasePreference(key, title, null, "SwitchPreference") {
|
||||
override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit): Element {
|
||||
userDialogMessage?.include()
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package app.revanced.patches.shared.settings.preference.impl
|
||||
|
||||
import app.revanced.patches.shared.settings.preference.BasePreference
|
||||
import app.revanced.patches.shared.settings.preference.BaseResource
|
||||
import app.revanced.patches.shared.settings.preference.DefaultBasePreference
|
||||
import org.w3c.dom.Document
|
||||
|
||||
/**
|
||||
@ -11,16 +11,14 @@ import org.w3c.dom.Document
|
||||
* @param title The title of the text preference.
|
||||
* @param inputType The input type of the text preference.
|
||||
* @param summary The summary of the text preference.
|
||||
* @param default The default value of the text preference.
|
||||
*/
|
||||
class TextPreference(
|
||||
key: String?,
|
||||
title: StringResource,
|
||||
summary: StringResource?,
|
||||
val inputType: InputType = InputType.TEXT,
|
||||
default: String? = null,
|
||||
tag: String = "app.revanced.integrations.settingsmenu.ResettableEditTextPreference"
|
||||
) : DefaultBasePreference<String>(key, title, summary, tag, default) {
|
||||
tag: String = "app.revanced.integrations.shared.settings.preference.ResettableEditTextPreference"
|
||||
) : BasePreference(key, title, summary, tag) {
|
||||
|
||||
override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit) =
|
||||
super.serialize(ownerDocument, resourceCallback).apply {
|
||||
|
Reference in New Issue
Block a user