Skip to content

Commit

Permalink
RMET-3048 :: Migrate GetLastRecord to HealthConnect (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgerardojacinto committed Apr 9, 2024
1 parent 259865d commit ba8ff7a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 42 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ The changes documented here do not include those from the original repository.

## [Unreleased]

## 2024-02-08
- Re-implement `GetLastRecord` feature:
- GetFitnessData (https://outsystemsrd.atlassian.net/browse/RMET-3048)
- GetHealthData (https://outsystemsrd.atlassian.net/browse/RMET-3065)
- GetProfileData (https://outsystemsrd.atlassian.net/browse/RMET-3066)

## 2024-02-05
- Re-implemented WriteProfieleData feature (https://outsystemsrd.atlassian.net/browse/RMET-3049).

Expand Down
2 changes: 1 addition & 1 deletion src/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies{

implementation("com.github.outsystems:oscore-android:1.2.0@aar")
implementation("com.github.outsystems:oscordova-android:1.2.0@aar")
implementation("com.github.outsystems:oshealthfitness-android:1.2.0.5@aar")
implementation("com.github.outsystems:oshealthfitness-android:1.2.0.8@aar")
implementation("com.github.outsystems:osnotificationpermissions-android:0.0.4@aar")

def roomVersion = "2.4.2"
Expand Down
72 changes: 31 additions & 41 deletions src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,52 +178,42 @@ class OSHealthFitness : CordovaImplementation() {
}

private fun writeData(args: JSONArray) {
val variable = args.getString(0)
val value = args.getDouble(1)
val healthRecordName: HealthRecordName
try {
val variable = args.getString(0)
val healthRecordName = HealthRecordName.valueOf(variable)
val value = args.getDouble(1)

when (variable) {
HealthRecordName.WEIGHT.name -> {
healthRecordName = HealthRecordName.WEIGHT
}
HealthRecordName.HEIGHT.name -> {
healthRecordName = HealthRecordName.HEIGHT
}
HealthRecordName.BODY_FAT_PERCENTAGE.name -> {
healthRecordName = HealthRecordName.BODY_FAT_PERCENTAGE
}
HealthRecordName.BASAL_METABOLIC_RATE.name -> {
healthRecordName = HealthRecordName.BASAL_METABOLIC_RATE
}
else -> {
sendPluginResult(
null,
Pair(
HealthFitnessError.WRITE_DATA_NOT_PROFILE_ERROR.code.toString(),
HealthFitnessError.WRITE_DATA_NOT_PROFILE_ERROR.message
)
)
return
}
healthConnectViewModel.writeData(
healthRecordName,
value,
getActivity().packageName,
{
sendPluginResult("success", null)
},
{
sendPluginResult(null, Pair(it.code.toString(), it.message))
}
)
} catch (e: Exception) {
sendPluginResult(null, Pair(HealthFitnessError.VARIABLE_NOT_AVAILABLE_ERROR.code.toString(), HealthFitnessError.VARIABLE_NOT_AVAILABLE_ERROR.message))
}

healthConnectViewModel.writeData(
healthRecordName,
value,
getActivity().packageName,
{
sendPluginResult("success", null)
},
{
sendPluginResult(null, Pair(it.code.toString(), it.message))
}
)
}

private fun getLastRecord(args: JSONArray) {
//process parameters
val variable = args.getString(0)
healthConnectViewModel.getLastRecord()
try {
healthConnectViewModel.getLastRecord(
HealthRecordName.valueOf(args.getString(0)),
{
sendPluginResult(it, null)
},
{
sendPluginResult(null, Pair(it.code.toString(), it.message))
}
)
} catch (e: Exception) {
sendPluginResult(null, Pair(HealthFitnessError.VARIABLE_NOT_AVAILABLE_ERROR.code.toString(), HealthFitnessError.VARIABLE_NOT_AVAILABLE_ERROR.message))
}

}

private fun setBackgroundJob(args: JSONArray) {
Expand Down

0 comments on commit ba8ff7a

Please sign in to comment.