diff --git a/app/build.gradle b/app/build.gradle
index f85ce610a2..6c46ff9077 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 26
targetSdkVersion 34
- versionCode 2228
- versionName "0.22.28"
+ versionCode 2229
+ versionName "0.22.29"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
diff --git a/app/src/main/java/org/ole/planet/myplanet/base/BaseRecyclerFragment.kt b/app/src/main/java/org/ole/planet/myplanet/base/BaseRecyclerFragment.kt
index ca3a3bb216..04fe1aa864 100644
--- a/app/src/main/java/org/ole/planet/myplanet/base/BaseRecyclerFragment.kt
+++ b/app/src/main/java/org/ole/planet/myplanet/base/BaseRecyclerFragment.kt
@@ -177,25 +177,31 @@ abstract class BaseRecyclerFragment
: BaseRecyclerParentFragment(), On
}
private fun getData(s: String, c: Class): List {
+ if (s.isEmpty()) return mRealm.where(c).findAll()
+
val queryParts = s.split(" ").filterNot { it.isEmpty() }
- return if (s.contains(" ")) {
+ val fieldName = if (c == RealmMyLibrary::class.java) "title" else "courseTitle"
+
+ return if (queryParts.size > 1) {
val data: RealmResults = mRealm.where(c).findAll()
data.filter { item ->
searchAndMatch(item, c, queryParts)
}
} else {
- mRealm.where(c).contains(if (c == RealmMyLibrary::class.java) "title" else "courseTitle", s, Case.INSENSITIVE).findAll()
+ mRealm.where(c)
+ .contains(fieldName, s, Case.INSENSITIVE)
+ .findAll()
}
}
private fun searchAndMatch(item: LI, c: Class, queryParts: List): Boolean {
- val title = if (c.isAssignableFrom(RealmMyLibrary::class.java)) {
- (item as RealmMyLibrary).title
- } else {
- (item as RealmMyCourse).courseTitle
- }
+ val title = when {
+ c.isAssignableFrom(RealmMyLibrary::class.java) -> (item as RealmMyLibrary).title
+ else -> (item as RealmMyCourse).courseTitle
+ }?.lowercase(Locale.getDefault()) ?: return false
+
return queryParts.all { queryPart ->
- title?.lowercase(Locale.getDefault())?.contains(queryPart.lowercase(Locale.getDefault())) == true
+ title.contains(queryPart.lowercase(Locale.getDefault()))
}
}
@@ -206,14 +212,22 @@ abstract class BaseRecyclerFragment : BaseRecyclerParentFragment(), On
} else {
getOurLibrary(model?.id, list)
}
- if (tags.isEmpty()) {
- return list
- }
- val libraries = mutableListOf()
- for (library in list) {
- filter(tags, library, libraries)
+
+ val libraries = if (tags.isNotEmpty()) {
+ val filteredLibraries = mutableListOf()
+ for (library in list) {
+ filter(tags, library, filteredLibraries)
+ }
+ filteredLibraries
+ } else {
+ list
}
- return libraries
+
+ return libraries.sortedWith(compareBy { library ->
+ !library.title?.lowercase()?.startsWith(s.lowercase())!! ?: true
+ }.thenBy { library ->
+ library.title?.lowercase() ?: ""
+ })
}
fun filterCourseByTag(s: String, tags: List): List {