mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	fix: fixed the Congratulation message being shown for a brief moment while switching off the switch
This commit is contained in:
		
							parent
							
								
									e95cd14321
								
							
						
					
					
						commit
						7442ec2a38
					
				
					 2 changed files with 21 additions and 7 deletions
				
			
		|  | @ -110,6 +110,12 @@ class ImageAdapter( | ||||||
|     private val _currentImagesCount = MutableStateFlow(0) |     private val _currentImagesCount = MutableStateFlow(0) | ||||||
|     val currentImagesCount = _currentImagesCount |     val currentImagesCount = _currentImagesCount | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Stores whether images are being loaded or not | ||||||
|  |      */ | ||||||
|  |     private val _isLoadingImages = MutableStateFlow(false) | ||||||
|  |     val isLoadingImages = _isLoadingImages | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * Coroutine Dispatchers and Scope. |      * Coroutine Dispatchers and Scope. | ||||||
|      */ |      */ | ||||||
|  | @ -191,8 +197,12 @@ class ImageAdapter( | ||||||
|                     // If the position is not already visited, that means the position is new then |                     // If the position is not already visited, that means the position is new then | ||||||
|                     // finds the next actionable image position from all images |                     // finds the next actionable image position from all images | ||||||
|                     if (!alreadyAddedPositions.contains(position)) { |                     if (!alreadyAddedPositions.contains(position)) { | ||||||
|                         processThumbnailForActionedImage(holder, position, uploadingContributionList) |                         processThumbnailForActionedImage( | ||||||
| 
 |                             holder, | ||||||
|  |                             position, | ||||||
|  |                             uploadingContributionList | ||||||
|  |                         ) | ||||||
|  |                         _isLoadingImages.value = false | ||||||
|                         // If the position is already visited, that means the image is already present |                         // If the position is already visited, that means the image is already present | ||||||
|                         // inside map, so it will fetch the image from the map and load in the holder |                         // inside map, so it will fetch the image from the map and load in the holder | ||||||
|                     } else { |                     } else { | ||||||
|  | @ -238,6 +248,7 @@ class ImageAdapter( | ||||||
|         position: Int, |         position: Int, | ||||||
|         uploadingContributionList: List<Contribution>, |         uploadingContributionList: List<Contribution>, | ||||||
|     ) { |     ) { | ||||||
|  |         _isLoadingImages.value = true | ||||||
|         val next = |         val next = | ||||||
|             imageLoader.nextActionableImage( |             imageLoader.nextActionableImage( | ||||||
|                 allImages, |                 allImages, | ||||||
|  | @ -275,6 +286,7 @@ class ImageAdapter( | ||||||
|             reachedEndOfFolder = true |             reachedEndOfFolder = true | ||||||
|             notifyItemRemoved(position) |             notifyItemRemoved(position) | ||||||
|         } |         } | ||||||
|  |         _isLoadingImages.value = false | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | @ -380,6 +392,7 @@ class ImageAdapter( | ||||||
|         emptyMap: TreeMap<Int, Image>, |         emptyMap: TreeMap<Int, Image>, | ||||||
|         uploadedImages: List<Contribution> = ArrayList(), |         uploadedImages: List<Contribution> = ArrayList(), | ||||||
|     ) { |     ) { | ||||||
|  |         _isLoadingImages.value = true | ||||||
|         allImages = fixedImages |         allImages = fixedImages | ||||||
|         val oldImageList: ArrayList<Image> = images |         val oldImageList: ArrayList<Image> = images | ||||||
|         val newImageList: ArrayList<Image> = ArrayList(newImages) |         val newImageList: ArrayList<Image> = ArrayList(newImages) | ||||||
|  |  | ||||||
|  | @ -258,12 +258,13 @@ class ImageFragment : | ||||||
|             repeatOnLifecycle(Lifecycle.State.STARTED) { |             repeatOnLifecycle(Lifecycle.State.STARTED) { | ||||||
|                 combine( |                 combine( | ||||||
|                     imageAdapter.currentImagesCount, |                     imageAdapter.currentImagesCount, | ||||||
|                     switchState |                     switchState, | ||||||
|                 ) { imageCount, isChecked -> |                     imageAdapter.isLoadingImages | ||||||
|                     imageCount to isChecked |                 ) { imageCount, isChecked, isLoadingImages -> | ||||||
|                 }.collect { (imageCount, isChecked) -> |                     Triple(imageCount, isChecked, isLoadingImages) | ||||||
|  |                 }.collect { (imageCount, isChecked, isLoadingImages) -> | ||||||
|                     binding?.allImagesUploadedOrMarked?.isVisible = |                     binding?.allImagesUploadedOrMarked?.isVisible = | ||||||
|                         !isChecked && imageCount == 0 && (switch?.isVisible == true) |                         !isLoadingImages && !isChecked && imageCount == 0 && (switch?.isVisible == true) | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 yuvraj-coder1
						yuvraj-coder1