fix(YouTube): Sort settings alphabetically despite punctuation (#3097)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
LisoUseInAIKyrios 2023-10-08 05:25:27 +04:00 committed by GitHub
parent 6e77812382
commit 46e3c97d24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 7 deletions

View file

@ -41,3 +41,8 @@ internal fun <T> Element.addDefault(default: T) {
)
}
}
internal fun CharSequence.removePunctuation(): String {
val punctuation = "\\p{P}+".toRegex()
return this.replace(punctuation, "")
}

View file

@ -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() }
)
}

View file

@ -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")
),

View file

@ -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 = [

View file

@ -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")
)