mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +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 | 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 | ||||||
|  | @ -27,12 +28,12 @@ import javax.inject.Singleton | ||||||
|  */ |  */ | ||||||
| @Singleton | @Singleton | ||||||
| class CategoriesPresenter | class CategoriesPresenter | ||||||
|     @Inject | @Inject | ||||||
|     constructor( | constructor( | ||||||
|     private val repository: UploadRepository, |     private val repository: UploadRepository, | ||||||
|     @param:Named(CommonsApplicationModule.IO_THREAD) private val ioScheduler: Scheduler, |     @param:Named(CommonsApplicationModule.IO_THREAD) private val ioScheduler: Scheduler, | ||||||
|     @param:Named(CommonsApplicationModule.MAIN_THREAD) private val mainThreadScheduler: Scheduler, |     @param:Named(CommonsApplicationModule.MAIN_THREAD) private val mainThreadScheduler: Scheduler, | ||||||
|     ) : CategoriesContract.UserActionListener { | ) : CategoriesContract.UserActionListener { | ||||||
|     companion object { |     companion object { | ||||||
|         private val DUMMY: CategoriesContract.View = proxy() |         private val DUMMY: CategoriesContract.View = proxy() | ||||||
|     } |     } | ||||||
|  | @ -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) | ||||||
|                         } |                         } | ||||||
|                     }, |                     }, | ||||||
|  | @ -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 |      * 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 +130,7 @@ class CategoriesPresenter | ||||||
|     override fun onDetachView() { |     override fun onDetachView() { | ||||||
|         view = DUMMY |         view = DUMMY | ||||||
|         compositeDisposable.clear() |         compositeDisposable.clear() | ||||||
|  |         isInitialLoad = true | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | @ -130,6 +138,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 +202,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) | ||||||
|                         } |                         } | ||||||
|                     }, |                     }, | ||||||
|  | @ -311,4 +326,4 @@ class CategoriesPresenter | ||||||
|                 .subscribe(::selectNewCategories), |                 .subscribe(::selectNewCategories), | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
|     } | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Zihan Pan
						Zihan Pan