Skip to content

Commit

Permalink
Added uploadUnsentTrips, getUnsentTripCount, sendCustomHeartbeats met…
Browse files Browse the repository at this point in the history
…hods
  • Loading branch information
sgusakovsky committed Oct 25, 2024
1 parent 96e79ef commit 6b59a3f
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions android/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions android/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions android/.idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions android/.idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions android/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions android/src/main/kotlin/com/telematicssdk/TelematicsSDKPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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<String?>("reason") as String
api.sendCustomHeartbeats(reason)
result.success(null)
}

private fun showPermissionWizard(call: MethodCall, result: Result) {
val enableAggressivePermissionsWizard =
call.argument<Boolean?>("enableAggressivePermissionsWizard") as Boolean
Expand Down
25 changes: 25 additions & 0 deletions ios/Classes/SwiftTelematicsSDKPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/src/tracking_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ class TrackingApi {

Future<bool?> stopManualTracking() => _channel.invokeMethod('stopManualTracking');

Future<bool?> uploadUnsentTrips() => _channel.invokeMethod('uploadUnsentTrips');

Future<int?> getUnsentTripCount() => _channel.invokeMethod('getUnsentTripCount');

Future<bool?> 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,
Expand Down

0 comments on commit 6b59a3f

Please sign in to comment.