mirror of
https://github.com/revanced/revanced-patches
synced 2024-12-05 02:33:20 +01:00
fix(youtube/settings): fix non functional back button in settings (#2178)
This commit is contained in:
parent
95bbf46e77
commit
46da83430f
@ -26,16 +26,11 @@ class ReturnYouTubeDislikeResourcePatch : ResourcePatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun execute(context: ResourceContext): PatchResult {
|
override fun execute(context: ResourceContext): PatchResult {
|
||||||
val youtubePackage = "com.google.android.youtube"
|
|
||||||
SettingsPatch.addPreference(
|
SettingsPatch.addPreference(
|
||||||
Preference(
|
Preference(
|
||||||
StringResource("revanced_ryd_settings_title", "Return YouTube Dislike"),
|
StringResource("revanced_ryd_settings_title", "Return YouTube Dislike"),
|
||||||
StringResource("revanced_ryd_settings_summary", "Settings for Return YouTube Dislike"),
|
StringResource("revanced_ryd_settings_summary", "Settings for Return YouTube Dislike"),
|
||||||
Preference.Intent(
|
SettingsPatch.createReVancedSettingsIntent("ryd_settings")
|
||||||
youtubePackage,
|
|
||||||
"ryd_settings",
|
|
||||||
"com.google.android.libraries.social.licenses.LicenseActivity"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
// merge strings
|
// merge strings
|
||||||
|
@ -22,16 +22,11 @@ import app.revanced.util.resources.ResourceUtils.mergeStrings
|
|||||||
class SponsorBlockResourcePatch : ResourcePatch {
|
class SponsorBlockResourcePatch : ResourcePatch {
|
||||||
|
|
||||||
override fun execute(context: ResourceContext): PatchResult {
|
override fun execute(context: ResourceContext): PatchResult {
|
||||||
val youtubePackage = "com.google.android.youtube"
|
|
||||||
SettingsPatch.addPreference(
|
SettingsPatch.addPreference(
|
||||||
Preference(
|
Preference(
|
||||||
StringResource("sb_settings", "SponsorBlock"),
|
StringResource("revanced_sponsorblock_settings_title", "SponsorBlock"),
|
||||||
StringResource("revanced_sponsorblock_settings_summary", "SponsorBlock related settings"),
|
StringResource("revanced_sponsorblock_settings_summary", "SponsorBlock related settings"),
|
||||||
Preference.Intent(
|
SettingsPatch.createReVancedSettingsIntent("sponsorblock_settings")
|
||||||
youtubePackage,
|
|
||||||
"sponsorblock_settings",
|
|
||||||
"com.google.android.libraries.social.licenses.LicenseActivity"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val classLoader = this.javaClass.classLoader
|
val classLoader = this.javaClass.classLoader
|
||||||
|
@ -60,14 +60,17 @@ class SettingsPatch : BytecodePatch(
|
|||||||
}
|
}
|
||||||
} ?: return SetThemeFingerprint.toErrorResult()
|
} ?: return SetThemeFingerprint.toErrorResult()
|
||||||
|
|
||||||
// set the theme based on the preference of the device
|
|
||||||
|
// Modify the license activity and remove all existing layout code.
|
||||||
|
// Must modify an existing activity and cannot add a new activity to the manifest,
|
||||||
|
// as that fails for root installations.
|
||||||
LicenseActivityFingerprint.result!!.apply licenseActivity@{
|
LicenseActivityFingerprint.result!!.apply licenseActivity@{
|
||||||
mutableMethod.apply {
|
mutableMethod.apply {
|
||||||
fun buildSettingsActivityInvokeString(
|
fun buildSettingsActivityInvokeString(
|
||||||
registers: String = "p0",
|
registers: String = "p0",
|
||||||
classDescriptor: String = SETTINGS_ACTIVITY_DESCRIPTOR,
|
classDescriptor: String = SETTINGS_ACTIVITY_DESCRIPTOR,
|
||||||
methodName: String = "initializeSettings",
|
methodName: String = "initializeSettings",
|
||||||
parameters: String = this@licenseActivity.mutableClass.type
|
parameters: String = "Landroid/app/Activity;"
|
||||||
) = getSetThemeInstructionString(registers, classDescriptor, methodName, parameters)
|
) = getSetThemeInstructionString(registers, classDescriptor, methodName, parameters)
|
||||||
|
|
||||||
// initialize the settings
|
// initialize the settings
|
||||||
@ -77,9 +80,6 @@ class SettingsPatch : BytecodePatch(
|
|||||||
return-void
|
return-void
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
// set the current theme
|
|
||||||
addInstruction(0, buildSettingsActivityInvokeString(methodName = "setTheme"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove method overrides
|
// remove method overrides
|
||||||
@ -88,14 +88,13 @@ class SettingsPatch : BytecodePatch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal companion object {
|
internal companion object {
|
||||||
private const val INTEGRATIONS_PACKAGE = "app/revanced/integrations"
|
private const val INTEGRATIONS_PACKAGE = "app/revanced/integrations"
|
||||||
|
|
||||||
private const val SETTINGS_ACTIVITY_DESCRIPTOR = "L$INTEGRATIONS_PACKAGE/settingsmenu/ReVancedSettingActivity;"
|
private const val SETTINGS_ACTIVITY_DESCRIPTOR = "L$INTEGRATIONS_PACKAGE/settingsmenu/ReVancedSettingActivity;"
|
||||||
|
|
||||||
private const val THEME_HELPER_DESCRIPTOR = "L$INTEGRATIONS_PACKAGE/utils/ThemeHelper;"
|
private const val THEME_HELPER_DESCRIPTOR = "L$INTEGRATIONS_PACKAGE/utils/ThemeHelper;"
|
||||||
private const val SET_THEME_METHOD_NAME = "setTheme"
|
private const val SET_THEME_METHOD_NAME = "setTheme"
|
||||||
|
|
||||||
@ -110,6 +109,15 @@ class SettingsPatch : BytecodePatch(
|
|||||||
fun renameIntentsTargetPackage(newPackage: String) {
|
fun renameIntentsTargetPackage(newPackage: String) {
|
||||||
SettingsResourcePatch.overrideIntentsTargetPackage = newPackage
|
SettingsResourcePatch.overrideIntentsTargetPackage = newPackage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an intent to open ReVanced settings of the given name
|
||||||
|
*/
|
||||||
|
fun createReVancedSettingsIntent(settingsName: String) = Preference.Intent(
|
||||||
|
"com.google.android.youtube",
|
||||||
|
settingsName,
|
||||||
|
"com.google.android.libraries.social.licenses.LicenseActivity"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +16,7 @@ import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
|||||||
import app.revanced.util.resources.ResourceUtils
|
import app.revanced.util.resources.ResourceUtils
|
||||||
import app.revanced.util.resources.ResourceUtils.copyResources
|
import app.revanced.util.resources.ResourceUtils.copyResources
|
||||||
import app.revanced.util.resources.ResourceUtils.mergeStrings
|
import app.revanced.util.resources.ResourceUtils.mergeStrings
|
||||||
|
import org.w3c.dom.Element
|
||||||
import org.w3c.dom.Node
|
import org.w3c.dom.Node
|
||||||
|
|
||||||
@Name("settings-resource-patch")
|
@Name("settings-resource-patch")
|
||||||
@ -34,40 +35,51 @@ class SettingsResourcePatch : AbstractSettingsResourcePatch(
|
|||||||
it.type == "string" && it.name == "app_theme_appearance_dark"
|
it.type == "string" && it.name == "app_theme_appearance_dark"
|
||||||
}!!.id
|
}!!.id
|
||||||
|
|
||||||
|
/*
|
||||||
// Create missing directory for the resources.
|
* copy layout resources
|
||||||
context["res/drawable-ldrtl-xxxhdpi"].mkdirs()
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Copy layout resources.
|
|
||||||
arrayOf(
|
arrayOf(
|
||||||
ResourceUtils.ResourceGroup(
|
ResourceUtils.ResourceGroup("layout", "revanced_settings_with_toolbar.xml")
|
||||||
"layout",
|
|
||||||
"revanced_settings_toolbar.xml",
|
|
||||||
"revanced_settings_with_toolbar.xml",
|
|
||||||
"revanced_settings_with_toolbar_layout.xml"
|
|
||||||
), ResourceUtils.ResourceGroup(
|
|
||||||
// required resource for back button, because when the base APK is used, this resource will not exist
|
|
||||||
"drawable-xxxhdpi", "quantum_ic_arrow_back_white_24.png"
|
|
||||||
), ResourceUtils.ResourceGroup(
|
|
||||||
// required resource for back button, because when the base APK is used, this resource will not exist
|
|
||||||
"drawable-ldrtl-xxxhdpi", "quantum_ic_arrow_back_white_24.png"
|
|
||||||
)
|
|
||||||
).forEach { resourceGroup ->
|
).forEach { resourceGroup ->
|
||||||
context.copyResources("settings", resourceGroup)
|
context.copyResources("settings", resourceGroup)
|
||||||
}
|
}
|
||||||
|
|
||||||
preferencesEditor = context.xmlEditor["res/xml/settings_fragment.xml"]
|
preferencesEditor = context.xmlEditor["res/xml/settings_fragment.xml"]
|
||||||
|
|
||||||
// Add the ReVanced settings to the YouTube settings.
|
// Modify the manifest and add an data intent filter to the LicenseActivity.
|
||||||
val youtubePackage = "com.google.android.youtube"
|
// Some devices freak out if undeclared data is passed to an intent,
|
||||||
|
// and this change appears to fix the issue.
|
||||||
|
context.xmlEditor["AndroidManifest.xml"].use { editor ->
|
||||||
|
// An xml regular expression would probably work better than this manual searching.
|
||||||
|
val manifestNodes = editor.file.getElementsByTagName("manifest").item(0).childNodes
|
||||||
|
for (i in 0..manifestNodes.length) {
|
||||||
|
val node = manifestNodes.item(i)
|
||||||
|
if (node != null && node.nodeName == "application") {
|
||||||
|
val applicationNodes = node.childNodes
|
||||||
|
for (j in 0..applicationNodes.length) {
|
||||||
|
val applicationChild = applicationNodes.item(j)
|
||||||
|
if (applicationChild is Element && applicationChild.nodeName == "activity"
|
||||||
|
&& applicationChild.getAttribute("android:name") == "com.google.android.libraries.social.licenses.LicenseActivity"
|
||||||
|
) {
|
||||||
|
val intentFilter = editor.file.createElement("intent-filter")
|
||||||
|
val mimeType = editor.file.createElement("data")
|
||||||
|
mimeType.setAttribute("android:mimeType", "text/plain")
|
||||||
|
intentFilter.appendChild(mimeType)
|
||||||
|
applicationChild.appendChild(intentFilter)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Add the ReVanced settings to the YouTube settings
|
||||||
SettingsPatch.addPreference(
|
SettingsPatch.addPreference(
|
||||||
Preference(
|
Preference(
|
||||||
StringResource("revanced_settings", "ReVanced"),
|
StringResource("revanced_settings", "ReVanced"),
|
||||||
StringResource("revanced_settings_summary", "ReVanced specific settings"),
|
StringResource("revanced_settings_summary", "ReVanced specific settings"),
|
||||||
Preference.Intent(
|
SettingsPatch.createReVancedSettingsIntent("revanced_settings")
|
||||||
youtubePackage, "revanced_settings", "com.google.android.libraries.social.licenses.LicenseActivity"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 200 B |
Binary file not shown.
Before Width: | Height: | Size: 194 B |
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
<string name="revanced_settings_title">ReVanced</string>
|
||||||
<string name="revanced_settings_confirm_user_dialog_title">Do you wish to proceed?</string>
|
<string name="revanced_settings_confirm_user_dialog_title">Do you wish to proceed?</string>
|
||||||
<string name="revanced_settings_reset">Reset</string>
|
<string name="revanced_settings_reset">Reset</string>
|
||||||
|
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@color/yt_white1" android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="4dp">
|
|
||||||
<android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:background="?attr/ytBrandBackgroundSolid" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:navigationIcon="@drawable/quantum_ic_arrow_back_white_24" app:title="@string/revanced_settings"/>
|
|
||||||
</FrameLayout>
|
|
@ -1,4 +1,33 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<merge>
|
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
<include layout="@layout/revanced_settings_with_toolbar_layout"/>
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:transitionGroup="true">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@color/yt_white1"
|
||||||
|
android:elevation="4dp">
|
||||||
|
|
||||||
|
<android.support.v7.widget.Toolbar
|
||||||
|
android:id="@+id/revanced_toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:background="?attr/ytBrandBackgroundSolid"
|
||||||
|
app:navigationIcon="@drawable/yt_outline_arrow_left_black_24"
|
||||||
|
app:title="@string/revanced_settings" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/revanced_settings_fragments"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
</merge>
|
</merge>
|
@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:fitsSystemWindows="true" android:layout_width="match_parent" android:layout_height="match_parent" android:transitionGroup="true">
|
|
||||||
<include layout="@layout/revanced_settings_toolbar"/>
|
|
||||||
<FrameLayout android:id="@+id/revanced_settings_fragments" android:layout_width="match_parent" android:layout_height="match_parent"/>
|
|
||||||
</LinearLayout>
|
|
Loading…
Reference in New Issue
Block a user