Skip to content

Commit

Permalink
RMET-3049 OSHealthFitnessLib-Android - Migrate WriteProfileData featu…
Browse files Browse the repository at this point in the history
…re (#97)

* feat: implement first version of writeProfileData

References: https://outsystemsrd.atlassian.net/browse/RMET-3049

* refactor: remove commented code

References: https://outsystemsrd.atlassian.net/browse/RMET-3049

* refactor: remove commented code

References: https://outsystemsrd.atlassian.net/browse/RMET-3049

* chore: update changelog

References: https://outsystemsrd.atlassian.net/browse/RMET-3049

* feat: update android lib version

References: https://outsystemsrd.atlassian.net/browse/RMET-3049
  • Loading branch information
alexgerardojacinto authored Feb 6, 2024
1 parent fafbcb0 commit 84e42f6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The changes documented here do not include those from the original repository.

## [Unreleased]

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

## 2024-02-01
- Re-implemented RequestPermissions feature (https://outsystemsrd.atlassian.net/browse/RMET-3046).

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.4@aar")
implementation("com.github.outsystems:oshealthfitness-android:1.2.0.5@aar")
implementation("com.github.outsystems:osnotificationpermissions-android:0.0.4@aar")

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

private fun writeData(args: JSONArray) {

//process parameters
val variable = args.getString(0)
val value = args.getDouble(1).toFloat()
val value = args.getDouble(1)
val healthRecordName: HealthRecordName

healthStore?.updateDataAsync(
variable,
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,
{ response ->
sendPluginResult(response)
getActivity().packageName,
{
sendPluginResult("success", null)
},
{ error ->
sendPluginResult(null, Pair(error.code.toString(), error.message))
{
sendPluginResult(null, Pair(it.code.toString(), it.message))
}

)
}

private fun getLastRecord(args: JSONArray) {
//process parameters
val variable = args.getString(0)
healthStore?.getLastRecordAsync(
variable,
{ response ->
val pluginResponseJson = gson.toJson(response)
sendPluginResult(pluginResponseJson)
},
{ error ->
sendPluginResult(null, Pair(error.code.toString(), error.message))
})
healthConnectViewModel.getLastRecord()
}

private fun setBackgroundJob(args: JSONArray) {
Expand Down

0 comments on commit 84e42f6

Please sign in to comment.