mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-07 10:35:49 +01:00
fix(youtube): no longer need to restart the app after changing copy-video-url
or downloads
patch (#372)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
5b53e02613
commit
6b15514885
@ -19,13 +19,12 @@ import app.revanced.integrations.utils.StringRef;
|
|||||||
|
|
||||||
public enum SettingsEnum {
|
public enum SettingsEnum {
|
||||||
//Download Settings
|
//Download Settings
|
||||||
// TODO: DOWNLOAD_PATH("revanced_download_path", STRING, Environment.getExternalStorageDirectory().getPath() + "/Download"),
|
DOWNLOADS_BUTTON_SHOWN("revanced_downloads_enabled", BOOLEAN, TRUE),
|
||||||
DOWNLOADS_BUTTON_SHOWN("revanced_downloads_enabled", BOOLEAN, TRUE, true),
|
|
||||||
DOWNLOADS_PACKAGE_NAME("revanced_downloads_package_name", STRING, "org.schabi.newpipe" /* NewPipe */, parents(DOWNLOADS_BUTTON_SHOWN)),
|
DOWNLOADS_PACKAGE_NAME("revanced_downloads_package_name", STRING, "org.schabi.newpipe" /* NewPipe */, parents(DOWNLOADS_BUTTON_SHOWN)),
|
||||||
|
|
||||||
// Copy video URL settings
|
// Copy video URL settings
|
||||||
COPY_VIDEO_URL_BUTTON_SHOWN("revanced_copy_video_url_enabled", BOOLEAN, TRUE, true),
|
COPY_VIDEO_URL_BUTTON_SHOWN("revanced_copy_video_url_enabled", BOOLEAN, TRUE),
|
||||||
COPY_VIDEO_URL_TIMESTAMP_BUTTON_SHOWN("revanced_copy_video_url_timestamp_enabled", BOOLEAN, TRUE, true),
|
COPY_VIDEO_URL_TIMESTAMP_BUTTON_SHOWN("revanced_copy_video_url_timestamp_enabled", BOOLEAN, TRUE),
|
||||||
|
|
||||||
// Video settings
|
// Video settings
|
||||||
OLD_STYLE_VIDEO_QUALITY_PLAYER_SETTINGS("revanced_use_old_style_quality_settings", BOOLEAN, TRUE),
|
OLD_STYLE_VIDEO_QUALITY_PLAYER_SETTINGS("revanced_use_old_style_quality_settings", BOOLEAN, TRUE),
|
||||||
|
@ -1,66 +1,64 @@
|
|||||||
package app.revanced.integrations.videoplayer;
|
package app.revanced.integrations.videoplayer;
|
||||||
|
|
||||||
import android.support.constraint.ConstraintLayout;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import java.lang.ref.WeakReference;
|
import app.revanced.integrations.settings.SettingsEnum;
|
||||||
|
|
||||||
import app.revanced.integrations.utils.LogHelper;
|
import app.revanced.integrations.utils.LogHelper;
|
||||||
import app.revanced.integrations.utils.ReVancedUtils;
|
import app.revanced.integrations.utils.ReVancedUtils;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class BottomControlButton {
|
public abstract class BottomControlButton {
|
||||||
WeakReference<ImageView> button = new WeakReference<>(null);
|
private static final Animation fadeIn = ReVancedUtils.getResourceAnimation("fade_in");
|
||||||
ConstraintLayout constraintLayout;
|
private static final Animation fadeOut = ReVancedUtils.getResourceAnimation("fade_out");
|
||||||
Boolean isButtonEnabled;
|
private final WeakReference<ImageView> buttonRef;
|
||||||
Boolean isShowing;
|
private final SettingsEnum setting;
|
||||||
|
protected boolean isVisible;
|
||||||
|
|
||||||
private Animation fadeIn;
|
static {
|
||||||
private Animation fadeOut;
|
// TODO: check if these durations are correct.
|
||||||
|
fadeIn.setDuration(ReVancedUtils.getResourceInteger("fade_duration_fast"));
|
||||||
public BottomControlButton(Object obj, String viewId, Boolean isEnabled, View.OnClickListener onClickListener) {
|
fadeOut.setDuration(ReVancedUtils.getResourceInteger("fade_duration_scheduled"));
|
||||||
try {
|
|
||||||
LogHelper.printDebug(() -> "Initializing button with id: " + viewId);
|
|
||||||
constraintLayout = (ConstraintLayout) obj;
|
|
||||||
isButtonEnabled = isEnabled;
|
|
||||||
|
|
||||||
ImageView imageView = constraintLayout.findViewById(ReVancedUtils.getResourceIdentifier(viewId, "id"));
|
|
||||||
if (imageView == null) {
|
|
||||||
LogHelper.printException(() -> "Couldn't find ImageView with id: " + viewId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
imageView.setOnClickListener(onClickListener);
|
|
||||||
button = new WeakReference<>(imageView);
|
|
||||||
|
|
||||||
fadeIn = ReVancedUtils.getResourceAnimation("fade_in");
|
|
||||||
fadeOut = ReVancedUtils.getResourceAnimation("fade_out");
|
|
||||||
fadeIn.setDuration(ReVancedUtils.getResourceInteger("fade_duration_fast"));
|
|
||||||
fadeOut.setDuration(ReVancedUtils.getResourceInteger("fade_duration_scheduled"));
|
|
||||||
|
|
||||||
isShowing = true;
|
|
||||||
setVisibility(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogHelper.printException(() -> "Failed to initialize button with id: " + viewId, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisibility(boolean showing) {
|
public BottomControlButton(@NonNull ViewGroup bottomControlsViewGroup, @NonNull String imageViewButtonId,
|
||||||
if (isShowing == showing) return;
|
@NonNull SettingsEnum booleanSetting, @NonNull View.OnClickListener onClickListener) {
|
||||||
|
LogHelper.printDebug(() -> "Initializing button: " + imageViewButtonId);
|
||||||
|
|
||||||
isShowing = showing;
|
if (booleanSetting.returnType != SettingsEnum.ReturnType.BOOLEAN) {
|
||||||
ImageView imageView = button.get();
|
throw new IllegalArgumentException();
|
||||||
|
|
||||||
if (constraintLayout == null || imageView == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (showing && isButtonEnabled) {
|
|
||||||
LogHelper.printDebug(() -> "Fading in");
|
|
||||||
imageView.setVisibility(View.VISIBLE);
|
|
||||||
imageView.startAnimation(fadeIn);
|
|
||||||
}
|
}
|
||||||
else if (imageView.getVisibility() == View.VISIBLE) {
|
|
||||||
LogHelper.printDebug(() -> "Fading out");
|
setting = booleanSetting;
|
||||||
|
|
||||||
|
// Create the button.
|
||||||
|
ImageView imageView = Objects.requireNonNull(bottomControlsViewGroup.findViewById(
|
||||||
|
ReVancedUtils.getResourceIdentifier(imageViewButtonId, "id")
|
||||||
|
));
|
||||||
|
imageView.setOnClickListener(onClickListener);
|
||||||
|
imageView.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
buttonRef = new WeakReference<>(imageView);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVisibility(boolean visible) {
|
||||||
|
if (isVisible == visible) return;
|
||||||
|
isVisible = visible;
|
||||||
|
|
||||||
|
ImageView imageView = buttonRef.get();
|
||||||
|
if (imageView == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
imageView.clearAnimation();
|
||||||
|
if (visible && setting.getBoolean()) {
|
||||||
|
imageView.startAnimation(fadeIn);
|
||||||
|
imageView.setVisibility(View.VISIBLE);
|
||||||
|
} else if (imageView.getVisibility() == View.VISIBLE) {
|
||||||
imageView.startAnimation(fadeOut);
|
imageView.startAnimation(fadeOut);
|
||||||
imageView.setVisibility(View.GONE);
|
imageView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,40 @@
|
|||||||
package app.revanced.integrations.videoplayer;
|
package app.revanced.integrations.videoplayer;
|
||||||
|
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import app.revanced.integrations.patches.CopyVideoUrlPatch;
|
import app.revanced.integrations.patches.CopyVideoUrlPatch;
|
||||||
import app.revanced.integrations.settings.SettingsEnum;
|
import app.revanced.integrations.settings.SettingsEnum;
|
||||||
|
import app.revanced.integrations.utils.LogHelper;
|
||||||
|
|
||||||
public class CopyVideoUrlButton extends BottomControlButton {
|
public class CopyVideoUrlButton extends BottomControlButton {
|
||||||
public static CopyVideoUrlButton instance;
|
@Nullable
|
||||||
|
private static CopyVideoUrlButton instance;
|
||||||
|
|
||||||
public CopyVideoUrlButton(Object obj) {
|
public CopyVideoUrlButton(ViewGroup viewGroup) {
|
||||||
super(
|
super(
|
||||||
obj,
|
viewGroup,
|
||||||
"copy_video_url_button",
|
"copy_video_url_button",
|
||||||
SettingsEnum.COPY_VIDEO_URL_BUTTON_SHOWN.getBoolean(),
|
SettingsEnum.COPY_VIDEO_URL_BUTTON_SHOWN,
|
||||||
view -> CopyVideoUrlPatch.copyUrl(false)
|
view -> CopyVideoUrlPatch.copyUrl(false)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
*/
|
||||||
public static void initializeButton(Object obj) {
|
public static void initializeButton(Object obj) {
|
||||||
instance = new CopyVideoUrlButton(obj);
|
try {
|
||||||
|
instance = new CopyVideoUrlButton((ViewGroup) obj);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "initializeButton failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
*/
|
||||||
public static void changeVisibility(boolean showing) {
|
public static void changeVisibility(boolean showing) {
|
||||||
if (instance != null) instance.setVisibility(showing);
|
if (instance != null) instance.setVisibility(showing);
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,40 @@
|
|||||||
package app.revanced.integrations.videoplayer;
|
package app.revanced.integrations.videoplayer;
|
||||||
|
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import app.revanced.integrations.patches.CopyVideoUrlPatch;
|
import app.revanced.integrations.patches.CopyVideoUrlPatch;
|
||||||
import app.revanced.integrations.settings.SettingsEnum;
|
import app.revanced.integrations.settings.SettingsEnum;
|
||||||
|
import app.revanced.integrations.utils.LogHelper;
|
||||||
|
|
||||||
public class CopyVideoUrlTimestampButton extends BottomControlButton {
|
public class CopyVideoUrlTimestampButton extends BottomControlButton {
|
||||||
public static CopyVideoUrlTimestampButton instance;
|
@Nullable
|
||||||
|
private static CopyVideoUrlTimestampButton instance;
|
||||||
|
|
||||||
public CopyVideoUrlTimestampButton(Object obj) {
|
public CopyVideoUrlTimestampButton(ViewGroup bottomControlsViewGroup) {
|
||||||
super(
|
super(
|
||||||
obj,
|
bottomControlsViewGroup,
|
||||||
"copy_video_url_timestamp_button",
|
"copy_video_url_timestamp_button",
|
||||||
SettingsEnum.COPY_VIDEO_URL_TIMESTAMP_BUTTON_SHOWN.getBoolean(),
|
SettingsEnum.COPY_VIDEO_URL_TIMESTAMP_BUTTON_SHOWN,
|
||||||
view -> CopyVideoUrlPatch.copyUrl(true)
|
view -> CopyVideoUrlPatch.copyUrl(true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initializeButton(Object obj) {
|
/**
|
||||||
instance = new CopyVideoUrlTimestampButton(obj);
|
* Injection point.
|
||||||
|
*/
|
||||||
|
public static void initializeButton(Object bottomControlsViewGroup) {
|
||||||
|
try {
|
||||||
|
instance = new CopyVideoUrlTimestampButton((ViewGroup) bottomControlsViewGroup);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "initializeButton failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
*/
|
||||||
public static void changeVisibility(boolean showing) {
|
public static void changeVisibility(boolean showing) {
|
||||||
if (instance != null) instance.setVisibility(showing);
|
if (instance != null) instance.setVisibility(showing);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@ package app.revanced.integrations.videoplayer;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import app.revanced.integrations.patches.VideoInformation;
|
import app.revanced.integrations.patches.VideoInformation;
|
||||||
import app.revanced.integrations.settings.SettingsEnum;
|
import app.revanced.integrations.settings.SettingsEnum;
|
||||||
@ -11,21 +14,32 @@ import app.revanced.integrations.utils.ReVancedUtils;
|
|||||||
import app.revanced.integrations.utils.StringRef;
|
import app.revanced.integrations.utils.StringRef;
|
||||||
|
|
||||||
public class DownloadButton extends BottomControlButton {
|
public class DownloadButton extends BottomControlButton {
|
||||||
public static DownloadButton instance;
|
@Nullable
|
||||||
|
private static DownloadButton instance;
|
||||||
|
|
||||||
public DownloadButton(Object obj) {
|
public DownloadButton(ViewGroup viewGroup) {
|
||||||
super(
|
super(
|
||||||
obj,
|
viewGroup,
|
||||||
"download_button",
|
"download_button",
|
||||||
SettingsEnum.DOWNLOADS_BUTTON_SHOWN.getBoolean(),
|
SettingsEnum.DOWNLOADS_BUTTON_SHOWN,
|
||||||
DownloadButton::onDownloadClick
|
DownloadButton::onDownloadClick
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
*/
|
||||||
public static void initializeButton(Object obj) {
|
public static void initializeButton(Object obj) {
|
||||||
instance = new DownloadButton(obj);
|
try {
|
||||||
|
instance = new DownloadButton((ViewGroup) obj);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "initializeButton failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
*/
|
||||||
public static void changeVisibility(boolean showing) {
|
public static void changeVisibility(boolean showing) {
|
||||||
if (instance != null) instance.setVisibility(showing);
|
if (instance != null) instance.setVisibility(showing);
|
||||||
}
|
}
|
||||||
@ -38,7 +52,6 @@ public class DownloadButton extends BottomControlButton {
|
|||||||
|
|
||||||
boolean packageEnabled = false;
|
boolean packageEnabled = false;
|
||||||
try {
|
try {
|
||||||
assert context != null;
|
|
||||||
packageEnabled = context.getPackageManager().getApplicationInfo(downloaderPackageName, 0).enabled;
|
packageEnabled = context.getPackageManager().getApplicationInfo(downloaderPackageName, 0).enabled;
|
||||||
} catch (PackageManager.NameNotFoundException error) {
|
} catch (PackageManager.NameNotFoundException error) {
|
||||||
LogHelper.printDebug(() -> "Downloader could not be found: " + error);
|
LogHelper.printDebug(() -> "Downloader could not be found: " + error);
|
||||||
|
Loading…
Reference in New Issue
Block a user