diff --git a/CHANGELOG.md b/CHANGELOG.md index ce66346d..e40f36b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/src/android/build.gradle b/src/android/build.gradle index 211d0e9a..7d9bbb17 100644 --- a/src/android/build.gradle +++ b/src/android/build.gradle @@ -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" diff --git a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt index 5ba0638d..c00922ee 100755 --- a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt +++ b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt @@ -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) {