From 0c4b58679a08607ebb94b7c5f78d65a92f2630b0 Mon Sep 17 00:00:00 2001 From: Nelson Lopes Silva <5671236+nflsilva@users.noreply.github.com> Date: Fri, 10 Dec 2021 15:21:09 +0000 Subject: [PATCH 1/3] Added delete background job features --- .../plugins/healthfitness/OSHealthFitness.kt | 25 +++++++--- .../HealthFitnessError.kt | 2 + .../background/database/AppDatabase.kt | 3 ++ .../background/database/BackgroundJob.kt | 25 +++++++++- .../background/database/BackgroundJobDao.kt | 9 ++-- .../background/database/DatabaseManager.kt | 16 ++++--- .../database/DatabaseManagerInterface.kt | 4 +- .../store/HealthFitnessManager.kt | 42 ++++++++++++++++ .../store/HealthFitnessManagerInterface.kt | 5 ++ .../store/HealthStore.kt | 48 +++++++++++++++++-- www/OSHealthFitness.js | 4 ++ 11 files changed, 162 insertions(+), 21 deletions(-) diff --git a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt index 25ce6de3..a7fd6281 100755 --- a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt +++ b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt @@ -59,7 +59,11 @@ class OSHealthFitness : CordovaImplementation() { getLastRecord(args) } "setBackgroundJob" -> { - setBackgroundJob(args) + //setBackgroundJob(args) + deleteBackgroundJob(args) + } + "deleteBackgroundJob" -> { + deleteBackgroundJob(args) } } return true @@ -67,7 +71,6 @@ class OSHealthFitness : CordovaImplementation() { //create array of permission oauth private fun initAndRequestPermissions(args : JSONArray) { - val customPermissions = args.getString(0) val allVariables = args.getString(1) val fitnessVariables = args.getString(2) @@ -88,7 +91,6 @@ class OSHealthFitness : CordovaImplementation() { catch (hse : HealthStoreException) { sendPluginResult(null, Pair(hse.error.code, hse.error.message)) } - } private fun areAndroidPermissionsGranted(permissions: List): Boolean { @@ -188,6 +190,19 @@ class OSHealthFitness : CordovaImplementation() { ) } + private fun deleteBackgroundJob(args: JSONArray) { + val parameters = args.getString(0) + healthStore?.deleteBackgroundJob( + "WEIGHT-HIGHER-100", + { response -> + sendPluginResult(response) + }, + { error -> + sendPluginResult(null, Pair(error.code, error.message)) + } + ) + } + override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent) { //super.onActivityResult(requestCode, resultCode, intent) try { @@ -197,7 +212,6 @@ class OSHealthFitness : CordovaImplementation() { val error = hse.error sendPluginResult(null, Pair(error.code, error.message)) } - } override fun areGooglePlayServicesAvailable(): Boolean { @@ -221,8 +235,7 @@ class OSHealthFitness : CordovaImplementation() { override fun onRequestPermissionResult( requestCode: Int, permissions: Array, - grantResults: IntArray - ) { + grantResults: IntArray) { when (requestCode) { ACTIVITY_LOCATION_PERMISSIONS_REQUEST_CODE -> { // If request is cancelled, the result arrays are empty. diff --git a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/HealthFitnessError.kt b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/HealthFitnessError.kt index ff95a875..402b910d 100644 --- a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/HealthFitnessError.kt +++ b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/HealthFitnessError.kt @@ -9,6 +9,8 @@ enum class HealthFitnessError(val code: Int, val message: String) { WRITE_DATA_ERROR(104, "Error while writing data."), BACKGROUND_JOB_ALREADY_EXISTS_ERROR(105, "The background job you are trying to set already exists."), BACKGROUND_JOB_GENERIC_ERROR(106, "The background job could not be created."), + BACKGROUND_JOB_DOES_NOT_EXISTS_ERROR(107, "The background job could not be found."), + UNSUBSCRIBE_ERROR(107, "The background job could not be deleted"), // Plugin Android specific errors WRITE_VALUE_OUT_OF_RANGE_ERROR(109, "Value provided is out of range for this variable"), diff --git a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/AppDatabase.kt b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/AppDatabase.kt index 38a1c9a8..a50c6564 100644 --- a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/AppDatabase.kt +++ b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/AppDatabase.kt @@ -25,6 +25,9 @@ abstract class AppDatabase : RoomDatabase() { database.execSQL( "ALTER TABLE ${BackgroundJob.TABLE_NAME} " + "ADD COLUMN next_notification_timestamp INTEGER NOT NULL DEFAULT 0") + database.execSQL( + "ALTER TABLE ${BackgroundJob.TABLE_NAME} " + + "ADD COLUMN active INTEGER NOT NULL DEFAULT 1") } } } diff --git a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/BackgroundJob.kt b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/BackgroundJob.kt index 4a187a8e..a69dce3a 100644 --- a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/BackgroundJob.kt +++ b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/BackgroundJob.kt @@ -1,8 +1,7 @@ package com.outsystems.plugins.healthfitnesslib.background.database +import androidx.room.* import androidx.room.ColumnInfo -import androidx.room.Entity -import androidx.room.ForeignKey @Entity( tableName = BackgroundJob.TABLE_NAME, @@ -22,15 +21,37 @@ open class BackgroundJob { LESSER_OR_EQUALS("LOWER_EQUALS"), EQUALS("EQUALS"), } + @ColumnInfo(name = "variable") var variable: String = "" + set(value){ + field = value + computeId() + } @ColumnInfo(name = "comparison") var comparison: String = "" + set(value){ + field = value + computeId() + } @ColumnInfo(name = "value") var value: Float = 0.0f + set(value){ + field = value + computeId() + } + @ColumnInfo(name = "time_unit") var timeUnit: String? = null @ColumnInfo(name = "time_unit_grouping") var timeUnitGrouping: Int? = null @ColumnInfo(name = "notification_id") var notificationId: Long? = null @ColumnInfo(name = "notification_frequency") var notificationFrequency: String = "ALWAYS" @ColumnInfo(name = "notification_frequency_grouping") var notificationFrequencyGrouping: Int = 1 @ColumnInfo(name = "next_notification_timestamp") var nextNotificationTimestamp: Long = 0 + @ColumnInfo(name = "active") var active: Boolean = true + + @Ignore + var id: String = "" + + private fun computeId() { + id = "${this.variable}-${this.comparison}-${this.value}".toLowerCase() + } companion object { const val TABLE_NAME: String= "backgroundJob" diff --git a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/BackgroundJobDao.kt b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/BackgroundJobDao.kt index 43415558..2ebd28a8 100644 --- a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/BackgroundJobDao.kt +++ b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/BackgroundJobDao.kt @@ -8,14 +8,17 @@ interface BackgroundJobDao { @Query("SELECT * FROM ${BackgroundJob.TABLE_NAME}") fun getAll(): List - //@Query("SELECT * FROM backgroundJob WHERE variable = :variable AND comparison = :comparison AND value = :value") - //fun findByPrimaryKey(variable: String, comparison: String, value: Float) + @Query("SELECT COUNT(*) FROM ${BackgroundJob.TABLE_NAME} WHERE variable = :name") + fun getBackgroundJobCountForVariable(name : String): Int + + @Query("SELECT * FROM ${BackgroundJob.TABLE_NAME} WHERE variable = :variable AND comparison = :comparison AND value = :value") + fun findByPrimaryKey(variable: String, comparison: String, value: Float): BackgroundJob? @Query("SELECT * FROM ${BackgroundJob.TABLE_NAME} WHERE variable = :name") fun findByVariableName(name : String): List @Insert - fun insert(backgroundJob: BackgroundJob) : Long + fun insert(backgroundJob: BackgroundJob): Long @Delete fun delete(backgroundJob: BackgroundJob) diff --git a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/DatabaseManager.kt b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/DatabaseManager.kt index da453546..edbc3648 100644 --- a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/DatabaseManager.kt +++ b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/DatabaseManager.kt @@ -52,19 +52,23 @@ class DatabaseManager(context : Context) : DatabaseManagerInterface { return notificationDao?.getAll() } - override fun fetchBackgroundJobs(variable : String) : List? { - return backgroundJobDao?.findByVariableName(variable) + override fun fetchBackgroundJob(variable: String, comparison: String, value: Float) : BackgroundJob? { + return backgroundJobDao?.findByPrimaryKey(variable, comparison, value) + } + + override fun fetchBackgroundJobCountForVariable(variable: String) : Int { + return backgroundJobDao?.getBackgroundJobCountForVariable(variable) ?: 0 } - //fun fetchBackgroundJob(variable: String, comparison: String, value: Float) { - // return backgroundJobDao?.findByPrimaryKey(variable, comparison, value) - //} + override fun fetchBackgroundJobs(variable: String) : List? { + return backgroundJobDao?.findByVariableName(variable) + } override fun fetchNotification(id : Long) : Notification? { return notificationDao?.findById(id)?.first() } - override fun deleteBackgroundJob(backgroundJob : BackgroundJob) { + override fun deleteBackgroundJob(backgroundJob: BackgroundJob) { backgroundJobDao?.delete(backgroundJob) } diff --git a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/DatabaseManagerInterface.kt b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/DatabaseManagerInterface.kt index 3d9091f8..c2f6f232 100644 --- a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/DatabaseManagerInterface.kt +++ b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/DatabaseManagerInterface.kt @@ -5,8 +5,10 @@ interface DatabaseManagerInterface { fun insert(notification: Notification) : Long? fun fetchNotifications() : List? fun fetchBackgroundJobs(variable : String) : List? + fun fetchBackgroundJob(variable: String, comparison: String, value: Float) : BackgroundJob? + fun fetchBackgroundJobCountForVariable(variable: String) : Int fun fetchNotification(id : Long) : Notification? - fun deleteBackgroundJob(backgroundJob : BackgroundJob) + fun deleteBackgroundJob(backgroundJob: BackgroundJob) fun updateBackgroundJob(backgroundJob: BackgroundJob) fun runInTransaction(closude : () -> Unit) } \ No newline at end of file diff --git a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthFitnessManager.kt b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthFitnessManager.kt index 6180bea6..c8e44ea2 100644 --- a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthFitnessManager.kt +++ b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthFitnessManager.kt @@ -8,15 +8,18 @@ import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignInAccount import com.google.android.gms.fitness.Fitness import com.google.android.gms.fitness.FitnessOptions +import com.google.android.gms.fitness.HistoryClient import com.google.android.gms.fitness.data.DataSet import com.google.android.gms.fitness.data.DataSource import com.google.android.gms.fitness.request.DataUpdateListenerRegistrationRequest import com.google.android.gms.fitness.request.SensorRequest import com.google.android.gms.fitness.result.DataReadResponse import com.google.android.gms.fitness.result.SessionReadResponse +import com.google.android.gms.tasks.Tasks.await import com.outsystems.plugins.healthfitness.HealthFitnessError import com.outsystems.plugins.healthfitnesslib.background.BackgroundJobParameters import com.outsystems.plugins.healthfitnesslib.background.VariableUpdateService +import kotlinx.coroutines.awaitAll import java.util.concurrent.TimeUnit class HealthFitnessManager(var context : Context, var activity : Activity? = null): HealthFitnessManagerInterface { @@ -139,6 +142,45 @@ class HealthFitnessManager(var context : Context, var activity : Activity? = nul } } + override fun unsubscribeFromAllUpdates(variable: GoogleFitVariable, + variableName : String, + onSuccess: () -> Unit, + onFailure: (Exception) -> Unit) { + + val account = getLastAccount() + if(account == null){ + onFailure(HealthStoreException(HealthFitnessError.VARIABLE_NOT_AUTHORIZED_ERROR)) + return + } + + val request = getSubscritionPendingIntent(variableName) + val dataSource = DataSource.Builder() + .setDataType(variable.dataType) + .setType(DataSource.TYPE_RAW) + .build() + + var success = true + await(Fitness.getRecordingClient(context, account) + .unsubscribe(dataSource) + .addOnFailureListener { success = false }) + + await(Fitness.getSensorsClient(context, account) + .remove(request) + .addOnFailureListener { success = false }) + + await(Fitness.getHistoryClient(context, account) + .unregisterDataUpdateListener(request) + .addOnFailureListener { success = false }) + + if(success){ + onSuccess() + } + else { + onFailure(HealthStoreException(HealthFitnessError.BACKGROUND_JOB_GENERIC_ERROR)) + } + + } + private fun areGoogleFitPermissionsGranted(account : GoogleSignInAccount?, options: FitnessOptions?): Boolean { account.let { options.let { diff --git a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthFitnessManagerInterface.kt b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthFitnessManagerInterface.kt index fb52a0e9..67725f6f 100644 --- a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthFitnessManagerInterface.kt +++ b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthFitnessManagerInterface.kt @@ -37,5 +37,10 @@ interface HealthFitnessManagerInterface { variableName: String, onSuccess: () -> Unit, onFailure: (Exception) -> Unit) + + fun unsubscribeFromAllUpdates(variable: GoogleFitVariable, + variableName : String, + onSuccess: () -> Unit, + onFailure: (Exception) -> Unit) } diff --git a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthStore.kt b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthStore.kt index e7a77ff7..cc8ff781 100644 --- a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthStore.kt +++ b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthStore.kt @@ -50,7 +50,6 @@ enum class EnumTimeUnit(val value : Pair) { MONTH(Pair("MONTH", TimeUnit.DAYS)), YEAR(Pair("YEAR", TimeUnit.DAYS)) } - enum class EnumJobFrequency(val value : String) { IMMEDIATE("IMMEDIATE"), HOUR("HOUR"), @@ -687,9 +686,9 @@ class HealthStore( this.timeUnitGrouping = parameters.timeUnitGrouping this.notificationFrequency = - parameters.notificationFrequency.toString() + "ALWAYS" //parameters.notificationFrequency.toString() this.notificationFrequencyGrouping = - parameters.notificationFrequencyGrouping!! + 0//parameters.notificationFrequencyGrouping!! this.nextNotificationTimestamp = System.currentTimeMillis() } @@ -741,6 +740,49 @@ class HealthStore( } } + fun deleteBackgroundJob(jogId: String, + onSuccess : (String) -> Unit, + onError : (HealthFitnessError) -> Unit) { + + val parameters = jogId.split("-") + val variableName: String + val comparison: String + val value: Float + val variable: GoogleFitVariable + + try { + variableName = parameters[0] + comparison = parameters[1] + value = parameters[2].toFloat() + variable = getVariableByName(variableName)!! + } + catch(e: Exception) { + onError(HealthFitnessError.BACKGROUND_JOB_DOES_NOT_EXISTS_ERROR) + return + } + + runBlocking { + launch(Dispatchers.IO) { + + val job = database.fetchBackgroundJob(variableName, comparison, value) + if(job != null) { + database.deleteBackgroundJob(job) + val jobCount = database.fetchBackgroundJobCountForVariable(variableName) + if(jobCount == 0) { + manager.unsubscribeFromAllUpdates( + variable, + variableName, + onSuccess = {}, + onFailure = {}) + } + } + else { + //onError(HealthFitnessError.BACKGROUND_JOB_DOES_NOT_EXISTS_ERROR) + } + } + } + } + companion object { const val GOOGLE_FIT_PERMISSIONS_REQUEST_CODE = 2 } diff --git a/www/OSHealthFitness.js b/www/OSHealthFitness.js index f0befab5..99537fe2 100644 --- a/www/OSHealthFitness.js +++ b/www/OSHealthFitness.js @@ -39,3 +39,7 @@ exports.getLastRecord = function (success, error, variable) { exports.setBackgroundJob = function (success, error, params) { exec(success, error, 'OSHealthFitness', 'setBackgroundJob', [params]); }; + +exports.deleteBackgroundJob = function (success, error, params) { + exec(success, error, 'OSHealthFitness', 'deleteBackgroundJob', [params]); +}; From 676e4fca718b5b58f4ea3d0490a33c46a9340137 Mon Sep 17 00:00:00 2001 From: Nelson Lopes Silva <5671236+nflsilva@users.noreply.github.com> Date: Fri, 10 Dec 2021 15:21:32 +0000 Subject: [PATCH 2/3] Small bug fix --- .../com/outsystems/plugins/healthfitness/OSHealthFitness.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt index a7fd6281..11c7e859 100755 --- a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt +++ b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt @@ -59,8 +59,7 @@ class OSHealthFitness : CordovaImplementation() { getLastRecord(args) } "setBackgroundJob" -> { - //setBackgroundJob(args) - deleteBackgroundJob(args) + setBackgroundJob(args) } "deleteBackgroundJob" -> { deleteBackgroundJob(args) From ef1343fba2c11300014008bf4355294b0f6ebda5 Mon Sep 17 00:00:00 2001 From: Nelson Lopes Silva <5671236+nflsilva@users.noreply.github.com> Date: Fri, 10 Dec 2021 17:33:10 +0000 Subject: [PATCH 3/3] Fixed a few bugs in delete background job. --- .../plugins/healthfitness/OSHealthFitness.kt | 2 +- .../background/VariableUpdateService.kt | 4 +++- .../background/database/AppDatabase.kt | 2 +- .../background/database/BackgroundJob.kt | 8 ++++---- .../oshealthfitnesslibrary/store/HealthStore.kt | 14 +++++++++----- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt index 11c7e859..fe15aa79 100755 --- a/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt +++ b/src/android/com/outsystems/plugins/healthfitness/OSHealthFitness.kt @@ -192,7 +192,7 @@ class OSHealthFitness : CordovaImplementation() { private fun deleteBackgroundJob(args: JSONArray) { val parameters = args.getString(0) healthStore?.deleteBackgroundJob( - "WEIGHT-HIGHER-100", + parameters, { response -> sendPluginResult(response) }, diff --git a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/VariableUpdateService.kt b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/VariableUpdateService.kt index bba2f99f..538a3db5 100644 --- a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/VariableUpdateService.kt +++ b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/VariableUpdateService.kt @@ -7,6 +7,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.os.Build +import android.util.Log import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import com.outsystems.plugins.healthfitnesslib.background.database.BackgroundJob @@ -56,7 +57,7 @@ class VariableUpdateService : BroadcastReceiver() { val currentTimestamp = System.currentTimeMillis() val nextNotificationTimestamp = job.nextNotificationTimestamp - if(currentTimestamp >= nextNotificationTimestamp || job.notificationFrequency == "ALWAYS") { + if(job.isActive && (currentTimestamp >= nextNotificationTimestamp || job.notificationFrequency == "ALWAYS")) { val nextNotificationCalendar = Calendar.getInstance() nextNotificationCalendar.timeInMillis = currentTimestamp @@ -140,6 +141,7 @@ class VariableUpdateService : BroadcastReceiver() { } }, { error -> + Log.e("Err", error.message) //TODO: What should we do with errors? } ) diff --git a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/AppDatabase.kt b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/AppDatabase.kt index a50c6564..39e5ffd1 100644 --- a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/AppDatabase.kt +++ b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/AppDatabase.kt @@ -27,7 +27,7 @@ abstract class AppDatabase : RoomDatabase() { "ADD COLUMN next_notification_timestamp INTEGER NOT NULL DEFAULT 0") database.execSQL( "ALTER TABLE ${BackgroundJob.TABLE_NAME} " + - "ADD COLUMN active INTEGER NOT NULL DEFAULT 1") + "ADD COLUMN isActive INTEGER NOT NULL DEFAULT 1") } } } diff --git a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/BackgroundJob.kt b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/BackgroundJob.kt index a69dce3a..9d26a059 100644 --- a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/BackgroundJob.kt +++ b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/background/database/BackgroundJob.kt @@ -16,10 +16,10 @@ open class BackgroundJob { enum class ComparisonOperationEnum(val id : String) { GREATER("HIGHER"), - GREATER_OR_EQUALS("HIGHER_EQUALS"), + GREATER_OR_EQUALS("HIGHER_EQUAL"), LESSER("LOWER"), - LESSER_OR_EQUALS("LOWER_EQUALS"), - EQUALS("EQUALS"), + LESSER_OR_EQUALS("LOWER_EQUAL"), + EQUALS("EQUAL"), } @ColumnInfo(name = "variable") var variable: String = "" @@ -44,7 +44,7 @@ open class BackgroundJob { @ColumnInfo(name = "notification_frequency") var notificationFrequency: String = "ALWAYS" @ColumnInfo(name = "notification_frequency_grouping") var notificationFrequencyGrouping: Int = 1 @ColumnInfo(name = "next_notification_timestamp") var nextNotificationTimestamp: Long = 0 - @ColumnInfo(name = "active") var active: Boolean = true + @ColumnInfo(name = "isActive") var isActive: Boolean = true @Ignore var id: String = "" diff --git a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthStore.kt b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthStore.kt index cc8ff781..534df197 100644 --- a/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthStore.kt +++ b/src/android/com/outsystems/plugins/healthfitness/oshealthfitnesslibrary/store/HealthStore.kt @@ -686,9 +686,9 @@ class HealthStore( this.timeUnitGrouping = parameters.timeUnitGrouping this.notificationFrequency = - "ALWAYS" //parameters.notificationFrequency.toString() + parameters.notificationFrequency.toString() this.notificationFrequencyGrouping = - 0//parameters.notificationFrequencyGrouping!! + parameters.notificationFrequencyGrouping!! this.nextNotificationTimestamp = System.currentTimeMillis() } @@ -772,12 +772,16 @@ class HealthStore( manager.unsubscribeFromAllUpdates( variable, variableName, - onSuccess = {}, - onFailure = {}) + onSuccess = { + onSuccess("success") + }, + onFailure = { + onError(HealthFitnessError.UNSUBSCRIBE_ERROR) + }) } } else { - //onError(HealthFitnessError.BACKGROUND_JOB_DOES_NOT_EXISTS_ERROR) + onError(HealthFitnessError.BACKGROUND_JOB_DOES_NOT_EXISTS_ERROR) } } }