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