Location fixes

This commit is contained in:
estevez-dev
2020-07-08 11:49:05 +03:00
parent 2fb296b7a8
commit 5aa6171c50
5 changed files with 9 additions and 20 deletions

View File

@ -136,10 +136,6 @@ public class LocationUpdatesService extends Service {
OneTimeWorkRequest uploadWorkRequest =
new OneTimeWorkRequest.Builder(SendDataHomeWorker.class)
.setBackoffCriteria(
BackoffPolicy.EXPONENTIAL,
10,
TimeUnit.SECONDS)
.setConstraints(constraints)
.setInputData(locationData)
.build();

View File

@ -1,6 +1,5 @@
package com.keyboardcrumbs.hassclient;
import android.app.AlarmManager;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
@ -29,8 +28,6 @@ import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.TimeUnit;
import static android.content.Context.NOTIFICATION_SERVICE;
public class LocationUpdatesWorker extends ListenableWorker {
private Context currentContext;
@ -73,10 +70,6 @@ public class LocationUpdatesWorker extends ListenableWorker {
OneTimeWorkRequest uploadWorkRequest =
new OneTimeWorkRequest.Builder(SendDataHomeWorker.class)
.setBackoffCriteria(
BackoffPolicy.EXPONENTIAL,
10,
TimeUnit.SECONDS)
.setConstraints(constraints)
.setInputData(locationData)
.build();

View File

@ -34,19 +34,19 @@ class LocationUtils {
static final int LOCATION_UPDATES_SERVICE = 1;
static final int LOCATION_UPDATES_WORKER = 2;
static final int DEFAULT_LOCATION_UPDATE_INTERVAL_S = 900; //15 minutes
static final int DEFAULT_LOCATION_UPDATE_INTERVAL_MS = 900000; //15 minutes
static final long MIN_WORKER_LOCATION_UPDATE_INTERVAL_MS = 900000; //15 minutes
static int getLocationUpdatesState(Context context) {
return (int) context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE).getLong(KEY_REQUESTING_LOCATION_UPDATES, LOCATION_UPDATES_DISABLED);
return context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE).getInt(KEY_REQUESTING_LOCATION_UPDATES, LOCATION_UPDATES_DISABLED);
}
static long getLocationUpdateIntervals(Context context) {
return context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE).getLong(KEY_LOCATION_UPDATE_INTERVAL, DEFAULT_LOCATION_UPDATE_INTERVAL_S) * 1000;
return context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE).getLong(KEY_LOCATION_UPDATE_INTERVAL, DEFAULT_LOCATION_UPDATE_INTERVAL_MS);
}
static int getLocationUpdatesPriority(Context context) {
return (int) context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE).getLong(KEY_LOCATION_UPDATE_PRIORITY, 102);
return context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE).getInt(KEY_LOCATION_UPDATE_PRIORITY, 102);
}
static boolean showNotification(Context context) {
@ -65,7 +65,7 @@ class LocationUtils {
.edit()
.putInt(KEY_LOCATION_UPDATE_PRIORITY, priority)
.putBoolean(KEY_LOCATION_SHOW_NOTIFICATION, showNotification)
.putLong(KEY_LOCATION_UPDATE_INTERVAL, interval/1000)
.putLong(KEY_LOCATION_UPDATE_INTERVAL, interval)
.apply();
}

View File

@ -29,7 +29,7 @@ public class MainActivity extends FlutterActivity {
private static final int REQUEST_PERMISSIONS_REQUEST_CODE = 34;
private int locationUpdatesType = LocationUtils.LOCATION_UPDATES_DISABLED;
private long locationUpdatesInterval = LocationUtils.DEFAULT_LOCATION_UPDATE_INTERVAL_S * 1000;
private long locationUpdatesInterval = LocationUtils.DEFAULT_LOCATION_UPDATE_INTERVAL_MS;
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
@ -66,7 +66,7 @@ public class MainActivity extends FlutterActivity {
break;
case "startLocationService":
try {
locationUpdatesInterval = (long) call.argument("location-updates-interval") * 1000;
locationUpdatesInterval = ((Number)call.argument("location-updates-interval")).longValue();
if (locationUpdatesInterval >= LocationUtils.MIN_WORKER_LOCATION_UPDATE_INTERVAL_MS) {
locationUpdatesType = LocationUtils.LOCATION_UPDATES_WORKER;
} else {