From 6b59a3f345b0342a009e12a7ac1446e7042d83bd Mon Sep 17 00:00:00 2001 From: "Gusakovsky, Sergey" Date: Fri, 25 Oct 2024 14:19:20 +0300 Subject: [PATCH] Added uploadUnsentTrips, getUnsentTripCount, sendCustomHeartbeats methods --- android/.idea/.name | 1 + android/.idea/compiler.xml | 6 +++++ android/.idea/gradle.xml | 18 +++++++++++++ android/.idea/kotlinc.xml | 6 +++++ android/.idea/migrations.xml | 10 ++++++++ android/.idea/misc.xml | 5 ++++ android/.idea/vcs.xml | 6 +++++ .../com/telematicssdk/TelematicsSDKPlugin.kt | 19 ++++++++++++++ ios/Classes/SwiftTelematicsSDKPlugin.swift | 25 +++++++++++++++++++ lib/src/tracking_api.dart | 7 ++++++ 10 files changed, 103 insertions(+) create mode 100644 android/.idea/.name create mode 100644 android/.idea/compiler.xml create mode 100644 android/.idea/gradle.xml create mode 100644 android/.idea/kotlinc.xml create mode 100644 android/.idea/migrations.xml create mode 100644 android/.idea/misc.xml create mode 100644 android/.idea/vcs.xml diff --git a/android/.idea/.name b/android/.idea/.name new file mode 100644 index 0000000..52af793 --- /dev/null +++ b/android/.idea/.name @@ -0,0 +1 @@ +telematics_sdk \ No newline at end of file diff --git a/android/.idea/compiler.xml b/android/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/android/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android/.idea/gradle.xml b/android/.idea/gradle.xml new file mode 100644 index 0000000..aeac74f --- /dev/null +++ b/android/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/android/.idea/kotlinc.xml b/android/.idea/kotlinc.xml new file mode 100644 index 0000000..fdf8d99 --- /dev/null +++ b/android/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/android/.idea/migrations.xml b/android/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/android/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/android/.idea/misc.xml b/android/.idea/misc.xml new file mode 100644 index 0000000..824785d --- /dev/null +++ b/android/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/android/.idea/vcs.xml b/android/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/android/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android/src/main/kotlin/com/telematicssdk/TelematicsSDKPlugin.kt b/android/src/main/kotlin/com/telematicssdk/TelematicsSDKPlugin.kt index bde0514..9b1a04c 100644 --- a/android/src/main/kotlin/com/telematicssdk/TelematicsSDKPlugin.kt +++ b/android/src/main/kotlin/com/telematicssdk/TelematicsSDKPlugin.kt @@ -95,6 +95,9 @@ class TelematicsSDKPlugin : ActivityAware, ActivityResultListener, FlutterPlugin "addFutureTrackTag" -> addFutureTrackTag(call, result) "removeFutureTrackTag" -> removeFutureTrackTag(call, result) "removeAllFutureTrackTags" -> removeAllFutureTrackTags(result) + "uploadUnsentTrips" -> uploadUnsentTrips(result) + "getUnsentTripCount" -> getUnsentTripCount(result) + "sendCustomHeartbeats" -> sendCustomHeartbeats(call, result) else -> result.notImplemented() } } @@ -191,6 +194,22 @@ class TelematicsSDKPlugin : ActivityAware, ActivityResultListener, FlutterPlugin result.success(stopResult) } + private fun uploadUnsentTrips(result: Result) { + api.uploadUnsentTrips() + result.success(null) + } + + private fun getUnsentTripCount(result: Result) { + val result = api.getUnsentTripCount() + result.success(isGranted) + } + + private fun sendCustomHeartbeats(call: MethodCall, result: Result) { + val reason = call.argument("reason") as String + api.sendCustomHeartbeats(reason) + result.success(null) + } + private fun showPermissionWizard(call: MethodCall, result: Result) { val enableAggressivePermissionsWizard = call.argument("enableAggressivePermissionsWizard") as Boolean diff --git a/ios/Classes/SwiftTelematicsSDKPlugin.swift b/ios/Classes/SwiftTelematicsSDKPlugin.swift index b7a3783..032a36b 100644 --- a/ios/Classes/SwiftTelematicsSDKPlugin.swift +++ b/ios/Classes/SwiftTelematicsSDKPlugin.swift @@ -112,6 +112,12 @@ public class SwiftTelematicsSDKPlugin: NSObject, FlutterPlugin, RPLowPowerModeDe getCurrentSpeed(result) case "getTracks": getTracks(call, result) + case "uploadUnsentTrips": + uploadUnsentTrips(result) + case "getUnsentTripCount": + getUnsentTripCount(result) + case "sendCustomHeartbeats": + sendCustomHeartbeats(call, result: result) default: print("not implemented") } @@ -191,6 +197,25 @@ public class SwiftTelematicsSDKPlugin: NSObject, FlutterPlugin, RPLowPowerModeDe result(nil) } + private func uploadUnsentTrips(_ result: @escaping FlutterResult) { + RPEntry.instance().uploadUnsentTrips() + result(nil) + } + + private func getUnsentTripCount(_ result: @escaping FlutterResult) { + RPEntry.instance().getUnsentTripCount { tripsCount in + result(tripsCount) + } + } + + private func sendCustomHeartbeats(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + let args = call.arguments as! [String: Any] + let reason = args["reason"] as! String + + RPEntry.instance().sendCustomHeartbeat(reason) + result(nil) + } + private func showPermissionWizard(_ call: FlutterMethodCall, _ result: @escaping FlutterReply) { RPPermissionsWizard.returnInstance().launch(finish: { _ in let wizardResult = RPEntry.isAllRequiredPermissionsGranted() ? Constants.WizardResult.allGranted : Constants.WizardResult.notAllGranted diff --git a/lib/src/tracking_api.dart b/lib/src/tracking_api.dart index 8429397..53bbd01 100644 --- a/lib/src/tracking_api.dart +++ b/lib/src/tracking_api.dart @@ -137,6 +137,13 @@ class TrackingApi { Future stopManualTracking() => _channel.invokeMethod('stopManualTracking'); + Future uploadUnsentTrips() => _channel.invokeMethod('uploadUnsentTrips'); + + Future getUnsentTripCount() => _channel.invokeMethod('getUnsentTripCount'); + + Future sendCustomHeartbeats({required String reason}) => + _channel.invokeMethod('sendCustomHeartbeats', {'reason': reason}); + /// `SDK can work in two modes`: /// `Aggressive` - heartbeats are sent every 20 minutes and SDK never sleeps. /// `Normal` - heartbeats are sent every 20 minutes but when system suspends SDK,