Skip to content

Commit 77fdbd1

Browse files
Merge pull request #30 from icapps/feature/ConfigOptions
Support additional configuration arguments
2 parents 087103e + 8b52ffa commit 77fdbd1

22 files changed

+220
-76
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.1.0 - 12-10-2021
2+
#Added
3+
- Added more options to android config to specify update interval
4+
- Added iOS specific options to control activity type and/or distance filter
5+
16
## 1.0.2 - 22-06-2021
27
#Fixed
38
- Formatting

analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ linter:
1919
- always_put_required_named_parameters_first
2020
- always_require_non_null_named_parameters
2121
- annotate_overrides
22-
- avoid_as
2322
- avoid_bool_literals_in_conditional_expressions
2423
- avoid_catching_errors
2524
- avoid_double_and_int_checks

android/src/main/kotlin/com/icapps/background_location_tracker/MethodCallHelper.kt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ internal class MethodCallHelper(private val ctx: Context) : MethodChannel.Method
3030
private fun initialize(ctx: Context, call: MethodCall, result: MethodChannel.Result) {
3131
val callbackHandleKey = "callback_handle"
3232
val loggingEnabledKey = "logging_enabled"
33+
val trackingIntervalKey = "android_update_interval_msec"
3334
val channelNameKey = "android_config_channel_name"
3435
val notificationBodyKey = "android_config_notification_body"
3536
val notificationIconKey = "android_config_notification_icon"
@@ -43,7 +44,8 @@ internal class MethodCallHelper(private val ctx: Context) : MethodChannel.Method
4344
notificationBodyKey,
4445
enableNotificationLocationUpdatesKey,
4546
cancelTrackingActionTextKey,
46-
enableCancelTrackingActionKey
47+
enableCancelTrackingActionKey,
48+
trackingIntervalKey
4749
)
4850
if (!call.checkRequiredFields(keys, result)) return
4951
val callbackHandle = call.argument<Long>(callbackHandleKey)!!
@@ -54,7 +56,9 @@ internal class MethodCallHelper(private val ctx: Context) : MethodChannel.Method
5456
val enableNotificationLocationUpdates = call.argument<Boolean>(enableNotificationLocationUpdatesKey)!!
5557
val cancelTrackingActionText = call.argument<String>(cancelTrackingActionTextKey)!!
5658
val enableCancelTrackingAction = call.argument<Boolean>(enableCancelTrackingActionKey)!!
59+
val trackingInterval = call.argument<Long>(trackingIntervalKey)!!
5760
SharedPrefsUtil.saveLoggingEnabled(ctx, loggingEnabled)
61+
SharedPrefsUtil.saveTrackingInterval(ctx, trackingInterval)
5862
Logger.enabled = loggingEnabled
5963
NotificationUtil.createNotificationChannels(ctx, channelName)
6064
SharedPrefsUtil.saveCallbackDispatcherHandleKey(ctx, callbackHandle)
@@ -70,20 +74,19 @@ internal class MethodCallHelper(private val ctx: Context) : MethodChannel.Method
7074
val enableNotificationLocationUpdatesKey = "android_config_enable_notification_location_updates"
7175
val enableCancelTrackingActionKey = "android_config_enable_cancel_tracking_action"
7276
val cancelTrackingActionTextKey = "android_config_cancel_tracking_action_text"
73-
val keys = listOf(
74-
notificationBodyKey,
75-
enableNotificationLocationUpdatesKey,
76-
cancelTrackingActionTextKey,
77-
enableCancelTrackingActionKey
78-
)
79-
if (!call.checkRequiredFields(keys, result)) return
80-
val notificationBody = call.argument<String>(notificationBodyKey)!!
77+
78+
val notificationBody = call.argument<String>(notificationBodyKey)
8179
val notificationIcon = call.argument<String>(notificationIconKey)
82-
val enableNotificationLocationUpdates = call.argument<Boolean>(enableNotificationLocationUpdatesKey)!!
83-
val cancelTrackingActionText = call.argument<String>(cancelTrackingActionTextKey)!!
84-
val enableCancelTrackingAction = call.argument<Boolean>(enableCancelTrackingActionKey)!!
85-
if (notificationBody != null && notificationIcon != null && cancelTrackingActionText != null && enableNotificationLocationUpdates != null && enableCancelTrackingAction != null) {
86-
SharedPrefsUtil.saveNotificationConfig(ctx, notificationBody, notificationIcon, cancelTrackingActionText, enableNotificationLocationUpdates, enableCancelTrackingAction)
80+
val enableNotificationLocationUpdates = call.argument<Boolean>(enableNotificationLocationUpdatesKey)
81+
val cancelTrackingActionText = call.argument<String>(cancelTrackingActionTextKey)
82+
val enableCancelTrackingAction = call.argument<Boolean>(enableCancelTrackingActionKey)
83+
if (notificationBody != null || notificationIcon != null || cancelTrackingActionText != null
84+
|| enableNotificationLocationUpdates != null || enableCancelTrackingAction != null) {
85+
SharedPrefsUtil.saveNotificationConfig(ctx, notificationBody ?: SharedPrefsUtil.getNotificationBody(ctx),
86+
notificationIcon ?: SharedPrefsUtil.getNotificationIcon(ctx),
87+
cancelTrackingActionText ?: SharedPrefsUtil.getCancelTrackingActionText(ctx),
88+
enableNotificationLocationUpdates ?: SharedPrefsUtil.isNotificationLocationUpdatesEnabled(ctx),
89+
enableCancelTrackingAction ?: SharedPrefsUtil.isCancelTrackingActionEnabled(ctx))
8790
}
8891
serviceConnection.service?.startTracking()
8992
result.success(true)

android/src/main/kotlin/com/icapps/background_location_tracker/service/LocationUpdatesService.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,11 @@ internal class LocationUpdatesService : Service() {
204204
* Sets the location request parameters.
205205
*/
206206
private fun createLocationRequest() {
207+
val interval = SharedPrefsUtil.trackingInterval(this)
207208
locationRequest = LocationRequest()
208209
locationRequest?.let {
209-
it.interval = UPDATE_INTERVAL_IN_MILLISECONDS
210-
it.fastestInterval = FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS
210+
it.interval = interval
211+
it.fastestInterval = interval / 2
211212
it.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
212213
}
213214
}
@@ -246,16 +247,5 @@ internal class LocationUpdatesService : Service() {
246247
const val ACTION_BROADCAST = "$PACKAGE_NAME.broadcast"
247248
const val EXTRA_LOCATION = "$PACKAGE_NAME.location"
248249
const val EXTRA_STARTED_FROM_NOTIFICATION = "$PACKAGE_NAME.started_from_notification"
249-
250-
/**
251-
* The desired interval for location updates. Inexact. Updates may be more or less frequent.
252-
*/
253-
private const val UPDATE_INTERVAL_IN_MILLISECONDS: Long = 10000
254-
255-
/**
256-
* The fastest rate for active location updates. Updates will never be more frequent
257-
* than this value.
258-
*/
259-
private const val FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS = UPDATE_INTERVAL_IN_MILLISECONDS / 2
260250
}
261251
}

android/src/main/kotlin/com/icapps/background_location_tracker/utils/SharedPrefsUtil.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ internal object SharedPrefsUtil {
88
private const val KEY_CALBACK_HANDLER = "background.location.tracker.manager.CALLBACK_DISPATCHER_HANDLE_KEY"
99
private const val KEY_IS_TRACKING = "background.location.tracker.manager.IS_TRACKING"
1010
private const val KEY_LOGGING_ENABED = "background.location.tracker.manager.LOGGIN_ENABLED"
11+
private const val KEY_TRACKING_INTERVAL = "background.location.tracker.manager.TRACKING_INTERVAL"
1112

1213
private const val KEY_NOTIFICATION_BODY = "background.location.tracker.manager.NOTIFICATION_BODY"
1314
private const val KEY_NOTIFICATION_ICON = "background.location.tracker.manager.NOTIFICATION_ICON"
@@ -44,8 +45,17 @@ internal object SharedPrefsUtil {
4445
.apply()
4546
}
4647

48+
fun saveTrackingInterval(ctx: Context, interval: Long) {
49+
ctx.prefs()
50+
.edit()
51+
.putLong(KEY_TRACKING_INTERVAL, interval)
52+
.apply()
53+
}
54+
4755
fun isLoggingEnabled(ctx: Context): Boolean = ctx.prefs().getBoolean(KEY_LOGGING_ENABED, false)
4856

57+
fun trackingInterval(ctx: Context): Long = ctx.prefs().getLong(KEY_TRACKING_INTERVAL, 10000)
58+
4959
//NotificationConfig
5060
fun saveNotificationConfig(ctx: Context, notificationBody: String, notificationIcon: String?, cancelTrackingActionText: String, enableNotificationLocationUpdates: Boolean, enableCancelTrackingAction: Boolean) {
5161
ctx.prefs()

coverage/filter_test_coverage.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ class LcovSection {
5050
final file = File(path);
5151
final content = file.readAsLinesSync();
5252
final sb = StringBuffer();
53-
getFilteredBody(body, content)
54-
.forEach((item) => sb..write(item)..write('\n'));
53+
getFilteredBody(body, content).forEach((item) => sb
54+
..write(item)
55+
..write('\n'));
5556
return sb.toString();
5657
}
5758

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Fri Jun 23 08:50:38 CEST 2017
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

example/ios/Flutter/AppFrameworkInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>8.0</string>
24+
<string>9.0</string>
2525
</dict>
2626
</plist>

example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PODS:
44
- Flutter (1.0.0)
55
- flutter_local_notifications (0.0.1):
66
- Flutter
7-
- "permission_handler (5.0.1+1)":
7+
- "permission_handler (5.1.0+2)":
88
- Flutter
99

1010
DEPENDENCIES:
@@ -25,10 +25,10 @@ EXTERNAL SOURCES:
2525

2626
SPEC CHECKSUMS:
2727
background_location_tracker: 3f0954d5a839b9bfffbdc887e679d183a7bbc1c9
28-
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
28+
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
2929
flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743
30-
permission_handler: eac8e15b4a1a3fba55b761d19f3f4e6b005d15b6
30+
permission_handler: ccb20a9fad0ee9b1314a52b70b76b473c5f8dab0
3131

3232
PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
3333

34-
COCOAPODS: 1.10.0
34+
COCOAPODS: 1.11.2

example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)