Location fixes
This commit is contained in:
		| @@ -136,10 +136,6 @@ public class LocationUpdatesService extends Service { | |||||||
|  |  | ||||||
|         OneTimeWorkRequest uploadWorkRequest = |         OneTimeWorkRequest uploadWorkRequest = | ||||||
|                 new OneTimeWorkRequest.Builder(SendDataHomeWorker.class) |                 new OneTimeWorkRequest.Builder(SendDataHomeWorker.class) | ||||||
|                         .setBackoffCriteria( |  | ||||||
|                                 BackoffPolicy.EXPONENTIAL, |  | ||||||
|                                 10, |  | ||||||
|                                 TimeUnit.SECONDS) |  | ||||||
|                         .setConstraints(constraints) |                         .setConstraints(constraints) | ||||||
|                         .setInputData(locationData) |                         .setInputData(locationData) | ||||||
|                         .build(); |                         .build(); | ||||||
|   | |||||||
| @@ -1,6 +1,5 @@ | |||||||
| package com.keyboardcrumbs.hassclient; | package com.keyboardcrumbs.hassclient; | ||||||
|  |  | ||||||
| import android.app.AlarmManager; |  | ||||||
| import android.app.NotificationChannel; | import android.app.NotificationChannel; | ||||||
| import android.app.NotificationManager; | import android.app.NotificationManager; | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
| @@ -29,8 +28,6 @@ import com.google.common.util.concurrent.ListenableFuture; | |||||||
|  |  | ||||||
| import java.util.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||||
|  |  | ||||||
| import static android.content.Context.NOTIFICATION_SERVICE; |  | ||||||
|  |  | ||||||
| public class LocationUpdatesWorker extends ListenableWorker { | public class LocationUpdatesWorker extends ListenableWorker { | ||||||
|  |  | ||||||
|     private Context currentContext; |     private Context currentContext; | ||||||
| @@ -73,10 +70,6 @@ public class LocationUpdatesWorker extends ListenableWorker { | |||||||
|  |  | ||||||
|                     OneTimeWorkRequest uploadWorkRequest = |                     OneTimeWorkRequest uploadWorkRequest = | ||||||
|                             new OneTimeWorkRequest.Builder(SendDataHomeWorker.class) |                             new OneTimeWorkRequest.Builder(SendDataHomeWorker.class) | ||||||
|                                     .setBackoffCriteria( |  | ||||||
|                                             BackoffPolicy.EXPONENTIAL, |  | ||||||
|                                             10, |  | ||||||
|                                             TimeUnit.SECONDS) |  | ||||||
|                                     .setConstraints(constraints) |                                     .setConstraints(constraints) | ||||||
|                                     .setInputData(locationData) |                                     .setInputData(locationData) | ||||||
|                                     .build(); |                                     .build(); | ||||||
|   | |||||||
| @@ -34,19 +34,19 @@ class LocationUtils { | |||||||
|     static final int LOCATION_UPDATES_SERVICE = 1; |     static final int LOCATION_UPDATES_SERVICE = 1; | ||||||
|     static final int LOCATION_UPDATES_WORKER = 2; |     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 final long MIN_WORKER_LOCATION_UPDATE_INTERVAL_MS = 900000; //15 minutes | ||||||
|  |  | ||||||
|     static int getLocationUpdatesState(Context context) { |     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) { |     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) { |     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) { |     static boolean showNotification(Context context) { | ||||||
| @@ -65,7 +65,7 @@ class LocationUtils { | |||||||
|                 .edit() |                 .edit() | ||||||
|                 .putInt(KEY_LOCATION_UPDATE_PRIORITY, priority) |                 .putInt(KEY_LOCATION_UPDATE_PRIORITY, priority) | ||||||
|                 .putBoolean(KEY_LOCATION_SHOW_NOTIFICATION, showNotification) |                 .putBoolean(KEY_LOCATION_SHOW_NOTIFICATION, showNotification) | ||||||
|                 .putLong(KEY_LOCATION_UPDATE_INTERVAL, interval/1000) |                 .putLong(KEY_LOCATION_UPDATE_INTERVAL, interval) | ||||||
|                 .apply(); |                 .apply(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -29,7 +29,7 @@ public class MainActivity extends FlutterActivity { | |||||||
|     private static final int REQUEST_PERMISSIONS_REQUEST_CODE = 34; |     private static final int REQUEST_PERMISSIONS_REQUEST_CODE = 34; | ||||||
|  |  | ||||||
|     private int locationUpdatesType = LocationUtils.LOCATION_UPDATES_DISABLED; |     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 |     @Override | ||||||
|     public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { |     public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { | ||||||
| @@ -66,7 +66,7 @@ public class MainActivity extends FlutterActivity { | |||||||
|                             break; |                             break; | ||||||
|                         case "startLocationService": |                         case "startLocationService": | ||||||
|                             try { |                             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) { |                                 if (locationUpdatesInterval >= LocationUtils.MIN_WORKER_LOCATION_UPDATE_INTERVAL_MS) { | ||||||
|                                     locationUpdatesType = LocationUtils.LOCATION_UPDATES_WORKER; |                                     locationUpdatesType = LocationUtils.LOCATION_UPDATES_WORKER; | ||||||
|                                 } else { |                                 } else { | ||||||
|   | |||||||
| @@ -40,7 +40,7 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> { | |||||||
|         _accuracy = prefs.getInt("location-updates-priority") ?? 102; |         _accuracy = prefs.getInt("location-updates-priority") ?? 102; | ||||||
|         _locationTrackingEnabled = (prefs.getInt("location-updates-state") ?? 0) > 0; |         _locationTrackingEnabled = (prefs.getInt("location-updates-state") ?? 0) > 0; | ||||||
|         _showNotification = prefs.getBool("location-updates-show-notification") ?? true; |         _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); |             AppSettings().defaultLocationUpdateIntervalSeconds); | ||||||
|       }); |       }); | ||||||
|     }); |     }); | ||||||
| @@ -100,7 +100,7 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> { | |||||||
|     if (state) { |     if (state) { | ||||||
|       try { |       try { | ||||||
|         await platform.invokeMethod('startLocationService', <String, dynamic>{ |         await platform.invokeMethod('startLocationService', <String, dynamic>{ | ||||||
|           'location-updates-interval': _locationInterval.inSeconds, |           'location-updates-interval': _locationInterval.inMilliseconds, | ||||||
|           'location-updates-priority': _accuracy, |           'location-updates-priority': _accuracy, | ||||||
|           'location-updates-show-notification': _showNotification |           'location-updates-show-notification': _showNotification | ||||||
|         }); |         }); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user