Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,8 @@ class ImageAdapter(
val selectedIndex: Int =
if (showAlreadyActionedImages) {
ImageHelper.getIndex(selectedImages, image)

// Getting selected index when switch is off
} else if (actionableImagesMap.size > position) {
ImageHelper
.getIndex(selectedImages, ArrayList(actionableImagesMap.values)[position])

// For any other case return -1
ImageHelper.getIndex(selectedImages, ArrayList(actionableImagesMap.values)[position])
} else {
-1
}
Expand Down Expand Up @@ -204,8 +199,6 @@ class ImageAdapter(
uploadingContributionList
)
_isLoadingImages.value = false
// If the position is already visited, that means the image is already present
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR removes a lot of comments here and below, is that intended?

By the way it seems to be working, I will test more tomorrow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologize for the confusion regarding the removed comments in the PR. The removal was unintentional and likely occurred during code cleanup to focus on the core fix for issue #6409. I’ve added the comments back to maintain clarity and documentation as per the original code. The changes still address the deselection issue by ensuring the UI updates correctly via the listener. Please let me know if there’s anything else I should adjust!

// inside map, so it will fetch the image from the map and load in the holder
} else {
val actionableImages: List<Image> = ArrayList(actionableImagesMap.values)
if (actionableImages.size > position) {
Expand All @@ -217,9 +210,6 @@ class ImageAdapter(
.into(holder.image)
}
}

// If switch is turned off, it just fetches the image from all images without any
// further operations
} else {
Glide
.with(holder.image)
Expand Down Expand Up @@ -263,10 +253,6 @@ class ImageAdapter(
// finding next actionable image will start from this position
if (next > -1) {
nextImagePosition = next + 1

// If map doesn't contains the next actionable image, that means it's a
// new actionable image, it will put it to the map as actionable images
// and it will load the new image in the view holder
if (!actionableImagesMap.containsKey(next)) {
actionableImagesMap[next] = allImages[next]
alreadyAddedPositions.add(imagePositionAsPerIncreasingOrder)
Expand All @@ -280,9 +266,6 @@ class ImageAdapter(
notifyItemInserted(position)
notifyItemRangeChanged(position, itemCount + 1)
}

// If next actionable image is not found, that means searching is
// complete till end, and it will stop searching.
} else {
reachedEndOfFolder = true
notifyItemRemoved(position)
Expand Down Expand Up @@ -348,6 +331,8 @@ class ImageAdapter(
numberOfSelectedImagesMarkedAsNotForUpload--
}
notifyItemChanged(position, ImageUnselected())
// Notify listener of deselection to update UI
imageSelectListener.onSelectedImagesChanged(selectedImages, numberOfSelectedImagesMarkedAsNotForUpload)
} else {
val image = images[position]
scope.launch(ioDispatcher) {
Expand All @@ -373,7 +358,6 @@ class ImageAdapter(
}
selectedImages.add(image)
notifyItemChanged(position, ImageSelectedOrUpdated())

imageSelectListener.onSelectedImagesChanged(selectedImages, numberOfSelectedImagesMarkedAsNotForUpload)
}
}
Expand Down Expand Up @@ -455,7 +439,6 @@ class ImageAdapter(
} else {
val iterator = actionableImagesMap.entries.iterator()
var index = 0

while (iterator.hasNext()) {
val entry = iterator.next()
if (entry.value == image) {
Expand Down Expand Up @@ -483,17 +466,10 @@ class ImageAdapter(
val showAlreadyActionedImages =
sharedPreferences.getBoolean(SHOW_ALREADY_ACTIONED_IMAGES_PREFERENCE_KEY, true)

// While switch is on initializes the holder with all images size
return if (showAlreadyActionedImages) {
allImages.size

// While switch is off and searching for next actionable has ended, initializes the holder
// with size of all actionable images
} else if (actionableImagesMap.size == allImages.size || reachedEndOfFolder) {
actionableImagesMap.size

// While switch is off, initializes the holder with and extra view holder so that finding
// and addition of the next actionable image in the adapter can be continued
} else {
actionableImagesMap.size + 1
}
Expand Down Expand Up @@ -632,4 +608,4 @@ class ImageAdapter(
fun setSingleSelection(single: Boolean) {
singleSelection = single
}
}
}