mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +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 | 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 | ||||||
|  | @ -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) | ||||||
|                             } |                             } | ||||||
|                         }, |                         }, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alex Gailis
						Alex Gailis