This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
forked from ReVanced/revanced-integrations
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube - Overlay buttons): Add
Whitelist
overlay button
- Loading branch information
Showing
12 changed files
with
598 additions
and
4 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
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
package app.revanced.integrations.youtube.patches.overlaybutton; | ||
|
||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import app.revanced.integrations.shared.utils.Logger; | ||
import app.revanced.integrations.youtube.settings.Settings; | ||
import app.revanced.integrations.youtube.settings.preference.WhitelistedChannelsPreference; | ||
import app.revanced.integrations.youtube.whitelist.Whitelist; | ||
|
||
@SuppressWarnings("unused") | ||
public class Whitelists extends BottomControlButton { | ||
@Nullable | ||
private static Whitelists instance; | ||
|
||
public Whitelists(ViewGroup bottomControlsViewGroup) { | ||
super( | ||
bottomControlsViewGroup, | ||
"whitelist_button", | ||
Settings.OVERLAY_BUTTON_WHITELIST, | ||
view -> Whitelist.showWhitelistDialog(view.getContext()), | ||
view -> { | ||
WhitelistedChannelsPreference.showWhitelistedChannelDialog(view.getContext()); | ||
return true; | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static void initialize(View bottomControlsViewGroup) { | ||
try { | ||
if (bottomControlsViewGroup instanceof ViewGroup viewGroup) { | ||
instance = new Whitelists(viewGroup); | ||
} | ||
} catch (Exception ex) { | ||
Logger.printException(() -> "initialize failure", ex); | ||
} | ||
} | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static void changeVisibility(boolean showing, boolean animation) { | ||
if (instance != null) instance.setVisibility(showing, animation); | ||
} | ||
|
||
public static void changeVisibilityNegatedImmediate() { | ||
if (instance != null) instance.setVisibilityNegatedImmediate(); | ||
} | ||
|
||
} |
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
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
164 changes: 164 additions & 0 deletions
164
.../app/revanced/integrations/youtube/settings/preference/WhitelistedChannelsPreference.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,164 @@ | ||
package app.revanced.integrations.youtube.settings.preference; | ||
|
||
import static app.revanced.integrations.shared.utils.StringRef.str; | ||
|
||
import android.app.AlertDialog; | ||
import android.content.Context; | ||
import android.preference.Preference; | ||
import android.util.AttributeSet; | ||
import android.view.Gravity; | ||
import android.view.View; | ||
import android.widget.ImageButton; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
|
||
import org.apache.commons.lang3.BooleanUtils; | ||
|
||
import java.util.ArrayList; | ||
|
||
import app.revanced.integrations.shared.utils.Utils; | ||
import app.revanced.integrations.youtube.patches.utils.PatchStatus; | ||
import app.revanced.integrations.youtube.utils.ThemeUtils; | ||
import app.revanced.integrations.youtube.whitelist.VideoChannel; | ||
import app.revanced.integrations.youtube.whitelist.Whitelist; | ||
import app.revanced.integrations.youtube.whitelist.Whitelist.WhitelistType; | ||
|
||
/** | ||
* @noinspection ALL | ||
*/ | ||
public class WhitelistedChannelsPreference extends Preference implements Preference.OnPreferenceClickListener { | ||
|
||
private static final WhitelistType whitelistTypePlaybackSpeed = WhitelistType.PLAYBACK_SPEED; | ||
private static final WhitelistType whitelistTypeSponsorBlock = WhitelistType.SPONSOR_BLOCK; | ||
private static final boolean playbackSpeedIncluded = PatchStatus.RememberPlaybackSpeed(); | ||
private static final boolean sponsorBlockIncluded = PatchStatus.SponsorBlock(); | ||
private static String[] mEntries; | ||
private static WhitelistType[] mEntryValues; | ||
|
||
static { | ||
final int entrySize = BooleanUtils.toInteger(playbackSpeedIncluded) | ||
+ BooleanUtils.toInteger(sponsorBlockIncluded); | ||
|
||
if (entrySize != 0 && mEntries == null && mEntryValues == null) { | ||
mEntries = new String[entrySize]; | ||
mEntryValues = new WhitelistType[entrySize]; | ||
|
||
int index = 0; | ||
if (playbackSpeedIncluded) { | ||
mEntries[index] = " " + whitelistTypePlaybackSpeed.getFriendlyName() + " "; | ||
mEntryValues[index] = whitelistTypePlaybackSpeed; | ||
index++; | ||
} | ||
if (sponsorBlockIncluded) { | ||
mEntries[index] = " " + whitelistTypeSponsorBlock.getFriendlyName() + " "; | ||
mEntryValues[index] = whitelistTypeSponsorBlock; | ||
} | ||
} | ||
} | ||
|
||
private void init() { | ||
setOnPreferenceClickListener(this); | ||
} | ||
|
||
public WhitelistedChannelsPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
init(); | ||
} | ||
public WhitelistedChannelsPreference(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
init(); | ||
} | ||
public WhitelistedChannelsPreference(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
init(); | ||
} | ||
public WhitelistedChannelsPreference(Context context) { | ||
super(context); | ||
init(); | ||
} | ||
|
||
@Override | ||
public boolean onPreferenceClick(Preference preference) { | ||
showWhitelistedChannelDialog(getContext()); | ||
|
||
return true; | ||
} | ||
|
||
public static void showWhitelistedChannelDialog(Context context) { | ||
AlertDialog.Builder builder = new AlertDialog.Builder(context); | ||
builder.setTitle(str("revanced_whitelist_settings_title")); | ||
builder.setItems(mEntries, (dialog, which) -> showWhitelistedChannelDialog(context, mEntryValues[which])); | ||
builder.setNegativeButton(android.R.string.cancel, null); | ||
builder.show(); | ||
} | ||
|
||
private static void showWhitelistedChannelDialog(Context context, WhitelistType whitelistType) { | ||
final ArrayList<VideoChannel> mEntries = Whitelist.getWhitelistedChannels(whitelistType); | ||
|
||
AlertDialog.Builder builder = new AlertDialog.Builder(context); | ||
builder.setTitle(whitelistType.getFriendlyName()); | ||
|
||
if (mEntries.isEmpty()) { | ||
TextView emptyView = new TextView(context); | ||
emptyView.setText(str("revanced_whitelist_empty")); | ||
emptyView.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); | ||
emptyView.setTextSize(16); | ||
emptyView.setPadding(60, 40, 60, 0); | ||
builder.setView(emptyView); | ||
} else { | ||
LinearLayout entriesContainer = new LinearLayout(context); | ||
entriesContainer.setOrientation(LinearLayout.VERTICAL); | ||
for (final VideoChannel entry : mEntries) { | ||
String author = entry.getChannelName(); | ||
View entryView = getEntryView(context, author, v -> { | ||
new AlertDialog.Builder(context) | ||
.setMessage(str("revanced_whitelist_remove_dialog_message", author, whitelistType.getFriendlyName())) | ||
.setPositiveButton(android.R.string.ok, (dialog, which) -> { | ||
Whitelist.removeFromWhitelist(whitelistType, entry.getChannelId()); | ||
entriesContainer.removeView(entriesContainer.findViewWithTag(author)); | ||
}) | ||
.setNegativeButton(android.R.string.cancel, null) | ||
.show(); | ||
}); | ||
entryView.setTag(author); | ||
entriesContainer.addView(entryView); | ||
} | ||
builder.setView(entriesContainer); | ||
} | ||
|
||
builder.setPositiveButton(android.R.string.ok, null); | ||
builder.show(); | ||
} | ||
|
||
private static View getEntryView(Context context, CharSequence entry, View.OnClickListener onDeleteClickListener) { | ||
LinearLayout.LayoutParams entryContainerParams = new LinearLayout.LayoutParams( | ||
new LinearLayout.LayoutParams( | ||
LinearLayout.LayoutParams.MATCH_PARENT, | ||
LinearLayout.LayoutParams.WRAP_CONTENT)); | ||
entryContainerParams.setMargins(60, 40, 60, 0); | ||
|
||
LinearLayout.LayoutParams entryLabelLayoutParams = new LinearLayout.LayoutParams( | ||
0, LinearLayout.LayoutParams.WRAP_CONTENT, 1); | ||
entryLabelLayoutParams.gravity = Gravity.CENTER; | ||
|
||
LinearLayout entryContainer = new LinearLayout(context); | ||
entryContainer.setOrientation(LinearLayout.HORIZONTAL); | ||
entryContainer.setLayoutParams(entryContainerParams); | ||
|
||
TextView entryLabel = new TextView(context); | ||
entryLabel.setText(entry); | ||
entryLabel.setLayoutParams(entryLabelLayoutParams); | ||
entryLabel.setTextSize(16); | ||
entryLabel.setOnClickListener(onDeleteClickListener); | ||
|
||
ImageButton deleteButton = new ImageButton(context); | ||
deleteButton.setImageDrawable(ThemeUtils.getTrashButtonDrawable()); | ||
deleteButton.setOnClickListener(onDeleteClickListener); | ||
deleteButton.setBackground(null); | ||
|
||
entryContainer.addView(entryLabel); | ||
entryContainer.addView(deleteButton); | ||
return entryContainer; | ||
} | ||
|
||
} |
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.