mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-30 22:34:02 +01:00
Merge pull request #1 from zihanpan/issue-5872-fix-search-error
Issue 5872 fix search error
This commit is contained in:
commit
a99e20f8bb
1 changed files with 20 additions and 7 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.upload.categories
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.text.TextUtils
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
|
|
@ -53,6 +54,7 @@ class CategoriesPresenter
|
|||
@Inject
|
||||
lateinit var categoryEditHelper: CategoryEditHelper
|
||||
|
||||
@SuppressLint("TimberArgCount")
|
||||
override fun onAttachView(view: CategoriesContract.View) {
|
||||
this.view = view
|
||||
compositeDisposable.add(
|
||||
|
|
@ -68,7 +70,7 @@ class CategoriesPresenter
|
|||
{
|
||||
setCategoryListValue(it)
|
||||
view.showProgress(false)
|
||||
if (it.isEmpty()) {
|
||||
if (it.isEmpty() && !isInitialLoad) {
|
||||
view.showError(R.string.no_categories_found)
|
||||
}
|
||||
},
|
||||
|
|
@ -81,6 +83,9 @@ class CategoriesPresenter
|
|||
)
|
||||
}
|
||||
|
||||
private var isInitialLoad = true //avoid initial empty content of edittext lead to showError
|
||||
|
||||
|
||||
/**
|
||||
* If media is null : Fetches categories from server according to the term
|
||||
* Else : Fetches existing categories by their name, fetches categories from server according
|
||||
|
|
@ -94,7 +99,7 @@ class CategoriesPresenter
|
|||
.map {
|
||||
it.filter { categoryItem ->
|
||||
!repository.isSpammyCategory(categoryItem.name) ||
|
||||
categoryItem.name == term
|
||||
categoryItem.name == term
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -114,7 +119,7 @@ class CategoriesPresenter
|
|||
.map {
|
||||
it.filter { categoryItem ->
|
||||
!repository.isSpammyCategory(categoryItem.name) ||
|
||||
categoryItem.name == term
|
||||
categoryItem.name == term
|
||||
}
|
||||
}.map { it.filterNot { categoryItem -> categoryItem.thumbnail == "hidden" } }
|
||||
}
|
||||
|
|
@ -123,6 +128,7 @@ class CategoriesPresenter
|
|||
override fun onDetachView() {
|
||||
view = DUMMY
|
||||
compositeDisposable.clear()
|
||||
isInitialLoad = true
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -130,6 +136,13 @@ class CategoriesPresenter
|
|||
* @param query
|
||||
*/
|
||||
override fun searchForCategories(query: String) {
|
||||
if (query.isBlank()) {
|
||||
if (!isInitialLoad) {
|
||||
view.showError(R.string.no_categories_found)
|
||||
}
|
||||
return
|
||||
}
|
||||
isInitialLoad = false
|
||||
searchTerms.onNext(query)
|
||||
}
|
||||
|
||||
|
|
@ -187,7 +200,7 @@ class CategoriesPresenter
|
|||
{
|
||||
setCategoryListValue(it)
|
||||
view.showProgress(false)
|
||||
if (it.isEmpty()) {
|
||||
if (it.isEmpty() && !isInitialLoad) {
|
||||
view.showError(R.string.no_categories_found)
|
||||
}
|
||||
},
|
||||
|
|
@ -223,9 +236,9 @@ class CategoriesPresenter
|
|||
) {
|
||||
val selectedCategories: MutableList<String> =
|
||||
(
|
||||
repository.selectedCategories.map { it.name }.toMutableList() +
|
||||
repository.selectedExistingCategories
|
||||
).toMutableList()
|
||||
repository.selectedCategories.map { it.name }.toMutableList() +
|
||||
repository.selectedExistingCategories
|
||||
).toMutableList()
|
||||
|
||||
if (selectedCategories.isNotEmpty()) {
|
||||
view.showProgressDialog()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue