Skip to content

Commit 6c4885a

Browse files
ILoveOpenSourceApplicationsLisoUseInAIKyrios
andauthored
fix(YouTube - Hide player components): Show correct end video thumbnail if Hide end screen suggested video is enabled (#4502)
Co-authored-by: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com>
1 parent 3c20829 commit 6c4885a

File tree

10 files changed

+170
-128
lines changed

10 files changed

+170
-128
lines changed

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/DisableSuggestedVideoEndScreenPatch.java

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package app.revanced.extension.youtube.patches;
2+
3+
import app.revanced.extension.youtube.settings.Settings;
4+
5+
@SuppressWarnings("unused")
6+
public final class HideEndScreenSuggestedVideoPatch {
7+
/**
8+
* Injection point.
9+
*/
10+
public static boolean hideEndScreenSuggestedVideo() {
11+
return Settings.HIDE_END_SCREEN_SUGGESTED_VIDEO.get();
12+
}
13+
}

extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ public class Settings extends BaseSettings {
125125
public static final BooleanSetting COPY_VIDEO_URL_TIMESTAMP = new BooleanSetting("revanced_copy_video_url_timestamp", TRUE);
126126
public static final BooleanSetting DISABLE_FULLSCREEN_AMBIENT_MODE = new BooleanSetting("revanced_disable_fullscreen_ambient_mode", TRUE, true);
127127
public static final BooleanSetting DISABLE_ROLLING_NUMBER_ANIMATIONS = new BooleanSetting("revanced_disable_rolling_number_animations", FALSE);
128-
public static final BooleanSetting DISABLE_SUGGESTED_VIDEO_END_SCREEN = new BooleanSetting("revanced_disable_suggested_video_end_screen", FALSE, true);
129128
public static final EnumSetting<FullscreenMode> EXIT_FULLSCREEN = new EnumSetting<>("revanced_exit_fullscreen", FullscreenMode.DISABLED);
130129
public static final BooleanSetting HIDE_AUTOPLAY_BUTTON = new BooleanSetting("revanced_hide_autoplay_button", TRUE, true);
131130
public static final BooleanSetting HIDE_CAPTIONS_BUTTON = new BooleanSetting("revanced_hide_captions_button", FALSE);
@@ -135,6 +134,7 @@ public class Settings extends BaseSettings {
135134
public static final BooleanSetting HIDE_COMMUNITY_GUIDELINES = new BooleanSetting("revanced_hide_community_guidelines", TRUE);
136135
public static final BooleanSetting HIDE_EMERGENCY_BOX = new BooleanSetting("revanced_hide_emergency_box", TRUE);
137136
public static final BooleanSetting HIDE_ENDSCREEN_CARDS = new BooleanSetting("revanced_hide_endscreen_cards", FALSE);
137+
public static final BooleanSetting HIDE_END_SCREEN_SUGGESTED_VIDEO = new BooleanSetting("revanced_end_screen_suggested_video", FALSE, true);
138138
public static final BooleanSetting HIDE_HIDE_CHANNEL_GUIDELINES = new BooleanSetting("revanced_hide_channel_guidelines", TRUE);
139139
public static final BooleanSetting HIDE_INFO_PANELS = new BooleanSetting("revanced_hide_info_panels", TRUE);
140140
public static final BooleanSetting HIDE_INFO_CARDS = new BooleanSetting("revanced_hide_info_cards", FALSE);
@@ -284,7 +284,6 @@ public class Settings extends BaseSettings {
284284
"revanced_seekbar_thumbnails_high_quality_dialog_message", new SeekbarThumbnailsHighQualityAvailability());
285285
public static final BooleanSetting SLIDE_TO_SEEK = new BooleanSetting("revanced_slide_to_seek", FALSE, true);
286286
public static final BooleanSetting SEEKBAR_CUSTOM_COLOR = new BooleanSetting("revanced_seekbar_custom_color", FALSE, true);
287-
private static final StringSetting DEPRECATED_SEEKBAR_CUSTOM_COLOR_PRIMARY = new StringSetting("revanced_seekbar_custom_color_value", "#FF0033");
288287
public static final StringSetting SEEKBAR_CUSTOM_COLOR_PRIMARY = new StringSetting("revanced_seekbar_custom_color_primary", "#FF0033", true, parent(SEEKBAR_CUSTOM_COLOR));
289288
public static final StringSetting SEEKBAR_CUSTOM_COLOR_ACCENT = new StringSetting("revanced_seekbar_custom_color_accent", "#FF2791", true, parent(SEEKBAR_CUSTOM_COLOR));
290289

@@ -322,7 +321,6 @@ public class Settings extends BaseSettings {
322321
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
323322
public static final IntegerSetting SWIPE_OVERLAY_OPACITY = new IntegerSetting("revanced_swipe_overlay_background_opacity", 60, true,
324323
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
325-
private static final IntegerSetting DEPRECATED_SWIPE_OVERLAY_BACKGROUND_ALPHA = new IntegerSetting("revanced_swipe_overlay_background_alpha", 127);
326324
public static final LongSetting SWIPE_OVERLAY_TIMEOUT = new LongSetting("revanced_swipe_overlay_timeout", 500L, true,
327325
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
328326
public static final BooleanSetting SWIPE_SAVE_AND_RESTORE_BRIGHTNESS = new BooleanSetting("revanced_swipe_save_and_restore_brightness", TRUE, true, parent(SWIPE_BRIGHTNESS));
@@ -384,9 +382,12 @@ public class Settings extends BaseSettings {
384382
public static final StringSetting SB_CATEGORY_UNSUBMITTED_COLOR = new StringSetting("sb_unsubmitted_color", "#FFFFFF");
385383

386384
// Deprecated migrations
387-
public static final StringSetting DEPRECATED_SB_UUID_OLD_MIGRATION_SETTING = new StringSetting("uuid", ""); // Delete sometime in 2024
385+
private static final StringSetting DEPRECATED_SB_UUID_OLD_MIGRATION_SETTING = new StringSetting("uuid", ""); // Delete sometime in 2024
388386
private static final BooleanSetting DEPRECATED_HIDE_PLAYER_BUTTONS = new BooleanSetting("revanced_hide_player_buttons", FALSE, true);
389387
private static final BooleanSetting DEPRECATED_HIDE_PLAYER_FLYOUT_VIDEO_QUALITY_FOOTER = new BooleanSetting("revanced_hide_video_quality_menu_footer", FALSE);
388+
private static final IntegerSetting DEPRECATED_SWIPE_OVERLAY_BACKGROUND_ALPHA = new IntegerSetting("revanced_swipe_overlay_background_alpha", 127);
389+
private static final StringSetting DEPRECATED_SEEKBAR_CUSTOM_COLOR_PRIMARY = new StringSetting("revanced_seekbar_custom_color_value", "#FF0033");
390+
private static final BooleanSetting DEPRECATED_DISABLE_SUGGESTED_VIDEO_END_SCREEN = new BooleanSetting("revanced_disable_suggested_video_end_screen", FALSE);
390391

391392
static {
392393
// region Migration
@@ -405,6 +406,8 @@ public class Settings extends BaseSettings {
405406

406407
migrateOldSettingToNew(DEPRECATED_HIDE_PLAYER_FLYOUT_VIDEO_QUALITY_FOOTER, HIDE_PLAYER_FLYOUT_VIDEO_QUALITY_FOOTER);
407408

409+
migrateOldSettingToNew(DEPRECATED_DISABLE_SUGGESTED_VIDEO_END_SCREEN, HIDE_END_SCREEN_SUGGESTED_VIDEO);
410+
408411
// Migrate renamed enum.
409412
//noinspection deprecation
410413
if (MINIPLAYER_TYPE.get() == MiniplayerType.PHONE) {

patches/api/patches.api

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,10 @@ public final class app/revanced/patches/youtube/layout/hide/endscreencards/HideE
11161116
public static final fun getHideEndscreenCardsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
11171117
}
11181118

1119+
public final class app/revanced/patches/youtube/layout/hide/endscreensuggestion/HideEndScreenSuggestedVideoPatchKt {
1120+
public static final fun getHideEndScreenSuggestedVideoPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
1121+
}
1122+
11191123
public final class app/revanced/patches/youtube/layout/hide/fullscreenambientmode/DisableFullscreenAmbientModePatchKt {
11201124
public static final fun getDisableFullscreenAmbientModePatch ()Lapp/revanced/patcher/patch/BytecodePatch;
11211125
}

patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/endscreencards/HideEndscreenCardsPatch.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ private val hideEndscreenCardsResourcePatch = resourcePatch {
4444
}
4545
}
4646

47+
private const val EXTENSION_CLASS_DESCRIPTOR =
48+
"Lapp/revanced/extension/youtube/patches/HideEndscreenCardsPatch;"
49+
4750
@Suppress("unused")
4851
val hideEndscreenCardsPatch = bytecodePatch(
4952
name = "Hide endscreen cards",
@@ -78,9 +81,7 @@ val hideEndscreenCardsPatch = bytecodePatch(
7881

7982
addInstruction(
8083
insertIndex,
81-
"invoke-static { v$viewRegister }, " +
82-
"Lapp/revanced/extension/youtube/patches/HideEndscreenCardsPatch;->" +
83-
"hideEndscreen(Landroid/view/View;)V",
84+
"invoke-static { v$viewRegister }, $EXTENSION_CLASS_DESCRIPTOR->hideEndscreen(Landroid/view/View;)V",
8485
)
8586
}
8687
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package app.revanced.patches.youtube.layout.hide.endscreensuggestion
2+
3+
import app.revanced.patcher.fingerprint
4+
import app.revanced.util.getReference
5+
import app.revanced.util.indexOfFirstInstruction
6+
import com.android.tools.smali.dexlib2.AccessFlags
7+
import com.android.tools.smali.dexlib2.Opcode
8+
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
9+
10+
internal val autoNavConstructorFingerprint = fingerprint {
11+
returns("V")
12+
accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR)
13+
strings("main_app_autonav")
14+
}
15+
16+
internal val autoNavStatusFingerprint = fingerprint {
17+
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
18+
returns("Z")
19+
parameters()
20+
}
21+
22+
internal val removeOnLayoutChangeListenerFingerprint = fingerprint {
23+
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
24+
returns("V")
25+
parameters()
26+
opcodes(
27+
Opcode.IPUT,
28+
Opcode.INVOKE_VIRTUAL
29+
)
30+
// This is the only reference present in the entire smali.
31+
custom { method, _ ->
32+
method.indexOfFirstInstruction {
33+
val reference = getReference<MethodReference>()
34+
reference?.name == "removeOnLayoutChangeListener" &&
35+
reference.definingClass.endsWith("/YouTubePlayerOverlaysLayout;")
36+
} >= 0
37+
}
38+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package app.revanced.patches.youtube.layout.hide.endscreensuggestion
2+
3+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
4+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
5+
import app.revanced.patcher.patch.bytecodePatch
6+
import app.revanced.patcher.util.smali.ExternalLabel
7+
import app.revanced.patches.all.misc.resources.addResources
8+
import app.revanced.patches.all.misc.resources.addResourcesPatch
9+
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
10+
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
11+
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
12+
import app.revanced.util.getReference
13+
import app.revanced.util.indexOfFirstInstructionOrThrow
14+
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
15+
import com.android.tools.smali.dexlib2.Opcode
16+
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
17+
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
18+
19+
private const val EXTENSION_CLASS_DESCRIPTOR =
20+
"Lapp/revanced/extension/youtube/patches/HideEndScreenSuggestedVideoPatch;"
21+
22+
@Suppress("unused")
23+
val hideEndScreenSuggestedVideoPatch = bytecodePatch(
24+
name = "Hide end screen suggested video",
25+
description = "Adds an option to hide the recommended video at the end of each video.",
26+
) {
27+
dependsOn(
28+
sharedExtensionPatch,
29+
addResourcesPatch,
30+
)
31+
32+
compatibleWith(
33+
"com.google.android.youtube"(
34+
"19.16.39",
35+
"19.25.37",
36+
"19.34.42",
37+
"19.43.41",
38+
"19.45.38",
39+
"19.46.42",
40+
"19.47.53",
41+
),
42+
)
43+
44+
execute {
45+
addResources("youtube", "layout.hide.endscreensuggestion.hideEndScreenSuggestedVideoPatch")
46+
47+
PreferenceScreen.PLAYER.addPreferences(
48+
SwitchPreference("revanced_end_screen_suggested_video"),
49+
)
50+
51+
removeOnLayoutChangeListenerFingerprint.let {
52+
val endScreenMethod = navigate(it.originalMethod).to(it.patternMatch!!.endIndex).stop()
53+
54+
endScreenMethod.apply {
55+
val autoNavStatusMethodName = autoNavStatusFingerprint.match(
56+
autoNavConstructorFingerprint.classDef
57+
).originalMethod.name
58+
59+
val invokeIndex = indexOfFirstInstructionOrThrow {
60+
val reference = getReference<MethodReference>()
61+
reference?.name == autoNavStatusMethodName &&
62+
reference.returnType == "Z" &&
63+
reference.parameterTypes.isEmpty()
64+
}
65+
val iGetObjectIndex = indexOfFirstInstructionReversedOrThrow(invokeIndex, Opcode.IGET_OBJECT)
66+
val invokeReference = getInstruction<ReferenceInstruction>(invokeIndex).reference
67+
val iGetObjectReference = getInstruction<ReferenceInstruction>(iGetObjectIndex).reference
68+
val opcodeName = getInstruction(invokeIndex).opcode.name
69+
70+
addInstructionsWithLabels(
71+
0,
72+
"""
73+
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->hideEndScreenSuggestedVideo()Z
74+
move-result v0
75+
if-eqz v0, :show_end_screen_recommendation
76+
77+
iget-object v0, p0, $iGetObjectReference
78+
79+
# This reference checks whether autoplay is turned on.
80+
$opcodeName { v0 }, $invokeReference
81+
move-result v0
82+
83+
# Hide suggested video end screen only when autoplay is turned off.
84+
if-nez v0, :show_end_screen_recommendation
85+
return-void
86+
""",
87+
ExternalLabel("show_end_screen_recommendation", getInstruction(0))
88+
)
89+
}
90+
}
91+
}
92+
}
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,9 @@
11
package app.revanced.patches.youtube.layout.hide.suggestedvideoendscreen
22

3-
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
4-
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
53
import app.revanced.patcher.patch.bytecodePatch
6-
import app.revanced.patcher.patch.resourcePatch
7-
import app.revanced.patches.all.misc.resources.addResources
8-
import app.revanced.patches.all.misc.resources.addResourcesPatch
9-
import app.revanced.patches.shared.misc.mapping.get
10-
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
11-
import app.revanced.patches.shared.misc.mapping.resourceMappings
12-
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
13-
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
14-
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
15-
import app.revanced.patches.youtube.misc.settings.settingsPatch
16-
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
4+
import app.revanced.patches.youtube.layout.hide.endscreensuggestion.hideEndScreenSuggestedVideoPatch
175

18-
internal var sizeAdjustableLiteAutoNavOverlay = -1L
19-
private set
20-
21-
internal val disableSuggestedVideoEndScreenResourcePatch = resourcePatch {
22-
dependsOn(
23-
settingsPatch,
24-
resourceMappingPatch,
25-
addResourcesPatch,
26-
)
27-
28-
execute {
29-
addResources("youtube", "layout.hide.suggestedvideoendscreen.disableSuggestedVideoEndScreenResourcePatch")
30-
31-
PreferenceScreen.PLAYER.addPreferences(
32-
SwitchPreference("revanced_disable_suggested_video_end_screen"),
33-
)
34-
35-
sizeAdjustableLiteAutoNavOverlay = resourceMappings[
36-
"layout",
37-
"size_adjustable_lite_autonav_overlay",
38-
]
39-
}
40-
}
41-
42-
private const val EXTENSION_CLASS_DESCRIPTOR =
43-
"Lapp/revanced/extension/youtube/patches/DisableSuggestedVideoEndScreenPatch;"
44-
45-
@Suppress("unused")
46-
val disableSuggestedVideoEndScreenPatch = bytecodePatch(
47-
name = "Disable suggested video end screen",
48-
description = "Adds an option to disable the suggested video end screen at the end of videos.",
49-
) {
50-
dependsOn(
51-
sharedExtensionPatch,
52-
disableSuggestedVideoEndScreenResourcePatch,
53-
)
54-
55-
compatibleWith(
56-
"com.google.android.youtube"(
57-
"19.16.39",
58-
"19.25.37",
59-
"19.34.42",
60-
"19.43.41",
61-
"19.45.38",
62-
"19.46.42",
63-
"19.47.53",
64-
),
65-
)
66-
67-
execute {
68-
createEndScreenViewFingerprint.method.apply {
69-
val addOnClickEventListenerIndex = createEndScreenViewFingerprint.patternMatch!!.endIndex - 1
70-
val viewRegister = getInstruction<FiveRegisterInstruction>(addOnClickEventListenerIndex).registerC
71-
72-
addInstruction(
73-
addOnClickEventListenerIndex + 1,
74-
"invoke-static {v$viewRegister}, " +
75-
"$EXTENSION_CLASS_DESCRIPTOR->closeEndScreen(Landroid/widget/ImageView;)V",
76-
)
77-
}
78-
}
79-
}
6+
@Deprecated("Use 'Hide suggested video end screen' instead.")
7+
val disableSuggestedVideoEndScreenPatch = bytecodePatch {
8+
dependsOn(hideEndScreenSuggestedVideoPatch)
9+
}

patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/suggestedvideoendscreen/Fingerprints.kt

Lines changed: 0 additions & 18 deletions
This file was deleted.

patches/src/main/resources/addresources/values/strings.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,13 @@ If changing this setting does not take effect, try switching to Incognito mode."
813813
<string name="revanced_hide_shorts_navigation_bar_summary_on">Navigation bar is hidden</string>
814814
<string name="revanced_hide_shorts_navigation_bar_summary_off">Navigation bar is shown</string>
815815
</patch>
816-
<patch id="layout.hide.suggestedvideoendscreen.disableSuggestedVideoEndScreenResourcePatch">
817-
<string name="revanced_disable_suggested_video_end_screen_title">Disable suggested video end screen</string>
818-
<string name="revanced_disable_suggested_video_end_screen_summary_on">Suggested videos will be disabled</string>
819-
<string name="revanced_disable_suggested_video_end_screen_summary_off">Suggested videos will be shown</string>
816+
<patch id="layout.hide.endscreensuggestion.hideEndScreenSuggestedVideoPatch">
817+
<string name="revanced_end_screen_suggested_video_title">Hide end screen suggested video</string>
818+
<string name="revanced_end_screen_suggested_video_summary_on">"End screen suggested video is hidden when autoplay is turned off
819+
820+
Autoplay can be changed in YouTube settings:
821+
Settings → Playback → Autoplay next video"</string>
822+
<string name="revanced_end_screen_suggested_video_summary_off">End screen suggested video is shown</string>
820823
</patch>
821824
<patch id="layout.hide.time.hideTimestampPatch">
822825
<string name="revanced_hide_timestamp_title">Hide video timestamp</string>

0 commit comments

Comments
 (0)