Skip to content

Commit a19ae2e

Browse files
authored
Fixes commons-app#5502 UploadMediaDetailFragment.java
1 parent d36e858 commit a19ae2e

File tree

1 file changed

+39
-45
lines changed

1 file changed

+39
-45
lines changed

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

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
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;
4039
import fr.free.nrw.commons.kvstore.JsonKvStore;
4140
import fr.free.nrw.commons.location.LatLng;
4241
import fr.free.nrw.commons.nearby.Place;
@@ -70,6 +69,11 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
7069
private static final int REQUEST_CODE_FOR_EDIT_ACTIVITY = 1212;
7170
private static final int REQUEST_CODE_FOR_VOICE_INPUT = 1213;
7271

72+
/**
73+
* Stores the rotation angle of the image in degrees.
74+
*/
75+
private int rotation = 0;
76+
7377
/**
7478
* A key for applicationKvStore. By this key we can retrieve the location of last UploadItem ex.
7579
* 12.3433,54.78897 from applicationKvStore.
@@ -196,10 +200,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
196200
}
197201

198202
if(savedInstanceState!=null){
199-
if(uploadMediaDetailAdapter.getItems().size()==0){
200-
uploadMediaDetailAdapter.setItems(savedInstanceState.getParcelableArrayList(UPLOAD_MEDIA_DETAILS));
201-
presenter.setUploadMediaDetails(uploadMediaDetailAdapter.getItems(), callback.getIndexInViewFlipper(this));
202-
}
203+
if(uploadMediaDetailAdapter.getItems().size()==0){
204+
uploadMediaDetailAdapter.setItems(savedInstanceState.getParcelableArrayList(UPLOAD_MEDIA_DETAILS));
205+
presenter.setUploadMediaDetails(uploadMediaDetailAdapter.getItems(), callback.getIndexInViewFlipper(this));
206+
}
203207
}
204208

205209
}
@@ -223,7 +227,7 @@ private void init() {
223227

224228
// If the image EXIF data contains the location, show the map icon with a green tick
225229
if (inAppPictureLocation != null ||
226-
(uploadableFile != null && uploadableFile.hasLocation())) {
230+
(uploadableFile != null && uploadableFile.hasLocation())) {
227231
Drawable mapTick = getResources().getDrawable(R.drawable.ic_map_available_20dp);
228232
locationImageView.setImageDrawable(mapTick);
229233
locationTextView.setText(R.string.edit_location);
@@ -252,10 +256,7 @@ private void attachImageViewScaleChangeListener() {
252256
photoViewBackgroundImage.setOnScaleChangeListener(
253257
(scaleFactor, focusX, focusY) -> {
254258
//Whenever the uses plays with the image, lets collapse the media detail container
255-
//only if it is not already collapsed, which resolves flickering of arrow
256-
if (isExpanded) {
257-
expandCollapseLlMediaDetail(false);
258-
}
259+
expandCollapseLlMediaDetail(false);
259260
});
260261
}
261262

@@ -310,35 +311,31 @@ public void onEditButtonClicked() {
310311
@Override
311312
public void showSimilarImageFragment(String originalFilePath, String possibleFilePath,
312313
ImageCoordinates similarImageCoordinates) {
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-
}
314+
SimilarImageDialogFragment newFragment = new SimilarImageDialogFragment();
315+
newFragment.setCallback(new SimilarImageDialogFragment.Callback() {
316+
@Override
317+
public void onPositiveResponse() {
318+
Timber.d("positive response from similar image fragment");
319+
presenter.useSimilarPictureCoordinates(similarImageCoordinates, callback.getIndexInViewFlipper(UploadMediaDetailFragment.this));
320+
321+
// set the description text when user selects to use coordinate from the other image
322+
// which was taken within 20s
323+
// fixing: https://github.com/commons-app/apps-android-commons/issues/4700
324+
uploadMediaDetailAdapter.getItems().get(0).setDescriptionText(
325+
getString(R.string.similar_coordinate_description_auto_set));
326+
updateMediaDetails(uploadMediaDetailAdapter.getItems());
327+
}
330328

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-
}
329+
@Override
330+
public void onNegativeResponse() {
331+
Timber.d("negative response from similar image fragment");
332+
}
333+
});
334+
Bundle args = new Bundle();
335+
args.putString("originalImagePath", originalFilePath);
336+
args.putString("possibleImagePath", possibleFilePath);
337+
newFragment.setArguments(args);
338+
newFragment.show(getChildFragmentManager(), "dialog");
342339
}
343340

344341
@Override
@@ -463,8 +460,7 @@ public void showDuplicatePicturePopup(UploadItem uploadItem) {
463460
false);
464461
} else {
465462
uploadItem.setImageQuality(ImageUtils.IMAGE_KEEP);
466-
// Calling below, instead of onNextButtonClicked() to not show locationDialog twice
467-
onImageValidationSuccess();
463+
onNextButtonClicked();
468464
}
469465
}
470466

@@ -487,11 +483,7 @@ public void showBadImagePopup(Integer errorCode,
487483

488484
// validate image only when same file name error does not occur
489485
// show the same file name error if exists.
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 {
486+
if ((errorCode & FILE_NAME_EXISTS) == 0) {
495487
uploadItem.setImageQuality(ImageUtils.IMAGE_KEEP);
496488
onImageValidationSuccess();
497489
}
@@ -530,6 +522,7 @@ public void showEditActivity(UploadItem uploadItem) {
530522
editableUploadItem = uploadItem;
531523
Intent intent = new Intent(getContext(), EditActivity.class);
532524
intent.putExtra("image", uploadableFile.getFilePath().toString());
525+
intent.putExtra("rotation",rotation);
533526
startActivityForResult(intent, REQUEST_CODE_FOR_EDIT_ACTIVITY);
534527
}
535528

@@ -615,6 +608,7 @@ public void onActivityResult(final int requestCode, final int resultCode,
615608
}
616609
if (requestCode == REQUEST_CODE_FOR_EDIT_ACTIVITY && resultCode == RESULT_OK) {
617610
String result = data.getStringExtra("editedImageFilePath");
611+
rotation = data.getIntExtra("editedImageRotation",0);
618612

619613
if (Objects.equals(result, "Error")) {
620614
Timber.e("Error in rotating image");

0 commit comments

Comments
 (0)