refactor(YouTube): Sort no title preference group by first sub preference title

This commit is contained in:
LisoUseInAIKyrios 2025-03-06 21:15:29 +02:00
parent 274df58056
commit fd6bc6ec36
3 changed files with 23 additions and 6 deletions

View File

@ -12,6 +12,7 @@ import android.view.ViewGroup;
*/ */
@SuppressWarnings({"unused", "deprecation"}) @SuppressWarnings({"unused", "deprecation"})
public class NoTitlePreferenceCategory extends PreferenceCategory { public class NoTitlePreferenceCategory extends PreferenceCategory {
public NoTitlePreferenceCategory(Context context, AttributeSet attrs) { public NoTitlePreferenceCategory(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
} }
@ -27,8 +28,27 @@ public class NoTitlePreferenceCategory extends PreferenceCategory {
@Override @Override
@SuppressLint("MissingSuperCall") @SuppressLint("MissingSuperCall")
protected View onCreateView(ViewGroup parent) { protected View onCreateView(ViewGroup parent) {
// Return an empty, zero-height view to eliminate spacing // Return an zero-height view to eliminate empty title space.
return new View(getContext()); return new View(getContext());
} }
@Override
public CharSequence getTitle() {
// Title can be used for sorting. Return the first sub preference title.
if (getPreferenceCount() > 0) {
return getPreference(0).getTitle();
}
return super.getTitle();
}
@Override
public int getTitleRes() {
if (getPreferenceCount() > 0) {
return getPreference(0).getTitleRes();
}
return super.getTitleRes();
}
} }

View File

@ -76,9 +76,7 @@ val spoofAppVersionPatch = bytecodePatch(
// Group the switch and list preference together, since General menu is sorted by name // Group the switch and list preference together, since General menu is sorted by name
// and the preferences can be scattered apart with non English langauges. // and the preferences can be scattered apart with non English langauges.
PreferenceCategory( PreferenceCategory(
key = null, titleKey = null,
// The title does not show, but is used for sorting the group.
titleKey = "revanced_spoof_app_version_title",
sorting = Sorting.UNSORTED, sorting = Sorting.UNSORTED,
tag = "app.revanced.extension.shared.settings.preference.NoTitlePreferenceCategory", tag = "app.revanced.extension.shared.settings.preference.NoTitlePreferenceCategory",
preferences = setOf( preferences = setOf(

View File

@ -101,8 +101,7 @@ val themePatch = bytecodePatch(
PreferenceScreen.SEEKBAR.addPreferences( PreferenceScreen.SEEKBAR.addPreferences(
PreferenceCategory( PreferenceCategory(
// Title is hidden, but is used for sorting the group. titleKey = null,
titleKey = "revanced_seekbar_custom_color_title",
sorting = Sorting.UNSORTED, sorting = Sorting.UNSORTED,
tag = "app.revanced.extension.shared.settings.preference.NoTitlePreferenceCategory", tag = "app.revanced.extension.shared.settings.preference.NoTitlePreferenceCategory",
preferences = preferences preferences = preferences