Location fixes
This commit is contained in:
		| @@ -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(); | ||||
|   | ||||
| @@ -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(); | ||||
|   | ||||
| @@ -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(); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
| @@ -40,7 +40,7 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> { | ||||
|         _accuracy = prefs.getInt("location-updates-priority") ?? 102; | ||||
|         _locationTrackingEnabled = (prefs.getInt("location-updates-state") ?? 0) > 0; | ||||
|         _showNotification = prefs.getBool("location-updates-show-notification") ?? true; | ||||
|         _locationInterval = Duration(seconds: prefs.getInt("location-updates-interval") ?? | ||||
|         _locationInterval = Duration(milliseconds: prefs.getInt("location-updates-interval") ?? | ||||
|             AppSettings().defaultLocationUpdateIntervalSeconds); | ||||
|       }); | ||||
|     }); | ||||
| @@ -100,7 +100,7 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> { | ||||
|     if (state) { | ||||
|       try { | ||||
|         await platform.invokeMethod('startLocationService', <String, dynamic>{ | ||||
|           'location-updates-interval': _locationInterval.inSeconds, | ||||
|           'location-updates-interval': _locationInterval.inMilliseconds, | ||||
|           'location-updates-priority': _accuracy, | ||||
|           'location-updates-show-notification': _showNotification | ||||
|         }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user