Skip to content

Commit

Permalink
Update HyperTrack SDK iOS to 5.8.1 and Android to 7.8.4 (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferologics authored Nov 13, 2024
1 parent 422517e commit 272f918
Show file tree
Hide file tree
Showing 27 changed files with 198 additions and 241 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.6.3] - 2024-11-13

### Changed

- Updated HyperTrack SDK iOS to [5.8.1](https://github.com/hypertrack/sdk-ios/releases/tag/5.8.1)
- Updated HyperTrack SDK Android to [7.8.4](https://github.com/hypertrack/sdk-android/releases/tag/7.8.4)

## [3.6.2] - 2024-09-24

### Changed
Expand Down Expand Up @@ -309,3 +316,4 @@ We are excited to announce the release of HyperTrack Ionic Capacitor SDK 2.0.0,
[3.6.0]: https://github.com/hypertrack/sdk-ionic-capacitor/releases/tag/3.6.0
[3.6.1]: https://github.com/hypertrack/sdk-ionic-capacitor/releases/tag/3.6.1
[3.6.2]: https://github.com/hypertrack/sdk-ionic-capacitor/releases/tag/3.6.2
[3.6.3]: https://github.com/hypertrack/sdk-ionic-capacitor/releases/tag/3.6.3
2 changes: 1 addition & 1 deletion HypertrackSdkIonicCapacitor.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '12.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
s.dependency 'HyperTrack','5.8.0'
s.dependency 'HyperTrack','5.8.1'
end
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

[![GitHub](https://img.shields.io/github/license/hypertrack/sdk-ionic-capacitor.svg?color=orange)](./LICENSE)
[![npm](https://img.shields.io/npm/v/hypertrack-sdk-ionic-capacitor.svg)](https://www.npmjs.com/package/hypertrack-sdk-ionic-capacitor)
[![iOS SDK](https://img.shields.io/badge/iOS%20SDK-5.8.0-brightgreen.svg)](https://github.com/hypertrack/sdk-ios)
[![Android SDK](https://img.shields.io/badge/Android%20SDK-7.8.3-brightgreen.svg)](https://github.com/hypertrack/sdk-android)
[![iOS SDK](https://img.shields.io/badge/iOS%20SDK-5.8.1-brightgreen.svg)](https://github.com/hypertrack/sdk-ios)
[![Android SDK](https://img.shields.io/badge/Android%20SDK-7.8.4-brightgreen.svg)](https://github.com/hypertrack/sdk-android)

[HyperTrack](https://www.hypertrack.com) lets you add live location tracking to your mobile app. Live location is made available along with ongoing activity, tracking controls and tracking outage with reasons.

Expand Down
5 changes: 5 additions & 0 deletions android/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[**/*.kt]
# TODO: use explicit instead of wildcard imports
ktlint_standard_no-wildcard-imports = disabled
# TODO: align with standard enum case naming
ktlint_standard_enum-entry-name-case = disabled
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ext {

buildscript {
ext.kotlin_version = project.hasProperty('kotlin_version') ? rootProject.ext.kotlin_version : '1.9.10'
ext.hypertrack_sdk_version = "7.8.3"
ext.hypertrack_sdk_version = "7.8.4"
ext.firebase_messaging_version = "23.1.1"

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import com.getcapacitor.JSObject
import com.getcapacitor.PluginCall
import com.hypertrack.sdk.capacitor.common.Failure
import com.hypertrack.sdk.capacitor.common.Serialized
import com.hypertrack.sdk.capacitor.common.WrapperResult
import com.hypertrack.sdk.capacitor.common.Success
import com.hypertrack.sdk.capacitor.common.WrapperResult
import org.json.JSONArray
import org.json.JSONObject

private const val KEY_ERRORS = "errors"

fun serializeErrorsForCapacitor(errors: List<Serialized>): Serialized {
return mapOf(
KEY_ERRORS to errors
fun serializeErrorsForCapacitor(errors: List<Serialized>): Serialized =
mapOf(
KEY_ERRORS to errors,
)
}

@Suppress("UNCHECKED_CAST")
internal fun <T> WrapperResult<T>.toPluginCall(call: PluginCall) {
Expand Down Expand Up @@ -47,8 +46,8 @@ internal fun <T> WrapperResult<T>.toPluginCall(call: PluginCall) {
}

@Suppress("UNCHECKED_CAST")
internal fun List<Any>.toJSArray(): JSArray {
return JSArray().also { writableArray ->
internal fun List<Any>.toJSArray(): JSArray =
JSArray().also { writableArray ->
forEach {
when (it) {
is Map<*, *> -> {
Expand All @@ -63,7 +62,6 @@ internal fun List<Any>.toJSArray(): JSArray {
}
}
}
}

@Suppress("UNCHECKED_CAST")
internal fun Map<String, Any?>.toJSObject(): JSObject {
Expand Down Expand Up @@ -91,7 +89,7 @@ internal fun Map<String, Any?>.toJSObject(): JSObject {
}
null -> {
throw IllegalArgumentException(
"Invalid JSON: $this \n Null JSON values are not supported"
"Invalid JSON: $this \n Null JSON values are not supported",
)
}
else -> {
Expand All @@ -102,13 +100,14 @@ internal fun Map<String, Any?>.toJSObject(): JSObject {
}
}

fun JSONObject.toMap(): Map<String, Any?> {
return keys().asSequence().associateWith { key ->
fun JSONObject.toMap(): Map<String, Any?> =
keys().asSequence().associateWith { key ->
when (val value = this.get(key)) {
is Boolean,
is Double,
is Int,
is String -> {
is String,
-> {
value
}
is JSONArray -> {
Expand All @@ -122,15 +121,15 @@ fun JSONObject.toMap(): Map<String, Any?> {
}
}
}
}

private fun JSONArray.toList(): List<Any> {
return (0..length()).mapNotNull { index ->
private fun JSONArray.toList(): List<Any> =
(0..length()).mapNotNull { index ->
when (val value = this.get(index)) {
is Boolean,
is Double,
is Int,
is String -> {
is String,
-> {
value
}
is JSONArray -> {
Expand All @@ -144,4 +143,3 @@ private fun JSONArray.toList(): List<Any> {
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.hypertrack.sdk.capacitor.common.Serialization.serializeOrders

@CapacitorPlugin(name = "HyperTrackCapacitorPlugin")
class HyperTrackCapacitorPlugin : Plugin() {

private var locateSubscription: HyperTrack.Cancellable? = null

init {
Expand Down Expand Up @@ -114,9 +113,10 @@ class HyperTrackCapacitorPlugin : Plugin() {
@PluginMethod
fun onSubscribedToLocate(call: PluginCall) {
locateSubscription?.cancel()
locateSubscription = HyperTrack.locate { result ->
sendLocateEvent(result)
}
locateSubscription =
HyperTrack.locate { result ->
sendLocateEvent(result)
}
}

@PluginMethod
Expand All @@ -132,42 +132,42 @@ class HyperTrackCapacitorPlugin : Plugin() {
private fun sendErrorsEvent(errors: Set<HyperTrack.Error>) {
sendEvent(
EVENT_ERRORS,
serializeErrorsForCapacitor(serializeErrors(errors)).toJSObject()
serializeErrorsForCapacitor(serializeErrors(errors)).toJSObject(),
)
}

private fun sendIsAvailableEvent(isAvailable: Boolean) {
sendEvent(
EVENT_IS_AVAILABLE,
Serialization.serializeIsAvailable(isAvailable).toJSObject()
Serialization.serializeIsAvailable(isAvailable).toJSObject(),
)
}

private fun sendIsTrackingEvent(isTracking: Boolean) {
sendEvent(
EVENT_IS_TRACKING,
Serialization.serializeIsTracking(isTracking).toJSObject()
Serialization.serializeIsTracking(isTracking).toJSObject(),
)
}

private fun sendLocationEvent(locationResult: Result<HyperTrack.Location, HyperTrack.LocationError>) {
sendEvent(
EVENT_LOCATION,
Serialization.serializeLocationResult(locationResult).toJSObject()
Serialization.serializeLocationResult(locationResult).toJSObject(),
)
}

private fun sendLocateEvent(locateResult: Result<HyperTrack.Location, Set<HyperTrack.Error>>) {
sendEvent(
EVENT_LOCATE,
Serialization.serializeLocateResult(locateResult).toJSObject()
Serialization.serializeLocateResult(locateResult).toJSObject(),
)
}

private fun sendOrdersEvent(orders: Collection<HyperTrack.Order>) {
sendEvent(
EVENT_ORDERS,
serializeOrders(orders).toJSObject()
serializeOrders(orders).toJSObject(),
)
}

Expand Down Expand Up @@ -195,7 +195,7 @@ class HyperTrackCapacitorPlugin : Plugin() {

private fun invokeSdkMethod(
method: SdkMethod,
call: PluginCall
call: PluginCall,
): WrapperResult<*> {
val argsJson = call.data
return when (method) {
Expand Down Expand Up @@ -290,15 +290,19 @@ class HyperTrackCapacitorPlugin : Plugin() {
}
}

private fun sendEvent(eventName: String, data: JSObject, retainUntilConsumed: Boolean = false) {
private fun sendEvent(
eventName: String,
data: JSObject,
retainUntilConsumed: Boolean = false,
) {
notifyListeners(eventName, data, retainUntilConsumed)
}

private inline fun <reified T, N> withArgs(
args: JSObject,
crossinline sdkMethodCall: (T) -> WrapperResult<N>
): WrapperResult<N> {
return when (T::class) {
crossinline sdkMethodCall: (T) -> WrapperResult<N>,
): WrapperResult<N> =
when (T::class) {
Map::class -> {
sdkMethodCall.invoke(args.toMap() as T)
}
Expand All @@ -307,7 +311,6 @@ class HyperTrackCapacitorPlugin : Plugin() {
Failure(IllegalArgumentException(args.toString()))
}
}
}

companion object {
private const val EVENT_ERRORS = "errors"
Expand Down
Loading

0 comments on commit 272f918

Please sign in to comment.