Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
fix(YouTube - Settings): Search bar in settings can't find RYD an…
Browse files Browse the repository at this point in the history
…d `SponsorBlock` settings
  • Loading branch information
anddea committed Sep 30, 2024
1 parent fd6e7d9 commit 2d6e03a
Show file tree
Hide file tree
Showing 17 changed files with 639 additions and 1,127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static app.revanced.integrations.shared.utils.Utils.isSDKAbove;

import android.content.Context;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,6 @@ public static String getTimeStamp(long time) {
}
}

public static void setPreferenceIcon(Preference preference, String str) {
final int iconResourceId = ResourceUtils.getDrawableIdentifier(str);
if (iconResourceId == 0) return;
preference.setIcon(iconResourceId);
}

public static void setEditTextDialogTheme(final AlertDialog.Builder builder) {
setEditTextDialogTheme(builder, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class ReturnYouTubeDislikePatch {
@Nullable
private static volatile String lastPrefetchedVideoId;

public static void onRYDStatusChange(boolean rydEnabled) {
public static void onRYDStatusChange() {
ReturnYouTubeDislikeApi.resetRateLimits();
// Must remove all values to protect against using stale data
// if the user enables RYD while a video is on screen.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public class ReturnYouTubeDislike {

leftSeparatorShape = new ShapeDrawable(new RectShape());
leftSeparatorShape.setBounds(leftSeparatorBounds);
locale = resources.getConfiguration().locale;
locale = resources.getConfiguration().getLocales().get(0);

ReturnYouTubeDislikeApi.toastOnConnectionError = Settings.RYD_TOAST_ON_CONNECTION_ERROR.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public class Settings extends BaseSettings {
/**
* Do not use directly, instead use {@link SponsorBlockSettings}
*/
public static final StringSetting SB_PRIVATE_USER_ID = new StringSetting("sb_private_user_id_Do_Not_Share", "");
public static final StringSetting SB_PRIVATE_USER_ID = new StringSetting("sb_private_user_id_Do_Not_Share", "", parent(SB_ENABLED));
public static final IntegerSetting SB_CREATE_NEW_SEGMENT_STEP = new IntegerSetting("sb_create_new_segment_step", 150, parent(SB_ENABLED));
public static final BooleanSetting SB_VOTING_BUTTON = new BooleanSetting("sb_voting_button", FALSE, parent(SB_ENABLED));
public static final BooleanSetting SB_CREATE_NEW_SEGMENT = new BooleanSetting("sb_create_new_segment", FALSE, parent(SB_ENABLED));
Expand All @@ -520,7 +520,7 @@ public class Settings extends BaseSettings {
public static final BooleanSetting SB_TRACK_SKIP_COUNT = new BooleanSetting("sb_track_skip_count", TRUE, parent(SB_ENABLED));
public static final FloatSetting SB_SEGMENT_MIN_DURATION = new FloatSetting("sb_min_segment_duration", 0F, parent(SB_ENABLED));
public static final BooleanSetting SB_VIDEO_LENGTH_WITHOUT_SEGMENTS = new BooleanSetting("sb_video_length_without_segments", FALSE, parent(SB_ENABLED));
public static final StringSetting SB_API_URL = new StringSetting("sb_api_url", "https://sponsor.ajay.app");
public static final StringSetting SB_API_URL = new StringSetting("sb_api_url", "https://sponsor.ajay.app", parent(SB_ENABLED));
public static final BooleanSetting SB_USER_IS_VIP = new BooleanSetting("sb_user_is_vip", FALSE);
public static final IntegerSetting SB_LOCAL_TIME_SAVED_NUMBER_SEGMENTS = new IntegerSetting("sb_local_time_saved_number_segments", 0);
public static final LongSetting SB_LOCAL_TIME_SAVED_MILLISECONDS = new LongSetting("sb_local_time_saved_milliseconds", 0L);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package app.revanced.integrations.youtube.settings.preference;

import static com.google.android.apps.youtube.app.settings.videoquality.VideoQualitySettingsActivity.setSearchViewVisibility;
import static com.google.android.apps.youtube.app.settings.videoquality.VideoQualitySettingsActivity.setToolbarText;
import static app.revanced.integrations.shared.settings.preference.AbstractPreferenceFragment.showRestartDialog;
import static app.revanced.integrations.shared.settings.preference.AbstractPreferenceFragment.updateListPreferenceSummary;
import static app.revanced.integrations.shared.utils.ResourceUtils.getIdIdentifier;
import static app.revanced.integrations.shared.utils.ResourceUtils.getXmlIdentifier;
import static app.revanced.integrations.shared.utils.StringRef.str;
import static app.revanced.integrations.shared.utils.Utils.getChildView;
Expand All @@ -15,7 +12,6 @@
import static app.revanced.integrations.youtube.settings.Settings.HIDE_PREVIEW_COMMENT_TYPE;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
Expand Down Expand Up @@ -84,6 +80,10 @@ public class ReVancedPreferenceFragment extends PreferenceFragment {

if (mPreference == null) return;

if (mPreference instanceof app.revanced.integrations.youtube.settings.preference.SegmentCategoryListPreference) {
return;
}

if (mPreference instanceof SwitchPreference switchPreference) {
BooleanSetting boolSetting = (BooleanSetting) setting;
if (settingImportInProgress) {
Expand Down Expand Up @@ -173,40 +173,6 @@ public ReVancedPreferenceFragment() {
// Required empty public constructor
}

@TargetApi(26)
public void setPreferenceFragmentToolbar(final String key) {
PreferenceFragment fragment;
switch (key) {
case "revanced_preference_screen_ryd" ->
fragment = new ReturnYouTubeDislikePreferenceFragment();
case "revanced_preference_screen_sb" -> fragment = new SponsorBlockPreferenceFragment();
default -> {
Logger.printException(() -> "Unknown key: " + key);
return;
}
}

final Preference mPreference = mPreferenceManager.findPreference(key);
if (mPreference == null) {
return;
}
mPreference.setOnPreferenceClickListener(pref -> {
// Set toolbar text
setToolbarText(pref.getTitle());

// Hide the search bar
setSearchViewVisibility(false);

getFragmentManager()
.beginTransaction()
.replace(getIdIdentifier("revanced_settings_fragments"), fragment)
.addToBackStack(null)
.setReorderingAllowed(true)
.commitAllowingStateLoss();
return false;
});
}

private void putPreferenceScreenMap(SortedMap<String, PreferenceScreen> preferenceScreenMap, PreferenceGroup preferenceGroup) {
if (preferenceGroup instanceof PreferenceScreen mPreferenceScreen) {
preferenceScreenMap.put(mPreferenceScreen.getKey(), mPreferenceScreen);
Expand Down Expand Up @@ -263,8 +229,6 @@ private void setPreferenceScreenToolbar() {
}
}

// TODO: Add ability to search for SB and RYD settings

// Map to store dependencies: key is the preference key, value is a list of dependent preferences
private final Map<String, List<Preference>> dependencyMap = new HashMap<>();
// Set to track already added preferences to avoid duplicates
Expand All @@ -283,12 +247,11 @@ public void onCreate(Bundle bundle) {
addPreferencesFromResource(getXmlIdentifier("revanced_prefs"));

// Initialize toolbars and other UI elements
setPreferenceFragmentToolbar("revanced_preference_screen_ryd");
setPreferenceFragmentToolbar("revanced_preference_screen_sb");
setPreferenceScreenToolbar();

// Initialize ReVanced settings
ReVancedSettingsPreference.initializeReVancedSettings();
SponsorBlockSettingsPreference.init(getActivity());

// Import/export
setBackupRestorePreference();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package app.revanced.integrations.youtube.settings.preference;

import static app.revanced.integrations.shared.utils.StringRef.str;
import static app.revanced.integrations.shared.utils.Utils.isSDKAbove;
import static app.revanced.integrations.youtube.patches.general.MiniplayerPatch.MiniplayerType.MODERN_1;
import static app.revanced.integrations.youtube.patches.general.MiniplayerPatch.MiniplayerType.MODERN_3;
import static app.revanced.integrations.youtube.utils.ExtendedUtils.isSpoofingToLessThan;

import android.preference.Preference;
import android.preference.SwitchPreference;

import app.revanced.integrations.shared.settings.Setting;
import app.revanced.integrations.youtube.patches.general.MiniplayerPatch;
import app.revanced.integrations.youtube.patches.utils.PatchStatus;
import app.revanced.integrations.youtube.patches.utils.ReturnYouTubeDislikePatch;
import app.revanced.integrations.youtube.returnyoutubedislike.ReturnYouTubeDislike;
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.youtube.utils.ExtendedUtils;

Expand Down Expand Up @@ -47,6 +51,7 @@ public static void initializeReVancedSettings() {
LayoutOverrideLinks();
MiniPlayerPreferenceLinks();
NavigationPreferenceLinks();
RYDPreferenceLinks();
SpeedOverlayPreferenceLinks();
QuickActionsPreferenceLinks();
TabletLayoutLinks();
Expand Down Expand Up @@ -211,6 +216,40 @@ private static void NavigationPreferenceLinks() {
);
}

/**
* Enable/Disable Preference related to RYD settings
*/
private static void RYDPreferenceLinks() {
if (!(mPreferenceManager.findPreference(Settings.RYD_ENABLED.key) instanceof SwitchPreference enabledPreference)) {
return;
}
if (!(mPreferenceManager.findPreference(Settings.RYD_SHORTS.key) instanceof SwitchPreference shortsPreference)) {
return;
}
if (!(mPreferenceManager.findPreference(Settings.RYD_DISLIKE_PERCENTAGE.key) instanceof SwitchPreference percentagePreference)) {
return;
}
if (!(mPreferenceManager.findPreference(Settings.RYD_COMPACT_LAYOUT.key) instanceof SwitchPreference compactLayoutPreference)) {
return;
}
final Preference.OnPreferenceChangeListener clearAllUICaches = (pref, newValue) -> {
ReturnYouTubeDislike.clearAllUICaches();

return true;
};
enabledPreference.setOnPreferenceChangeListener((pref, newValue) -> {
ReturnYouTubeDislikePatch.onRYDStatusChange();

return true;
});
String shortsSummary = ReturnYouTubeDislikePatch.IS_SPOOFING_TO_NON_LITHO_SHORTS_PLAYER
? str("revanced_ryd_shorts_summary_on")
: str("revanced_ryd_shorts_summary_on_disclaimer");
shortsPreference.setSummaryOn(shortsSummary);
percentagePreference.setOnPreferenceChangeListener(clearAllUICaches);
compactLayoutPreference.setOnPreferenceChangeListener(clearAllUICaches);
}

/**
* Enable/Disable Preference related to Speed overlay settings
*/
Expand All @@ -232,4 +271,4 @@ private static void WhitelistPreferenceLinks() {
}
}
}
}
}
Loading

0 comments on commit 2d6e03a

Please sign in to comment.