Skip to content

Upload: drop duplicate images and display warning in custom selector#6765

Open
Akul-Tyagi wants to merge 2 commits intocommons-app:mainfrom
Akul-Tyagi:fix/custom-selector-duplicate-warning
Open

Upload: drop duplicate images and display warning in custom selector#6765
Akul-Tyagi wants to merge 2 commits intocommons-app:mainfrom
Akul-Tyagi:fix/custom-selector-duplicate-warning

Conversation

@Akul-Tyagi
Copy link
Contributor

@Akul-Tyagi Akul-Tyagi commented Mar 19, 2026

Fixes #6764

The Problem

In the custom selector flow, selecting duplicate content images (matching SHA1 hashes) silently reduced the number of images passed forward to the upload screen. This caused UX confusion because users would select N images but see fewer in the upload details. Additionally, if users realize they made a mistake, they needed an in place way to correct their selection without entirely leaving the selector flow.

The Solution & Justification

I updated the custom selector's completion flow to:

  • Preserve all selected images, preventing the silent dropping of duplicates.
  • Show a duplicate warning dialog when duplicate content selections are detected.
  • Provide two explicit actions in the dialog:
  • OK: Continues to the upload screen with all selected images.
  • Review selection: Dismisses the dialog and keeps the user on the selector screen to adjust their choices.

This approach is minimal and tightly scoped to the custom selector's done flow. It improves clarity, keeps the behavior explicit, and brings the custom selector's duplicate handling closer to parity with the normal selector.

Alternative Solutions Considered

I considered completely blocking the upload of duplicates directly from the selector. However, I discarded this because the normal selector currently permits duplicate selections, and blocking it here would create an inconsistent experience across the app. A non blocking warning dialog provides the safest, most informative UX.

Testing Performed

  • Compiled and ran the betaDebug variant successfully.

  • Passed targeted unit tests: :app:testBetaDebugUnitTest --tests "fr.free.nrw.commons.customselector.ui.selector.CustomSelectorActivityTest"

  • Passed broader adapter tests: :app:testBetaDebugUnitTest --tests "fr.free.nrw.commons.customselector.ui.selector." --tests "fr.free.nrw.commons.customselector.ui.adapter."

  • Manually verified that the duplicate warning is shown when identical images are selected.

  • Manually verified that tapping "Review selection" dismisses the dialog and retains the current selection state.

  • Manually verified that tapping "OK" proceeds to the upload details screen successfully.

Videos
Before :

Screen_Recording_20260318_082650_Commons.mp4

After :

Screen_Recording_20260321_163221_Commons.mp4

Updated CustomSelectorActivity to prevent silent dropping of duplicate images. Added a warning dialog with a 'Review selection' option to improve UX and maintain parity with the normal selector.
@RitikaPahwa4444
Copy link
Collaborator

We should rather block duplicates from the normal selector as well. I don't think duplicate uploads are helpful. Just a warning that duplicate images would be dropped should suffice.

@github-actions
Copy link

✅ Generated APK variants!

@Akul-Tyagi
Copy link
Contributor Author

Updated this PR as discussed - custom selector now drops duplicates and shows a warning. Kept normal selector out of scope; tracking that separately in Issue #6771 . Ready for review!

@Akul-Tyagi Akul-Tyagi changed the title Upload: preserve duplicate images in custom selector and add warning Upload: drop duplicate images and display warning in custom selector Mar 21, 2026
@RitikaPahwa4444
Copy link
Collaborator

A quick one: when does the custom selector decide to drop the duplicates? Could you point me to that logic in the existing code base?

@Akul-Tyagi
Copy link
Contributor Author

The duplicate dropping happens inside the onDone() flow in CustomSelectorActivity.kt.
The original code used distinctBy on the SHA1 hash to silently filter the selected images before passing them to finishPickImages():

val uniqueImages = selectedImages.distinctBy { image ->
CustomSelectorUtils.getImageSHA1(image.uri, ioDispatcher, fileUtilsWrapper, contentResolver)
}

My change preserves the same SHA1-based deduplication logic but replaces the silent distinctBy with an explicit loop that tracks seen hashes, so we can also detect whether any duplicates were present.

If they were, we show the warning dialog first before calling finishPickImages() with the deduplicated list.
If there are no duplicates, we call finishPickImages() directly - no dialog, no change in behavior.

So the actual dedup key and mechanism is unchanged - only the user visibility of the drop is new.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Custom selector silently drops duplicate content images

2 participants