mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
5195: Fix crash on setting location for pictures with no EXIF location (#5205)
* LocationPickerActivity: fix crash on setting location for pictures with no EXIF location * strings.xml: remove extra string introduced * optimise constants * LocationPickerActivity: request for permission only on tapping target icon * remove newline * handle location permissions using LocationPermissionsHelper
This commit is contained in:
parent
6881158743
commit
4caa8a509b
5 changed files with 53 additions and 20 deletions
|
|
@ -57,6 +57,10 @@ import fr.free.nrw.commons.MapStyle;
|
|||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.location.LocationPermissionsHelper;
|
||||
import fr.free.nrw.commons.location.LocationPermissionsHelper.Dialog;
|
||||
import fr.free.nrw.commons.location.LocationPermissionsHelper.LocationPermissionCallback;
|
||||
import fr.free.nrw.commons.location.LocationServiceManager;
|
||||
import fr.free.nrw.commons.theme.BaseActivity;
|
||||
import fr.free.nrw.commons.utils.SystemThemeUtils;
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -148,6 +152,9 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
|
|||
SystemThemeUtils systemThemeUtils;
|
||||
private boolean isDarkTheme;
|
||||
|
||||
@Inject
|
||||
LocationServiceManager locationManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
|
||||
|
|
@ -452,11 +459,40 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
|
|||
fabCenterOnLocation = findViewById(R.id.center_on_gps);
|
||||
fabCenterOnLocation.setOnClickListener(view -> getCenter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Animate map to move to desired Latitude and Longitude
|
||||
* Center the map at user's current location
|
||||
*/
|
||||
void getCenter() {
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()),15.0));
|
||||
private void getCenter() {
|
||||
LocationPermissionsHelper.Dialog locationAccessDialog = new Dialog(
|
||||
R.string.location_permission_title,
|
||||
R.string.upload_map_location_access
|
||||
);
|
||||
|
||||
LocationPermissionsHelper.Dialog locationOffDialog = new Dialog(
|
||||
R.string.ask_to_turn_location_on,
|
||||
R.string.upload_map_location_access
|
||||
);
|
||||
LocationPermissionsHelper locationPermissionsHelper = new LocationPermissionsHelper(
|
||||
this, locationManager, new LocationPermissionCallback() {
|
||||
@Override
|
||||
public void onLocationPermissionDenied(String toastMessage) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationPermissionGranted() {
|
||||
fr.free.nrw.commons.location.LatLng currLocation = locationManager.getLastLocation();
|
||||
final CameraPosition position;
|
||||
position = new CameraPosition.Builder()
|
||||
.target(new com.mapbox.mapboxsdk.geometry.LatLng(currLocation.getLatitude(), currLocation.getLongitude(), 0)) // Sets the new camera position
|
||||
.zoom(mapboxMap.getCameraPosition().zoom) // Same zoom level
|
||||
.build();
|
||||
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 1000);
|
||||
}
|
||||
});
|
||||
locationPermissionsHelper.handleLocationPermissions(locationAccessDialog, locationOffDialog);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -90,7 +90,12 @@ public class ContributionController {
|
|||
activity, locationManager,
|
||||
new LocationPermissionCallback() {
|
||||
@Override
|
||||
public void onLocationPermissionDenied() {
|
||||
public void onLocationPermissionDenied(String toastMessage) {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
toastMessage,
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
initiateCameraUpload(activity);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,12 +68,8 @@ public class LocationPermissionsHelper {
|
|||
},
|
||||
() -> {
|
||||
if (callback != null) {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
R.string.in_app_camera_location_permission_denied,
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
callback.onLocationPermissionDenied();
|
||||
callback.onLocationPermissionDenied(activity.getString(
|
||||
R.string.in_app_camera_location_permission_denied));
|
||||
}
|
||||
},
|
||||
locationAccessDialog.dialogTitleResource,
|
||||
|
|
@ -102,14 +98,8 @@ public class LocationPermissionsHelper {
|
|||
activity.getString(R.string.title_app_shortcut_setting),
|
||||
activity.getString(R.string.cancel),
|
||||
() -> openLocationSettings(),
|
||||
() -> {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
R.string.in_app_camera_location_unavailable,
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
callback.onLocationPermissionDenied();
|
||||
});
|
||||
() -> callback.onLocationPermissionDenied(activity.getString(
|
||||
R.string.in_app_camera_location_unavailable)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -131,7 +121,7 @@ public class LocationPermissionsHelper {
|
|||
* Handle onPermissionDenied within individual classes based on the requirements
|
||||
*/
|
||||
public interface LocationPermissionCallback {
|
||||
void onLocationPermissionDenied();
|
||||
void onLocationPermissionDenied(String toastMessage);
|
||||
void onLocationPermissionGranted();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
LocationPermissionsHelper locationPermissionsHelper = new LocationPermissionsHelper(
|
||||
activity, locationManager, new LocationPermissionCallback() {
|
||||
@Override
|
||||
public void onLocationPermissionDenied() {
|
||||
public void onLocationPermissionDenied(String toastMessage) {
|
||||
// dismiss the dialog
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -280,6 +280,7 @@
|
|||
<string name="copy_wikicode">Copy the wikitext to the clipboard</string>
|
||||
<string name="wikicode_copied">The wikitext was copied to the clipboard</string>
|
||||
<string name="nearby_location_not_available">Nearby might not work properly, Location not available.</string>
|
||||
<string name="upload_location_access_denied">Location access denied. Please set your location manually to use this feature.</string>
|
||||
<string name="location_permission_rationale_nearby">Permission required to display a list of nearby places</string>
|
||||
|
||||
<string name="nearby_directions">Directions</string>
|
||||
|
|
@ -621,6 +622,7 @@ Upload your first media by tapping on the add button.</string>
|
|||
<string name="recommend_high_accuracy_mode">For best results, choose the High Accuracy mode.</string>
|
||||
<string name="ask_to_turn_location_on">Turn on location?</string>
|
||||
<string name="nearby_needs_location">Nearby needs location enabled to work properly</string>
|
||||
<string name="upload_map_location_access">You need to give access to your current location to set location automatically.</string>
|
||||
<string name="use_location_from_similar_image">Did you shoot these two pictures at the same place? Do you want to use the latitude/longitude of the picture on the right?</string>
|
||||
<string name="load_more">Load More</string>
|
||||
<string name="nearby_no_results">No places found, try changing your search criteria.</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue