mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-07 10:35:49 +01:00
feat(youtube/return-youtube-dislike): style for minimum width (#284)
This commit is contained in:
parent
c3eff913dd
commit
a80fab7070
@ -254,9 +254,11 @@ public class ReturnYouTubeDislike {
|
|||||||
}
|
}
|
||||||
replacementSpannable = newSpannableWithDislikes(oldSpannable, voteData);
|
replacementSpannable = newSpannableWithDislikes(oldSpannable, voteData);
|
||||||
} else {
|
} else {
|
||||||
String leftSegmentedSeparatorString = ReVancedUtils.isRightToLeftTextLayout() ? "\u200F| " : "| ";
|
final boolean useCompactLayout = SettingsEnum.RYD_USE_COMPACT_LAYOUT.getBoolean();
|
||||||
|
// if compact layout, use a "half space" character
|
||||||
|
String middleSegmentedSeparatorString = useCompactLayout ? "\u2009 • \u2009" : " • ";
|
||||||
|
|
||||||
if (oldLikesString.contains(leftSegmentedSeparatorString)) {
|
if (oldLikesString.contains(middleSegmentedSeparatorString)) {
|
||||||
return false; // dislikes was previously added
|
return false; // dislikes was previously added
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,14 +289,11 @@ public class ReturnYouTubeDislike {
|
|||||||
} else {
|
} else {
|
||||||
Spannable likesSpan = newSpanUsingStylingOfAnotherSpan(oldSpannable, oldLikesString);
|
Spannable likesSpan = newSpanUsingStylingOfAnotherSpan(oldSpannable, oldLikesString);
|
||||||
|
|
||||||
// left and middle separator
|
// middle separator
|
||||||
String middleSegmentedSeparatorString = " • ";
|
|
||||||
Spannable leftSeparatorSpan = newSpanUsingStylingOfAnotherSpan(oldSpannable, leftSegmentedSeparatorString);
|
|
||||||
Spannable middleSeparatorSpan = newSpanUsingStylingOfAnotherSpan(oldSpannable, middleSegmentedSeparatorString);
|
Spannable middleSeparatorSpan = newSpanUsingStylingOfAnotherSpan(oldSpannable, middleSegmentedSeparatorString);
|
||||||
final int separatorColor = ThemeHelper.isDarkTheme()
|
final int separatorColor = ThemeHelper.isDarkTheme()
|
||||||
? 0x29AAAAAA // transparent dark gray
|
? 0x29AAAAAA // transparent dark gray
|
||||||
: 0xFFD9D9D9; // light gray
|
: 0xFFD9D9D9; // light gray
|
||||||
addSpanStyling(leftSeparatorSpan, new ForegroundColorSpan(separatorColor));
|
|
||||||
addSpanStyling(middleSeparatorSpan, new ForegroundColorSpan(separatorColor));
|
addSpanStyling(middleSeparatorSpan, new ForegroundColorSpan(separatorColor));
|
||||||
CharacterStyle noAntiAliasingStyle = new CharacterStyle() {
|
CharacterStyle noAntiAliasingStyle = new CharacterStyle() {
|
||||||
@Override
|
@Override
|
||||||
@ -302,43 +301,49 @@ public class ReturnYouTubeDislike {
|
|||||||
tp.setAntiAlias(false); // draw without anti-aliasing, to give a sharper edge
|
tp.setAntiAlias(false); // draw without anti-aliasing, to give a sharper edge
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
addSpanStyling(leftSeparatorSpan, noAntiAliasingStyle);
|
|
||||||
addSpanStyling(middleSeparatorSpan, noAntiAliasingStyle);
|
addSpanStyling(middleSeparatorSpan, noAntiAliasingStyle);
|
||||||
|
|
||||||
Spannable dislikeSpan = newSpannableWithDislikes(oldSpannable, voteData);
|
Spannable dislikeSpan = newSpannableWithDislikes(oldSpannable, voteData);
|
||||||
|
|
||||||
// Increase the size of the left separator, so it better matches the stock separator on the right.
|
|
||||||
// But when using a larger font, the entire span (including the like/dislike text) becomes shifted downward.
|
|
||||||
// To correct this, use additional spans to move the alignment back upward by a relative amount.
|
|
||||||
setSegmentedAdjustmentValues();
|
|
||||||
class RelativeVerticalOffsetSpan extends CharacterStyle {
|
|
||||||
final float relativeVerticalShiftRatio;
|
|
||||||
|
|
||||||
RelativeVerticalOffsetSpan(float relativeVerticalShiftRatio) {
|
|
||||||
this.relativeVerticalShiftRatio = relativeVerticalShiftRatio;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDrawState(TextPaint tp) {
|
|
||||||
tp.baselineShift -= (int) (relativeVerticalShiftRatio * tp.getFontMetrics().top);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// shift everything up, to compensate for the vertical movement caused by the font change below
|
|
||||||
// each section needs it's own Relative span, otherwise alignment is wrong
|
|
||||||
addSpanStyling(leftSeparatorSpan, new RelativeVerticalOffsetSpan(segmentedLeftSeparatorVerticalShiftRatio));
|
|
||||||
|
|
||||||
addSpanStyling(likesSpan, new RelativeVerticalOffsetSpan(segmentedVerticalShiftRatio));
|
|
||||||
addSpanStyling(middleSeparatorSpan, new RelativeVerticalOffsetSpan(segmentedVerticalShiftRatio));
|
|
||||||
addSpanStyling(dislikeSpan, new RelativeVerticalOffsetSpan(segmentedVerticalShiftRatio));
|
|
||||||
|
|
||||||
// important: must add size scaling after vertical offset (otherwise alignment gets off)
|
|
||||||
addSpanStyling(leftSeparatorSpan, new RelativeSizeSpan(segmentedLeftSeparatorFontRatio));
|
|
||||||
addSpanStyling(leftSeparatorSpan, new ScaleXSpan(segmentedLeftSeparatorHorizontalScaleRatio));
|
|
||||||
// middle separator does not need resizing
|
|
||||||
|
|
||||||
// put everything together
|
|
||||||
SpannableStringBuilder builder = new SpannableStringBuilder();
|
SpannableStringBuilder builder = new SpannableStringBuilder();
|
||||||
builder.append(leftSeparatorSpan);
|
|
||||||
|
if (!useCompactLayout) {
|
||||||
|
String leftSegmentedSeparatorString = ReVancedUtils.isRightToLeftTextLayout() ? "\u200F| " : "| ";
|
||||||
|
Spannable leftSeparatorSpan = newSpanUsingStylingOfAnotherSpan(oldSpannable, leftSegmentedSeparatorString);
|
||||||
|
addSpanStyling(leftSeparatorSpan, new ForegroundColorSpan(separatorColor));
|
||||||
|
addSpanStyling(leftSeparatorSpan, noAntiAliasingStyle);
|
||||||
|
|
||||||
|
// Use a left separator with a larger font and visually match the stock right separator.
|
||||||
|
// But with a larger font, the entire span (including the like/dislike text) becomes shifted downward.
|
||||||
|
// To correct this, use additional spans to move the alignment back upward by a relative amount.
|
||||||
|
setSegmentedAdjustmentValues();
|
||||||
|
class RelativeVerticalOffsetSpan extends CharacterStyle {
|
||||||
|
final float relativeVerticalShiftRatio;
|
||||||
|
|
||||||
|
RelativeVerticalOffsetSpan(float relativeVerticalShiftRatio) {
|
||||||
|
this.relativeVerticalShiftRatio = relativeVerticalShiftRatio;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDrawState(TextPaint tp) {
|
||||||
|
tp.baselineShift -= (int) (relativeVerticalShiftRatio * tp.getFontMetrics().top);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// each section needs it's own Relative span, otherwise alignment is wrong
|
||||||
|
addSpanStyling(leftSeparatorSpan, new RelativeVerticalOffsetSpan(segmentedLeftSeparatorVerticalShiftRatio));
|
||||||
|
|
||||||
|
addSpanStyling(likesSpan, new RelativeVerticalOffsetSpan(segmentedVerticalShiftRatio));
|
||||||
|
addSpanStyling(middleSeparatorSpan, new RelativeVerticalOffsetSpan(segmentedVerticalShiftRatio));
|
||||||
|
addSpanStyling(dislikeSpan, new RelativeVerticalOffsetSpan(segmentedVerticalShiftRatio));
|
||||||
|
|
||||||
|
// important: must add size scaling after vertical offset (otherwise alignment gets off)
|
||||||
|
addSpanStyling(leftSeparatorSpan, new RelativeSizeSpan(segmentedLeftSeparatorFontRatio));
|
||||||
|
addSpanStyling(leftSeparatorSpan, new ScaleXSpan(segmentedLeftSeparatorHorizontalScaleRatio));
|
||||||
|
// middle separator does not need resizing
|
||||||
|
|
||||||
|
builder.append(leftSeparatorSpan);
|
||||||
|
}
|
||||||
|
|
||||||
builder.append(likesSpan);
|
builder.append(likesSpan);
|
||||||
builder.append(middleSeparatorSpan);
|
builder.append(middleSeparatorSpan);
|
||||||
builder.append(dislikeSpan);
|
builder.append(dislikeSpan);
|
||||||
@ -369,9 +374,9 @@ public class ReturnYouTubeDislike {
|
|||||||
LogHelper.printDebug(() -> "Device manufacturer: '" + deviceManufacturer + "' SDK: " + deviceSdkVersion);
|
LogHelper.printDebug(() -> "Device manufacturer: '" + deviceManufacturer + "' SDK: " + deviceSdkVersion);
|
||||||
|
|
||||||
//
|
//
|
||||||
// IMPORTANT: configurations must be with the default system font size setting.
|
// Important: configurations must be with the device default system font, and default font size.
|
||||||
//
|
//
|
||||||
// In generally, a single configuration will give perfect layout for all devices of the same manufacturer
|
// In general, a single configuration will give perfect layout for all devices of the same manufacturer.
|
||||||
final String configManufacturer;
|
final String configManufacturer;
|
||||||
final int configSdk;
|
final int configSdk;
|
||||||
switch (deviceManufacturer) {
|
switch (deviceManufacturer) {
|
||||||
@ -394,7 +399,7 @@ public class ReturnYouTubeDislike {
|
|||||||
segmentedLeftSeparatorHorizontalScaleRatio = 0.7f;
|
segmentedLeftSeparatorHorizontalScaleRatio = 0.7f;
|
||||||
break;
|
break;
|
||||||
case "OnePlus":
|
case "OnePlus":
|
||||||
configManufacturer = "oneplus";
|
configManufacturer = "OnePlus";
|
||||||
configSdk = 33;
|
configSdk = 33;
|
||||||
// tested on OnePlus 8 Pro
|
// tested on OnePlus 8 Pro
|
||||||
segmentedLeftSeparatorVerticalShiftRatio = -0.075f;
|
segmentedLeftSeparatorVerticalShiftRatio = -0.075f;
|
||||||
@ -402,7 +407,6 @@ public class ReturnYouTubeDislike {
|
|||||||
segmentedLeftSeparatorFontRatio = 1.87f;
|
segmentedLeftSeparatorFontRatio = 1.87f;
|
||||||
segmentedLeftSeparatorHorizontalScaleRatio = 0.50f;
|
segmentedLeftSeparatorHorizontalScaleRatio = 0.50f;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LogHelper.printDebug(() -> "Using layout adjustments based on manufacturer: '" + configManufacturer + "' SDK: " + configSdk);
|
LogHelper.printDebug(() -> "Using layout adjustments based on manufacturer: '" + configManufacturer + "' SDK: " + configSdk);
|
||||||
|
@ -126,6 +126,7 @@ public enum SettingsEnum {
|
|||||||
RYD_USER_ID("ryd_userId", null, SharedPrefHelper.SharedPrefNames.RYD, ReturnType.STRING),
|
RYD_USER_ID("ryd_userId", null, SharedPrefHelper.SharedPrefNames.RYD, ReturnType.STRING),
|
||||||
RYD_ENABLED("ryd_enabled", true, SharedPrefHelper.SharedPrefNames.RYD, ReturnType.BOOLEAN),
|
RYD_ENABLED("ryd_enabled", true, SharedPrefHelper.SharedPrefNames.RYD, ReturnType.BOOLEAN),
|
||||||
RYD_SHOW_DISLIKE_PERCENTAGE("ryd_show_dislike_percentage", false, SharedPrefHelper.SharedPrefNames.RYD, ReturnType.BOOLEAN),
|
RYD_SHOW_DISLIKE_PERCENTAGE("ryd_show_dislike_percentage", false, SharedPrefHelper.SharedPrefNames.RYD, ReturnType.BOOLEAN),
|
||||||
|
RYD_USE_COMPACT_LAYOUT("ryd_use_compact_layout", false, SharedPrefHelper.SharedPrefNames.RYD, ReturnType.BOOLEAN),
|
||||||
|
|
||||||
// SponsorBlock settings
|
// SponsorBlock settings
|
||||||
SB_ENABLED("sb-enabled", true, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN),
|
SB_ENABLED("sb-enabled", true, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN),
|
||||||
|
@ -29,18 +29,27 @@ public class ReturnYouTubeDislikeSettingsFragment extends PreferenceFragment {
|
|||||||
*/
|
*/
|
||||||
private SwitchPreference percentagePreference;
|
private SwitchPreference percentagePreference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If segmented like/dislike button uses smaller compact layout
|
||||||
|
*/
|
||||||
|
private SwitchPreference compactLayoutPreference;
|
||||||
|
|
||||||
private void updateUIState() {
|
private void updateUIState() {
|
||||||
final boolean rydIsEnabled = SettingsEnum.RYD_ENABLED.getBoolean();
|
final boolean rydIsEnabled = SettingsEnum.RYD_ENABLED.getBoolean();
|
||||||
final boolean dislikePercentageEnabled = SettingsEnum.RYD_SHOW_DISLIKE_PERCENTAGE.getBoolean();
|
|
||||||
|
|
||||||
enabledPreference.setSummary(rydIsEnabled
|
enabledPreference.setSummary(rydIsEnabled
|
||||||
? str("revanced_ryd_enable_summary_on")
|
? str("revanced_ryd_enable_summary_on")
|
||||||
: str("revanced_ryd_enable_summary_off"));
|
: str("revanced_ryd_enable_summary_off"));
|
||||||
|
|
||||||
percentagePreference.setSummary(dislikePercentageEnabled
|
percentagePreference.setSummary(SettingsEnum.RYD_SHOW_DISLIKE_PERCENTAGE.getBoolean()
|
||||||
? str("revanced_ryd_dislike_percentage_summary_on")
|
? str("revanced_ryd_dislike_percentage_summary_on")
|
||||||
: str("revanced_ryd_dislike_percentage_summary_off"));
|
: str("revanced_ryd_dislike_percentage_summary_off"));
|
||||||
percentagePreference.setEnabled(rydIsEnabled);
|
percentagePreference.setEnabled(rydIsEnabled);
|
||||||
|
|
||||||
|
compactLayoutPreference.setSummary(SettingsEnum.RYD_USE_COMPACT_LAYOUT.getBoolean()
|
||||||
|
? str("revanced_ryd_compact_layout_summary_on")
|
||||||
|
: str("revanced_ryd_compact_layout_summary_off"));
|
||||||
|
compactLayoutPreference.setEnabled(rydIsEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -80,6 +89,19 @@ public class ReturnYouTubeDislikeSettingsFragment extends PreferenceFragment {
|
|||||||
});
|
});
|
||||||
preferenceScreen.addPreference(percentagePreference);
|
preferenceScreen.addPreference(percentagePreference);
|
||||||
|
|
||||||
|
compactLayoutPreference = new SwitchPreference(context);
|
||||||
|
compactLayoutPreference.setKey(SettingsEnum.RYD_USE_COMPACT_LAYOUT.getPath());
|
||||||
|
compactLayoutPreference.setDefaultValue(SettingsEnum.RYD_USE_COMPACT_LAYOUT.getDefaultValue());
|
||||||
|
compactLayoutPreference.setChecked(SettingsEnum.RYD_USE_COMPACT_LAYOUT.getBoolean());
|
||||||
|
compactLayoutPreference.setTitle(str("revanced_ryd_compact_layout_title"));
|
||||||
|
compactLayoutPreference.setOnPreferenceChangeListener((pref, newValue) -> {
|
||||||
|
SettingsEnum.RYD_USE_COMPACT_LAYOUT.saveValue((Boolean)newValue);
|
||||||
|
|
||||||
|
updateUIState();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
preferenceScreen.addPreference(compactLayoutPreference);
|
||||||
|
|
||||||
updateUIState();
|
updateUIState();
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,12 +133,15 @@ public class ReVancedUtils {
|
|||||||
return context.getResources().getConfiguration().smallestScreenWidthDp >= 600;
|
return context.getResources().getConfiguration().smallestScreenWidthDp >= 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final boolean isRightToLeftTextLayout =
|
private static Boolean isRightToLeftTextLayout;
|
||||||
new Bidi(Locale.getDefault().getDisplayLanguage(), Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT).isRightToLeft();
|
|
||||||
/**
|
/**
|
||||||
* If the device language uses right to left text layout (hebrew, arabic, etc)
|
* If the device language uses right to left text layout (hebrew, arabic, etc)
|
||||||
*/
|
*/
|
||||||
public static boolean isRightToLeftTextLayout() {
|
public static boolean isRightToLeftTextLayout() {
|
||||||
|
if (isRightToLeftTextLayout == null) {
|
||||||
|
String displayLanguage = Locale.getDefault().getDisplayLanguage();
|
||||||
|
isRightToLeftTextLayout = new Bidi(displayLanguage, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT).isRightToLeft();
|
||||||
|
}
|
||||||
return isRightToLeftTextLayout;
|
return isRightToLeftTextLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user