Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(YouTube): Do not hide player controls when using double tap to skip forward #4487

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ private static void createToolbar(Activity activity, String toolbarTitleResource
// This is required to fix submenu title alignment issue with Android ASOP 15+
ViewGroup toolBarParent = activity.findViewById(
getResourceIdentifier("revanced_toolbar_parent", "id"));
ViewGroup dummyToolbar = toolBarParent.findViewById(getResourceIdentifier(
"revanced_toolbar", "id"));
ViewGroup dummyToolbar = Utils.getChildViewByResourceName(toolBarParent,"revanced_toolbar");
toolbarLayoutParams = dummyToolbar.getLayoutParams();
toolBarParent.removeView(dummyToolbar);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ enum class PlayerType {

/**
* A regular video is minimized.
*
* When spoofing to 16.x YouTube and watching a short with a regular video in the background,
* the type can be this (and not [HIDDEN]).
*/
WATCH_WHILE_MINIMIZED,
WATCH_WHILE_MAXIMIZED,
Expand Down Expand Up @@ -56,8 +53,7 @@ enum class PlayerType {
val newType = nameToPlayerType[enumName]
if (newType == null) {
Logger.printException { "Unknown PlayerType encountered: $enumName" }
} else if (current != newType) {
Logger.printDebug { "PlayerType changed to: $newType" }
} else {
current = newType
}
}
Expand All @@ -68,9 +64,13 @@ enum class PlayerType {
@JvmStatic
var current
get() = currentPlayerType
private set(value) {
currentPlayerType = value
onChange(currentPlayerType)
private set(type) {
if (currentPlayerType != type) {
Logger.printDebug { "Changed to: $type" }

currentPlayerType = type
onChange(type)
}
}

@Volatile // Read/write from different threads.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package app.revanced.extension.youtube.sponsorblock.ui;

import android.view.View;

import androidx.annotation.Nullable;

import app.revanced.extension.shared.Logger;
import app.revanced.extension.youtube.patches.VideoInformation;
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.youtube.videoplayer.PlayerControlButton;

public class CreateSegmentButton {
@Nullable
private static PlayerControlButton instance;

public static void hideControls() {
if (instance != null) instance.hide();
}

/**
* injection point
*/
public static void initialize(View controlsView) {
try {
instance = new PlayerControlButton(
controlsView,
"revanced_sb_create_segment_button",
null,
CreateSegmentButton::shouldBeShown,
v -> SponsorBlockViewController.toggleNewSegmentLayoutVisibility(),
null
);
} catch (Exception ex) {
Logger.printException(() -> "initialize failure", ex);
}
}

/**
* Injection point
*/
public static void setVisibilityImmediate(boolean visible) {
if (instance != null) instance.setVisibilityImmediate(visible);
}

/**
* Injection point
*/
public static void setVisibility(boolean visible, boolean animated) {
if (instance != null) instance.setVisibility(visible, animated);
}

private static boolean shouldBeShown() {
return Settings.SB_ENABLED.get() && Settings.SB_CREATE_NEW_SEGMENT.get()
&& !VideoInformation.isAtEndOfVideo();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.youtube.shared.PlayerType;
import app.revanced.extension.youtube.sponsorblock.objects.SponsorSegment;
import app.revanced.extension.youtube.videoplayer.PlayerControlTopButton;
import kotlin.Unit;

public class SponsorBlockViewController {
Expand Down Expand Up @@ -239,8 +238,8 @@ public static void endOfVideoReached() {
// but if buttons are showing when the end of the video is reached then they need
// to be forcefully hidden
if (!Settings.AUTO_REPEAT.get()) {
CreateSegmentButtonController.hideControls();
VotingButtonController.hideControls();
CreateSegmentButton.hideControls();
VotingButton.hideControls();
}
} catch (Exception ex) {
Logger.printException(() -> "endOfVideoReached failure", ex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package app.revanced.extension.youtube.sponsorblock.ui;

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

import androidx.annotation.Nullable;

import java.util.Objects;

import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.Utils;
import app.revanced.extension.youtube.patches.VideoInformation;
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.youtube.sponsorblock.SegmentPlaybackController;
import app.revanced.extension.youtube.sponsorblock.SponsorBlockUtils;
import app.revanced.extension.youtube.videoplayer.PlayerControlTopButton;
import app.revanced.extension.youtube.videoplayer.PlayerControlButton;

public class VotingButtonController extends PlayerControlTopButton {
public class VotingButton {
@Nullable
private static VotingButtonController instance;
private static PlayerControlButton instance;

public static void hideControls() {
if (instance != null) instance.hide();
Expand All @@ -26,36 +22,36 @@ public static void hideControls() {
/**
* injection point
*/
public static void initialize(View youtubeControlsLayout) {
public static void initialize(View controlsView) {
try {
Logger.printDebug(() -> "initializing voting button");
ImageView imageView = Objects.requireNonNull(Utils.getChildViewByResourceName(
youtubeControlsLayout, "revanced_sb_voting_button"));
instance = new VotingButtonController(imageView);
instance = new PlayerControlButton(
controlsView,
"revanced_sb_voting_button",
null,
VotingButton::shouldBeShown,
v -> SponsorBlockUtils.onVotingClicked(v.getContext()),
null
);
} catch (Exception ex) {
Logger.printException(() -> "initialize failure", ex);
}
}

/**
* injection point
* Injection point
*/
public static void changeVisibilityImmediate(boolean visible) {
public static void setVisibilityImmediate(boolean visible) {
if (instance != null) instance.setVisibilityImmediate(visible);
}

/**
* injection point
* Injection point
*/
public static void changeVisibility(boolean visible, boolean animated) {
public static void setVisibility(boolean visible, boolean animated) {
if (instance != null) instance.setVisibility(visible, animated);
}

private VotingButtonController(ImageView imageView) {
super(imageView, v -> SponsorBlockUtils.onVotingClicked(v.getContext()));
}

protected boolean shouldBeShown() {
private static boolean shouldBeShown() {
return Settings.SB_ENABLED.get() && Settings.SB_VOTING_BUTTON.get()
&& SegmentPlaybackController.videoHasSegments() && !VideoInformation.isAtEndOfVideo();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
package app.revanced.extension.youtube.videoplayer;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

import app.revanced.extension.shared.Logger;
import app.revanced.extension.youtube.patches.CopyVideoUrlPatch;
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.shared.Logger;
import app.revanced.extension.youtube.shared.PlayerType;

@SuppressWarnings("unused")
public class CopyVideoUrlButton extends PlayerControlBottomButton {
public class CopyVideoUrlButton {
@Nullable
private static CopyVideoUrlButton instance;

public CopyVideoUrlButton(ViewGroup viewGroup) {
super(
viewGroup,
"revanced_copy_video_url_button",
Settings.COPY_VIDEO_URL,
view -> CopyVideoUrlPatch.copyUrl(false),
view -> {
CopyVideoUrlPatch.copyUrl(true);
return true;
}
);
}
private static PlayerControlButton instance;

/**
* Injection point.
*/
public static void initializeButton(View view) {
public static void initializeButton(View controlsView) {
try {
instance = new CopyVideoUrlButton((ViewGroup) view);
instance = new PlayerControlButton(
controlsView,
"revanced_copy_video_url_button",
"revanced_copy_video_url_button_placeholder",
Settings.COPY_VIDEO_URL::get,
view -> CopyVideoUrlPatch.copyUrl(false),
view -> {
CopyVideoUrlPatch.copyUrl(true);
return true;
}
);
} catch (Exception ex) {
Logger.printException(() -> "initializeButton failure", ex);
}
Expand All @@ -41,14 +38,14 @@ public static void initializeButton(View view) {
/**
* injection point
*/
public static void changeVisibilityImmediate(boolean visible) {
public static void setVisibilityImmediate(boolean visible) {
if (instance != null) instance.setVisibilityImmediate(visible);
}

/**
* injection point
*/
public static void changeVisibility(boolean visible, boolean animated) {
public static void setVisibility(boolean visible, boolean animated) {
if (instance != null) instance.setVisibility(visible, animated);
}
}
Loading