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

fix(YouTube - Settings): Use multiline preference title for localized languages #727

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions app/src/main/java/app/revanced/integrations/shared/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,35 @@ public static void sortPreferenceGroups(@NonNull PreferenceGroup group) {
}
}

/**
* Set all preferences to multiline titles if the device is not using an English variant.
* The English strings are heavily scrutinized and all titles fit on screen
* except 2 or 3 preference strings and those do not affect readability.
*
* Allowing multiline for those 2 or 3 English preferences looks weird and out of place,
* and visually it looks better to clip the text and keep all titles 1 line.
*/
@SuppressWarnings("deprecation")
public static void setPreferenceTitlesToMultiLineIfNeeded(PreferenceGroup group) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return;
}

String deviceLanguage = Utils.getContext().getResources().getConfiguration().locale.getLanguage();
if (deviceLanguage.equals("en")) {
return;
}

for (int i = 0, prefCount = group.getPreferenceCount(); i < prefCount; i++) {
Preference pref = group.getPreference(i);
pref.setSingleLineTitle(false);
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved

if (pref instanceof PreferenceGroup) {
setPreferenceTitlesToMultiLineIfNeeded((PreferenceGroup) pref);
}
}
}

/**
* If {@link Fragment} uses [Android library] rather than [AndroidX library],
* the Dialog theme corresponding to [Android library] should be used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static app.revanced.integrations.shared.StringRef.str;

@SuppressWarnings({"unused", "deprecation"})
@SuppressWarnings("deprecation")
public abstract class AbstractPreferenceFragment extends PreferenceFragment {
/**
* Indicates that if a preference changes,
Expand Down Expand Up @@ -80,10 +80,12 @@ public abstract class AbstractPreferenceFragment extends PreferenceFragment {
*/
protected void initialize() {
final var identifier = Utils.getResourceIdentifier("revanced_prefs", "xml");

if (identifier == 0) return;
addPreferencesFromResource(identifier);
Utils.sortPreferenceGroups(getPreferenceScreen());

PreferenceScreen screen = getPreferenceScreen();
Utils.sortPreferenceGroups(screen);
Utils.setPreferenceTitlesToMultiLineIfNeeded(screen);
}

private void showSettingUserDialogConfirmation(SwitchPreference switchPref, BooleanSetting setting) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ public static void adjustMiniplayerOpacity(ImageView view) {
* Injection point.
*/
public static boolean getModernFeatureFlagsActiveOverride(boolean original) {
if (original) Logger.printDebug(() -> "getModernFeatureFlagsActiveOverride original: " + original);

if (CURRENT_TYPE == ORIGINAL) {
return original;
}
Expand All @@ -209,8 +207,6 @@ public static boolean getModernFeatureFlagsActiveOverride(boolean original) {
* Injection point.
*/
public static boolean enableMiniplayerDoubleTapAction(boolean original) {
if (original) Logger.printDebug(() -> "enableMiniplayerDoubleTapAction original: " + true);

if (CURRENT_TYPE == ORIGINAL) {
return original;
}
Expand All @@ -222,8 +218,6 @@ public static boolean enableMiniplayerDoubleTapAction(boolean original) {
* Injection point.
*/
public static boolean enableMiniplayerDragAndDrop(boolean original) {
if (original) Logger.printDebug(() -> "enableMiniplayerDragAndDrop original: " + true);

if (CURRENT_TYPE == ORIGINAL) {
return original;
}
Expand All @@ -236,8 +230,6 @@ public static boolean enableMiniplayerDragAndDrop(boolean original) {
* Injection point.
*/
public static boolean setRoundedCorners(boolean original) {
if (original) Logger.printDebug(() -> "setRoundedCorners original: " + true);

if (CURRENT_TYPE.isModern()) {
return MINIPLAYER_ROUNDED_CORNERS_ENABLED;
}
Expand Down Expand Up @@ -271,8 +263,6 @@ public static float setMovementBoundFactor(float original) {
* Injection point.
*/
public static boolean setDropShadow(boolean original) {
if (original) Logger.printDebug(() -> "setViewElevation original: " + true);

return original;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public static boolean filter(@Nullable String lithoIdentifier, @NonNull StringBu
// Potentially the buffer may have been null or never set up until now.
// Use an empty buffer so the litho id/path filters still work correctly.
if (protobufBuffer == null) {
Logger.printDebug(() -> "Proto buffer is null, using an empty buffer array");
bufferArray = EMPTY_BYTE_ARRAY;
} else if (!protobufBuffer.hasArray()) {
Logger.printDebug(() -> "Proto buffer does not have an array, using an empty buffer array");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private static boolean arrayContains(float[] array, float value) {
/**
* Initialize a settings preference list with the available playback speeds.
*/
@SuppressWarnings("deprecation")
public static void initializeListPreference(ListPreference preference) {
if (preferenceListEntries == null) {
preferenceListEntries = new String[customPlaybackSpeeds.length];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package app.revanced.integrations.youtube.settings.preference;

import android.os.Build;
import android.preference.ListPreference;
import android.preference.Preference;

import androidx.annotation.RequiresApi;

import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.shared.settings.preference.AbstractPreferenceFragment;
import app.revanced.integrations.youtube.patches.playback.speed.CustomPlaybackSpeedPatch;
Expand All @@ -18,7 +15,6 @@
*/
public class ReVancedPreferenceFragment extends AbstractPreferenceFragment {

@RequiresApi(api = Build.VERSION_CODES.O)
@Override
protected void initialize() {
super.initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.preference.SwitchPreference;

import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.shared.Utils;
import app.revanced.integrations.shared.settings.Setting;
import app.revanced.integrations.shared.settings.BaseSettings;
import app.revanced.integrations.youtube.patches.ReturnYouTubeDislikePatch;
Expand Down Expand Up @@ -218,6 +219,8 @@ public void onCreate(Bundle savedInstanceState) {
"revanced_ryd_statistics_getNumberOfRateLimitRequestsEncountered_non_zero_summary"));
preferenceScreen.addPreference(statisticPreference);
}

Utils.setPreferenceTitlesToMultiLineIfNeeded(preferenceScreen);
} catch (Exception ex) {
Logger.printException(() -> "onCreate failure", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ public void onCreate(Bundle savedInstanceState) {
addAboutCategory(context, preferenceScreen);

updateUI();

Utils.setPreferenceTitlesToMultiLineIfNeeded(preferenceScreen);
} catch (Exception ex) {
Logger.printException(() -> "onCreate failure", ex);
}
Expand Down Expand Up @@ -468,6 +470,8 @@ private void fetchAndDisplayStats() {
Utils.runOnMainThread(() -> { // get back on main thread to modify UI elements
addUserStats(loadingPlaceholderPreference, stats);
addLocalUserStats();

Utils.setPreferenceTitlesToMultiLineIfNeeded(statsCategory);
});
});
} else {
Expand Down
Loading