mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	Fix categories searching problem of photo uploading
This commit is contained in:
		
							parent
							
								
									63f1ed8a2d
								
							
						
					
					
						commit
						1e31497f10
					
				
					 1 changed files with 291 additions and 276 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) | ||||
|                         } | ||||
|                     }, | ||||
|  | @ -79,8 +81,13 @@ class CategoriesPresenter | |||
|                     }, | ||||
|                 ), | ||||
|         ) | ||||
| 
 | ||||
|         //isInitialLoad = false | ||||
|     } | ||||
| 
 | ||||
|     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 | ||||
|  | @ -123,6 +130,7 @@ class CategoriesPresenter | |||
|     override fun onDetachView() { | ||||
|         view = DUMMY | ||||
|         compositeDisposable.clear() | ||||
|         isInitialLoad = true | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | @ -130,6 +138,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 +202,7 @@ class CategoriesPresenter | |||
|                     { | ||||
|                         setCategoryListValue(it) | ||||
|                         view.showProgress(false) | ||||
|                             if (it.isEmpty()) { | ||||
|                         if (it.isEmpty() && !isInitialLoad) { | ||||
|                             view.showError(R.string.no_categories_found) | ||||
|                         } | ||||
|                     }, | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Zihan Pan
						Zihan Pan