mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Add a dialog to prompt user if location is off in Nearby when L… (#3438)
This commit is contained in:
parent
15bccdf650
commit
021105ac4d
4 changed files with 44 additions and 1 deletions
|
|
@ -6,7 +6,6 @@ import android.location.Location;
|
|||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
|
@ -214,6 +213,14 @@ public class LocationServiceManager implements LocationListener {
|
|||
Timber.d("Provider %s disabled", provider);
|
||||
}
|
||||
|
||||
public boolean isNetworkProviderEnabled() {
|
||||
return locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
||||
}
|
||||
|
||||
public boolean isGPSProviderEnabled() {
|
||||
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
||||
}
|
||||
|
||||
public enum LocationChangeType{
|
||||
LOCATION_SIGNIFICANTLY_CHANGED, //Went out of borders of nearby markers
|
||||
LOCATION_SLIGHTLY_CHANGED, //User might be walking or driving
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ public interface NearbyParentFragmentContract {
|
|||
void setFABRecenterAction(android.view.View.OnClickListener onClickListener);
|
||||
void animateFABs();
|
||||
void recenterMap(LatLng curLatLng);
|
||||
void showLocationOffDialog();
|
||||
void openLocationSettings();
|
||||
void hideBottomSheet();
|
||||
void hideBottomDetailsSheet();
|
||||
void displayBottomSheetWithInfo(Marker marker);
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ import android.content.BroadcastReceiver;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
|
|
@ -56,6 +58,7 @@ import com.mapbox.pluginscalebar.ScaleBarOptions;
|
|||
import com.mapbox.pluginscalebar.ScaleBarPlugin;
|
||||
import com.pedrogomez.renderers.RVRendererAdapter;
|
||||
|
||||
import fr.free.nrw.commons.utils.DialogUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -1251,6 +1254,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
@Override
|
||||
public void recenterMap(fr.free.nrw.commons.location.LatLng curLatLng) {
|
||||
if (curLatLng == null) {
|
||||
if (!(locationManager.isNetworkProviderEnabled() || locationManager.isGPSProviderEnabled())) {
|
||||
showLocationOffDialog();
|
||||
}
|
||||
return;
|
||||
}
|
||||
addCurrentLocationMarker(curLatLng);
|
||||
|
|
@ -1281,6 +1287,28 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
mapBox.animateCamera(CameraUpdateFactory.newCameraPosition(position), 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLocationOffDialog() {
|
||||
// This creates a dialog box that prompts the user to enable location
|
||||
DialogUtil
|
||||
.showAlertDialog(getActivity(), getString(R.string.ask_to_turn_location_on), getString(R.string.nearby_needs_location),
|
||||
getString(R.string.yes), getString(R.string.no), this::openLocationSettings, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openLocationSettings() {
|
||||
// This method opens the location settings of the device along with a followup toast.
|
||||
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||
PackageManager packageManager = getActivity().getPackageManager();
|
||||
|
||||
if (intent.resolveActivity(packageManager)!= null) {
|
||||
startActivity(intent);
|
||||
Toast.makeText(getContext(), R.string.recommend_high_accuracy_mode, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(getContext(), R.string.cannot_open_location_settings, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideBottomSheet() {
|
||||
bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
||||
|
|
|
|||
|
|
@ -602,4 +602,10 @@ Upload your first media by tapping on the add button.</string>
|
|||
<string name="theme_default_name">Default</string>
|
||||
<string name="theme_dark_name">Dark</string>
|
||||
<string name="theme_light_name">Light</string>
|
||||
|
||||
<string name="cannot_open_location_settings">Failed to open location settings. Please turn on location manually</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>
|
||||
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue