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