From 46e3c97d24e282e4d7d444603af4fb475ae03315 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sun, 8 Oct 2023 05:25:27 +0400 Subject: [PATCH] fix(YouTube): Sort settings alphabetically despite punctuation (#3097) Co-authored-by: oSumAtrIX --- .../shared/settings/preference/ComponentsExtensions.kt | 5 +++++ .../shared/settings/util/AbstractPreferenceScreen.kt | 7 ++++--- .../layout/hide/general/HideLayoutComponentsPatch.kt | 4 ++-- .../layout/hide/loadmorebutton/HideLoadMoreButtonPatch.kt | 2 +- .../hide/loadmorebutton/HideLoadMoreButtonResourcePatch.kt | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/shared/settings/preference/ComponentsExtensions.kt b/src/main/kotlin/app/revanced/patches/shared/settings/preference/ComponentsExtensions.kt index 21207188..7e13127f 100644 --- a/src/main/kotlin/app/revanced/patches/shared/settings/preference/ComponentsExtensions.kt +++ b/src/main/kotlin/app/revanced/patches/shared/settings/preference/ComponentsExtensions.kt @@ -40,4 +40,9 @@ internal fun Element.addDefault(default: T) { } ) } +} + +internal fun CharSequence.removePunctuation(): String { + val punctuation = "\\p{P}+".toRegex() + return this.replace(punctuation, "") } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/settings/util/AbstractPreferenceScreen.kt b/src/main/kotlin/app/revanced/patches/shared/settings/util/AbstractPreferenceScreen.kt index 30402f5a..1c38980b 100644 --- a/src/main/kotlin/app/revanced/patches/shared/settings/util/AbstractPreferenceScreen.kt +++ b/src/main/kotlin/app/revanced/patches/shared/settings/util/AbstractPreferenceScreen.kt @@ -4,6 +4,7 @@ import app.revanced.patches.shared.settings.preference.BasePreference import app.revanced.patches.shared.settings.preference.impl.PreferenceCategory import app.revanced.patches.shared.settings.preference.impl.PreferenceScreen import app.revanced.patches.shared.settings.preference.impl.StringResource +import app.revanced.patches.shared.settings.preference.removePunctuation import java.io.Closeable abstract class AbstractPreferenceScreen( @@ -35,8 +36,8 @@ abstract class AbstractPreferenceScreen( return PreferenceScreen( key, StringResource("${key}_title", title), - preferences.sortedBy { it.title.value.lowercase() } + - categories.sortedBy { it.title.lowercase() }.map { it.transform() }, + preferences.sortedBy { it.title.value.removePunctuation().lowercase() } + + categories.sortedBy { it.title.removePunctuation().lowercase() }.map { it.transform() }, summary?.let { summary -> StringResource("${key}_summary", summary) } @@ -63,7 +64,7 @@ abstract class AbstractPreferenceScreen( return PreferenceCategory( key, StringResource("${key}_title", title), - preferences.sortedBy { it.title.value.lowercase() } + preferences.sortedBy { it.title.value.removePunctuation().lowercase() } ) } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt index d88ad6cd..2199142c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt @@ -53,14 +53,14 @@ object HideLayoutComponentsPatch : BytecodePatch( ), SwitchPreference( "revanced_hide_join_membership_button", - StringResource("revanced_hide_join_membership_button_title", "Hide \"Join\" button"), + StringResource("revanced_hide_join_membership_button_title", "Hide \\\'Join\\\' button"), StringResource("revanced_hide_join_membership_button_summary_on", "Button is hidden"), StringResource("revanced_hide_join_membership_button_summary_off", "Button is shown") ), SwitchPreference( "revanced_hide_notify_me_button", - StringResource("revanced_hide_notify_me_button_title", "Hide \"Notify me\" button"), + StringResource("revanced_hide_notify_me_button_title", "Hide \\\'Notify me\\\' button"), StringResource("revanced_hide_notify_me_button_summary_on", "Button is hidden"), StringResource("revanced_hide_notify_me_button_summary_off", "Button is shown") ), diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/loadmorebutton/HideLoadMoreButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/loadmorebutton/HideLoadMoreButtonPatch.kt index 83321ce0..d9a0278e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/loadmorebutton/HideLoadMoreButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/loadmorebutton/HideLoadMoreButtonPatch.kt @@ -11,7 +11,7 @@ import app.revanced.patches.youtube.layout.hide.loadmorebutton.fingerprints.Hide import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch( - name = "Hide \"Load more\" button", + name = "Hide \'Load more\' button", description = "Hides the button under videos that loads similar videos.", dependencies = [HideLoadMoreButtonResourcePatch::class], compatiblePackages = [ diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/loadmorebutton/HideLoadMoreButtonResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/loadmorebutton/HideLoadMoreButtonResourcePatch.kt index ae2e7a8e..65f733af 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/loadmorebutton/HideLoadMoreButtonResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/loadmorebutton/HideLoadMoreButtonResourcePatch.kt @@ -21,7 +21,7 @@ object HideLoadMoreButtonResourcePatch : ResourcePatch() { SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( SwitchPreference( "revanced_hide_load_more_button", - StringResource("revanced_hide_load_more_button_title", "Hide \"Load More\" button"), + StringResource("revanced_hide_load_more_button_title", "Hide \\\'Load More\\\' button"), StringResource("revanced_hide_load_more_button_summary_on", "Button is hidden"), StringResource("revanced_hide_load_more_button_summary_off", "Button is shown") )