Skip to content

Commit

Permalink
feat(youtube/settings): disable preferences and add dialog messages t…
Browse files Browse the repository at this point in the history
…o preferences (#1801)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
LisoUseInAIKyrios and oSumAtrIX committed Apr 16, 2023
1 parent 33f7953 commit 05023ba
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +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.IResource
import app.revanced.patches.shared.settings.preference.addDefault
import app.revanced.patches.shared.settings.preference.addSummary
import app.revanced.patches.shared.settings.preference.SummaryType
import app.revanced.patches.shared.settings.preference.*
import app.revanced.patches.shared.settings.resource.patch.AbstractSettingsResourcePatch.Companion.include
import org.w3c.dom.Document
import org.w3c.dom.Element

Expand All @@ -16,16 +13,21 @@ import org.w3c.dom.Element
* @param default The default value of the switch.
* @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.
*/
internal class SwitchPreference(
key: String, title: StringResource,
val default: Boolean = false,
val summaryOn: StringResource? = null,
val summaryOff: StringResource? = null
val summaryOff: StringResource? = null,
val userDialogMessage: StringResource? = null
) : BasePreference(key, title) {
override val tag: String = "SwitchPreference"

override fun serialize(ownerDocument: Document, resourceCallback: ((IResource) -> Unit)?): Element {
// dialog message is stored as a regular string and later referenced by SettingsEnum
userDialogMessage?.include()

return super.serialize(ownerDocument, resourceCallback).apply {
addDefault(default)
addSummary(summaryOn?.also { resourceCallback?.invoke(it) }, SummaryType.ON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ class SpoofAppVersionPatch : BytecodePatch(
"revanced_spoof_app_version",
StringResource("revanced_spoof_app_version_title", "Spoof app version"),
false,
StringResource("revanced_spoof_app_version_summary_on", "Version spoofed to 17.30.34. If switched off, the old UI layout may remain until logging out or clearing app data"),
StringResource("revanced_spoof_app_version_summary_off", "Version not spoofed")
StringResource("revanced_spoof_app_version_summary_on", "Version spoofed to 17.30.34"),
StringResource("revanced_spoof_app_version_summary_off", "Version not spoofed"),
StringResource("revanced_spoof_app_version_user_dialog_message",
"App version will be spoofed to 17.30.34. This will give the old UI layout, but unknown side effects may occur."
+ " If later turned off, the old UI layout may remain until you log out or clear the app data.")
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ class DebuggingPatch : ResourcePatch {
),
true,
StringResource("revanced_debug_toast_on_error_summary_on", "Toast shown if error occurs"),
StringResource("revanced_debug_toast_on_error_summary_off", "Toast not shown if error occurs")
StringResource("revanced_debug_toast_on_error_summary_off", "Toast not shown if error occurs"),
StringResource("revanced_debug_toast_on_error_user_dialog_message",
"Turning off error toasts hides all ReVanced error notifications." +
" This includes hiding normal network connection timeouts, " +
"but also hides notification of any unexpected and more serious errors."
)
),
),
StringResource("revanced_debug_summary", "Enable or disable debugging options")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class SpoofSignatureVerificationPatch : BytecodePatch(
StringResource("revanced_spoof_signature_verification_title", "Spoof app signature"),
true,
StringResource("revanced_spoof_signature_verification_summary_on", "App signature spoofed"),
StringResource("revanced_spoof_signature_verification_summary_off", "App signature not spoofed")
StringResource("revanced_spoof_signature_verification_summary_off", "App signature not spoofed"),
StringResource("revanced_spoof_signature_verification_user_dialog_message",
"Signature spoofing can fix playback issues, but may causes side effects.")
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import app.revanced.patches.shared.settings.resource.patch.AbstractSettingsResou
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
import app.revanced.util.resources.ResourceUtils
import app.revanced.util.resources.ResourceUtils.copyResources
import app.revanced.util.resources.ResourceUtils.mergeStrings
import org.w3c.dom.Node

@Name("settings-resource-patch")
Expand Down Expand Up @@ -77,6 +78,8 @@ class SettingsResourcePatch : AbstractSettingsResourcePatch(
)
)

context.mergeStrings("settings/host/values/strings.xml")

return PatchResultSuccess()
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/settings/host/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="revanced_settings_confirm_user_dialog_title">Do you wish to proceed?</string>
</resources>

0 comments on commit 05023ba

Please sign in to comment.