implemented #29: improved search

This commit is contained in:
Josia Pietsch 2024-09-06 14:14:42 +02:00
parent 25905f1116
commit 25483f65ac
Signed by: jrpie
GPG key ID: E70B571D66986A2D

View file

@ -29,6 +29,7 @@ import de.jrpie.android.launcher.openAppSettings
import de.jrpie.android.launcher.transformGrayscale import de.jrpie.android.launcher.transformGrayscale
import de.jrpie.android.launcher.uninstallApp import de.jrpie.android.launcher.uninstallApp
import java.util.* import java.util.*
import kotlin.text.Regex.Companion.escapeReplacement
/** /**
* A [RecyclerView] (efficient scrollable list) containing all apps on the users device. * A [RecyclerView] (efficient scrollable list) containing all apps on the users device.
@ -160,8 +161,17 @@ class AppsRecyclerAdapter(val activity: Activity,
*/ */
fun filter(text: String) { fun filter(text: String) {
// normalize text for search // normalize text for search
var allowedSpecialCharacters = text
.lowercase(Locale.ROOT)
.toCharArray()
.distinct()
.filter { c -> ! ((c in 'a'..'z') || (c in '0'..'9')) }
.map { c -> escapeReplacement(c.toString())}
.fold("") { x,y -> x+y }
var disallowedCharsRegex = "[^a-z0-9$allowedSpecialCharacters]".toRegex()
fun normalize(text: String): String{ fun normalize(text: String): String{
return text.lowercase(Locale.ROOT).replace("[^a-z0-9]".toRegex(), "") return text.lowercase(Locale.ROOT).replace(disallowedCharsRegex, "")
} }
appsListDisplayed.clear() appsListDisplayed.clear()
if (text.isEmpty()) { if (text.isEmpty()) {