Skip to content

Commit ff85d49

Browse files
LisoUseInAIKyriosoSumAtrIX
authored andcommitted
fix(YouTube - Settings): Use multiline preference title for localized languages (ReVanced#3821)
1 parent bc67001 commit ff85d49

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

extensions/shared/src/main/java/app/revanced/extension/shared/Utils.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,35 @@ public static void sortPreferenceGroups(@NonNull PreferenceGroup group) {
722722
}
723723
}
724724

725+
/**
726+
* Set all preferences to multiline titles if the device is not using an English variant.
727+
* The English strings are heavily scrutinized and all titles fit on screen
728+
* except 2 or 3 preference strings and those do not affect readability.
729+
*
730+
* Allowing multiline for those 2 or 3 English preferences looks weird and out of place,
731+
* and visually it looks better to clip the text and keep all titles 1 line.
732+
*/
733+
@SuppressWarnings("deprecation")
734+
public static void setPreferenceTitlesToMultiLineIfNeeded(PreferenceGroup group) {
735+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
736+
return;
737+
}
738+
739+
String deviceLanguage = Utils.getContext().getResources().getConfiguration().locale.getLanguage();
740+
if (deviceLanguage.equals("en")) {
741+
return;
742+
}
743+
744+
for (int i = 0, prefCount = group.getPreferenceCount(); i < prefCount; i++) {
745+
Preference pref = group.getPreference(i);
746+
pref.setSingleLineTitle(false);
747+
748+
if (pref instanceof PreferenceGroup) {
749+
setPreferenceTitlesToMultiLineIfNeeded((PreferenceGroup) pref);
750+
}
751+
}
752+
}
753+
725754
/**
726755
* If {@link Fragment} uses [Android library] rather than [AndroidX library],
727756
* the Dialog theme corresponding to [Android library] should be used.

extensions/shared/src/main/java/app/revanced/extension/shared/settings/preference/AbstractPreferenceFragment.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import static app.revanced.extension.shared.StringRef.str;
1919

20-
@SuppressWarnings({"unused", "deprecation"})
20+
@SuppressWarnings("deprecation")
2121
public abstract class AbstractPreferenceFragment extends PreferenceFragment {
2222
/**
2323
* Indicates that if a preference changes,
@@ -80,10 +80,12 @@ public abstract class AbstractPreferenceFragment extends PreferenceFragment {
8080
*/
8181
protected void initialize() {
8282
final var identifier = Utils.getResourceIdentifier("revanced_prefs", "xml");
83-
8483
if (identifier == 0) return;
8584
addPreferencesFromResource(identifier);
86-
Utils.sortPreferenceGroups(getPreferenceScreen());
85+
86+
PreferenceScreen screen = getPreferenceScreen();
87+
Utils.sortPreferenceGroups(screen);
88+
Utils.setPreferenceTitlesToMultiLineIfNeeded(screen);
8789
}
8890

8991
private void showSettingUserDialogConfirmation(SwitchPreference switchPref, BooleanSetting setting) {

extensions/shared/src/main/java/app/revanced/extension/youtube/patches/MiniplayerPatch.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public boolean isAvailable() {
137137
MiniplayerType type = Settings.MINIPLAYER_TYPE.get();
138138
return (!IS_19_20_OR_GREATER && (type == MODERN_1 || type == MODERN_3))
139139
|| (!IS_19_26_OR_GREATER && type == MODERN_1
140-
&& !Settings.MINIPLAYER_DOUBLE_TAP_ACTION.get() && !Settings.MINIPLAYER_DRAG_AND_DROP.get())
140+
&& !Settings.MINIPLAYER_DOUBLE_TAP_ACTION.get() && !Settings.MINIPLAYER_DRAG_AND_DROP.get())
141141
|| (IS_19_29_OR_GREATER && type == MODERN_3);
142142
}
143143
}
@@ -196,8 +196,6 @@ public static void adjustMiniplayerOpacity(ImageView view) {
196196
* Injection point.
197197
*/
198198
public static boolean getModernFeatureFlagsActiveOverride(boolean original) {
199-
if (original) Logger.printDebug(() -> "getModernFeatureFlagsActiveOverride original: " + original);
200-
201199
if (CURRENT_TYPE == ORIGINAL) {
202200
return original;
203201
}
@@ -209,8 +207,6 @@ public static boolean getModernFeatureFlagsActiveOverride(boolean original) {
209207
* Injection point.
210208
*/
211209
public static boolean enableMiniplayerDoubleTapAction(boolean original) {
212-
if (original) Logger.printDebug(() -> "enableMiniplayerDoubleTapAction original: " + true);
213-
214210
if (CURRENT_TYPE == ORIGINAL) {
215211
return original;
216212
}
@@ -222,8 +218,6 @@ public static boolean enableMiniplayerDoubleTapAction(boolean original) {
222218
* Injection point.
223219
*/
224220
public static boolean enableMiniplayerDragAndDrop(boolean original) {
225-
if (original) Logger.printDebug(() -> "enableMiniplayerDragAndDrop original: " + true);
226-
227221
if (CURRENT_TYPE == ORIGINAL) {
228222
return original;
229223
}
@@ -236,8 +230,6 @@ public static boolean enableMiniplayerDragAndDrop(boolean original) {
236230
* Injection point.
237231
*/
238232
public static boolean setRoundedCorners(boolean original) {
239-
if (original) Logger.printDebug(() -> "setRoundedCorners original: " + true);
240-
241233
if (CURRENT_TYPE.isModern()) {
242234
return MINIPLAYER_ROUNDED_CORNERS_ENABLED;
243235
}
@@ -271,8 +263,6 @@ public static float setMovementBoundFactor(float original) {
271263
* Injection point.
272264
*/
273265
public static boolean setDropShadow(boolean original) {
274-
if (original) Logger.printDebug(() -> "setViewElevation original: " + true);
275-
276266
return original;
277267
}
278268

extensions/shared/src/main/java/app/revanced/extension/youtube/patches/components/LithoFilterPatch.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ public static boolean filter(@Nullable String lithoIdentifier, @NonNull StringBu
155155
// Potentially the buffer may have been null or never set up until now.
156156
// Use an empty buffer so the litho id/path filters still work correctly.
157157
if (protobufBuffer == null) {
158-
Logger.printDebug(() -> "Proto buffer is null, using an empty buffer array");
159158
bufferArray = EMPTY_BYTE_ARRAY;
160159
} else if (!protobufBuffer.hasArray()) {
161160
Logger.printDebug(() -> "Proto buffer does not have an array, using an empty buffer array");

0 commit comments

Comments
 (0)