This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
forked from inotia00/revanced-integrations
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Channel Whitelist): Bello world !
- Loading branch information
1 parent
f43c512
commit 256d7f1
Showing
16 changed files
with
767 additions
and
1 deletion.
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
191 changes: 191 additions & 0 deletions
191
app/src/main/java/app/revanced/integrations/youtube/patches/overlaybutton/Whitelists.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,191 @@ | ||
package app.revanced.integrations.youtube.patches.overlaybutton; | ||
|
||
import static app.revanced.integrations.youtube.utils.ResourceUtils.anim; | ||
import static app.revanced.integrations.youtube.utils.ResourceUtils.findView; | ||
import static app.revanced.integrations.youtube.utils.ResourceUtils.integer; | ||
import static app.revanced.integrations.youtube.utils.StringRef.str; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.app.AlertDialog; | ||
import android.content.Context; | ||
import android.support.constraint.ConstraintLayout; | ||
import android.view.View; | ||
import android.view.animation.Animation; | ||
import android.widget.ImageView; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
import app.revanced.integrations.youtube.patches.utils.PatchStatus; | ||
import app.revanced.integrations.youtube.patches.video.VideoInformation; | ||
import app.revanced.integrations.youtube.settings.SettingsEnum; | ||
import app.revanced.integrations.youtube.utils.LogHelper; | ||
import app.revanced.integrations.youtube.whitelist.Whitelist; | ||
import app.revanced.integrations.youtube.whitelist.WhitelistType; | ||
import app.revanced.integrations.youtube.whitelist.requests.WhitelistRequester; | ||
|
||
public class Whitelists { | ||
static WeakReference<ImageView> buttonView = new WeakReference<>(null); | ||
@SuppressLint("StaticFieldLeak") | ||
static ConstraintLayout constraintLayout; | ||
static int fadeDurationFast; | ||
static int fadeDurationScheduled; | ||
static Animation fadeIn; | ||
static Animation fadeOut; | ||
public static boolean isButtonEnabled; | ||
static boolean isShowing; | ||
static boolean isScrubbed; | ||
|
||
static boolean isSBWhitelisted; | ||
static boolean isSPEEDWhitelisted; | ||
|
||
static boolean isSBIncluded; | ||
static boolean isSPEEDIncluded; | ||
|
||
public static void initialize(Object obj) { | ||
try { | ||
constraintLayout = (ConstraintLayout) obj; | ||
|
||
isSBWhitelisted = Whitelist.isChannelSBWhitelisted(); | ||
isSPEEDWhitelisted = Whitelist.isChannelSPEEDWhitelisted(); | ||
|
||
isSBIncluded = PatchStatus.SponsorBlock(); | ||
isSPEEDIncluded = PatchStatus.VideoSpeed(); | ||
|
||
isButtonEnabled = setValue(); | ||
|
||
ImageView imageView = findView(constraintLayout, "whitelist_button"); | ||
imageView.setOnClickListener(view -> Whitelists.OpenDialog(view.getContext())); | ||
buttonView = new WeakReference<>(imageView); | ||
|
||
fadeDurationFast = integer("fade_duration_fast"); | ||
fadeDurationScheduled = integer("fade_duration_scheduled"); | ||
|
||
fadeIn = anim("fade_in"); | ||
fadeIn.setDuration(fadeDurationFast); | ||
|
||
fadeOut = anim("fade_out"); | ||
fadeOut.setDuration(fadeDurationScheduled); | ||
|
||
isShowing = true; | ||
isScrubbed = false; | ||
changeVisibility(false); | ||
|
||
} catch (Exception ex) { | ||
LogHelper.printException(() -> "Unable to set FrameLayout", ex); | ||
} | ||
} | ||
|
||
public static void refreshVisibility() { | ||
isButtonEnabled = setValue(); | ||
} | ||
|
||
private static boolean setValue() { | ||
boolean isEnabled = SettingsEnum.OVERLAY_BUTTON_WHITELIST.getBoolean(); | ||
|
||
return isEnabled && (isSBIncluded || isSPEEDIncluded); | ||
} | ||
|
||
public static void changeVisibility(boolean currentVisibility) { | ||
ImageView imageView = buttonView.get(); | ||
|
||
if (isShowing == currentVisibility || constraintLayout == null || imageView == null) return; | ||
|
||
isShowing = currentVisibility; | ||
|
||
if (isScrubbed && isButtonEnabled) { | ||
isScrubbed = false; | ||
imageView.setVisibility(View.VISIBLE); | ||
return; | ||
} | ||
|
||
if (currentVisibility && isButtonEnabled) { | ||
imageView.setVisibility(View.VISIBLE); | ||
imageView.startAnimation(fadeIn); | ||
} else if (imageView.getVisibility() == View.VISIBLE) { | ||
imageView.startAnimation(fadeOut); | ||
imageView.setVisibility(View.GONE); | ||
} | ||
} | ||
|
||
public static void changeVisibilityNegatedImmediate(boolean isUserScrubbing) { | ||
ImageView imageView = buttonView.get(); | ||
|
||
if (constraintLayout == null || imageView == null || !isUserScrubbing) return; | ||
|
||
isShowing = false; | ||
isScrubbed = true; | ||
imageView.setVisibility(View.GONE); | ||
} | ||
|
||
public static void OpenDialog(Context context) { | ||
String included = str("revanced_whitelisting_included"); | ||
String excluded = str("revanced_whitelisting_excluded"); | ||
|
||
isSBWhitelisted = Whitelist.isChannelSBWhitelisted(); | ||
isSPEEDWhitelisted = Whitelist.isChannelSPEEDWhitelisted(); | ||
|
||
AlertDialog.Builder builder; | ||
builder = new AlertDialog.Builder(context); | ||
|
||
builder.setTitle(str("revanced_whitelisting_title")); | ||
|
||
StringBuilder msgBuilder = new StringBuilder(); | ||
msgBuilder.append(str("revanced_whitelisting_channel_name")); | ||
msgBuilder.append(":\n"); | ||
msgBuilder.append(VideoInformation.getChannelName()); | ||
msgBuilder.append("\n\n"); | ||
|
||
if (isSPEEDIncluded) { | ||
msgBuilder.append(str("revanced_whitelisting_speed")); | ||
msgBuilder.append(":\n"); | ||
msgBuilder.append(isSPEEDWhitelisted ? included : excluded); | ||
msgBuilder.append("\n\n"); | ||
builder.setNeutralButton(str("revanced_whitelisting_speed_button"), | ||
(dialog, id) -> { | ||
WhitelistListener(WhitelistType.SPEED, isSPEEDWhitelisted, context); | ||
dialog.dismiss(); | ||
} | ||
); | ||
} | ||
|
||
if (isSBIncluded) { | ||
msgBuilder.append(str("revanced_whitelisting_sponsorblock")); | ||
msgBuilder.append(":\n"); | ||
msgBuilder.append(isSBWhitelisted ? included : excluded); | ||
builder.setPositiveButton(str("revanced_whitelisting_sponsorblock_button"), | ||
(dialog, id) -> { | ||
WhitelistListener(WhitelistType.SPONSORBLOCK, isSBWhitelisted, context); | ||
dialog.dismiss(); | ||
} | ||
); | ||
} | ||
|
||
builder.setMessage(msgBuilder.toString()); | ||
|
||
AlertDialog dialog = builder.create(); | ||
dialog.show(); | ||
} | ||
|
||
public static void WhitelistListener(WhitelistType whitelistType, boolean status, Context context) { | ||
if (!status) { | ||
addToWhiteList(whitelistType); | ||
} else { | ||
removeFromWhitelist(whitelistType, context); | ||
} | ||
} | ||
|
||
private static void removeFromWhitelist(WhitelistType whitelistType, Context context) { | ||
ImageView imageView = buttonView.get(); | ||
if (constraintLayout == null || imageView == null) return; | ||
|
||
try { | ||
Whitelist.removeFromWhitelist(whitelistType, VideoInformation.getChannelName(), context); | ||
} catch (Exception ex) { | ||
LogHelper.printException(() -> "Failed to remove from whitelist", ex); | ||
} | ||
} | ||
|
||
private static void addToWhiteList(WhitelistType whitelistType) { | ||
new Thread(() -> WhitelistRequester.addChannelToWhitelist(whitelistType)).start(); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
app/src/main/java/app/revanced/integrations/youtube/patches/video/VideoChannel.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,29 @@ | ||
package app.revanced.integrations.youtube.patches.video; | ||
|
||
import java.io.Serializable; | ||
|
||
public class VideoChannel implements Serializable { | ||
private String author; | ||
private String channelId; | ||
|
||
public VideoChannel(String author, String channelId) { | ||
this.author = author; | ||
this.channelId = channelId; | ||
} | ||
|
||
public String getAuthor() { | ||
return author; | ||
} | ||
|
||
public void setAuthor(String author) { | ||
this.author = author; | ||
} | ||
|
||
public String getChannelId() { | ||
return channelId; | ||
} | ||
|
||
public void setChannelId(String channelId) { | ||
this.channelId = channelId; | ||
} | ||
} |
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
Oops, something went wrong.