fix(YouTube - Settings): When a string resource is not found, the default value of some settings is not valid

This commit is contained in:
inotia00 2025-01-31 20:43:35 +09:00
parent b7aa8dcc44
commit 58752ec547
2 changed files with 40 additions and 9 deletions

View File

@ -9,6 +9,8 @@ import java.util.regex.Pattern;
import app.revanced.extension.shared.patches.components.Filter; import app.revanced.extension.shared.patches.components.Filter;
import app.revanced.extension.shared.patches.components.StringFilterGroup; import app.revanced.extension.shared.patches.components.StringFilterGroup;
import app.revanced.extension.shared.settings.StringSetting;
import app.revanced.extension.shared.utils.ResourceUtils;
import app.revanced.extension.youtube.settings.Settings; import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.youtube.shared.NavigationBar; import app.revanced.extension.youtube.shared.NavigationBar;
import app.revanced.extension.youtube.shared.RootView; import app.revanced.extension.youtube.shared.RootView;
@ -70,10 +72,26 @@ public final class FeedVideoViewsFilter extends Filter {
return false; return false;
} }
private final String ARROW = " -> "; private static final String ARROW = " -> ";
private final String VIEWS = "views"; private static final String VIEWS = "views";
private final String[] parts = Settings.HIDE_VIDEO_VIEW_COUNTS_MULTIPLIER.get().split("\\n"); private static final StringSetting HIDE_VIDEO_VIEW_COUNTS_MULTIPLIER =
private Pattern[] viewCountPatterns = null; Settings.HIDE_VIDEO_VIEW_COUNTS_MULTIPLIER;
private static final String HIDE_VIDEO_VIEW_COUNTS_MULTIPLIER_DEFAULT_VALUE =
"revanced_hide_video_view_counts_multiplier_default_value";
private static String[] parts;
private static Pattern[] viewCountPatterns = null;
static {
final String multiplierString = HIDE_VIDEO_VIEW_COUNTS_MULTIPLIER.get();
if (multiplierString.equals(HIDE_VIDEO_VIEW_COUNTS_MULTIPLIER_DEFAULT_VALUE) &&
ResourceUtils.getContext() != null) {
String defaultValue = ResourceUtils.getString(HIDE_VIDEO_VIEW_COUNTS_MULTIPLIER_DEFAULT_VALUE);
if (!multiplierString.equals(defaultValue)) {
HIDE_VIDEO_VIEW_COUNTS_MULTIPLIER.save(defaultValue);
}
}
parts = HIDE_VIDEO_VIEW_COUNTS_MULTIPLIER.get().split("\\n");
}
/** /**
* Hide videos based on views count * Hide videos based on views count

View File

@ -23,6 +23,7 @@ import java.util.Objects;
import app.revanced.extension.shared.settings.BaseSettings; import app.revanced.extension.shared.settings.BaseSettings;
import app.revanced.extension.shared.settings.BooleanSetting; import app.revanced.extension.shared.settings.BooleanSetting;
import app.revanced.extension.shared.settings.IntegerSetting; import app.revanced.extension.shared.settings.IntegerSetting;
import app.revanced.extension.shared.settings.StringSetting;
import app.revanced.extension.shared.utils.Logger; import app.revanced.extension.shared.utils.Logger;
import app.revanced.extension.shared.utils.ResourceUtils; import app.revanced.extension.shared.utils.ResourceUtils;
import app.revanced.extension.shared.utils.Utils; import app.revanced.extension.shared.utils.Utils;
@ -116,19 +117,32 @@ public class PlayerPatch {
* view id R.id.content * view id R.id.content
*/ */
private static final int contentId = ResourceUtils.getIdIdentifier("content"); private static final int contentId = ResourceUtils.getIdIdentifier("content");
private static final boolean expandDescriptionEnabled = Settings.EXPAND_VIDEO_DESCRIPTION.get(); private static final boolean EXPAND_VIDEO_DESCRIPTION = Settings.EXPAND_VIDEO_DESCRIPTION.get();
private static final String descriptionString = Settings.EXPAND_VIDEO_DESCRIPTION_STRINGS.get(); private static final StringSetting EXPAND_VIDEO_DESCRIPTION_STRINGS = Settings.EXPAND_VIDEO_DESCRIPTION_STRINGS;
private static final String EXPAND_VIDEO_DESCRIPTION_STRINGS_DEFAULT_VALUE = "revanced_expand_video_description_strings_default_value";
static {
final String descriptionString = EXPAND_VIDEO_DESCRIPTION_STRINGS.get();
if (descriptionString.equals(EXPAND_VIDEO_DESCRIPTION_STRINGS_DEFAULT_VALUE) &&
Utils.getContext() != null) {
String defaultValue = ResourceUtils.getString(EXPAND_VIDEO_DESCRIPTION_STRINGS_DEFAULT_VALUE);
if (!descriptionString.equals(defaultValue)) {
EXPAND_VIDEO_DESCRIPTION_STRINGS.save(defaultValue);
}
}
}
private static boolean isDescriptionPanel = false; private static boolean isDescriptionPanel = false;
public static void setContentDescription(String contentDescription) { public static void setContentDescription(String contentDescription) {
if (!expandDescriptionEnabled) { if (!EXPAND_VIDEO_DESCRIPTION) {
return; return;
} }
if (contentDescription == null || contentDescription.isEmpty()) { if (contentDescription == null || contentDescription.isEmpty()) {
isDescriptionPanel = false; isDescriptionPanel = false;
return; return;
} }
final String descriptionString = EXPAND_VIDEO_DESCRIPTION_STRINGS.get();
if (descriptionString.isEmpty()) { if (descriptionString.isEmpty()) {
isDescriptionPanel = false; isDescriptionPanel = false;
return; return;
@ -141,9 +155,8 @@ public class PlayerPatch {
*/ */
private static long lastTimeDescriptionViewInvoked; private static long lastTimeDescriptionViewInvoked;
public static void onVideoDescriptionCreate(RecyclerView recyclerView) { public static void onVideoDescriptionCreate(RecyclerView recyclerView) {
if (!expandDescriptionEnabled) if (!EXPAND_VIDEO_DESCRIPTION)
return; return;
recyclerView.getViewTreeObserver().addOnDrawListener(() -> { recyclerView.getViewTreeObserver().addOnDrawListener(() -> {