fix(youtube/settings): fix non functional back button in settings (#2178)

This commit is contained in:
LisoUseInAIKyrios 2023-05-20 00:45:12 +04:00 committed by oSumAtrIX
parent 95bbf46e77
commit 46da83430f
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4
10 changed files with 85 additions and 54 deletions

View file

@ -26,16 +26,11 @@ class ReturnYouTubeDislikeResourcePatch : ResourcePatch {
}
override fun execute(context: ResourceContext): PatchResult {
val youtubePackage = "com.google.android.youtube"
SettingsPatch.addPreference(
Preference(
StringResource("revanced_ryd_settings_title", "Return YouTube Dislike"),
StringResource("revanced_ryd_settings_summary", "Settings for Return YouTube Dislike"),
Preference.Intent(
youtubePackage,
"ryd_settings",
"com.google.android.libraries.social.licenses.LicenseActivity"
)
SettingsPatch.createReVancedSettingsIntent("ryd_settings")
)
)
// merge strings

View file

@ -22,16 +22,11 @@ import app.revanced.util.resources.ResourceUtils.mergeStrings
class SponsorBlockResourcePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
val youtubePackage = "com.google.android.youtube"
SettingsPatch.addPreference(
Preference(
StringResource("sb_settings", "SponsorBlock"),
StringResource("revanced_sponsorblock_settings_title", "SponsorBlock"),
StringResource("revanced_sponsorblock_settings_summary", "SponsorBlock related settings"),
Preference.Intent(
youtubePackage,
"sponsorblock_settings",
"com.google.android.libraries.social.licenses.LicenseActivity"
)
SettingsPatch.createReVancedSettingsIntent("sponsorblock_settings")
)
)
val classLoader = this.javaClass.classLoader

View file

@ -60,14 +60,17 @@ class SettingsPatch : BytecodePatch(
}
} ?: 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@{
mutableMethod.apply {
fun buildSettingsActivityInvokeString(
registers: String = "p0",
classDescriptor: String = SETTINGS_ACTIVITY_DESCRIPTOR,
methodName: String = "initializeSettings",
parameters: String = this@licenseActivity.mutableClass.type
parameters: String = "Landroid/app/Activity;"
) = getSetThemeInstructionString(registers, classDescriptor, methodName, parameters)
// initialize the settings
@ -77,9 +80,6 @@ class SettingsPatch : BytecodePatch(
return-void
"""
)
// set the current theme
addInstruction(0, buildSettingsActivityInvokeString(methodName = "setTheme"))
}
// remove method overrides
@ -88,14 +88,13 @@ class SettingsPatch : BytecodePatch(
}
}
return PatchResultSuccess()
}
internal companion object {
private const val INTEGRATIONS_PACKAGE = "app/revanced/integrations"
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 SET_THEME_METHOD_NAME = "setTheme"
@ -110,6 +109,15 @@ class SettingsPatch : BytecodePatch(
fun renameIntentsTargetPackage(newPackage: String) {
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"
)
}
/**

View file

@ -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.copyResources
import app.revanced.util.resources.ResourceUtils.mergeStrings
import org.w3c.dom.Element
import org.w3c.dom.Node
@Name("settings-resource-patch")
@ -34,40 +35,51 @@ class SettingsResourcePatch : AbstractSettingsResourcePatch(
it.type == "string" && it.name == "app_theme_appearance_dark"
}!!.id
// Create missing directory for the resources.
context["res/drawable-ldrtl-xxxhdpi"].mkdirs()
// Copy layout resources.
/*
* copy layout resources
*/
arrayOf(
ResourceUtils.ResourceGroup(
"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"
)
ResourceUtils.ResourceGroup("layout", "revanced_settings_with_toolbar.xml")
).forEach { resourceGroup ->
context.copyResources("settings", resourceGroup)
}
preferencesEditor = context.xmlEditor["res/xml/settings_fragment.xml"]
// Add the ReVanced settings to the YouTube settings.
val youtubePackage = "com.google.android.youtube"
// Modify the manifest and add an data intent filter to the LicenseActivity.
// 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(
Preference(
StringResource("revanced_settings", "ReVanced"),
StringResource("revanced_settings_summary", "ReVanced specific settings"),
Preference.Intent(
youtubePackage, "revanced_settings", "com.google.android.libraries.social.licenses.LicenseActivity"
)
SettingsPatch.createReVancedSettingsIntent("revanced_settings")
)
)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 B

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<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_reset">Reset</string>

View file

@ -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>

View file

@ -1,4 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<merge>
<include layout="@layout/revanced_settings_with_toolbar_layout"/>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
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>

View file

@ -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>