Skip to content

Commit

Permalink
Failed attempt to replace the imageview with a custom class. Works bu…
Browse files Browse the repository at this point in the history
…t does not fix any issues.
  • Loading branch information
LisoUseInAIKyrios committed Feb 18, 2025
1 parent 6f8a621 commit 1717a64
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package app.revanced.extension.youtube.patches;

import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;

import java.lang.ref.WeakReference;

import app.revanced.extension.shared.Logger;
import app.revanced.extension.youtube.videoplayer.HookedTouchImageView;

@SuppressWarnings("unused")
public class PlayerControlsPatch {
Expand All @@ -20,37 +20,26 @@ private static boolean fullscreenButtonVisibilityCallbacksExist() {
/**
* Injection point.
*/
public static void setFullscreenCloseButton(ImageView imageButton) {
fullscreenButtonRef = new WeakReference<>(imageButton);
Logger.printDebug(() -> "Fullscreen button set");

if (!fullscreenButtonVisibilityCallbacksExist()) {
return;
}

// Add a global listener, since the protected method
// View#onVisibilityChanged() does not have any call backs.
imageButton.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
int lastVisibility = View.VISIBLE;

@Override
public void onGlobalLayout() {
try {
final int visibility = imageButton.getVisibility();
if (lastVisibility != visibility) {
lastVisibility = visibility;
public static void setFullscreenCloseButton(ImageView view) {
try {
HookedTouchImageView imageButton = (HookedTouchImageView) view;
fullscreenButtonRef = new WeakReference<>(imageButton);
Logger.printDebug(() -> "Fullscreen button set");

if (!fullscreenButtonVisibilityCallbacksExist()) {
return;
}

Logger.printDebug(() -> "fullscreen button visibility: "
+ (visibility == View.VISIBLE ? "VISIBLE" :
visibility == View.GONE ? "GONE" : "INVISIBLE"));
imageButton.setVisibilityChangeListener((listenerView, visibility) -> {
Logger.printDebug(() -> "fullscreen button visibility: "
+ (visibility == View.VISIBLE ? "VISIBLE" :
visibility == View.GONE ? "GONE" : "INVISIBLE"));

fullscreenButtonVisibilityChanged(visibility == View.VISIBLE);
}
} catch (Exception ex) {
Logger.printDebug(() -> "OnGlobalLayoutListener failure", ex);
}
}
});
fullscreenButtonVisibilityChanged(visibility == View.VISIBLE);
});
} catch (Exception ex) {
Logger.printException(() -> "setFullscreenCloseButton failure", ex);
}
}

// noinspection EmptyMethod
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package app.revanced.extension.youtube.videoplayer;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

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

import com.google.android.libraries.youtube.common.ui.TouchImageView;

import app.revanced.extension.shared.Logger;

public class HookedTouchImageView extends TouchImageView {
public interface HookedTouchImageViewListener {
void onVisibilityChanged(HookedTouchImageView view, int visibility);
}

@Nullable
private HookedTouchImageViewListener listener;

private int lastVisibility = View.VISIBLE;

public HookedTouchImageView(Context context) {
super(context);
}

public HookedTouchImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public HookedTouchImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

public HookedTouchImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}

public void setVisibilityChangeListener(@NonNull HookedTouchImageViewListener listener) {
this.listener = listener;
}

@Override
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);

try {
if (listener != null && lastVisibility != visibility) {
lastVisibility = visibility;
listener.onVisibilityChanged(this, visibility);
}
} catch (Exception ex) {
Logger.printDebug(() -> "onVisibilityChanged failure", ex);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.google.android.libraries.youtube.common.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

public class TouchImageView extends ImageView {

public TouchImageView(Context context) {
super(context);
}

public TouchImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public TouchImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

public TouchImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,20 @@ val playerControlsResourcePatch = resourcePatch {
lateinit var bottomTargetDocument: Document

execute {
val targetResourceName = "youtube_controls_bottom_ui_container.xml"

bottomUiContainerResourceId = resourceMappings["id", "bottom_ui_container_stub"]
controlsLayoutStub = resourceMappings["id", "controls_layout_stub"]
heatseekerViewstub = resourceMappings["id", "heatseeker_viewstub"]
fullscreenButton = resourceMappings["id", "fullscreen_button"]

bottomTargetDocument = document("res/layout/$targetResourceName")
// fullscreenButton = resourceMappings["id", "cf_fullscreen_button"]
bottomTargetDocument = document("res/layout/youtube_controls_bottom_ui_container.xml")

// Use a custom class for the fullscreen button to listen for visibility changes and animations.
val fullscreenButtonFile = get("res/layout/youtube_controls_fullscreen_button.xml")
val fullscreenButtonXml = fullscreenButtonFile.readText().replace(
"com.google.android.libraries.youtube.common.ui.TouchImageView",
"app.revanced.extension.youtube.videoplayer.HookedTouchImageView"
)
fullscreenButtonFile.writeText(fullscreenButtonXml)

val bottomTargetElement: Node = bottomTargetDocument.getElementsByTagName(
"android.support.constraint.ConstraintLayout",
Expand Down

0 comments on commit 1717a64

Please sign in to comment.