Skip to content

Commit

Permalink
Stage 1
Browse files Browse the repository at this point in the history
* Add `deviceID` methods: `setDeviceID`, `getDeviceID`, `clearDeviceID`.
* Add permissions check method: `isAllRequiredPermissionsAndSensorsGranted`.
* Add SDK status manipulation: `isSdkEnabled`, `setEnableSdk`.
* Add tracking manipulation: `isTracking`, `startTracking`, `stopTracking`.
* Add tags manipulation: `getTrackTags`, `addTrackTags`, `removeTrackTags`.
* Add PermissionWizard methods.
* iOS: add `lowerPowerMode`.
* iOS: add `setAggressiveHeartbeats` with brief documentation.
  • Loading branch information
dkrutskikh committed Apr 15, 2021
1 parent adb8227 commit ccf5238
Show file tree
Hide file tree
Showing 28 changed files with 1,123 additions and 83 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Changelog

## 0.1.0

* Add `deviceID` methods: `setDeviceID`, `getDeviceID`, `clearDeviceID`.
* Add permissions check method: `isAllRequiredPermissionsAndSensorsGranted`.
* Add SDK status manipulation: `isSdkEnabled`, `setEnableSdk`.
* Add tracking manipulation: `isTracking`, `startTracking`, `stopTracking`.
* Add tags manipulation: `getTrackTags`, `addTrackTags`, `removeTrackTags`.
* Add future tag manipulation: `getFutureTrackTags`, `addFutureTrackTag`, `removeFutureTrackTag`, `removeAllFutureTrackTags`.
* Add PermissionWizard methods.
* iOS: add `lowerPowerMode`.
* iOS: add `setAggressiveHeartbeats` with brief documentation.

## 0.0.1

* TODO: Describe initial release.
* Initial version
129 changes: 128 additions & 1 deletion LICENSE

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,27 @@ add network permissions
}
```

### iOS

Add permissions in your project's `ios/Runner/Info.plist`:
``` xml
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>location</string>
<string>remote-notification</string>
</array>
<key>NSMotionUsageDescription</key>
<string>Please, provide permissions for this Demo</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Please, provide permissions for this Demo</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Please, provide permissions for this Demo</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Please, provide permissions for this Demo</string>
```
## Links
[https://telematicssdk.com/](https://telematicssdk.com/)
28 changes: 28 additions & 0 deletions android/src/main/kotlin/com/telematicssdk/TagsExtentions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.telematicssdk

import org.json.JSONObject
import com.raxeltelematics.v2.sdk.server.model.sdk.TrackTag
import com.raxeltelematics.v2.sdk.server.model.sdk.raw_tags.Tag

fun TrackTag.toJsonString(): String {
val json = mapOf<String, Any?>(
"source" to source,
"tag" to tag,
"type" to type,
)

val jsonObject = JSONObject(json)

return jsonObject.toString()
}

fun Tag.toJsonString(): String {
val json = mapOf<String, Any?>(
"source" to source,
"tag" to tag,
)

val jsonObject = JSONObject(json)

return jsonObject.toString()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.telematicssdk

import com.raxeltelematics.v2.sdk.TagsProcessingListener
import com.raxeltelematics.v2.sdk.model.database.models.raw_tags.Status
import com.raxeltelematics.v2.sdk.server.model.sdk.raw_tags.Tag
import io.flutter.plugin.common.MethodChannel

class TagsProcessingListenerImp(private val channel: MethodChannel) : TagsProcessingListener {
override fun onTagAdd(status: Status, tag: Tag, activationTime: Long) {
val json = mapOf<String, Any>(
"status" to status.name,
"tag" to tag.toJsonString(),
"activationTime" to activationTime
)

channel.invokeMethod("onTagAdd", json)
}

override fun onTagRemove(status: Status, tag: Tag, deactivationTime: Long) {
val json = mapOf<String, Any>(
"status" to status.name,
"tag" to tag.toJsonString(),
"deactivationTime" to deactivationTime
)

channel.invokeMethod("onTagRemove", json)
}

override fun onAllTagsRemove(status: Status, deactivatedTagsCount: Int, time: Long) {
val json = mapOf<String, Any>(
"status" to status.name,
"deactivatedTagsCount" to deactivatedTagsCount,
"time" to time
)

channel.invokeMethod("onAllTagsRemove", json)
}

override fun onGetTags(status: Status, tags: Array<Tag>?, time: Long) {
val json = mapOf<String, Any?>(
"status" to status.name,
"tags" to tags?.map { it.toJsonString() },
"time" to time
)

channel.invokeMethod("onGetTags", json)
}
}
8 changes: 8 additions & 0 deletions android/src/main/kotlin/com/telematicssdk/TelematicsSDKApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ open class TelematicsSDKApp : FlutterApplication() {
}
}

/**
* Default Setting constructor
* Stop tracking time is 5 minute.
* Parking radius is 100 meters.
* Auto start tracking is true.
* hfOn - true if HIGH FREQUENCY data recording from sensors (acc, gyro) is ON and false otherwise.
* isElmOn - true if data recording from ELM327 devices is ON and false otherwise.
*/
open fun setTelematicsSettings(): Settings {
val settings = Settings(
stopTrackingTimeout = Settings.stopTrackingTimeHigh,
Expand Down
125 changes: 109 additions & 16 deletions android/src/main/kotlin/com/telematicssdk/TelematicsSDKPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import androidx.annotation.NonNull
import org.json.JSONObject
import com.raxeltelematics.v2.sdk.TrackingApi
import com.raxeltelematics.v2.sdk.server.model.sdk.TrackTag
import com.raxeltelematics.v2.sdk.utils.permissions.PermissionsWizardActivity

import io.flutter.embedding.engine.plugins.FlutterPlugin
Expand All @@ -16,6 +18,14 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry.ActivityResultListener

class WizardConstants {
companion object {
const val allGranted = "WIZARD_RESULT_ALL_GRANTED"
const val notAllGranted = "WIZARD_RESULT_NOT_ALL_GRANTED"
const val canceled = "WIZARD_RESULT_CANCELED"
}
}

/** TelematicsSDKPlugin */
class TelematicsSDKPlugin : ActivityAware, ActivityResultListener, FlutterPlugin,
MethodCallHandler {
Expand All @@ -40,6 +50,9 @@ class TelematicsSDKPlugin : ActivityAware, ActivityResultListener, FlutterPlugin
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "telematics_sdk")
channel.setMethodCallHandler(this)
context = flutterPluginBinding.applicationContext

/// register callbacks
api.addTagsProcessingCallback(TagsProcessingListenerImp(channel))
}

override fun onDetachedFromActivity() {
Expand Down Expand Up @@ -69,9 +82,16 @@ class TelematicsSDKPlugin : ActivityAware, ActivityResultListener, FlutterPlugin
"isTracking" -> isTracking(result)
"setDeviceID" -> setDeviceID(call, result)
"setEnableSdk" -> setEnableSdk(call, result)
"showPermissionWizard" -> showPermissionWizard(call, result)
"startTracking" -> startTracking(result)
"stopTracking" -> stopTracking(result)
"showPermissionWizard" -> showPermissionWizard(call, result)
"getTrackTags" -> getTrackTags(call, result)
"addTrackTags" -> addTrackTags(call, result)
"removeTrackTags" -> removeTrackTags(call, result)
"getFutureTrackTags" -> getFutureTrackTags(result)
"addFutureTrackTag" -> addFutureTrackTag(call, result)
"removeFutureTrackTag" -> removeFutureTrackTag(call, result)
"removeAllFutureTrackTags" -> removeAllFutureTrackTags(result)
else -> result.notImplemented()
}
}
Expand All @@ -82,11 +102,11 @@ class TelematicsSDKPlugin : ActivityAware, ActivityResultListener, FlutterPlugin

when (resultCode) {
PermissionsWizardActivity.WIZARD_RESULT_ALL_GRANTED -> wizardResult =
"WIZARD_RESULT_ALL_GRANTED"
WizardConstants.allGranted
PermissionsWizardActivity.WIZARD_RESULT_NOT_ALL_GRANTED -> wizardResult =
"WIZARD_RESULT_NOT_ALL_GRANTED"
WizardConstants.notAllGranted
PermissionsWizardActivity.WIZARD_RESULT_CANCELED -> wizardResult =
"WIZARD_RESULT_CANCELED"
WizardConstants.canceled
}

channel.invokeMethod("onPermissionWizardResult", wizardResult)
Expand All @@ -96,65 +116,69 @@ class TelematicsSDKPlugin : ActivityAware, ActivityResultListener, FlutterPlugin
return false
}

private fun clearDeviceID(@NonNull result: Result) {
private fun clearDeviceID(result: Result) {
api.clearDeviceID()

result.success(null)
}

private fun getDeviceId(@NonNull result: Result) {
private fun getDeviceId(result: Result) {
val deviceId = api.getDeviceId()

result.success(deviceId)
}

private fun isSdkEnabled(@NonNull result: Result) {
private fun isSdkEnabled(result: Result) {
val isEnabled = api.isSdkEnabled()

result.success(isEnabled)
}

private fun isTracking(@NonNull result: Result) {
private fun isTracking(result: Result) {
val isTracking = api.isTracking()

result.success(isTracking)
}

private fun isAllRequiredPermissionsAndSensorsGranted(@NonNull result: Result) {
private fun isAllRequiredPermissionsAndSensorsGranted(result: Result) {
val isGranted = api.isAllRequiredPermissionsAndSensorsGranted()

result.success(isGranted)
}

private fun setDeviceID(@NonNull call: MethodCall, @NonNull result: Result) {
private fun setDeviceID(call: MethodCall, result: Result) {
val deviceId = call.argument<String?>("deviceId") as String

api.setDeviceID(deviceId)

result.success(null)
}

private fun setEnableSdk(@NonNull call: MethodCall, @NonNull result: Result) {
private fun setEnableSdk(call: MethodCall, result: Result) {
val enable = call.argument<Boolean?>("enable") as Boolean
val uploadBeforeDisabling = call.argument<Boolean?>("uploadBeforeDisabling") as Boolean

api.setEnableSdk(enable)

if (!enable && uploadBeforeDisabling) {
api.setDisableWithUpload()
} else {
api.setEnableSdk(enable)
}
result.success(null)
}

private fun startTracking(@NonNull result: Result) {
private fun startTracking(result: Result) {
val startResult = api.startTracking()

result.success(startResult)
}

private fun stopTracking(@NonNull result: Result) {
private fun stopTracking(result: Result) {
val stopResult = api.stopTracking()

result.success(stopResult)
}

private fun showPermissionWizard(@NonNull call: MethodCall, @NonNull result: Result) {
private fun showPermissionWizard(call: MethodCall, result: Result) {
val enableAggressivePermissionsWizard =
call.argument<Boolean?>("enableAggressivePermissionsWizard") as Boolean
val enableAggressivePermissionsWizardPage =
Expand All @@ -170,4 +194,73 @@ class TelematicsSDKPlugin : ActivityAware, ActivityResultListener, FlutterPlugin

result.success(null)
}

private fun getTrackTags(call: MethodCall, result: Result) {
val trackId = call.argument<String?>("trackId") as String

val res = api.getTrackTags(trackId).map { it.toJsonString() }.toTypedArray()

result.success(res)
}

private fun addTrackTags(call: MethodCall, result: Result) {
val trackId = call.argument<String?>("trackId") as String
val strings = call.argument<Array<String>?>("tags") as Array<String>

val tags = strings.map {
val json = JSONObject(it)
val tag = json["tag"] as String
val source = json["source"] as String
TrackTag(tag, source)
}.toTypedArray()

val res = api.addTrackTags(trackId, tags).map { it.toJsonString() }.toTypedArray()

result.success(res)
}

private fun removeTrackTags(call: MethodCall, result: Result) {
val trackId = call.argument<String?>("trackId") as String
val strings = call.argument<Array<String>?>("tags") as Array<String>

val tags = strings.map {
val json = JSONObject(it)
val tag = json["tag"] as String
val source = json["source"] as String
TrackTag(tag, source)
}.toTypedArray()

val res = api.removeTrackTags(trackId, tags).map { it.toJsonString() }.toTypedArray()

result.success(res)
}

private fun getFutureTrackTags(result: Result) {
api.getFutureTrackTags()

result.success(null)
}

private fun addFutureTrackTag(call: MethodCall, result: Result) {
val tag = call.argument<String?>("tag") as String
val source = call.argument<String?>("source") as String

api.addFutureTrackTag(tag, source)

result.success(null)
}

private fun removeFutureTrackTag(call: MethodCall, result: Result) {
val tag = call.argument<String?>("tag") as String

api.removeFutureTrackTag(tag)

result.success(null)
}

private fun removeAllFutureTrackTags(result: Result) {
api.removeAllFutureTrackTags()

result.success(null)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.telematicssdk

import com.raxeltelematics.v2.sdk.server.model.sdk.TrackTag

fun TrackTag.toJsonString(): String {
return "{\"source\": \"$source\", \"tag\": \"$tag\", \"type\": \"$type\"}";
}
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# platform :ios, '10.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 51;
objects = {

/* Begin PBXBuildFile section */
Expand Down
Loading

0 comments on commit ccf5238

Please sign in to comment.