fix: fixed the Congratulation message being shown for a brief moment while switching off the switch

This commit is contained in:
yuvraj-coder1 2025-01-09 02:05:39 +05:30
parent e95cd14321
commit 7442ec2a38
2 changed files with 21 additions and 7 deletions

View file

@ -110,6 +110,12 @@ class ImageAdapter(
private val _currentImagesCount = MutableStateFlow(0)
val currentImagesCount = _currentImagesCount
/**
* Stores whether images are being loaded or not
*/
private val _isLoadingImages = MutableStateFlow(false)
val isLoadingImages = _isLoadingImages
/**
* Coroutine Dispatchers and Scope.
*/
@ -191,8 +197,12 @@ class ImageAdapter(
// If the position is not already visited, that means the position is new then
// finds the next actionable image position from all images
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
// inside map, so it will fetch the image from the map and load in the holder
} else {
@ -238,6 +248,7 @@ class ImageAdapter(
position: Int,
uploadingContributionList: List<Contribution>,
) {
_isLoadingImages.value = true
val next =
imageLoader.nextActionableImage(
allImages,
@ -275,6 +286,7 @@ class ImageAdapter(
reachedEndOfFolder = true
notifyItemRemoved(position)
}
_isLoadingImages.value = false
}
/**
@ -380,6 +392,7 @@ class ImageAdapter(
emptyMap: TreeMap<Int, Image>,
uploadedImages: List<Contribution> = ArrayList(),
) {
_isLoadingImages.value = true
allImages = fixedImages
val oldImageList: ArrayList<Image> = images
val newImageList: ArrayList<Image> = ArrayList(newImages)

View file

@ -258,12 +258,13 @@ class ImageFragment :
repeatOnLifecycle(Lifecycle.State.STARTED) {
combine(
imageAdapter.currentImagesCount,
switchState
) { imageCount, isChecked ->
imageCount to isChecked
}.collect { (imageCount, isChecked) ->
switchState,
imageAdapter.isLoadingImages
) { imageCount, isChecked, isLoadingImages ->
Triple(imageCount, isChecked, isLoadingImages)
}.collect { (imageCount, isChecked, isLoadingImages) ->
binding?.allImagesUploadedOrMarked?.isVisible =
!isChecked && imageCount == 0 && (switch?.isVisible == true)
!isLoadingImages && !isChecked && imageCount == 0 && (switch?.isVisible == true)
}
}
}