add open in sb.ltn.fi button

This commit is contained in:
caneleex 2022-01-27 23:05:46 +01:00
parent 3960dcad6e
commit 5fafc46cb7
7 changed files with 101 additions and 8 deletions

View File

@ -0,0 +1,37 @@
package fi.vanced.libraries.youtube.ui;
import static pl.jakubweg.StringRef.str;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import fi.vanced.libraries.youtube.player.VideoInformation;
import fi.vanced.utils.VancedUtils;
import pl.jakubweg.SponsorBlockSettings;
import pl.jakubweg.SponsorBlockUtils;
public class SBBrowserButton extends SlimButton {
private static final String BROWSER_URL = "https://sb.ltn.fi/video/";
public SBBrowserButton(Context context, ViewGroup container) {
super(context, container, SLIM_METADATA_BUTTON_ID,
SponsorBlockUtils.isSBButtonEnabled(context, SponsorBlockSettings.PREFERENCES_KEY_BROWSER_BUTTON));
initialize();
}
private void initialize() {
this.button_icon.setImageResource(VancedUtils.getIdentifier("vanced_sb_browser", "drawable"));
this.button_text.setText(str("action_browser"));
}
@Override
public void onClick(View v) {
Uri uri = Uri.parse(BROWSER_URL + VideoInformation.currentVideoId);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
context.startActivity(intent);
}
}

View File

@ -14,15 +14,15 @@ import fi.vanced.libraries.youtube.player.VideoInformation;
import fi.vanced.libraries.youtube.whitelisting.Whitelist;
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.SponsorBlockUtils;
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, WhitelistType.SPONSORBLOCK.getSharedPreferencesName(), WhitelistType.SPONSORBLOCK.getPreferenceEnabledName(), false));
SponsorBlockUtils.isSBButtonEnabled(context, WhitelistType.SPONSORBLOCK.getPreferenceEnabledName()));
initialize();
}

View File

@ -1,6 +1,8 @@
package fi.vanced.libraries.youtube.ui;
import static fi.razerman.youtube.XGlobals.debug;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_BROWSER_BUTTON;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED;
import android.content.Context;
import android.content.SharedPreferences;
@ -14,6 +16,7 @@ import fi.vanced.libraries.youtube.whitelisting.Whitelist;
import fi.vanced.libraries.youtube.whitelisting.WhitelistType;
import fi.vanced.utils.SharedPrefUtils;
import fi.vanced.utils.VancedUtils;
import pl.jakubweg.SponsorBlockSettings;
public class SlimButtonContainer extends SlimMetadataScrollableButtonContainerLayout {
private static final String TAG = "VI - Slim - Container";
@ -22,6 +25,7 @@ public class SlimButtonContainer extends SlimMetadataScrollableButtonContainerLa
private CopyWithTimestamp copyWithTimestampButton;
public static AdButton adBlockButton;
public static SBWhitelistButton sbWhitelistButton;
private SBBrowserButton sbBrowserButton;
private final Context context;
SharedPreferences.OnSharedPreferenceChangeListener listener;
@ -52,6 +56,7 @@ public class SlimButtonContainer extends SlimMetadataScrollableButtonContainerLa
copyWithTimestampButton = new CopyWithTimestamp(context, this);
adBlockButton = new AdButton(context, this);
sbWhitelistButton = new SBWhitelistButton(context, this);
sbBrowserButton = new SBBrowserButton(context, this);
new SponsorBlockVoting(context, this);
addSharedPrefsChangeListener();
@ -75,6 +80,29 @@ public class SlimButtonContainer extends SlimMetadataScrollableButtonContainerLa
copyWithTimestampButton.setVisible(ButtonVisibility.isVisibleInContainer(context, "pref_copy_video_url_timestamp_button_list"));
return;
}
if (PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED.equals(key)) {
if (sbWhitelistButton != null) {
if (SponsorBlockSettings.isSponsorBlockEnabled) {
toggleWhitelistButton();
}
else {
Whitelist.setEnabled(WhitelistType.SPONSORBLOCK, false);
sbWhitelistButton.setVisible(false);
}
}
if (sbBrowserButton != null) {
if (SponsorBlockSettings.isSponsorBlockEnabled) {
toggleBrowserButton();
}
else {
sbBrowserButton.setVisible(false);
}
}
}
if (PREFERENCES_KEY_BROWSER_BUTTON.equals(key) && sbBrowserButton != null) {
toggleBrowserButton();
return;
}
WhitelistType whitelistAds = WhitelistType.ADS;
String adsEnabledPreferenceName = whitelistAds.getPreferenceEnabledName();
if (adsEnabledPreferenceName.equals(key) && adBlockButton != null) {
@ -83,12 +111,8 @@ public class SlimButtonContainer extends SlimMetadataScrollableButtonContainerLa
adBlockButton.setVisible(enabled);
return;
}
WhitelistType whitelistSB = WhitelistType.SPONSORBLOCK;
String sbEnabledPreferenceName = whitelistSB.getPreferenceEnabledName();
if (sbEnabledPreferenceName.equals(key) && sbWhitelistButton != null) {
boolean enabled = SharedPrefUtils.getBoolean(context, whitelistSB.getSharedPreferencesName(), sbEnabledPreferenceName, false);
Whitelist.setEnabled(whitelistSB, enabled);
sbWhitelistButton.setVisible(enabled);
if (WhitelistType.SPONSORBLOCK.getPreferenceEnabledName().equals(key) && sbWhitelistButton != null) {
toggleWhitelistButton();
return;
}
}
@ -102,4 +126,16 @@ public class SlimButtonContainer extends SlimMetadataScrollableButtonContainerLa
context.getSharedPreferences(WhitelistType.SPONSORBLOCK.getSharedPreferencesName(), Context.MODE_PRIVATE)
.registerOnSharedPreferenceChangeListener(listener);
}
private void toggleWhitelistButton() {
WhitelistType whitelistSB = WhitelistType.SPONSORBLOCK;
String sbEnabledPreferenceName = whitelistSB.getPreferenceEnabledName();
boolean enabled = SharedPrefUtils.getBoolean(context, whitelistSB.getSharedPreferencesName(), sbEnabledPreferenceName, false);
Whitelist.setEnabled(whitelistSB, enabled);
sbWhitelistButton.setVisible(enabled);
}
private void toggleBrowserButton() {
sbBrowserButton.setVisible(SharedPrefUtils.getBoolean(context, SponsorBlockSettings.PREFERENCES_NAME, PREFERENCES_KEY_BROWSER_BUTTON, false));
}
}

View File

@ -2,6 +2,7 @@ package pl.jakubweg;
import static fi.razerman.youtube.XGlobals.debug;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_ADJUST_NEW_SEGMENT_STEP;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_BROWSER_BUTTON;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_COUNT_SKIPS;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_MIN_DURATION;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_NEW_SEGMENT_ENABLED;
@ -291,6 +292,15 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
screen.addPreference(preference);
}
{
Preference preference = new SwitchPreference(context);
preference.setTitle(str("general_browser_button"));
preference.setSummary(str("general_browser_button_sum"));
preference.setKey(PREFERENCES_KEY_BROWSER_BUTTON);
preferencesToDisableWhenSBDisabled.add(preference);
screen.addPreference(preference);
}
{
EditTextPreference preference = new EditTextPreference(context);
preference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);

View File

@ -32,6 +32,7 @@ public class SponsorBlockSettings {
public static final String PREFERENCES_KEY_SKIPPED_SEGMENTS_TIME = "sb-skipped-segments-time";
public static final String PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS = "sb-length-without-segments";
public static final String PREFERENCES_KEY_CATEGORY_COLOR_SUFFIX = "_color";
public static final String PREFERENCES_KEY_BROWSER_BUTTON = "sb-browser-button";
public static final SegmentBehaviour DefaultBehaviour = SegmentBehaviour.SKIP_AUTOMATICALLY;

View File

@ -16,6 +16,7 @@ import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_MIN_DURATION;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SHOW_TOAST_WHEN_SKIP;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_UUID;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_NAME;
import static pl.jakubweg.SponsorBlockSettings.countSkips;
import static pl.jakubweg.SponsorBlockSettings.getPreferences;
import static pl.jakubweg.SponsorBlockSettings.isSponsorBlockEnabled;
@ -59,6 +60,7 @@ import java.util.List;
import java.util.Objects;
import java.util.TimeZone;
import fi.vanced.utils.SharedPrefUtils;
import pl.jakubweg.objects.SponsorSegment;
import pl.jakubweg.objects.UserStats;
import pl.jakubweg.requests.SBRequester;
@ -608,6 +610,10 @@ public abstract class SponsorBlockUtils {
return isSponsorBlockEnabled && setting;
}
public static boolean isSBButtonEnabled(Context context, String key) {
return isSettingEnabled(SharedPrefUtils.getBoolean(context, PREFERENCES_NAME, key, false));
}
public enum VoteOption {
UPVOTE(str("vote_upvote")),
DOWNVOTE(str("vote_downvote")),

View File

@ -318,6 +318,8 @@
<string name="general_time_without_sb_sum">This time appears in brackets next to the current time. This shows the total video duration minus any segments.</string>
<string name="general_whitelisting">Channel whitelisting</string>
<string name="general_whitelisting_sum">Use the Segments button under the player to whitelist a channel</string>
<string name="general_browser_button">Enable SB Browser button</string>
<string name="general_browser_button_sum">Clicking this button under the player will open a sb.ltn.fi page where you can take a look at the segments</string>
<string name="segments_preview">Preview/Recap</string>
<string name="segments_preview_sum">Quick recap of previous episodes, or a preview of what\'s coming up later in the current video. Meant for edited together clips, not for spoken summaries.</string>
<string name="stats">Stats</string>
@ -346,6 +348,7 @@
<string name="action_tcopy">Timestamp</string>
<string name="action_ads">Ads</string>
<string name="action_segments">Segments</string>
<string name="action_browser">SB Browser</string>
<string name="vanced_video_ad_settings_title">Video ad settings</string>
<string name="vanced_videoadwhitelisting_title">Video ad whitelisting</string>