-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(youtube):
copy-video-url
patch (#263)
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de> Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
1 parent
1f74ccf
commit e856d9d
Showing
10 changed files
with
237 additions
and
165 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
app/src/main/java/app/revanced/integrations/patches/CopyVideoUrlPatch.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; | ||
|
||
import android.content.Context; | ||
import android.widget.Toast; | ||
|
||
import app.revanced.integrations.sponsorblock.StringRef; | ||
import app.revanced.integrations.utils.LogHelper; | ||
import app.revanced.integrations.utils.ReVancedUtils; | ||
|
||
public class CopyVideoUrlPatch { | ||
public static void copyUrl(Boolean withTimestamp) { | ||
try { | ||
String url = String.format("https://youtu.be/%s", VideoInformation.getCurrentVideoId()); | ||
if (withTimestamp) { | ||
long seconds = VideoInformation.getVideoTime() / 1000; | ||
url += String.format("?t=%s", seconds); | ||
} | ||
|
||
Context context = ReVancedUtils.getContext(); | ||
|
||
ReVancedUtils.setClipboard(url); | ||
if (context != null) Toast.makeText(context, StringRef.str("share_copy_url_success"), Toast.LENGTH_SHORT).show(); | ||
} catch (Exception e) { | ||
LogHelper.printException(() -> "Failed to generate video url", e); | ||
} | ||
} | ||
} |
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
27 changes: 0 additions & 27 deletions
27
app/src/main/java/app/revanced/integrations/patches/downloads/DownloadsPatch.java
This file was deleted.
Oops, something went wrong.
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
86 changes: 86 additions & 0 deletions
86
app/src/main/java/app/revanced/integrations/videoplayer/BottomControlButton.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,86 @@ | ||
package app.revanced.integrations.videoplayer; | ||
|
||
import android.content.Context; | ||
import android.support.constraint.ConstraintLayout; | ||
import android.view.View; | ||
import android.view.animation.Animation; | ||
import android.view.animation.AnimationUtils; | ||
import android.widget.ImageView; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
import app.revanced.integrations.utils.LogHelper; | ||
import app.revanced.integrations.utils.ReVancedUtils; | ||
|
||
public abstract class BottomControlButton { | ||
WeakReference<ImageView> button = new WeakReference<>(null); | ||
ConstraintLayout constraintLayout; | ||
Boolean isButtonEnabled; | ||
Boolean isShowing; | ||
|
||
private Animation fadeIn; | ||
private Animation fadeOut; | ||
|
||
public BottomControlButton(Object obj, String viewId, Boolean isEnabled, View.OnClickListener onClickListener) { | ||
try { | ||
LogHelper.printDebug(() -> "Initializing button with id: " + viewId); | ||
constraintLayout = (ConstraintLayout) obj; | ||
isButtonEnabled = isEnabled; | ||
|
||
ImageView imageView = constraintLayout.findViewById(getIdentifier(viewId, "id")); | ||
if (imageView == null) { | ||
LogHelper.printDebug(() -> "Couldn't find ImageView with id: " + viewId); | ||
return; | ||
} | ||
|
||
imageView.setOnClickListener(onClickListener); | ||
|
||
button = new WeakReference<>(imageView); | ||
fadeIn = getAnimation("fade_in"); | ||
fadeOut = getAnimation("fade_out"); | ||
|
||
int fadeDurationFast = getInteger("fade_duration_fast"); | ||
int fadeDurationScheduled = getInteger("fade_duration_scheduled"); | ||
fadeIn.setDuration(fadeDurationFast); | ||
fadeOut.setDuration(fadeDurationScheduled); | ||
isShowing = true; | ||
setVisibility(false); | ||
} catch (Exception e) { | ||
LogHelper.printException(() -> "Failed to initialize button with id: " + viewId, e); | ||
} | ||
} | ||
|
||
public void setVisibility(boolean showing) { | ||
if (isShowing == showing) return; | ||
|
||
isShowing = showing; | ||
ImageView imageView = button.get(); | ||
|
||
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"); | ||
imageView.startAnimation(fadeOut); | ||
imageView.setVisibility(View.GONE); | ||
} | ||
} | ||
|
||
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")); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/app/revanced/integrations/videoplayer/CopyVideoUrlButton.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,26 @@ | ||
package app.revanced.integrations.videoplayer; | ||
|
||
|
||
import app.revanced.integrations.patches.CopyVideoUrlPatch; | ||
import app.revanced.integrations.settings.SettingsEnum; | ||
|
||
public class CopyVideoUrlButton extends BottomControlButton { | ||
public static CopyVideoUrlButton instance; | ||
|
||
public CopyVideoUrlButton(Object obj) { | ||
super( | ||
obj, | ||
"copy_video_url_button", | ||
SettingsEnum.COPY_VIDEO_URL_BUTTON_SHOWN.getBoolean(), | ||
view -> CopyVideoUrlPatch.copyUrl(false) | ||
); | ||
} | ||
|
||
public static void initializeButton(Object obj) { | ||
instance = new CopyVideoUrlButton(obj); | ||
} | ||
|
||
public static void changeVisibility(boolean showing) { | ||
if (instance != null) instance.setVisibility(showing); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/app/revanced/integrations/videoplayer/CopyVideoUrlTimestampButton.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,26 @@ | ||
package app.revanced.integrations.videoplayer; | ||
|
||
import app.revanced.integrations.patches.CopyVideoUrlPatch; | ||
import app.revanced.integrations.settings.SettingsEnum; | ||
|
||
public class CopyVideoUrlTimestampButton extends BottomControlButton { | ||
public static CopyVideoUrlTimestampButton instance; | ||
|
||
public CopyVideoUrlTimestampButton(Object obj) { | ||
super( | ||
obj, | ||
"copy_video_url_timestamp_button", | ||
SettingsEnum.COPY_VIDEO_URL_TIMESTAMP_BUTTON_SHOWN.getBoolean(), | ||
view -> CopyVideoUrlPatch.copyUrl(true) | ||
); | ||
} | ||
|
||
public static void initializeButton(Object obj) { | ||
instance = new CopyVideoUrlTimestampButton(obj); | ||
} | ||
|
||
public static void changeVisibility(boolean showing) { | ||
if (instance != null) instance.setVisibility(showing); | ||
} | ||
|
||
} |
Oops, something went wrong.