Fixes #5502 UploadMediaDetailFragment.java

This commit is contained in:
Kanahia 2024-02-28 22:35:36 +05:30 committed by GitHub
parent d36e858995
commit a19ae2e507
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -36,7 +36,6 @@ import fr.free.nrw.commons.R;
import fr.free.nrw.commons.edit.EditActivity;
import fr.free.nrw.commons.contributions.MainActivity;
import fr.free.nrw.commons.filepicker.UploadableFile;
import fr.free.nrw.commons.kvstore.BasicKvStore;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.nearby.Place;
@ -70,6 +69,11 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
private static final int REQUEST_CODE_FOR_EDIT_ACTIVITY = 1212;
private static final int REQUEST_CODE_FOR_VOICE_INPUT = 1213;
/**
* Stores the rotation angle of the image in degrees.
*/
private int rotation = 0;
/**
* A key for applicationKvStore. By this key we can retrieve the location of last UploadItem ex.
* 12.3433,54.78897 from applicationKvStore.
@ -196,10 +200,10 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
}
if(savedInstanceState!=null){
if(uploadMediaDetailAdapter.getItems().size()==0){
uploadMediaDetailAdapter.setItems(savedInstanceState.getParcelableArrayList(UPLOAD_MEDIA_DETAILS));
presenter.setUploadMediaDetails(uploadMediaDetailAdapter.getItems(), callback.getIndexInViewFlipper(this));
}
if(uploadMediaDetailAdapter.getItems().size()==0){
uploadMediaDetailAdapter.setItems(savedInstanceState.getParcelableArrayList(UPLOAD_MEDIA_DETAILS));
presenter.setUploadMediaDetails(uploadMediaDetailAdapter.getItems(), callback.getIndexInViewFlipper(this));
}
}
}
@ -223,7 +227,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
// If the image EXIF data contains the location, show the map icon with a green tick
if (inAppPictureLocation != null ||
(uploadableFile != null && uploadableFile.hasLocation())) {
(uploadableFile != null && uploadableFile.hasLocation())) {
Drawable mapTick = getResources().getDrawable(R.drawable.ic_map_available_20dp);
locationImageView.setImageDrawable(mapTick);
locationTextView.setText(R.string.edit_location);
@ -252,10 +256,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
photoViewBackgroundImage.setOnScaleChangeListener(
(scaleFactor, focusX, focusY) -> {
//Whenever the uses plays with the image, lets collapse the media detail container
//only if it is not already collapsed, which resolves flickering of arrow
if (isExpanded) {
expandCollapseLlMediaDetail(false);
}
expandCollapseLlMediaDetail(false);
});
}
@ -310,35 +311,31 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
@Override
public void showSimilarImageFragment(String originalFilePath, String possibleFilePath,
ImageCoordinates similarImageCoordinates) {
BasicKvStore basicKvStore = new BasicKvStore(getActivity(), "IsAnyImageCancelled");
if (!basicKvStore.getBoolean("IsAnyImageCancelled", false)) {
SimilarImageDialogFragment newFragment = new SimilarImageDialogFragment();
newFragment.setCallback(new SimilarImageDialogFragment.Callback() {
@Override
public void onPositiveResponse() {
Timber.d("positive response from similar image fragment");
presenter.useSimilarPictureCoordinates(similarImageCoordinates,
callback.getIndexInViewFlipper(UploadMediaDetailFragment.this));
SimilarImageDialogFragment newFragment = new SimilarImageDialogFragment();
newFragment.setCallback(new SimilarImageDialogFragment.Callback() {
@Override
public void onPositiveResponse() {
Timber.d("positive response from similar image fragment");
presenter.useSimilarPictureCoordinates(similarImageCoordinates, callback.getIndexInViewFlipper(UploadMediaDetailFragment.this));
// set the description text when user selects to use coordinate from the other image
// which was taken within 120s
// fixing: https://github.com/commons-app/apps-android-commons/issues/4700
uploadMediaDetailAdapter.getItems().get(0).setDescriptionText(
getString(R.string.similar_coordinate_description_auto_set));
updateMediaDetails(uploadMediaDetailAdapter.getItems());
}
// set the description text when user selects to use coordinate from the other image
// which was taken within 20s
// fixing: https://github.com/commons-app/apps-android-commons/issues/4700
uploadMediaDetailAdapter.getItems().get(0).setDescriptionText(
getString(R.string.similar_coordinate_description_auto_set));
updateMediaDetails(uploadMediaDetailAdapter.getItems());
}
@Override
public void onNegativeResponse() {
Timber.d("negative response from similar image fragment");
}
});
Bundle args = new Bundle();
args.putString("originalImagePath", originalFilePath);
args.putString("possibleImagePath", possibleFilePath);
newFragment.setArguments(args);
newFragment.show(getChildFragmentManager(), "dialog");
}
@Override
public void onNegativeResponse() {
Timber.d("negative response from similar image fragment");
}
});
Bundle args = new Bundle();
args.putString("originalImagePath", originalFilePath);
args.putString("possibleImagePath", possibleFilePath);
newFragment.setArguments(args);
newFragment.show(getChildFragmentManager(), "dialog");
}
@Override
@ -463,8 +460,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
false);
} else {
uploadItem.setImageQuality(ImageUtils.IMAGE_KEEP);
// Calling below, instead of onNextButtonClicked() to not show locationDialog twice
onImageValidationSuccess();
onNextButtonClicked();
}
}
@ -487,11 +483,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
// validate image only when same file name error does not occur
// show the same file name error if exists.
// If image with same file name exists check the bit in errorCode is set or not
if ((errorCode & FILE_NAME_EXISTS) != 0) {
Timber.d("Trying to show duplicate picture popup");
showDuplicatePicturePopup(uploadItem);
} else {
if ((errorCode & FILE_NAME_EXISTS) == 0) {
uploadItem.setImageQuality(ImageUtils.IMAGE_KEEP);
onImageValidationSuccess();
}
@ -530,6 +522,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
editableUploadItem = uploadItem;
Intent intent = new Intent(getContext(), EditActivity.class);
intent.putExtra("image", uploadableFile.getFilePath().toString());
intent.putExtra("rotation",rotation);
startActivityForResult(intent, REQUEST_CODE_FOR_EDIT_ACTIVITY);
}
@ -615,6 +608,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
}
if (requestCode == REQUEST_CODE_FOR_EDIT_ACTIVITY && resultCode == RESULT_OK) {
String result = data.getStringExtra("editedImageFilePath");
rotation = data.getIntExtra("editedImageRotation",0);
if (Objects.equals(result, "Error")) {
Timber.e("Error in rotating image");