Skip to content

Commit

Permalink
feat(YouTube): Support version 19.44.39
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 authored and anddea committed Dec 21, 2024
1 parent bf8afdd commit 22419fd
Show file tree
Hide file tree
Showing 24 changed files with 382 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class SponsorBlockSettings {
public void settingsImported(@Nullable Context context) {
SegmentCategory.loadAllCategoriesFromSettings();
}

@Override
public void settingsExported(@Nullable Context context) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.app.AlertDialog;
import android.content.Context;
import android.util.TypedValue;
import android.view.ViewGroup;
import android.widget.FrameLayout;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public class PlayerPatch {

// region [Ambient mode control] patch

/**
* Constant found in: androidx.window.embedding.DividerAttributes
*/
private static final int DIVIDER_ATTRIBUTES_COLOR_SYSTEM_DEFAULT = -16777216;

public static boolean bypassAmbientModeRestrictions(boolean original) {
return (!Settings.BYPASS_AMBIENT_MODE_RESTRICTIONS.get() && original) || Settings.DISABLE_AMBIENT_MODE.get();
}
Expand All @@ -82,6 +87,14 @@ public static boolean disableAmbientModeInFullscreen() {
return !Settings.DISABLE_AMBIENT_MODE_IN_FULLSCREEN.get();
}

public static int getFullScreenBackgroundColor(int originalColor) {
if (Settings.DISABLE_AMBIENT_MODE_IN_FULLSCREEN.get()) {
return DIVIDER_ATTRIBUTES_COLOR_SYSTEM_DEFAULT;
}

return originalColor;
}

// endregion

// region [Change player flyout menu toggles] patch
Expand Down Expand Up @@ -424,6 +437,35 @@ public static boolean hidePreviousNextButton(boolean previousOrNextButtonVisible
return !Settings.HIDE_PLAYER_PREVIOUS_NEXT_BUTTON.get() && previousOrNextButtonVisible;
}

private static final int playerControlPreviousButtonTouchAreaId =
ResourceUtils.getIdIdentifier("player_control_previous_button_touch_area");
private static final int playerControlNextButtonTouchAreaId =
ResourceUtils.getIdIdentifier("player_control_next_button_touch_area");

public static void hidePreviousNextButtons(View parentView) {
if (!Settings.HIDE_PLAYER_PREVIOUS_NEXT_BUTTON.get()) {
return;
}

// Must use a deferred call to main thread to hide the button.
// Otherwise the layout crashes if set to hidden now.
Utils.runOnMainThread(() -> {
hideView(parentView, playerControlPreviousButtonTouchAreaId);
hideView(parentView, playerControlNextButtonTouchAreaId);
});
}

private static void hideView(View parentView, int resourceId) {
View nextPreviousButton = parentView.findViewById(resourceId);

if (nextPreviousButton == null) {
Logger.printException(() -> "Could not find player previous / next button");
return;
}

Utils.hideViewByRemovingFromParentUnderCondition(true, nextPreviousButton);
}

public static boolean hideMusicButton() {
return Settings.HIDE_PLAYER_YOUTUBE_MUSIC_BUTTON.get();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package app.revanced.extension.youtube.patches.shorts;

import static app.revanced.extension.shared.utils.ResourceUtils.getString;
import static app.revanced.extension.shared.utils.Utils.dpToPx;
import static app.revanced.extension.youtube.patches.components.ShortsCustomActionsFilter.isShortsFlyoutMenuVisible;
import static app.revanced.extension.youtube.utils.ExtendedUtils.isSpoofingToLessThan;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.ColorFilter;
Expand All @@ -10,13 +15,26 @@
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.StateListDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.*;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.apache.commons.lang3.StringUtils;

import java.lang.ref.WeakReference;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;

import app.revanced.extension.shared.settings.BooleanSetting;
import app.revanced.extension.shared.utils.Logger;
import app.revanced.extension.shared.utils.ResourceUtils;
Expand All @@ -26,17 +44,6 @@
import app.revanced.extension.youtube.shared.ShortsPlayerState;
import app.revanced.extension.youtube.utils.ThemeUtils;
import app.revanced.extension.youtube.utils.VideoUtils;
import org.apache.commons.lang3.StringUtils;

import java.lang.ref.WeakReference;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;

import static app.revanced.extension.shared.utils.ResourceUtils.getString;
import static app.revanced.extension.shared.utils.Utils.dpToPx;
import static app.revanced.extension.youtube.patches.components.ShortsCustomActionsFilter.isShortsFlyoutMenuVisible;
import static app.revanced.extension.youtube.utils.ExtendedUtils.isSpoofingToLessThan;

@SuppressWarnings("unused")
public final class CustomActionsPatch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void settingsImported(@Nullable Context context) {
SegmentCategory.loadAllCategoriesFromSettings();
SponsorBlockSettingsPreference.updateSegmentCategories();
}

@Override
public void settingsExported(@Nullable Context context) {
showExportWarningIfNeeded(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ internal val actionBarRingoBackgroundFingerprint = legacyFingerprint(
returnType = "Landroid/view/View;",
literals = listOf(actionBarRingoBackground),
customFingerprint = { method, _ ->
indexOfStaticInstruction(method) >= 0
indexOfActionBarRingoBackgroundTabletInstruction(method) >= 0
}
)

internal fun indexOfStaticInstruction(method: Method) =
internal fun indexOfActionBarRingoBackgroundTabletInstruction(method: Method) =
method.indexOfFirstInstruction {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_STATIC &&
Expand Down Expand Up @@ -54,7 +54,7 @@ internal val actionBarRingoTextFingerprint = legacyFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
customFingerprint = { method, _ ->
indexOfStartDelayInstruction(method) >= 0 &&
indexOfStaticInstructions(method) >= 0
indexOfActionBarRingoTextTabletInstructions(method) >= 0
}
)

Expand All @@ -64,7 +64,7 @@ internal fun indexOfStartDelayInstruction(method: Method) =
getReference<MethodReference>()?.name == "setStartDelay"
}

internal fun indexOfStaticInstructions(method: Method) =
internal fun indexOfActionBarRingoTextTabletInstructions(method: Method) =
method.indexOfFirstInstructionReversed(indexOfStartDelayInstruction(method)) {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_STATIC &&
Expand Down Expand Up @@ -175,24 +175,6 @@ internal val setActionBarRingoFingerprint = legacyFingerprint(
literals = listOf(actionBarRingo),
)

internal val setWordMarkHeaderFingerprint = legacyFingerprint(
name = "setWordMarkHeaderFingerprint",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
returnType = "V",
parameters = listOf("Landroid/widget/ImageView;"),
opcodes = listOf(
Opcode.IGET_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT,
Opcode.IF_NEZ,
Opcode.IGET_BOOLEAN,
Opcode.IF_EQZ,
Opcode.IGET_OBJECT,
Opcode.CONST,
Opcode.INVOKE_STATIC,
)
)

@Suppress("SpellCheckingInspection")
internal val yoodlesImageViewFingerprint = legacyFingerprint(
name = "yoodlesImageViewFingerprint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ val toolBarComponentsPatch = bytecodePatch(
"invoke-static {v$viewRegister}, $GENERAL_CLASS_DESCRIPTOR->setWideSearchBarLayout(Landroid/view/View;)V"
)

val targetIndex = indexOfStaticInstruction(this) + 1
val targetIndex = indexOfActionBarRingoBackgroundTabletInstruction(this) + 1
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA

injectSearchBarHook(
Expand All @@ -180,7 +180,7 @@ val toolBarComponentsPatch = bytecodePatch(
}

actionBarRingoTextFingerprint.methodOrThrow(actionBarRingoBackgroundFingerprint).apply {
val targetIndex = indexOfStaticInstruction(this) + 1
val targetIndex = indexOfActionBarRingoTextTabletInstructions(this) + 1
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA

injectSearchBarHook(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,43 @@ import app.revanced.patcher.patch.resourcePatch
import app.revanced.patcher.patch.stringOption
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.patch.PatchList.CUSTOM_SHORTS_ACTION_BUTTONS
import app.revanced.patches.youtube.utils.playservice.is_19_36_or_greater
import app.revanced.patches.youtube.utils.playservice.versionCheckPatch
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
import app.revanced.patches.youtube.utils.settings.settingsPatch
import app.revanced.util.ResourceGroup
import app.revanced.util.copyResources
import app.revanced.util.inputStreamFromBundledResourceOrThrow
import app.revanced.util.lowerCaseOrThrow
import java.nio.file.Files
import java.nio.file.StandardCopyOption

private const val DEFAULT_ICON = "cairo"
private const val YOUTUBE_ICON = "youtube"

private val sizeArray = arrayOf(
"xxxhdpi",
"xxhdpi",
"xhdpi",
"hdpi",
"mdpi"
)

private val drawableDirectories = sizeArray.map { "drawable-$it" }

@Suppress("unused")
val shortsActionButtonsPatch = resourcePatch(
CUSTOM_SHORTS_ACTION_BUTTONS.title,
CUSTOM_SHORTS_ACTION_BUTTONS.summary,
) {
compatibleWith(COMPATIBLE_PACKAGE)

dependsOn(settingsPatch)
dependsOn(
settingsPatch,
versionCheckPatch
)

val iconType = stringOption(
val iconTypeOption = stringOption(
key = "iconType",
default = DEFAULT_ICON,
values = mapOf(
Expand All @@ -41,7 +59,7 @@ val shortsActionButtonsPatch = resourcePatch(
execute {

// Check patch options first.
val iconType = iconType
val iconType = iconTypeOption
.lowerCaseOrThrow()

if (iconType == YOUTUBE_ICON) {
Expand All @@ -50,40 +68,41 @@ val shortsActionButtonsPatch = resourcePatch(
return@execute
}

arrayOf(
"xxxhdpi",
"xxhdpi",
"xhdpi",
"hdpi",
"mdpi"
).forEach { dpi ->
copyResources(
"youtube/shorts/actionbuttons/$iconType",
ResourceGroup(
"drawable-$dpi",
"ic_remix_filled_white_shadowed.webp",
"ic_right_comment_shadowed.webp",
"ic_right_dislike_off_shadowed.webp",
"ic_right_dislike_on_shadowed.webp",
"ic_right_like_off_shadowed.webp",
"ic_right_like_on_shadowed.webp",
"ic_right_share_shadowed.webp",

// for older versions only
"ic_remix_filled_white_24.webp",
"ic_right_dislike_on_32c.webp",
"ic_right_like_on_32c.webp"
),
ResourceGroup(
"drawable",
"ic_right_comment_32c.xml",
"ic_right_dislike_off_32c.xml",
"ic_right_like_off_32c.xml",
"ic_right_share_32c.xml"
)
)
val sourceResourceDirectory = "youtube/shorts/actionbuttons/$iconType"

val resourceMap = ShortsActionButtons.entries.map { it.newResource to it.resources }
val res = get("res")

for ((toFileName, fromResourceArray) in resourceMap) {
fromResourceArray.forEach { fromFileName ->
drawableDirectories.forEach { drawableDirectory ->
val fromFile = "$drawableDirectory/$fromFileName.webp"
val fromPath = res.resolve(fromFile).toPath()
val toFile = "$drawableDirectory/$toFileName.webp"
val toPath = res.resolve(toFile).toPath()
val inputStreamForLegacy = inputStreamFromBundledResourceOrThrow(sourceResourceDirectory, fromFile)
val inputStreamForNew = inputStreamFromBundledResourceOrThrow(sourceResourceDirectory, fromFile)

Files.copy(inputStreamForLegacy, fromPath, StandardCopyOption.REPLACE_EXISTING)

if (is_19_36_or_greater) {
Files.copy(inputStreamForNew, toPath, StandardCopyOption.REPLACE_EXISTING)
}
}
}
}

copyResources(
sourceResourceDirectory,
ResourceGroup(
"drawable",
"ic_right_comment_32c.xml",
"ic_right_dislike_off_32c.xml",
"ic_right_like_off_32c.xml",
"ic_right_share_32c.xml"
)
)

addPreference(CUSTOM_SHORTS_ACTION_BUTTONS)

if (iconType == DEFAULT_ICON) {
Expand All @@ -99,6 +118,46 @@ val shortsActionButtonsPatch = resourcePatch(
"reel_search_bold_24dp.xml"
)
)

}
}

internal enum class ShortsActionButtons(val newResource: String, vararg val resources: String) {
LIKE(
"youtube_shorts_like_outline_32dp",
// This replaces the new icon.
"ic_right_like_off_shadowed",
),
LIKE_FILLED(
"youtube_shorts_like_fill_32dp",
"ic_right_like_on_32c",
// This replaces the new icon.
"ic_right_like_on_shadowed",
),
DISLIKE(
"youtube_shorts_dislike_outline_32dp",
// This replaces the new icon.
"ic_right_dislike_off_shadowed",
),
DISLIKE_FILLED(
"youtube_shorts_dislike_fill_32dp",
"ic_right_dislike_on_32c",
// This replaces the new icon.
"ic_right_dislike_on_shadowed",
),
COMMENT(
"youtube_shorts_comment_outline_32dp",
// This replaces the new icon.
"ic_right_comment_shadowed",
),
SHARE(
"youtube_shorts_share_outline_32dp",
// This replaces the new icon.
"ic_right_share_shadowed",
),
REMIX(
"youtube_shorts_remix_outline_32dp",
"ic_remix_filled_white_24",
// This replaces the new icon.
"ic_remix_filled_white_shadowed",
),
}
Loading

0 comments on commit 22419fd

Please sign in to comment.