refactor(hide-category-bar): add Hide category bar in search results setting

This commit is contained in:
inotia00 2023-03-28 21:46:19 +09:00
parent 49aca64088
commit e41fc03e64
5 changed files with 47 additions and 2 deletions

View File

@ -0,0 +1,22 @@
package app.revanced.patches.youtube.layout.general.categorybar.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
object SearchResultsChipBarFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.CONST,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.barContainerHeightLabelId
} == true
}
)

View File

@ -16,6 +16,7 @@ import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.layout.general.categorybar.fingerprints.FilterBarHeightFingerprint
import app.revanced.patches.youtube.layout.general.categorybar.fingerprints.RelatedChipCloudFingerprint
import app.revanced.patches.youtube.layout.general.categorybar.fingerprints.SearchResultsChipBarFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.GENERAL_LAYOUT
@ -36,7 +37,8 @@ import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
class CategoryBarPatch : BytecodePatch(
listOf(
FilterBarHeightFingerprint,
RelatedChipCloudFingerprint
RelatedChipCloudFingerprint,
SearchResultsChipBarFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
@ -74,6 +76,23 @@ class CategoryBarPatch : BytecodePatch(
}
} ?: return RelatedChipCloudFingerprint.toErrorResult()
/**
* Category Bar in search results
*/
SearchResultsChipBarFingerprint.result?.let {
with (it.mutableMethod) {
val targetIndex = it.scanResult.patternScanResult!!.endIndex - 2
val register = (instruction(targetIndex) as OneRegisterInstruction).registerA
addInstructions(
targetIndex + 1, """
invoke-static {v$register}, $GENERAL_LAYOUT->hideCategoryBarInSearchResults(I)I
move-result v$register
"""
)
}
} ?: return SearchResultsChipBarFingerprint.toErrorResult()
/*
* Add settings
*/

View File

@ -20,6 +20,7 @@ class SharedResourceIdPatch : ResourcePatch {
var accountSwitcherAccessibilityLabelId: Long = -1
var appearanceStringId: Long = -1
var backgroundCategoryLabelId: Long = -1
var barContainerHeightLabelId: Long = -1
var bottomUiContainerResourceId: Long = -1
var chapterRepeatOnResourceId: Long = -1
var compactLinkLabelId: Long = -1
@ -54,6 +55,7 @@ class SharedResourceIdPatch : ResourcePatch {
accountSwitcherAccessibilityLabelId = findSharedResourceId("string", "account_switcher_accessibility_label")
appearanceStringId = findSharedResourceId("string", "app_theme_appearance_dark")
backgroundCategoryLabelId = findSharedResourceId("string", "pref_background_and_offline_category")
barContainerHeightLabelId = findSharedResourceId("dimen", "bar_container_height")
bottomUiContainerResourceId = findSharedResourceId("id", "bottom_ui_container_stub")
chapterRepeatOnResourceId = findSharedResourceId("string", "chapter_repeat_on")
compactLinkLabelId = findSharedResourceId("layout", "compact_link")

View File

@ -320,6 +320,7 @@ Please do not report any issues you encounter while using this feature."</string
<string name="revanced_hide_cast_button_title">Hide cast button</string>
<string name="revanced_hide_category_bar_in_feed_title">Hide category bar in feed</string>
<string name="revanced_hide_category_bar_in_related_video_title">Hide category bar in related video</string>
<string name="revanced_hide_category_bar_in_search_results_title">Hide category bar in search results</string>
<string name="revanced_hide_category_bar_summary_off">Category bar is shown</string>
<string name="revanced_hide_category_bar_summary_on">Category bar is hidden</string>
<string name="revanced_hide_channel_watermark_summary_off">Channel watermark is shown</string>

View File

@ -118,7 +118,8 @@
<!-- SETTINGS: HIDE_CATEGORY_BAR
<SwitchPreference android:title="@string/revanced_hide_category_bar_in_feed_title" android:key="revanced_hide_category_bar_in_feed" android:defaultValue="false" android:summaryOn="@string/revanced_hide_category_bar_summary_on" android:summaryOff="@string/revanced_hide_category_bar_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_category_bar_in_related_video_title" android:key="revanced_hide_category_bar_in_related_video" android:defaultValue="false" android:summaryOn="@string/revanced_hide_category_bar_summary_on" android:summaryOff="@string/revanced_hide_category_bar_summary_off" />SETTINGS: HIDE_CATEGORY_BAR -->
<SwitchPreference android:title="@string/revanced_hide_category_bar_in_related_video_title" android:key="revanced_hide_category_bar_in_related_video" android:defaultValue="false" android:summaryOn="@string/revanced_hide_category_bar_summary_on" android:summaryOff="@string/revanced_hide_category_bar_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_category_bar_in_search_results_title" android:key="revanced_hide_category_bar_in_search_results" android:defaultValue="false" android:summaryOn="@string/revanced_hide_category_bar_summary_on" android:summaryOff="@string/revanced_hide_category_bar_summary_off" />SETTINGS: HIDE_CATEGORY_BAR -->
<!-- SETTINGS: HIDE_GENERAL_LAYOUT_ADS
<SwitchPreference android:title="@string/revanced_adremover_merchandise_title" android:key="revanced_adremover_merchandise" android:defaultValue="true" android:summaryOn="@string/revanced_adremover_merchandise_summary_on" android:summaryOff="@string/revanced_adremover_merchandise_summary_off" />