mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-12-03 01:02:55 +01:00
final touches
This commit is contained in:
parent
d04c8f99ab
commit
16073a7f74
@ -13,7 +13,6 @@ import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;
|
||||
|
||||
@ -240,8 +239,6 @@ public class ReturnYouTubeDislikes {
|
||||
Log.d(TAG, "Like button " + likeActive + " | Dislike button " + dislikeActive);
|
||||
}
|
||||
|
||||
Toast.makeText(YouTubeTikTokRoot_Application.getAppContext(), "Voting value: " + votingValue, Toast.LENGTH_SHORT).show();
|
||||
|
||||
sendVote(votingValue);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
@ -22,7 +22,7 @@ public class AdButton extends SlimButton {
|
||||
|
||||
public AdButton(Context context, ViewGroup container) {
|
||||
super(context, container, SlimButton.SLIM_METADATA_BUTTON_ID,
|
||||
SharedPrefUtils.getBoolean(context, "youtube", WhitelistType.ADS.getPreferenceEnabledName(), false));
|
||||
SharedPrefUtils.getBoolean(context, WhitelistType.ADS.getSharedPreferencesName(), WhitelistType.ADS.getPreferenceEnabledName(), false));
|
||||
|
||||
initialize();
|
||||
}
|
||||
@ -55,7 +55,7 @@ public class AdButton extends SlimButton {
|
||||
private void removeFromWhitelist() {
|
||||
try {
|
||||
Whitelist.removeFromWhitelist(WhitelistType.ADS, this.context, VideoInformation.channelName);
|
||||
this.button_icon.setEnabled(false);
|
||||
changeEnabled(false);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Log.e(TAG, "Failed to remove from whitelist", ex);
|
||||
|
@ -2,6 +2,7 @@ package fi.vanced.libraries.youtube.ui;
|
||||
|
||||
import static fi.razerman.youtube.XGlobals.debug;
|
||||
import static fi.vanced.libraries.youtube.player.VideoInformation.currentVideoId;
|
||||
import static pl.jakubweg.StringRef.str;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
@ -15,35 +16,34 @@ import fi.vanced.libraries.youtube.whitelisting.WhitelistType;
|
||||
import fi.vanced.libraries.youtube.whitelisting.requests.WhitelistRequester;
|
||||
import fi.vanced.utils.SharedPrefUtils;
|
||||
import fi.vanced.utils.VancedUtils;
|
||||
import pl.jakubweg.SponsorBlockSettings;
|
||||
|
||||
public class SBWhitelistButton extends SlimButton {
|
||||
public static final String TAG = "VI - SBWhitelistButton";
|
||||
|
||||
public SBWhitelistButton(Context context, ViewGroup container) {
|
||||
super(context, container, SlimButton.SLIM_METADATA_BUTTON_ID,
|
||||
SharedPrefUtils.getBoolean(context, SponsorBlockSettings.PREFERENCES_NAME, WhitelistType.SPONSORBLOCK.getPreferenceEnabledName(), false));
|
||||
SharedPrefUtils.getBoolean(context, WhitelistType.SPONSORBLOCK.getSharedPreferencesName(), WhitelistType.SPONSORBLOCK.getPreferenceEnabledName(), false));
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
this.button_icon.setImageResource(VancedUtils.getIdentifier("vanced_sb_logo", "drawable"));
|
||||
this.button_text.setText("SB");
|
||||
changeEnabled(Whitelist.shouldShowSegments());
|
||||
this.button_icon.setImageResource(VancedUtils.getIdentifier("vanced_yt_sb_button", "drawable"));
|
||||
this.button_text.setText(str("action_segments"));
|
||||
changeEnabled(Whitelist.isChannelSBWhitelisted());
|
||||
}
|
||||
|
||||
public void changeEnabled(boolean enabled) {
|
||||
if (debug) {
|
||||
Log.d(TAG, "changeEnabled " + enabled);
|
||||
}
|
||||
this.button_icon.setEnabled(enabled);
|
||||
this.button_icon.setEnabled(!enabled); // enabled == true -> strikethrough (no segments), enabled == false -> clear (segments)
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
this.view.setEnabled(false);
|
||||
if (this.button_icon.isEnabled()) {
|
||||
if (Whitelist.isChannelSBWhitelisted()) {
|
||||
removeFromWhitelist();
|
||||
return;
|
||||
}
|
||||
@ -55,7 +55,7 @@ public class SBWhitelistButton extends SlimButton {
|
||||
private void removeFromWhitelist() {
|
||||
try {
|
||||
Whitelist.removeFromWhitelist(WhitelistType.SPONSORBLOCK, this.context, VideoInformation.channelName);
|
||||
this.button_icon.setEnabled(false);
|
||||
changeEnabled(false);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Log.e(TAG, "Failed to remove from whitelist", ex);
|
||||
|
@ -78,7 +78,7 @@ public class SlimButtonContainer extends SlimMetadataScrollableButtonContainerLa
|
||||
WhitelistType whitelistAds = WhitelistType.ADS;
|
||||
String adsEnabledPreferenceName = whitelistAds.getPreferenceEnabledName();
|
||||
if (adsEnabledPreferenceName.equals(key) && adBlockButton != null) {
|
||||
boolean enabled = SharedPrefUtils.getBoolean(context, "youtube", adsEnabledPreferenceName, false);
|
||||
boolean enabled = SharedPrefUtils.getBoolean(context, whitelistAds.getSharedPreferencesName(), adsEnabledPreferenceName, false);
|
||||
Whitelist.setEnabled(whitelistAds, enabled);
|
||||
adBlockButton.setVisible(enabled);
|
||||
return;
|
||||
@ -86,7 +86,7 @@ public class SlimButtonContainer extends SlimMetadataScrollableButtonContainerLa
|
||||
WhitelistType whitelistSB = WhitelistType.SPONSORBLOCK;
|
||||
String sbEnabledPreferenceName = whitelistSB.getPreferenceEnabledName();
|
||||
if (sbEnabledPreferenceName.equals(key) && sbWhitelistButton != null) {
|
||||
boolean enabled = SharedPrefUtils.getBoolean(context, "youtube", sbEnabledPreferenceName, false);
|
||||
boolean enabled = SharedPrefUtils.getBoolean(context, whitelistSB.getSharedPreferencesName(), sbEnabledPreferenceName, false);
|
||||
Whitelist.setEnabled(whitelistSB, enabled);
|
||||
sbWhitelistButton.setVisible(enabled);
|
||||
return;
|
||||
@ -97,7 +97,9 @@ public class SlimButtonContainer extends SlimMetadataScrollableButtonContainerLa
|
||||
}
|
||||
};
|
||||
|
||||
context.getSharedPreferences("youtube", Context.MODE_PRIVATE)
|
||||
context.getSharedPreferences(WhitelistType.ADS.getSharedPreferencesName(), Context.MODE_PRIVATE)
|
||||
.registerOnSharedPreferenceChangeListener(listener);
|
||||
context.getSharedPreferences(WhitelistType.SPONSORBLOCK.getSharedPreferencesName(), Context.MODE_PRIVATE)
|
||||
.registerOnSharedPreferenceChangeListener(listener);
|
||||
}
|
||||
}
|
||||
|
@ -51,14 +51,14 @@ public class Whitelist {
|
||||
adBlockButton.changeEnabled(shouldShowAds());
|
||||
}
|
||||
if (enabledMap.get(WhitelistType.SPONSORBLOCK) && sbWhitelistButton != null) {
|
||||
sbWhitelistButton.changeEnabled(shouldShowSegments());
|
||||
sbWhitelistButton.changeEnabled(isChannelSBWhitelisted());
|
||||
}
|
||||
}
|
||||
|
||||
// the rest
|
||||
|
||||
public static boolean shouldShowSegments() {
|
||||
return !isWhitelisted(WhitelistType.SPONSORBLOCK);
|
||||
public static boolean isChannelSBWhitelisted() {
|
||||
return isWhitelisted(WhitelistType.SPONSORBLOCK);
|
||||
}
|
||||
|
||||
private static Map<WhitelistType, ArrayList<ChannelModel>> parseWhitelist(Context context) {
|
||||
@ -98,7 +98,7 @@ public class Whitelist {
|
||||
private static Map<WhitelistType, Boolean> parseEnabledMap(Context context) {
|
||||
Map<WhitelistType, Boolean> enabledMap = new EnumMap<>(WhitelistType.class);
|
||||
for (WhitelistType whitelistType : WhitelistType.values()) {
|
||||
enabledMap.put(whitelistType, SharedPrefUtils.getBoolean(context, "youtube", whitelistType.getPreferenceEnabledName()));
|
||||
enabledMap.put(whitelistType, SharedPrefUtils.getBoolean(context, whitelistType.getSharedPreferencesName(), whitelistType.getPreferenceEnabledName()));
|
||||
}
|
||||
return enabledMap;
|
||||
}
|
||||
|
@ -1,15 +1,19 @@
|
||||
package fi.vanced.libraries.youtube.whitelisting;
|
||||
|
||||
import pl.jakubweg.SponsorBlockSettings;
|
||||
|
||||
public enum WhitelistType {
|
||||
ADS("Ads", "vanced_whitelist_ads_enabled"),
|
||||
SPONSORBLOCK("SponsorBlock", "vanced_whitelist_sb_enabled");
|
||||
ADS("Ads", "youtube", "vanced_whitelist_ads_enabled"),
|
||||
SPONSORBLOCK("SponsorBlock", SponsorBlockSettings.PREFERENCES_NAME, "vanced_whitelist_sb_enabled");
|
||||
|
||||
private final String friendlyName;
|
||||
private final String preferencesName;
|
||||
private final String sharedPreferencesName;
|
||||
private final String preferenceEnabledName;
|
||||
|
||||
WhitelistType(String friendlyName, String preferenceEnabledName) {
|
||||
WhitelistType(String friendlyName, String sharedPreferencesName, String preferenceEnabledName) {
|
||||
this.friendlyName = friendlyName;
|
||||
this.sharedPreferencesName = sharedPreferencesName;
|
||||
this.preferencesName = "whitelist_" + name();
|
||||
this.preferenceEnabledName = preferenceEnabledName;
|
||||
}
|
||||
@ -18,6 +22,10 @@ public enum WhitelistType {
|
||||
return friendlyName;
|
||||
}
|
||||
|
||||
public String getSharedPreferencesName() {
|
||||
return sharedPreferencesName;
|
||||
}
|
||||
|
||||
public String getPreferencesName() {
|
||||
return preferencesName;
|
||||
}
|
||||
|
@ -47,7 +47,8 @@ public class WhitelistRequester {
|
||||
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
|
||||
os.write(input, 0, input.length);
|
||||
}
|
||||
if (connection.getResponseCode() == 200) {
|
||||
int responseCode = connection.getResponseCode();
|
||||
if (responseCode == 200) {
|
||||
JSONObject json = getJSONObject(connection);
|
||||
JSONObject videoInfo = json.getJSONObject("videoDetails");
|
||||
ChannelModel channelModel = new ChannelModel(videoInfo.getString("author"), videoInfo.getString("channelId"));
|
||||
@ -58,36 +59,41 @@ public class WhitelistRequester {
|
||||
|
||||
boolean success = Whitelist.addToWhitelist(whitelistType, context, channelModel);
|
||||
String whitelistTypeName = whitelistType.getFriendlyName();
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
runOnMainThread(() -> {
|
||||
if (success) {
|
||||
buttonIcon.setEnabled(true);
|
||||
buttonIcon.setEnabled(whitelistType != WhitelistType.SPONSORBLOCK);
|
||||
Toast.makeText(context, str("vanced_whitelisting_added", author, whitelistTypeName), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else {
|
||||
buttonIcon.setEnabled(false);
|
||||
buttonIcon.setEnabled(whitelistType == WhitelistType.SPONSORBLOCK);
|
||||
Toast.makeText(context, str("vanced_whitelisting_add_failed", author, whitelistTypeName), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
view.setEnabled(true);
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (debug) {
|
||||
Log.d(TAG, "player fetch response was " + connection.getResponseCode());
|
||||
Log.d(TAG, "player fetch response was " + responseCode);
|
||||
}
|
||||
|
||||
buttonIcon.setEnabled(false);
|
||||
view.setEnabled(true);
|
||||
runOnMainThread(() -> {
|
||||
Toast.makeText(context, str("vanced_whitelisting_fetch_failed", responseCode), Toast.LENGTH_SHORT).show();
|
||||
buttonIcon.setEnabled(true);
|
||||
view.setEnabled(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Log.e(TAG, "Failed to fetch channelId", ex);
|
||||
view.setEnabled(true);
|
||||
runOnMainThread(() -> view.setEnabled(true));
|
||||
}
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
private static void runOnMainThread(Runnable runnable) {
|
||||
new Handler(Looper.getMainLooper()).post(runnable);
|
||||
}
|
||||
|
||||
private static HttpURLConnection getConnectionFromRoute(Route route, String... params) throws IOException {
|
||||
return Requester.getConnectionFromRoute(YT_API_URL, route, params);
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ public class PlayerController {
|
||||
public static void executeDownloadSegments(String videoId) {
|
||||
videoHasSegments = false;
|
||||
timeWithoutSegments = "";
|
||||
if (!Whitelist.shouldShowSegments())
|
||||
if (Whitelist.isChannelSBWhitelisted())
|
||||
return;
|
||||
SponsorSegment[] segments = SBRequester.getSegments(videoId);
|
||||
Arrays.sort(segments);
|
||||
|
14
app/src/main/res/drawable/vanced_yt_sb.xml
Normal file
14
app/src/main/res/drawable/vanced_yt_sb.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="m11.9403,24a2.7465,2.7465 0,0 1,-1.4425 -0.4082c-6.466,-3.9887 -10.3901,-10.8963 -10.4974,-18.4791a2.7427,2.7427 0,0 1,1.4366 -2.4545,22.0799 22.0799,0 0,1 21.0067,0 2.7427,2.7427 0,0 1,1.4366 2.4558c-0.1069,7.5815 -4.031,14.4891 -10.4966,18.4774a2.7465,2.7465 0,0 1,-1.4434 0.4086zM11.9403,0.832a21.2214,21.2214 0,0 0,-10.1062 2.5576,1.9128 1.9128,0 0,0 -1.0014,1.7125c0.1031,7.2959 3.8793,13.9436 10.1015,17.7815a1.9517,1.9517 0,0 0,2.0117 0c6.2222,-3.8387 9.998,-10.4856 10.1015,-17.7815a1.9124,1.9124 0,0 0,-1.0014 -1.7129,21.2222 21.2222,0 0,0 -10.1058,-2.5572z"
|
||||
android:strokeWidth="0.0422534"
|
||||
android:fillColor="?ytTextPrimary"/>
|
||||
<path
|
||||
android:pathData="m12.0301,1.804a20.2774,20.2774 0,0 0,-9.7325 2.4391,0.952 0.952,0 0,0 -0.4943,0.8451c0.1014,7.1763 3.9296,13.4459 9.6405,16.9685a0.9499,0.9499 0,0 0,0.9925 0c5.711,-3.5227 9.5391,-9.7922 9.6405,-16.9685a0.952,0.952 0,0 0,-0.4944 -0.8451,20.2774 20.2774,0 0,0 -9.5524,-2.4391zM9.3134,6.1581 L17.3783,10.8144 9.3134,15.4708z"
|
||||
android:strokeWidth="0.0422534"
|
||||
android:fillColor="?ytTextPrimary"/>
|
||||
</vector>
|
14
app/src/main/res/drawable/vanced_yt_sb_blocked.xml
Normal file
14
app/src/main/res/drawable/vanced_yt_sb_blocked.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="m10.7249,0.0335a22.0803,22.0803 0,0 0,-7.8389 1.9415l0.6151,0.6169a21.2217,21.2217 0,0 1,8.4394 -1.7598,21.2225 21.2225,0 0,1 10.1059,2.5573 1.9124,1.9124 0,0 1,1.0014 1.7129c-0.0664,4.6809 -1.6465,9.0932 -4.4123,12.6696l0.5933,0.595c2.916,-3.7317 4.5828,-8.3507 4.6519,-13.2528a2.7427,2.7427 0,0 0,-1.4366 -2.4558,22.0803 22.0803,0 0,0 -11.7191,-2.6248zM1.6261,2.5691a22.0803,22.0803 0,0 0,-0.1892 0.0892,2.7427 2.7427,0 0,0 -1.4366,2.4545c0.1073,7.5829 4.0314,14.4906 10.4976,18.4794a2.7465,2.7465 0,0 0,1.4426 0.4082,2.7465 2.7465,0 0,0 1.4434,-0.4086c1.898,-1.1708 3.5749,-2.5947 5.0027,-4.2118l-0.5895,-0.5912c-1.3818,1.5735 -3.008,2.9583 -4.8509,4.0953a1.9517,1.9517 0,0 1,-2.0118 0c-6.2223,-3.8379 -9.9986,-10.4858 -10.1017,-17.7818a1.9128,1.9128 0,0 1,1.0015 -1.7125,21.2217 21.2217,0 0,1 0.413,-0.1977z"
|
||||
android:strokeWidth="0.0422541"
|
||||
android:fillColor="?ytTextPrimary"/>
|
||||
<path
|
||||
android:pathData="m12.0303,1.804a20.2777,20.2777 0,0 0,-7.8092 1.5316l5.0924,5.1079v-2.2854l8.065,4.6564 -3.6183,2.0891 4.1686,4.1811c2.5489,-3.3367 4.0847,-7.4873 4.1484,-11.9965a0.952,0.952 0,0 0,-0.4944 -0.8451,20.2777 20.2777,0 0,0 -9.5526,-2.4392zM2.9589,3.9275a20.2777,20.2777 0,0 0,-0.6612 0.3158,0.952 0.952,0 0,0 -0.4943,0.8451c0.1014,7.1764 3.9296,13.4461 9.6407,16.9688a0.9499,0.9499 0,0 0,0.9926 0c1.7467,-1.0774 3.3161,-2.4129 4.6578,-3.9516l-4.5096,-4.5232 -3.2711,1.8886v-5.1697z"
|
||||
android:strokeWidth="0.0422541"
|
||||
android:fillColor="?ytTextPrimary"/>
|
||||
</vector>
|
6
app/src/main/res/drawable/vanced_yt_sb_button.xml
Normal file
6
app/src/main/res/drawable/vanced_yt_sb_button.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_enabled="true" android:drawable="@drawable/vanced_yt_sb" />
|
||||
<item android:state_enabled="false" android:drawable="@drawable/vanced_yt_sb_blocked" />
|
||||
</selector>
|
@ -339,6 +339,7 @@
|
||||
<string name="action_copy">Copy</string>
|
||||
<string name="action_tcopy">TCopy</string>
|
||||
<string name="action_ads">Ads</string>
|
||||
<string name="action_segments">Segments</string>
|
||||
|
||||
<string name="vanced_video_ad_settings_title">Video ad settings</string>
|
||||
<string name="vanced_videoadwhitelisting_title">Video ad whitelisting</string>
|
||||
@ -348,6 +349,7 @@
|
||||
<string name="vanced_whitelisting_removed" formatted="false">Channel %s was removed from the %s whitelist</string>
|
||||
<string name="vanced_whitelisting_add_failed" formatted="false">Failed to add channel %s to the %s whitelist</string>
|
||||
<string name="vanced_whitelisting_remove_failed" formatted="false">Failed to remove channel %s from the %s whitelist</string>
|
||||
<string name="vanced_whitelisting_fetch_failed" formatted="false">Failed to retrieve channel details, received code %d</string>
|
||||
<string name="vanced_button_location_entry_none">Hidden</string>
|
||||
<string name="vanced_button_location_entry_player">In player</string>
|
||||
<string name="vanced_button_location_entry_buttoncontainer">Under player</string>
|
||||
|
Loading…
Reference in New Issue
Block a user