Skip to content

Commit b18117b

Browse files
Resolved Problems in UploadMediaDetails flow and UX commons-app#5511 (commons-app#5527)
* Fixed arrow flickering issue on zoom * Resolved issue point 1 and 3 * Resolved issue point 2 * Minor changes * Update UploadActivity.java --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
1 parent a308a1c commit b18117b

File tree

5 files changed

+96
-35
lines changed

5 files changed

+96
-35
lines changed

app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.java

+31
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import fr.free.nrw.commons.contributions.MainActivity;
4949
import fr.free.nrw.commons.filepicker.Constants.RequestCodes;
5050
import fr.free.nrw.commons.filepicker.UploadableFile;
51+
import fr.free.nrw.commons.kvstore.BasicKvStore;
5152
import fr.free.nrw.commons.kvstore.JsonKvStore;
5253
import fr.free.nrw.commons.location.LatLng;
5354
import fr.free.nrw.commons.location.LocationPermissionsHelper;
@@ -329,6 +330,8 @@ public void checkStoragePermissions() {
329330

330331
@Override
331332
protected void onStop() {
333+
// Resetting setImageCancelled to false
334+
setImageCancelled(false);
332335
super.onStop();
333336
}
334337

@@ -711,6 +714,34 @@ private boolean isLocationTagUncheckedInTheSettings() {
711714
return true;
712715
}
713716

717+
/**
718+
* Changes current image when one image upload is cancelled, to highlight next image in the top thumbnail.
719+
* Fixes: <a href="https://github.com/commons-app/apps-android-commons/issues/5511">Issue</a>
720+
*
721+
* @param index Index of image to be removed
722+
* @param maxSize Max size of the {@code uploadableFiles}
723+
*/
724+
@Override
725+
public void highlightNextImageOnCancelledImage(int index, int maxSize) {
726+
if (vpUpload != null && index < (maxSize)) {
727+
vpUpload.setCurrentItem(index + 1, false);
728+
vpUpload.setCurrentItem(index, false);
729+
}
730+
}
731+
732+
/**
733+
* Used to check if user has cancelled upload of any image in current upload
734+
* so that location compare doesn't show up again in same upload.
735+
* Fixes: <a href="https://github.com/commons-app/apps-android-commons/issues/5511">Issue</a>
736+
*
737+
* @param isCancelled Is true when user has cancelled upload of any image in current upload
738+
*/
739+
@Override
740+
public void setImageCancelled(boolean isCancelled) {
741+
BasicKvStore basicKvStore = new BasicKvStore(this,"IsAnyImageCancelled");
742+
basicKvStore.putBoolean("IsAnyImageCancelled", isCancelled);
743+
}
744+
714745
/**
715746
* Calculate the difference between current location and
716747
* location recorded before capturing the image

app/src/main/java/fr/free/nrw/commons/upload/UploadContract.java

+18
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ public interface View {
2020

2121
void askUserToLogIn();
2222

23+
/**
24+
* Changes current image when one image upload is cancelled, to highlight next image in the top thumbnail.
25+
* Fixes: <a href="https://github.com/commons-app/apps-android-commons/issues/5511">Issue</a>
26+
*
27+
* @param index Index of image to be removed
28+
* @param maxSize Max size of the {@code uploadableFiles}
29+
*/
30+
void highlightNextImageOnCancelledImage(int index, int maxSize);
31+
32+
/**
33+
* Used to check if user has cancelled upload of any image in current upload
34+
* so that location compare doesn't show up again in same upload.
35+
* Fixes: <a href="https://github.com/commons-app/apps-android-commons/issues/5511">Issue</a>
36+
*
37+
* @param isCancelled Is true when user has cancelled upload of any image in current upload
38+
*/
39+
void setImageCancelled(boolean isCancelled);
40+
2341
void showProgress(boolean shouldShow);
2442

2543
void showMessage(int messageResourceId);

app/src/main/java/fr/free/nrw/commons/upload/UploadPresenter.java

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public void deletePictureAtIndex(int index) {
141141
if (index == uploadableFiles.size() - 1) {//If the next fragment to be shown is not one of the MediaDetailsFragment, lets hide the top card
142142
view.showHideTopCard(false);
143143
}
144+
view.setImageCancelled(true);
144145
repository.deletePicture(uploadableFiles.get(index).getFilePath());
145146
if (uploadableFiles.size() == 1) {
146147
view.showMessage(R.string.upload_cancelled);
@@ -155,6 +156,7 @@ public void deletePictureAtIndex(int index) {
155156

156157
//In case lets update the number of uploadable media
157158
view.updateTopCardTitle();
159+
view.highlightNextImageOnCancelledImage(index, uploadableFiles.size());
158160

159161
}
160162

app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.java

+40-27
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import fr.free.nrw.commons.edit.EditActivity;
3737
import fr.free.nrw.commons.contributions.MainActivity;
3838
import fr.free.nrw.commons.filepicker.UploadableFile;
39+
import fr.free.nrw.commons.kvstore.BasicKvStore;
3940
import fr.free.nrw.commons.kvstore.JsonKvStore;
4041
import fr.free.nrw.commons.location.LatLng;
4142
import fr.free.nrw.commons.nearby.Place;
@@ -251,7 +252,10 @@ private void attachImageViewScaleChangeListener() {
251252
photoViewBackgroundImage.setOnScaleChangeListener(
252253
(scaleFactor, focusX, focusY) -> {
253254
//Whenever the uses plays with the image, lets collapse the media detail container
254-
expandCollapseLlMediaDetail(false);
255+
//only if it is not already collapsed, which resolves flickering of arrow
256+
if (isExpanded) {
257+
expandCollapseLlMediaDetail(false);
258+
}
255259
});
256260
}
257261

@@ -306,31 +310,35 @@ public void onEditButtonClicked() {
306310
@Override
307311
public void showSimilarImageFragment(String originalFilePath, String possibleFilePath,
308312
ImageCoordinates similarImageCoordinates) {
309-
SimilarImageDialogFragment newFragment = new SimilarImageDialogFragment();
310-
newFragment.setCallback(new SimilarImageDialogFragment.Callback() {
311-
@Override
312-
public void onPositiveResponse() {
313-
Timber.d("positive response from similar image fragment");
314-
presenter.useSimilarPictureCoordinates(similarImageCoordinates, callback.getIndexInViewFlipper(UploadMediaDetailFragment.this));
315-
316-
// set the description text when user selects to use coordinate from the other image
317-
// which was taken within 20s
318-
// fixing: https://github.com/commons-app/apps-android-commons/issues/4700
319-
uploadMediaDetailAdapter.getItems().get(0).setDescriptionText(
320-
getString(R.string.similar_coordinate_description_auto_set));
321-
updateMediaDetails(uploadMediaDetailAdapter.getItems());
322-
}
313+
BasicKvStore basicKvStore = new BasicKvStore(getActivity(), "IsAnyImageCancelled");
314+
if (!basicKvStore.getBoolean("IsAnyImageCancelled", false)) {
315+
SimilarImageDialogFragment newFragment = new SimilarImageDialogFragment();
316+
newFragment.setCallback(new SimilarImageDialogFragment.Callback() {
317+
@Override
318+
public void onPositiveResponse() {
319+
Timber.d("positive response from similar image fragment");
320+
presenter.useSimilarPictureCoordinates(similarImageCoordinates,
321+
callback.getIndexInViewFlipper(UploadMediaDetailFragment.this));
322+
323+
// set the description text when user selects to use coordinate from the other image
324+
// which was taken within 120s
325+
// fixing: https://github.com/commons-app/apps-android-commons/issues/4700
326+
uploadMediaDetailAdapter.getItems().get(0).setDescriptionText(
327+
getString(R.string.similar_coordinate_description_auto_set));
328+
updateMediaDetails(uploadMediaDetailAdapter.getItems());
329+
}
323330

324-
@Override
325-
public void onNegativeResponse() {
326-
Timber.d("negative response from similar image fragment");
327-
}
328-
});
329-
Bundle args = new Bundle();
330-
args.putString("originalImagePath", originalFilePath);
331-
args.putString("possibleImagePath", possibleFilePath);
332-
newFragment.setArguments(args);
333-
newFragment.show(getChildFragmentManager(), "dialog");
331+
@Override
332+
public void onNegativeResponse() {
333+
Timber.d("negative response from similar image fragment");
334+
}
335+
});
336+
Bundle args = new Bundle();
337+
args.putString("originalImagePath", originalFilePath);
338+
args.putString("possibleImagePath", possibleFilePath);
339+
newFragment.setArguments(args);
340+
newFragment.show(getChildFragmentManager(), "dialog");
341+
}
334342
}
335343

336344
@Override
@@ -455,7 +463,8 @@ public void showDuplicatePicturePopup(UploadItem uploadItem) {
455463
false);
456464
} else {
457465
uploadItem.setImageQuality(ImageUtils.IMAGE_KEEP);
458-
onNextButtonClicked();
466+
// Calling below, instead of onNextButtonClicked() to not show locationDialog twice
467+
onImageValidationSuccess();
459468
}
460469
}
461470

@@ -478,7 +487,11 @@ public void showBadImagePopup(Integer errorCode,
478487

479488
// validate image only when same file name error does not occur
480489
// show the same file name error if exists.
481-
if ((errorCode & FILE_NAME_EXISTS) == 0) {
490+
// If image with same file name exists check the bit in errorCode is set or not
491+
if ((errorCode & FILE_NAME_EXISTS) != 0) {
492+
Timber.d("Trying to show duplicate picture popup");
493+
showDuplicatePicturePopup(uploadItem);
494+
} else {
482495
uploadItem.setImageQuality(ImageUtils.IMAGE_KEEP);
483496
onImageValidationSuccess();
484497
}

app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaPresenter.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -345,17 +345,14 @@ public void handleBadImage(Integer errorCode,
345345
view.showMessage(R.string.add_caption_toast, R.color.color_error);
346346
}
347347

348-
// If image with same file name exists check the bit in errorCode is set or not
349-
if ((errorCode & FILE_NAME_EXISTS) != 0) {
350-
Timber.d("Trying to show duplicate picture popup");
351-
view.showDuplicatePicturePopup(uploadItem);
352-
}
353-
354-
// If image has some other problems, show popup accordingly
348+
// If image has some problems, show popup accordingly
355349
if (errorCode != EMPTY_CAPTION && errorCode != FILE_NAME_EXISTS) {
356350
view.showBadImagePopup(errorCode, uploadItem);
351+
} else if ((errorCode & FILE_NAME_EXISTS) != 0) {
352+
// When image has duplicate caption problem
353+
Timber.d("Trying to show duplicate picture popup");
354+
view.showDuplicatePicturePopup(uploadItem);
357355
}
358-
359356
}
360357

361358
/**

0 commit comments

Comments
 (0)