Merge pull request #4148 from bykoianko/master-switchon-location-services-immediately

Android. Switching on or off using location sevices immediately on changing check state.
This commit is contained in:
Alexander Marchuk 2016-08-24 17:43:03 +03:00 committed by GitHub
commit 0f1b7c18ad
3 changed files with 14 additions and 12 deletions

View file

@ -112,7 +112,7 @@ class GoogleFusedLocationProvider extends BaseLocationProvider
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// Location settings are not satisfied, but this can be fixed by showing the user a dialog.
// Location settings are not satisfied. AndroidNativeProvider should be used.
resolveError(status);
return;
@ -131,15 +131,7 @@ class GoogleFusedLocationProvider extends BaseLocationProvider
if (LocationHelper.INSTANCE.isLocationStopped())
return;
LocationHelper.INSTANCE.stop();
Activity activity = MwmApplication.backgroundTracker().getTopActivity();
if (activity != null)
{
try
{
status.startResolutionForResult(activity, LocationHelper.REQUEST_RESOLVE_ERROR);
} catch (IntentSender.SendIntentException ignored) {}
}
LocationHelper.INSTANCE.initProvider(true /* forceNative */);
}
private void requestLocationUpdates()

View file

@ -255,6 +255,10 @@ public enum LocationHelper
public void initProvider(boolean forceNative)
{
mActive = !mListeners.isEmpty();
if (mActive)
stopInternal();
final MwmApplication application = MwmApplication.get();
final boolean containsGoogleServices = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(application) == ConnectionResult.SUCCESS;
final boolean googleServicesTurnedInSettings = Config.useGoogleServices();

View file

@ -8,6 +8,7 @@ import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.util.Config;
import com.mapswithme.util.statistics.MytargetHelper;
import com.mapswithme.util.statistics.Statistics;
@ -49,8 +50,13 @@ public class MiscPrefsFragment extends BaseXmlSettingsFragment
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
Config.setUseGoogleService((Boolean) newValue);
// TODO (trashkalmar): Reinitialize location provider
boolean oldVal = Config.useGoogleServices();
boolean newVal = ((Boolean) newValue).booleanValue();
if (oldVal != newVal)
{
Config.setUseGoogleService(newVal);
LocationHelper.INSTANCE.initProvider(false /* forceNative */);
}
return true;
}
});