mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
Fix Crash in LocationPickerActivity when device configuration is changed (#5500)
* Fix Crash in LocationPickerActivity when device configuration is changed (UI Modes) * clean up * fix * fix * fix * fix * removed faulty test * cleanup * fix and tests added
This commit is contained in:
parent
161e2edc31
commit
fec6dba341
5 changed files with 111 additions and 60 deletions
|
|
@ -938,12 +938,14 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
startActivityForResult(new LocationPicker.IntentBuilder()
|
||||
|
||||
startActivity(new LocationPicker.IntentBuilder()
|
||||
.defaultLocation(new CameraPosition.Builder()
|
||||
.target(new LatLng(defaultLatitude, defaultLongitude))
|
||||
.zoom(16).build())
|
||||
.activityKey("MediaActivity")
|
||||
.build(getActivity()), REQUEST_CODE);
|
||||
.media(media)
|
||||
.build(getActivity()));
|
||||
}
|
||||
|
||||
@OnClick(R.id.description_edit)
|
||||
|
|
@ -1121,32 +1123,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
@Nullable final Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
|
||||
|
||||
assert data != null;
|
||||
final CameraPosition cameraPosition = LocationPicker.getCameraPosition(data);
|
||||
|
||||
if (cameraPosition != null) {
|
||||
|
||||
final String latitude = String.valueOf(cameraPosition.target.getLatitude());
|
||||
final String longitude = String.valueOf(cameraPosition.target.getLongitude());
|
||||
final String accuracy = String.valueOf(cameraPosition.target.getAltitude());
|
||||
String currentLatitude = null;
|
||||
String currentLongitude = null;
|
||||
|
||||
if (media.getCoordinates() != null) {
|
||||
currentLatitude = String.valueOf(media.getCoordinates().getLatitude());
|
||||
currentLongitude = String.valueOf(media.getCoordinates().getLongitude());
|
||||
}
|
||||
|
||||
if (!latitude.equals(currentLatitude) || !longitude.equals(currentLongitude)) {
|
||||
updateCoordinates(latitude, longitude, accuracy);
|
||||
} else if (media.getCoordinates() == null) {
|
||||
updateCoordinates(latitude, longitude, accuracy);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (requestCode == REQUEST_CODE_EDIT_DESCRIPTION && resultCode == RESULT_OK) {
|
||||
if (requestCode == REQUEST_CODE_EDIT_DESCRIPTION && resultCode == RESULT_OK) {
|
||||
final String updatedWikiText = data.getStringExtra(UPDATED_WIKITEXT);
|
||||
compositeDisposable.add(descriptionEditHelper.addDescription(getContext(), media,
|
||||
updatedWikiText)
|
||||
|
|
@ -1174,11 +1151,6 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
progressBarEditDescription.setVisibility(GONE);
|
||||
editDescription.setVisibility(VISIBLE);
|
||||
|
||||
} else if (requestCode == REQUEST_CODE && resultCode == RESULT_CANCELED) {
|
||||
viewUtil.showShortToast(getContext(),
|
||||
requireContext()
|
||||
.getString(R.string.coordinates_picking_unsuccessful));
|
||||
|
||||
} else if (requestCode == REQUEST_CODE_EDIT_DESCRIPTION && resultCode == RESULT_CANCELED) {
|
||||
progressBarEditDescription.setVisibility(GONE);
|
||||
editDescription.setVisibility(VISIBLE);
|
||||
|
|
@ -1196,24 +1168,6 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
media.setCaptions(updatedCaptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetched coordinates are replaced with existing coordinates by a POST API call.
|
||||
* @param Latitude to be added
|
||||
* @param Longitude to be added
|
||||
* @param Accuracy to be added
|
||||
*/
|
||||
public void updateCoordinates(final String Latitude, final String Longitude,
|
||||
final String Accuracy) {
|
||||
compositeDisposable.add(coordinateEditHelper.makeCoordinatesEdit(getContext(), media,
|
||||
Latitude, Longitude, Accuracy)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(s -> {
|
||||
Timber.d("Coordinates are added.");
|
||||
coordinates.setText(prettyCoordinates(media));
|
||||
}));
|
||||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
@OnClick(R.id.nominateDeletion)
|
||||
public void onDeleteButtonClicked(){
|
||||
|
|
@ -1598,4 +1552,5 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
SharedPreferences imageBackgroundColorPref = this.getImageBackgroundColorPref();
|
||||
return imageBackgroundColorPref.getInt(IMAGE_BACKGROUND_COLOR, DEFAULT_IMAGE_BACKGROUND_COLOR);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue