Skip to content

Commit

Permalink
Merge pull request #23 from icapps/feature/#22-update-notification-text
Browse files Browse the repository at this point in the history
#22: Added option to update the notification text you start tracking.
  • Loading branch information
vanlooverenkoen authored Feb 8, 2021
2 parents f5f318a + f06cfed commit 03f717d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ internal class MethodCallHelper(private val ctx: Context) : MethodChannel.Method
private fun isTracking(ctx: Context, call: MethodCall, result: MethodChannel.Result) = result.success(SharedPrefsUtil.isTracking(ctx))

private fun startTracking(ctx: Context, call: MethodCall, result: MethodChannel.Result) {
val notificationBodyKey = "android_config_notification_body"
val notificationIconKey = "android_config_notification_icon"
val enableNotificationLocationUpdatesKey = "android_config_enable_notification_location_updates"
val enableCancelTrackingActionKey = "android_config_enable_cancel_tracking_action"
val cancelTrackingActionTextKey = "android_config_cancel_tracking_action_text"
val keys = listOf(
notificationBodyKey,
enableNotificationLocationUpdatesKey,
cancelTrackingActionTextKey,
enableCancelTrackingActionKey
)
if (!call.checkRequiredFields(keys, result)) return
val notificationBody = call.argument<String>(notificationBodyKey)!!
val notificationIcon = call.argument<String>(notificationIconKey)
val enableNotificationLocationUpdates = call.argument<Boolean>(enableNotificationLocationUpdatesKey)!!
val cancelTrackingActionText = call.argument<String>(cancelTrackingActionTextKey)!!
val enableCancelTrackingAction = call.argument<Boolean>(enableCancelTrackingActionKey)!!
if (notificationBody != null && notificationIcon != null && cancelTrackingActionText != null && enableNotificationLocationUpdates != null && enableCancelTrackingAction != null) {
SharedPrefsUtil.saveNotificationConfig(ctx, notificationBody, notificationIcon, cancelTrackingActionText, enableNotificationLocationUpdates, enableCancelTrackingAction)
}
serviceConnection.service?.startTracking()
result.success(true)
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/background_location_tracker_manager.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:background_location_tracker/background_location_tracker.dart';
import 'package:background_location_tracker/src/channel/background_channel.dart';
import 'package:background_location_tracker/src/channel/foreground_channel.dart';
import 'package:background_location_tracker/src/model/background_location_update_data.dart';
Expand All @@ -17,7 +18,7 @@ class BackgroundLocationTrackerManager {

static Future<bool> isTracking() async => ForegroundChannel.isTracking();

static Future<void> startTracking() async => ForegroundChannel.startTracking();
static Future<void> startTracking({AndroidConfig config}) async => ForegroundChannel.startTracking(config: config);

static Future<void> stopTracking() async => ForegroundChannel.stopTracking();

Expand Down
14 changes: 13 additions & 1 deletion lib/src/channel/foreground_channel.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:ui';
import 'package:background_location_tracker/src/model/config/android_config.dart';
import 'package:background_location_tracker/src/model/config/background_location_tracker_config.dart';
import 'package:flutter/services.dart';

Expand Down Expand Up @@ -28,7 +29,18 @@ class ForegroundChannel {

static Future<bool> isTracking() => _foregroundChannel.invokeMethod('isTracking');

static Future<void> startTracking() => _foregroundChannel.invokeMethod('startTracking');
static Future<void> startTracking({AndroidConfig config}) {
return _foregroundChannel.invokeMethod(
'startTracking',
{
'android_config_notification_body': config?.notificationBody,
'android_config_notification_icon': config?.notificationIcon,
'android_config_enable_notification_location_updates': config?.enableNotificationLocationUpdates,
'android_config_cancel_tracking_action_text': config?.cancelTrackingActionText,
'android_config_enable_cancel_tracking_action': config?.enableCancelTrackingAction,
},
);
}

static Future<void> stopTracking() => _foregroundChannel.invokeMethod('stopTracking');
}

0 comments on commit 03f717d

Please sign in to comment.