Skip to content

Commit

Permalink
add metadata as well
Browse files Browse the repository at this point in the history
  • Loading branch information
KennyHuRadar committed Mar 4, 2025
1 parent 7dcc706 commit 3c542e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apply plugin: "org.jetbrains.dokka"
apply plugin: 'io.radar.mvnpublish'

ext {
radarVersion = '3.21.3-beta.1'
radarVersion = '3.21.3-beta.2'
}

String buildNumber = ".${System.currentTimeMillis()}"
Expand Down
26 changes: 20 additions & 6 deletions sdk/src/main/java/io/radar/sdk/RadarApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ internal class RadarApiClient(
val options = Radar.getTrackingOptions()
val tripOptions = RadarSettings.getTripOptions(context)
val anonymous = RadarSettings.getAnonymousTrackingEnabled(context)
var userMetadata = JSONObject()
try {
params.putOpt("anonymous", anonymous)
if (anonymous) {
Expand Down Expand Up @@ -294,6 +295,11 @@ internal class RadarApiClient(
if (location.hasBearing() && !location.bearing.isNaN()) {
params.putOpt("course", location.bearing)
}

if (location.hasAltitude() && !location.altitude.isNaN()) {
params.putOpt("altitude", location.altitude)
userMetadata.putOpt("altitude", location.altitude)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (location.hasVerticalAccuracy() && !location.verticalAccuracyMeters.isNaN()) {
params.putOpt("verticalAccuracy", location.verticalAccuracyMeters)
Expand Down Expand Up @@ -391,19 +397,20 @@ internal class RadarApiClient(
} catch (_: Exception) {

}

if (RadarSettings.getSdkConfiguration(context).useLocationMetadata) {
val metadata = JSONObject()
metadata.putOpt("motionActivityData", RadarState.getLastMotionActivity(context))

userMetadata.putOpt("motionActivityData", RadarState.getLastMotionActivity(context))
if (location.hasSpeed() && !location.speed.isNaN()) {
metadata.putOpt("speed",location.speed)
userMetadata.putOpt("speed",location.speed)
}
if (location.hasBearing() && !location.bearing.isNaN()) {
metadata.putOpt("bearing", location.bearing)
userMetadata.putOpt("bearing", location.bearing)
}
if (RadarState.getLastPressure(context) != null) {
metadata.putOpt("pressureHPa", RadarState.getLastPressure(context))
userMetadata.putOpt("pressureHPa", RadarState.getLastPressure(context))
}
params.putOpt("locationMetadata", metadata)
params.putOpt("locationMetadata", userMetadata)
}
} catch (e: JSONException) {
callback?.onComplete(RadarStatus.ERROR_BAD_REQUEST)
Expand Down Expand Up @@ -463,6 +470,12 @@ internal class RadarApiClient(
RadarEvent.fromJson(eventsArr)
}
val user = res.optJSONObject("user")?.let { userObj ->
// Merge existing metadata with userMetadata
val existingMetadata = userObj.optJSONObject("metadata") ?: JSONObject()
userMetadata.keys().forEach { key ->
existingMetadata.putOpt(key, userMetadata.get(key))
}
userObj.putOpt("metadata", existingMetadata)
RadarUser.fromJson(userObj)
}
val nearbyGeofences = res.optJSONArray("nearbyGeofences")?.let { nearbyGeofencesArr ->
Expand Down Expand Up @@ -492,6 +505,7 @@ internal class RadarApiClient(

val beaconIds = mutableSetOf<String>()
user.beacons?.forEach { beacon -> beacon._id?.let { _id -> beaconIds.add(_id) } }

RadarState.setBeaconIds(context, beaconIds)
}

Expand Down

0 comments on commit 3c542e2

Please # to comment.