From a6aa11884936df81b7836cd8169e92e3d0bee3c7 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 16 May 2022 10:31:28 +0700 Subject: [PATCH 1/2] Remove accents from search strings --- app/build.gradle | 3 +++ .../foundation/e/blisslauncher/core/Utilities.java | 6 ++++++ .../features/launcher/LauncherActivity.java | 12 +++++++----- .../e/blisslauncher/buildsrc/Dependencies.kt | 4 ++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5133006d1c..910511d7f7 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -159,6 +159,9 @@ dependencies { implementation Libs.AndroidX.Room.runtime kapt Libs.AndroidX.Room.compiler + // Apache Commons + implementation Libs.ApacheCommons.commonsLang + // Unit test dependencies testImplementation Libs.junit testImplementation Libs.robolectric diff --git a/app/src/main/java/foundation/e/blisslauncher/core/Utilities.java b/app/src/main/java/foundation/e/blisslauncher/core/Utilities.java index 51492aa865..60939bd9c5 100755 --- a/app/src/main/java/foundation/e/blisslauncher/core/Utilities.java +++ b/app/src/main/java/foundation/e/blisslauncher/core/Utilities.java @@ -14,6 +14,8 @@ import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; +import org.apache.commons.lang3.StringUtils; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.lang.reflect.Method; @@ -217,4 +219,8 @@ public class Utilities { public static int boundToRange(int value, int lowerBound, int upperBound) { return Math.max(lowerBound, Math.min(value, upperBound)); } + + public static String stripCaseAndAccents(String input) { + return StringUtils.stripAccents(input.toLowerCase()); + } } diff --git a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java index 7d5b99b7a3..4e6bb9f0a8 100755 --- a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java @@ -79,6 +79,8 @@ import androidx.viewpager.widget.ViewPager; import com.jakewharton.rxbinding3.widget.RxTextView; +import org.apache.commons.lang3.StringUtils; + import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; @@ -1595,7 +1597,7 @@ public class LauncherActivity extends AppCompatActivity implements private Observable searchForLauncherItems( CharSequence charSequence) { - String query = charSequence.toString().toLowerCase(); + String query = Utilities.stripCaseAndAccents(charSequence.toString()); SuggestionsResult suggestionsResult = new SuggestionsResult( query); List launcherItems = new ArrayList<>(); @@ -1606,11 +1608,11 @@ public class LauncherActivity extends AppCompatActivity implements if (launcherItem.itemType == Constants.ITEM_TYPE_FOLDER) { FolderItem folderItem = (FolderItem) launcherItem; for (LauncherItem item : folderItem.items) { - if (item.title.toString().toLowerCase().contains(query)) { + if (Utilities.stripCaseAndAccents(item.title.toString()).contains(query)) { launcherItems.add(item); } } - } else if (launcherItem.title.toString().toLowerCase().contains(query)) { + } else if (Utilities.stripCaseAndAccents(launcherItem.title.toString()).contains(query)) { launcherItems.add(launcherItem); } } @@ -1622,11 +1624,11 @@ public class LauncherActivity extends AppCompatActivity implements if (launcherItem.itemType == Constants.ITEM_TYPE_FOLDER) { FolderItem folderItem = (FolderItem) launcherItem; for (LauncherItem item : folderItem.items) { - if (item.title.toString().toLowerCase().contains(query)) { + if (Utilities.stripCaseAndAccents(item.title.toString()).contains(query)) { launcherItems.add(item); } } - } else if (launcherItem.title.toString().toLowerCase().contains(query)) { + } else if (Utilities.stripCaseAndAccents(launcherItem.title.toString()).contains(query)) { launcherItems.add(launcherItem); } } diff --git a/buildSrc/src/main/java/foundation/e/blisslauncher/buildsrc/Dependencies.kt b/buildSrc/src/main/java/foundation/e/blisslauncher/buildsrc/Dependencies.kt index 6160b2b8b7..0ee7c3d5d1 100644 --- a/buildSrc/src/main/java/foundation/e/blisslauncher/buildsrc/Dependencies.kt +++ b/buildSrc/src/main/java/foundation/e/blisslauncher/buildsrc/Dependencies.kt @@ -34,6 +34,10 @@ object Libs { const val robolectric = "org.robolectric:robolectric:${Versions.robolectric}" const val mockK = "io.mockk:mockk:${Versions.mockK}" + object ApacheCommons { + const val commonsLang = "org.apache.commons:commons-lang3:3.12.0" + } + object Google { const val firebaseCore = "com.google.firebase:firebase-core:${Versions.firebase_core}" const val crashlytics = "com.crashlytics.sdk.android:crashlytics:${Versions.crashlytics}" -- GitLab From fb442a74aa7b6359db8304f1319a967238c13d6f Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 16 May 2022 15:28:49 +0700 Subject: [PATCH 2/2] Remove unused import --- .../e/blisslauncher/features/launcher/LauncherActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java index 4e6bb9f0a8..d380d9d5cd 100755 --- a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java @@ -79,7 +79,6 @@ import androidx.viewpager.widget.ViewPager; import com.jakewharton.rxbinding3.widget.RxTextView; -import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.Calendar; -- GitLab