diff --git a/app/build.gradle b/app/build.gradle
index eba129d..b957308 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -8,8 +8,8 @@ android {
applicationId "by.vshkl.translate2"
minSdkVersion 19
targetSdkVersion 25
- versionCode 2
- versionName "0.5.0"
+ versionCode 3
+ versionName "0.5.1"
vectorDrawables.useSupportLibrary = true
resConfigs "en", "ru", "be"
buildConfigField("String", "ENCRYPTED_PREFERENCES_PWD", ENCRYPTED_PREFERENCES_PWD)
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 99a005c..0a570ad 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -10,6 +10,9 @@
+
+
+
stops) {
if (map != null) {
- map.setOnCameraMoveListener(() -> addItemsToMap(stops, map.getCameraPosition().zoom));
+ map.setOnCameraMoveListener(() -> {
+ addItemsToMap(stops, map.getCameraPosition().zoom);
+ requestLocationUpdates = false;
+ stopLocationUpdates();
+ });
}
}
@Override
public void showSelectedStop(final Stop stop, final boolean bookmarked, final boolean fromNavDrawer) {
- map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(stop.getLatitude(), stop.getLongitude()), Constants.ZOOM_POSITION),
+ map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(stop.getLatitude(), stop.getLongitude()),
+ Constants.ZOOM_POSITION),
new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {
@@ -402,7 +426,7 @@ void updateCoordinates() {
boolean hasProvider = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
|| lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (hasProvider) {
- showUserLocation();
+ startLocationUpdates();
} else {
turnOnLocation();
}
@@ -518,23 +542,6 @@ private void setupMap() {
map.setOnMarkerClickListener(this);
}
- private void showUserLocation() {
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
- != PackageManager.PERMISSION_GRANTED
- && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
- != PackageManager.PERMISSION_GRANTED) {
- return;
- }
-
- if (googleApiClient.isConnected()) {
- LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, getLocationRequest(), location -> {
- LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
- map.setMyLocationEnabled(true);
- map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, Constants.ZOOM_POSITION));
- });
- }
- }
-
private void loadWebView(String url) {
CookieManager.getInstance().setCookie("", CookieUtils.getCookies(getApplicationContext()));
wvDashboard.clearHistory();
@@ -622,6 +629,22 @@ private void turnOnLocation() {
});
}
+ private void startLocationUpdates() {
+ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
+ != PackageManager.PERMISSION_GRANTED
+ && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
+ != PackageManager.PERMISSION_GRANTED) {
+ return;
+ }
+ if (googleApiClient.isConnected() && requestLocationUpdates) {
+ LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, getLocationRequest(), this);
+ }
+ }
+
+ private void stopLocationUpdates() {
+ LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, this);
+ }
+
private LocationRequest getLocationRequest() {
if (locationRequest == null) {
locationRequest = LocationRequest.create();