mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-04-29 22:24:27 +02:00
fix(YouTube - Wide search bar): Do not force phone layout for tablet devices (#4827)
This commit is contained in:
parent
3e64a4c18f
commit
0cb38f9f36
@ -1,11 +1,48 @@
|
|||||||
package app.revanced.extension.youtube.patches;
|
package app.revanced.extension.youtube.patches;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import app.revanced.extension.shared.Logger;
|
||||||
|
import app.revanced.extension.shared.Utils;
|
||||||
import app.revanced.extension.youtube.settings.Settings;
|
import app.revanced.extension.youtube.settings.Settings;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class WideSearchbarPatch {
|
public final class WideSearchbarPatch {
|
||||||
|
|
||||||
|
private static final Boolean WIDE_SEARCHBAR_ENABLED = Settings.WIDE_SEARCHBAR.get();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
*/
|
||||||
public static boolean enableWideSearchbar(boolean original) {
|
public static boolean enableWideSearchbar(boolean original) {
|
||||||
return Settings.WIDE_SEARCHBAR.get() || original;
|
return WIDE_SEARCHBAR_ENABLED || original;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
*/
|
||||||
|
public static void setActionBar(View view) {
|
||||||
|
try {
|
||||||
|
if (!WIDE_SEARCHBAR_ENABLED) return;
|
||||||
|
|
||||||
|
View searchBarView = Utils.getChildViewByResourceName(view, "search_bar");
|
||||||
|
|
||||||
|
final int paddingLeft = searchBarView.getPaddingLeft();
|
||||||
|
final int paddingRight = searchBarView.getPaddingRight();
|
||||||
|
final int paddingTop = searchBarView.getPaddingTop();
|
||||||
|
final int paddingBottom = searchBarView.getPaddingBottom();
|
||||||
|
final int paddingStart = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
|
||||||
|
8, Resources.getSystem().getDisplayMetrics());
|
||||||
|
|
||||||
|
if (Utils.isRightToLeftTextLayout()) {
|
||||||
|
searchBarView.setPadding(paddingLeft, paddingTop, paddingStart, paddingBottom);
|
||||||
|
} else {
|
||||||
|
searchBarView.setPadding(paddingStart, paddingTop, paddingRight, paddingBottom);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.printException(() -> "setActionBar failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package app.revanced.patches.youtube.layout.hide.general
|
package app.revanced.patches.youtube.layout.hide.general
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint
|
import app.revanced.patcher.fingerprint
|
||||||
|
import app.revanced.patches.youtube.layout.searchbar.wideSearchbarLayoutFingerprint
|
||||||
import app.revanced.util.literal
|
import app.revanced.util.literal
|
||||||
import com.android.tools.smali.dexlib2.AccessFlags
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
@ -67,6 +68,9 @@ internal val showWatermarkFingerprint = fingerprint {
|
|||||||
parameters("L", "L")
|
parameters("L", "L")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Matches same method as [wideSearchbarLayoutFingerprint].
|
||||||
|
*/
|
||||||
internal val yoodlesImageViewFingerprint = fingerprint {
|
internal val yoodlesImageViewFingerprint = fingerprint {
|
||||||
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
|
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
|
||||||
returns("Landroid/view/View;")
|
returns("Landroid/view/View;")
|
||||||
|
@ -44,14 +44,12 @@ var crowdfundingBoxId = -1L
|
|||||||
private set
|
private set
|
||||||
var youTubeLogo = -1L
|
var youTubeLogo = -1L
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var filterBarHeightId = -1L
|
var filterBarHeightId = -1L
|
||||||
private set
|
private set
|
||||||
var relatedChipCloudMarginId = -1L
|
var relatedChipCloudMarginId = -1L
|
||||||
private set
|
private set
|
||||||
var barContainerHeightId = -1L
|
var barContainerHeightId = -1L
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var fabButtonId = -1L
|
var fabButtonId = -1L
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
@ -1,31 +1,27 @@
|
|||||||
package app.revanced.patches.youtube.layout.searchbar
|
package app.revanced.patches.youtube.layout.searchbar
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint
|
import app.revanced.patcher.fingerprint
|
||||||
|
import app.revanced.patches.youtube.layout.hide.general.yoodlesImageViewFingerprint
|
||||||
|
import app.revanced.util.containsLiteralInstruction
|
||||||
|
import app.revanced.util.literal
|
||||||
import com.android.tools.smali.dexlib2.AccessFlags
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
|
||||||
|
|
||||||
internal val createSearchSuggestionsFingerprint = fingerprint {
|
|
||||||
opcodes(
|
|
||||||
Opcode.INVOKE_STATIC,
|
|
||||||
Opcode.MOVE_RESULT,
|
|
||||||
Opcode.CONST_4,
|
|
||||||
)
|
|
||||||
strings("ss_rds")
|
|
||||||
}
|
|
||||||
|
|
||||||
internal val setWordmarkHeaderFingerprint = fingerprint {
|
internal val setWordmarkHeaderFingerprint = fingerprint {
|
||||||
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
|
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
|
||||||
returns("V")
|
returns("V")
|
||||||
parameters("Landroid/widget/ImageView;")
|
parameters("Landroid/widget/ImageView;")
|
||||||
opcodes(
|
custom { methodDef, _ ->
|
||||||
Opcode.IGET_OBJECT,
|
methodDef.containsLiteralInstruction(ytWordmarkHeaderId) &&
|
||||||
Opcode.INVOKE_STATIC,
|
methodDef.containsLiteralInstruction(ytPremiumWordmarkHeaderId)
|
||||||
Opcode.MOVE_RESULT,
|
}
|
||||||
Opcode.IF_NEZ,
|
}
|
||||||
Opcode.IGET_BOOLEAN,
|
|
||||||
Opcode.IF_EQZ,
|
/**
|
||||||
Opcode.IGET_OBJECT,
|
* Matches the same method as [yoodlesImageViewFingerprint].
|
||||||
Opcode.CONST,
|
*/
|
||||||
null, // invoke-static or invoke-virtual.
|
internal val wideSearchbarLayoutFingerprint = fingerprint {
|
||||||
)
|
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
|
||||||
|
returns("Landroid/view/View;")
|
||||||
|
parameters("L", "L")
|
||||||
|
literal { actionBarRingoId }
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,68 @@
|
|||||||
package app.revanced.patches.youtube.layout.searchbar
|
package app.revanced.patches.youtube.layout.searchbar
|
||||||
|
|
||||||
import app.revanced.patcher.Fingerprint
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||||
import app.revanced.patcher.patch.BytecodePatchContext
|
|
||||||
import app.revanced.patcher.patch.bytecodePatch
|
import app.revanced.patcher.patch.bytecodePatch
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
import app.revanced.patcher.patch.resourcePatch
|
||||||
import app.revanced.patches.all.misc.resources.addResources
|
import app.revanced.patches.all.misc.resources.addResources
|
||||||
import app.revanced.patches.all.misc.resources.addResourcesPatch
|
import app.revanced.patches.all.misc.resources.addResourcesPatch
|
||||||
|
import app.revanced.patches.shared.misc.mapping.get
|
||||||
|
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
|
||||||
|
import app.revanced.patches.shared.misc.mapping.resourceMappings
|
||||||
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
|
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
|
||||||
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
|
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
|
||||||
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
|
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
|
||||||
import app.revanced.patches.youtube.misc.settings.settingsPatch
|
import app.revanced.patches.youtube.misc.settings.settingsPatch
|
||||||
|
import app.revanced.util.addInstructionsAtControlFlowLabel
|
||||||
|
import app.revanced.util.findInstructionIndicesReversedOrThrow
|
||||||
|
import app.revanced.util.getReference
|
||||||
|
import app.revanced.util.indexOfFirstInstructionOrThrow
|
||||||
|
import app.revanced.util.indexOfFirstLiteralInstructionOrThrow
|
||||||
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||||
|
|
||||||
private const val EXTENSION_CLASS_DESCRIPTOR =
|
private const val EXTENSION_CLASS_DESCRIPTOR =
|
||||||
"Lapp/revanced/extension/youtube/patches/WideSearchbarPatch;"
|
"Lapp/revanced/extension/youtube/patches/WideSearchbarPatch;"
|
||||||
|
|
||||||
|
internal var ytWordmarkHeaderId = -1L
|
||||||
|
private set
|
||||||
|
internal var ytPremiumWordmarkHeaderId = -1L
|
||||||
|
private set
|
||||||
|
internal var actionBarRingoId = -1L
|
||||||
|
private set
|
||||||
|
|
||||||
|
private val wideSearchbarResourcePatch = resourcePatch {
|
||||||
|
dependsOn(resourceMappingPatch)
|
||||||
|
|
||||||
|
execute {
|
||||||
|
ytWordmarkHeaderId = resourceMappings[
|
||||||
|
"attr",
|
||||||
|
"ytWordmarkHeader",
|
||||||
|
]
|
||||||
|
|
||||||
|
ytPremiumWordmarkHeaderId = resourceMappings[
|
||||||
|
"attr",
|
||||||
|
"ytPremiumWordmarkHeader",
|
||||||
|
]
|
||||||
|
|
||||||
|
actionBarRingoId = resourceMappings[
|
||||||
|
"layout",
|
||||||
|
"action_bar_ringo_background",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val wideSearchbarPatch = bytecodePatch(
|
val wideSearchbarPatch = bytecodePatch(
|
||||||
name = "Wide search bar",
|
name = "Wide search bar",
|
||||||
description = "Adds an option to replace the search icon with a wide search bar. This will hide the YouTube logo when active.",
|
description = "Adds an option to replace the search icon with a wide search bar. " +
|
||||||
|
"This will hide the YouTube logo when active.",
|
||||||
) {
|
) {
|
||||||
dependsOn(
|
dependsOn(
|
||||||
sharedExtensionPatch,
|
sharedExtensionPatch,
|
||||||
settingsPatch,
|
settingsPatch,
|
||||||
addResourcesPatch,
|
addResourcesPatch,
|
||||||
|
wideSearchbarResourcePatch,
|
||||||
)
|
)
|
||||||
|
|
||||||
compatibleWith(
|
compatibleWith(
|
||||||
@ -46,37 +84,45 @@ val wideSearchbarPatch = bytecodePatch(
|
|||||||
SwitchPreference("revanced_wide_searchbar"),
|
SwitchPreference("revanced_wide_searchbar"),
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
setWordmarkHeaderFingerprint.let {
|
||||||
* Navigate a fingerprints method at a given index mutably.
|
// Navigate to the method that checks if the YT logo is shown beside the search bar.
|
||||||
*
|
val shouldShowLogoMethod = with(it.originalMethod) {
|
||||||
* @param index The index to navigate to.
|
val invokeStaticIndex = indexOfFirstInstructionOrThrow {
|
||||||
* @param from The fingerprint to navigate the method on.
|
opcode == Opcode.INVOKE_STATIC &&
|
||||||
* @return The [MutableMethod] which was navigated on.
|
getReference<MethodReference>()?.returnType == "Z"
|
||||||
*/
|
}
|
||||||
fun BytecodePatchContext.walkMutable(index: Int, from: Fingerprint) =
|
navigate(this).to(invokeStaticIndex).stop()
|
||||||
navigate(from.originalMethod).to(index).stop()
|
}
|
||||||
|
|
||||||
/**
|
shouldShowLogoMethod.apply {
|
||||||
* Injects instructions required for certain methods.
|
findInstructionIndicesReversedOrThrow(Opcode.RETURN).forEach { index ->
|
||||||
*/
|
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||||
fun MutableMethod.injectSearchBarHook() {
|
|
||||||
val insertIndex = implementation!!.instructions.size - 1
|
|
||||||
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
|
|
||||||
|
|
||||||
addInstructions(
|
addInstructionsAtControlFlowLabel(
|
||||||
insertIndex,
|
index,
|
||||||
|
"""
|
||||||
|
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->enableWideSearchbar(Z)Z
|
||||||
|
move-result v$register
|
||||||
"""
|
"""
|
||||||
invoke-static {v$insertRegister}, $EXTENSION_CLASS_DESCRIPTOR->enableWideSearchbar(Z)Z
|
|
||||||
move-result v$insertRegister
|
|
||||||
""",
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mapOf(
|
// Fix missing left padding when using wide searchbar.
|
||||||
setWordmarkHeaderFingerprint to 1,
|
wideSearchbarLayoutFingerprint.method.apply {
|
||||||
createSearchSuggestionsFingerprint to createSearchSuggestionsFingerprint.patternMatch!!.startIndex,
|
val layoutIndex = indexOfFirstLiteralInstructionOrThrow(actionBarRingoId)
|
||||||
).forEach { (fingerprint, callIndex) ->
|
val inflateIndex = indexOfFirstInstructionOrThrow(layoutIndex) {
|
||||||
walkMutable(callIndex, fingerprint).injectSearchBarHook()
|
val reference = getReference<MethodReference>()
|
||||||
|
reference?.definingClass == "Landroid/view/LayoutInflater;"
|
||||||
|
&& reference.name == "inflate"
|
||||||
|
}
|
||||||
|
val register = getInstruction<OneRegisterInstruction>(inflateIndex + 1).registerA
|
||||||
|
|
||||||
|
addInstruction(
|
||||||
|
inflateIndex + 2,
|
||||||
|
"invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->setActionBar(Landroid/view/View;)V"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user