generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(youtube): import / export of revanced settings (#2077)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
1 parent
78803f8
commit b59cb3e
Showing
79 changed files
with
437 additions
and
572 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/app/revanced/patches/shared/settings/preference/DefaultBasePreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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. | ||
*/ | ||
internal 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) } | ||
} |
23 changes: 0 additions & 23 deletions
23
src/main/kotlin/app/revanced/patches/shared/settings/preference/IPreference.kt
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
src/main/kotlin/app/revanced/patches/shared/settings/preference/IResource.kt
This file was deleted.
Oops, something went wrong.
21 changes: 8 additions & 13 deletions
21
src/main/kotlin/app/revanced/patches/shared/settings/preference/impl/ArrayResource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,29 @@ | ||
package app.revanced.patches.shared.settings.preference.impl | ||
|
||
import app.revanced.patches.shared.settings.preference.BaseResource | ||
import app.revanced.patches.shared.settings.preference.IResource | ||
import org.w3c.dom.Document | ||
import org.w3c.dom.Element | ||
|
||
// TODO: allow specifying an array resource file instead of using a list of StringResources | ||
/** | ||
* Represents an array resource. | ||
* An array resource. | ||
* | ||
* @param name The name of the array resource. | ||
* @param items The items of the array resource. | ||
*/ | ||
// TODO: allow specifying an array resource file instead of using a list of StringResources | ||
internal data class ArrayResource( | ||
override val name: String, | ||
internal class ArrayResource( | ||
name: String, | ||
val items: List<StringResource> | ||
) : BaseResource(name) { | ||
override val tag = "string-array" | ||
|
||
override fun serialize(ownerDocument: Document, resourceCallback: ((IResource) -> Unit)?): Element { | ||
return super.serialize(ownerDocument, resourceCallback).apply { | ||
) : BaseResource(name, "string-array") { | ||
override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit) = | ||
super.serialize(ownerDocument, resourceCallback).apply { | ||
setAttribute("name", name) | ||
|
||
items.forEach { item -> | ||
resourceCallback?.invoke(item) | ||
resourceCallback.invoke(item) | ||
|
||
this.appendChild(ownerDocument.createElement("item").also { itemNode -> | ||
itemNode.textContent = "@string/${item.name}" | ||
}) | ||
} | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/app/revanced/patches/shared/settings/preference/impl/InputType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 12 additions & 9 deletions
21
...n/kotlin/app/revanced/patches/shared/settings/preference/impl/NonInteractivePreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 17 additions & 20 deletions
37
src/main/kotlin/app/revanced/patches/shared/settings/preference/impl/Preference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,41 @@ | ||
package app.revanced.patches.shared.settings.preference.impl | ||
|
||
import app.revanced.patches.shared.settings.preference.BasePreference | ||
import app.revanced.patches.shared.settings.preference.IResource | ||
import app.revanced.patches.shared.settings.preference.addSummary | ||
import app.revanced.patches.shared.settings.preference.BaseResource | ||
import org.w3c.dom.Document | ||
import org.w3c.dom.Element | ||
|
||
/** | ||
* A Preference object. | ||
* A preference object. | ||
* | ||
* @param key The key of the preference. | ||
* @param title The title of the preference. | ||
* @param intent The intent of the preference. | ||
* @param summary The summary of the text preference. | ||
* @param intent The intent of the preference. | ||
*/ | ||
internal class Preference( | ||
key: String, | ||
title: StringResource, | ||
val intent: Intent, | ||
val summary: StringResource? = null | ||
) : BasePreference(key, title) { | ||
override val tag: String = "Preference" | ||
|
||
/* Key-less constructor */ | ||
summary: StringResource, | ||
val intent: Intent | ||
) : BasePreference(key, title, summary, "Preference") { | ||
constructor( | ||
title: StringResource, | ||
intent: Intent, | ||
summary: StringResource? = null | ||
) : this("", title, intent, summary) | ||
|
||
override fun serialize(ownerDocument: Document, resourceCallback: ((IResource) -> Unit)?): Element { | ||
return super.serialize(ownerDocument, resourceCallback).apply { | ||
addSummary(summary?.also { resourceCallback?.invoke(it) }) | ||
summary: StringResource, | ||
intent: Intent | ||
) : this("", title, summary, intent) | ||
|
||
override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit) = | ||
super.serialize(ownerDocument, resourceCallback).apply { | ||
this.appendChild(ownerDocument.createElement("intent").also { intentNode -> | ||
intentNode.setAttribute("android:targetPackage", intent.targetPackage) | ||
intentNode.setAttribute("android:data", intent.data) | ||
intentNode.setAttribute("android:targetClass", intent.targetClass) | ||
}) | ||
} | ||
} | ||
|
||
data class Intent(val targetPackage: String, val data: String, val targetClass: String) | ||
internal class Intent( | ||
internal val targetPackage: String, | ||
internal val data: String, | ||
internal val targetClass: String | ||
) | ||
} |
Oops, something went wrong.