-
Notifications
You must be signed in to change notification settings - Fork 27
Persist altitude adjustments clientside #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -456,6 +456,13 @@ internal class RadarApiClient( | |||||||||||||||||||
| params.putOpt("locationMetadata", locationMetadata) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| params.putOpt("pushNotificationToken", RadarSettings.pushNotificationToken) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Include stored altitudeAdjustments from previous track responses | ||||||||||||||||||||
| val altitudeAdjustments = RadarState.getAltitudeAdjustments(context) | ||||||||||||||||||||
| if (altitudeAdjustments != null && altitudeAdjustments.length() > 0) { | ||||||||||||||||||||
| params.putOpt("altitudeAdjustments", altitudeAdjustments) | ||||||||||||||||||||
| logger.d("Including ${altitudeAdjustments.length()} altitude adjustments in track request") | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| } catch (e: JSONException) { | ||||||||||||||||||||
| callback?.onComplete(RadarStatus.ERROR_BAD_REQUEST) | ||||||||||||||||||||
|
|
@@ -514,6 +521,11 @@ internal class RadarApiClient( | |||||||||||||||||||
| RadarEvent.fromJson(eventsArr) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| val user = res.optJSONObject("user")?.let { userObj -> | ||||||||||||||||||||
| // Extract and store altitudeAdjustments from user object | ||||||||||||||||||||
| val altitudeAdjustmentsObj = userObj.optJSONArray("altitudeAdjustments") | ||||||||||||||||||||
| if (altitudeAdjustmentsObj != null) { | ||||||||||||||||||||
| RadarState.setAltitudeAdjustments(context, altitudeAdjustmentsObj) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+524
to
+528
|
||||||||||||||||||||
| // Extract and store altitudeAdjustments from user object | |
| val altitudeAdjustmentsObj = userObj.optJSONArray("altitudeAdjustments") | |
| if (altitudeAdjustmentsObj != null) { | |
| RadarState.setAltitudeAdjustments(context, altitudeAdjustmentsObj) | |
| } | |
| // Extract and store altitudeAdjustments from user object. | |
| // Always call setter so altitude adjustments can be cleared when absent or null. | |
| val altitudeAdjustmentsObj = userObj.optJSONArray("altitudeAdjustments") | |
| RadarState.setAltitudeAdjustments(context, altitudeAdjustmentsObj) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import android.os.Build | |
| import androidx.annotation.RequiresApi | ||
| import androidx.core.content.edit | ||
| import io.radar.sdk.model.RadarBeacon | ||
| import org.json.JSONArray | ||
| import org.json.JSONObject | ||
|
|
||
| internal object RadarState { | ||
|
|
@@ -40,6 +41,7 @@ internal object RadarState { | |
| private const val KEY_LAST_BEACON_UIDS = "last_beacon_uids" | ||
| private const val KEY_LAST_MOTION_ACTIVITY = "last_motion_activity" | ||
| private const val KEY_LAST_PRESSURE = "last_pressure" | ||
| private const val KEY_ALTITUDE_ADJUSTMENTS = "altitude_adjustments" | ||
|
|
||
| private fun getSharedPreferences(context: Context): SharedPreferences { | ||
| return context.getSharedPreferences("RadarSDK", Context.MODE_PRIVATE) | ||
|
|
@@ -289,4 +291,22 @@ internal object RadarState { | |
| putString(KEY_LAST_PRESSURE, jsonString) | ||
| } | ||
| } | ||
|
|
||
| internal fun getAltitudeAdjustments(context: Context): JSONArray? { | ||
| val jsonString = getSharedPreferences(context).getString(KEY_ALTITUDE_ADJUSTMENTS, null) | ||
| return jsonString?.let { | ||
| try { | ||
| JSONArray(it) | ||
| } catch (e: Exception) { | ||
| null | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+295
to
+304
|
||
|
|
||
| internal fun setAltitudeAdjustments(context: Context, altitudeAdjustments: JSONArray?) { | ||
| val jsonString = altitudeAdjustments?.toString() | ||
| getSharedPreferences(context).edit { | ||
| putString(KEY_ALTITUDE_ADJUSTMENTS, jsonString) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new altitude adjustments persistence feature lacks test coverage. Given that the repository has comprehensive tests for similar persistence features (e.g., tags persistence in test_Radar_tags_persistence at line 516), consider adding tests to verify that altitude adjustments are correctly persisted to SharedPreferences and included in track requests. Tests should cover scenarios where altitude adjustments are retrieved from storage and included in requests, and where they are extracted from responses and stored.