forked from ReVanced/revanced-integrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
233 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/src/main/java/android/support/constraint/ConstraintLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package android.support.constraint; | ||
|
||
import android.content.Context; | ||
import android.view.ViewGroup; | ||
|
||
/** | ||
* "CompileOnly" class | ||
* because android.support.constraint.ConstraintLayout is deprecated | ||
* in favour of androidx.constraintlayout.widget.ConstraintLayout. | ||
* | ||
* This class will not be included and "replaced" by the real package's class. | ||
*/ | ||
public class ConstraintLayout extends ViewGroup { | ||
public ConstraintLayout(Context context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
protected void onLayout(boolean changed, int l, int t, int r, int b) { } | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/app/revanced/integrations/patches/downloads/DownloadsPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package app.revanced.integrations.patches.downloads; | ||
|
||
import app.revanced.integrations.utils.LogHelper; | ||
|
||
/** | ||
* Used by app.revanced.patches.youtube.interaction.downloads.bytecode.patch.DownloadsBytecodePatch | ||
*/ | ||
public class DownloadsPatch { | ||
private static String videoId; | ||
|
||
/** | ||
* Called when the video changes | ||
* @param videoId The current video id | ||
*/ | ||
public static void setVideoId(String videoId) { | ||
LogHelper.debug(DownloadsPatch.class, "newVideoLoaded - " + videoId); | ||
|
||
DownloadsPatch.videoId = videoId; | ||
} | ||
|
||
/** | ||
* @return The current video id | ||
*/ | ||
public static String getCurrentVideoId() { | ||
return videoId; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
app/src/main/java/app/revanced/integrations/patches/downloads/views/DownloadOptions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package app.revanced.integrations.patches.downloads.views | ||
|
||
class DownloadOptions { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
app/src/main/java/app/revanced/integrations/videoplayer/Copy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
app/src/main/java/app/revanced/integrations/videoplayer/DownloadButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package app.revanced.integrations.videoplayer; | ||
|
||
import android.app.AlertDialog; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.support.constraint.ConstraintLayout; | ||
import android.view.View; | ||
import android.view.animation.Animation; | ||
import android.view.animation.AnimationUtils; | ||
import android.widget.ImageView; | ||
import android.widget.Toast; | ||
|
||
|
||
import java.lang.ref.WeakReference; | ||
|
||
import app.revanced.integrations.patches.downloads.DownloadsPatch; | ||
import app.revanced.integrations.settings.SettingsEnum; | ||
import app.revanced.integrations.sponsorblock.StringRef; | ||
import app.revanced.integrations.utils.LogHelper; | ||
import app.revanced.integrations.utils.ReVancedUtils; | ||
import app.revanced.integrations.utils.SharedPrefHelper; | ||
|
||
/* loaded from: classes6.dex */ | ||
//ToDo: Refactor | ||
public class DownloadButton { | ||
static WeakReference<ImageView> _button = new WeakReference<>(null); | ||
static ConstraintLayout _constraintLayout; | ||
static int fadeDurationFast; | ||
static int fadeDurationScheduled; | ||
static Animation fadeIn; | ||
static Animation fadeOut; | ||
public static boolean isDownloadButtonEnabled; | ||
static boolean isShowing; | ||
|
||
public static void initializeDownloadButton(Object obj) { | ||
try { | ||
LogHelper.debug(DownloadButton.class, "initializing"); | ||
_constraintLayout = (ConstraintLayout) obj; | ||
isDownloadButtonEnabled = shouldBeShown(); | ||
ImageView imageView = _constraintLayout.findViewById(getIdentifier("download_button", "id")); | ||
if (imageView == null) { | ||
LogHelper.debug(DownloadButton.class, "Couldn't find imageView with id \"download_button\""); | ||
return; | ||
} | ||
|
||
imageView.setOnClickListener(view -> { | ||
LogHelper.debug(DownloadButton.class, "Download button clicked"); | ||
|
||
final var context = view.getContext(); | ||
final var powerTubePackageName = "ussr.razar.youtube_dl"; | ||
|
||
boolean packageEnabled = false; | ||
try { | ||
assert context != null; | ||
packageEnabled = context.getPackageManager().getApplicationInfo(powerTubePackageName, 0).enabled; | ||
} catch (PackageManager.NameNotFoundException error) { | ||
LogHelper.debug(DownloadButton.class, "PowerTube could not be found: " + error); | ||
} | ||
|
||
// If the package is not installed, show the toast | ||
if (!packageEnabled) { | ||
Toast.makeText(context, StringRef.str("powertube_not_installed_warning"), Toast.LENGTH_SHORT).show(); | ||
Toast.makeText(context, StringRef.str("powertube_not_installed_notice"), Toast.LENGTH_LONG).show(); | ||
return; | ||
} | ||
|
||
// Launch PowerTube intent | ||
try { | ||
String content = String.format("https://youtu.be/%s", DownloadsPatch.getCurrentVideoId()); | ||
|
||
Intent intent = new Intent("android.intent.action.SEND"); | ||
intent.setType("text/plain"); | ||
intent.setPackage(powerTubePackageName); | ||
intent.putExtra("android.intent.extra.TEXT", content); | ||
context.startActivity(intent); | ||
|
||
LogHelper.debug(DownloadButton.class, "Launched the intent with the content: " + content); | ||
} catch (Exception error) { | ||
LogHelper.debug(DownloadButton.class, "Failed to launch the intent: " + error); | ||
} | ||
|
||
//var options = Arrays.asList("Video", "Audio").toArray(new CharSequence[0]); | ||
// | ||
//new AlertDialog.Builder(view.getContext()) | ||
// .setItems(options, (dialog, which) -> { | ||
// LogHelper.debug(DownloadButton.class, String.valueOf(options[which])); | ||
// }) | ||
// .show(); | ||
// TODO: show popup and download via newpipe | ||
}); | ||
_button = new WeakReference<>(imageView); | ||
fadeDurationFast = getInteger("fade_duration_fast"); | ||
fadeDurationScheduled = getInteger("fade_duration_scheduled"); | ||
Animation animation = getAnimation("fade_in"); | ||
fadeIn = animation; | ||
animation.setDuration(fadeDurationFast); | ||
Animation animation2 = getAnimation("fade_out"); | ||
fadeOut = animation2; | ||
animation2.setDuration(fadeDurationScheduled); | ||
isShowing = true; | ||
changeVisibility(false); | ||
|
||
} catch (Exception e) { | ||
LogHelper.printException(DownloadButton.class, "Unable to set FrameLayout", e); | ||
} | ||
} | ||
|
||
public static void changeVisibility(boolean z) { | ||
if (isShowing == z) return; | ||
|
||
isShowing = z; | ||
ImageView imageView = _button.get(); | ||
if (_constraintLayout != null && imageView != null) { | ||
if (z && isDownloadButtonEnabled) { | ||
LogHelper.debug(DownloadButton.class, "Fading in"); | ||
imageView.setVisibility(View.VISIBLE); | ||
imageView.startAnimation(fadeIn); | ||
} else if (imageView.getVisibility() == View.VISIBLE) { | ||
LogHelper.debug(DownloadButton.class, "Fading out"); | ||
imageView.startAnimation(fadeOut); | ||
imageView.setVisibility(View.GONE); | ||
} | ||
} | ||
} | ||
|
||
public static void refreshShouldBeShown() { | ||
isDownloadButtonEnabled = shouldBeShown(); | ||
} | ||
|
||
private static boolean shouldBeShown() { | ||
if (!SettingsEnum.DOWNLOAD_BUTTON_SHOWN.getBoolean()) { | ||
return false; | ||
} | ||
|
||
Context appContext = ReVancedUtils.getContext(); | ||
if (appContext == null) { | ||
LogHelper.printException(DownloadButton.class, "shouldBeShown - context is null!"); | ||
return false; | ||
} | ||
String string = SharedPrefHelper.getString(appContext, SharedPrefHelper.SharedPrefNames.YOUTUBE, "pref_download_button_list", "PLAYER" /* TODO: set the default to null, as this will be set by the settings page later */); | ||
if (string == null || string.isEmpty()) { | ||
return false; | ||
} | ||
return string.equalsIgnoreCase("PLAYER"); | ||
} | ||
|
||
private static int getIdentifier(String str, String str2) { | ||
Context appContext = ReVancedUtils.getContext(); | ||
return appContext.getResources().getIdentifier(str, str2, appContext.getPackageName()); | ||
} | ||
|
||
private static int getInteger(String str) { | ||
return ReVancedUtils.getContext().getResources().getInteger(getIdentifier(str, "integer")); | ||
} | ||
private static Animation getAnimation(String str) { | ||
return AnimationUtils.loadAnimation(ReVancedUtils.getContext(), getIdentifier(str, "anim")); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters