This commit is contained in:
Milos Kozak 2022-05-10 20:28:19 +02:00
parent 4e44055014
commit aaed25c5f8
2 changed files with 10 additions and 11 deletions

View file

@ -6,16 +6,15 @@ import android.provider.Telephony
import androidx.work.Data import androidx.work.Data
import androidx.work.OneTimeWorkRequest import androidx.work.OneTimeWorkRequest
import dagger.android.DaggerBroadcastReceiver import dagger.android.DaggerBroadcastReceiver
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.BundleLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
import info.nightscout.androidaps.plugins.source.* import info.nightscout.androidaps.plugins.source.*
import info.nightscout.androidaps.services.Intents import info.nightscout.androidaps.services.Intents
import info.nightscout.androidaps.utils.extensions.copyDouble import info.nightscout.androidaps.utils.extensions.copyDouble
import info.nightscout.androidaps.utils.extensions.copyInt
import info.nightscout.androidaps.utils.extensions.copyLong import info.nightscout.androidaps.utils.extensions.copyLong
import info.nightscout.androidaps.utils.extensions.copyString import info.nightscout.androidaps.utils.extensions.copyString
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.BundleLogger
import info.nightscout.shared.logging.LTag
import javax.inject.Inject import javax.inject.Inject
open class DataReceiver : DaggerBroadcastReceiver() { open class DataReceiver : DaggerBroadcastReceiver() {
@ -31,7 +30,7 @@ open class DataReceiver : DaggerBroadcastReceiver() {
when (intent.action) { when (intent.action) {
Intents.ACTION_NEW_BG_ESTIMATE -> Intents.ACTION_NEW_BG_ESTIMATE ->
OneTimeWorkRequest.Builder(XdripPlugin.XdripWorker::class.java) OneTimeWorkRequest.Builder(XdripPlugin.XdripWorker::class.java)
.setInputData(dataWorker.storeInputData(bundle, intent)).build() .setInputData(dataWorker.storeInputData(bundle, intent.action)).build()
Intents.POCTECH_BG -> Intents.POCTECH_BG ->
OneTimeWorkRequest.Builder(PoctechPlugin.PoctechWorker::class.java) OneTimeWorkRequest.Builder(PoctechPlugin.PoctechWorker::class.java)
.setInputData(Data.Builder().also { .setInputData(Data.Builder().also {
@ -59,16 +58,16 @@ open class DataReceiver : DaggerBroadcastReceiver() {
}.build()).build() }.build()).build()
Telephony.Sms.Intents.SMS_RECEIVED_ACTION -> Telephony.Sms.Intents.SMS_RECEIVED_ACTION ->
OneTimeWorkRequest.Builder(SmsCommunicatorPlugin.SmsCommunicatorWorker::class.java) OneTimeWorkRequest.Builder(SmsCommunicatorPlugin.SmsCommunicatorWorker::class.java)
.setInputData(dataWorker.storeInputData(bundle, intent)).build() .setInputData(dataWorker.storeInputData(bundle, intent.action)).build()
Intents.EVERSENSE_BG -> Intents.EVERSENSE_BG ->
OneTimeWorkRequest.Builder(EversensePlugin.EversenseWorker::class.java) OneTimeWorkRequest.Builder(EversensePlugin.EversenseWorker::class.java)
.setInputData(dataWorker.storeInputData(bundle, intent)).build() .setInputData(dataWorker.storeInputData(bundle, intent.action)).build()
Intents.DEXCOM_BG -> Intents.DEXCOM_BG ->
OneTimeWorkRequest.Builder(DexcomPlugin.DexcomWorker::class.java) OneTimeWorkRequest.Builder(DexcomPlugin.DexcomWorker::class.java)
.setInputData(dataWorker.storeInputData(bundle, intent)).build() .setInputData(dataWorker.storeInputData(bundle, intent.action)).build()
Intents.AIDEX_NEW_BG_ESTIMATE -> Intents.AIDEX_NEW_BG_ESTIMATE ->
OneTimeWorkRequest.Builder(AidexPlugin.AidexWorker::class.java) OneTimeWorkRequest.Builder(AidexPlugin.AidexWorker::class.java)
.setInputData(dataWorker.storeInputData(bundle, intent)).build() .setInputData(dataWorker.storeInputData(bundle, intent.action)).build()
else -> null else -> null
}?.let { request -> dataWorker.enqueue(request) } }?.let { request -> dataWorker.enqueue(request) }
} }

View file

@ -56,10 +56,10 @@ class DataWorker @Inject constructor(
return value as JSONObject? return value as JSONObject?
} }
fun storeInputData(value: Any, intent: Intent? = null) = fun storeInputData(value: Any, action: String? = null) =
Data.Builder() Data.Builder()
.putLong(STORE_KEY, store(value)) .putLong(STORE_KEY, store(value))
.putString(ACTION_KEY, intent?.action).build() .putString(ACTION_KEY, action).build()
fun enqueue(request: OneTimeWorkRequest) { fun enqueue(request: OneTimeWorkRequest) {
WorkManager.getInstance(context) WorkManager.getInstance(context)