Bolus, Carbs, BolusCalcResult new way of upload to NS
This commit is contained in:
parent
c9c02458d6
commit
df1e2c53db
|
@ -5,10 +5,13 @@ import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
|
import android.os.Build
|
||||||
import com.j256.ormlite.android.apptools.OpenHelperManager
|
import com.j256.ormlite.android.apptools.OpenHelperManager
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.DaggerApplication
|
import dagger.android.DaggerApplication
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
|
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventIfNewTransaction
|
||||||
import info.nightscout.androidaps.database.transactions.VersionChangeTransaction
|
import info.nightscout.androidaps.database.transactions.VersionChangeTransaction
|
||||||
import info.nightscout.androidaps.db.CompatDBHelper
|
import info.nightscout.androidaps.db.CompatDBHelper
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper
|
import info.nightscout.androidaps.db.DatabaseHelper
|
||||||
|
@ -27,9 +30,11 @@ import info.nightscout.androidaps.receivers.KeepAliveReceiver.KeepAliveManager
|
||||||
import info.nightscout.androidaps.receivers.NetworkChangeReceiver
|
import info.nightscout.androidaps.receivers.NetworkChangeReceiver
|
||||||
import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver
|
import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver
|
||||||
import info.nightscout.androidaps.utils.ActivityMonitor
|
import info.nightscout.androidaps.utils.ActivityMonitor
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.locale.LocaleHelper.update
|
import info.nightscout.androidaps.utils.locale.LocaleHelper.update
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import net.danlew.android.joda.JodaTimeAndroid
|
import net.danlew.android.joda.JodaTimeAndroid
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -49,6 +54,7 @@ class MainApp : DaggerApplication() {
|
||||||
@Inject lateinit var plugins: List<@JvmSuppressWildcards PluginBase>
|
@Inject lateinit var plugins: List<@JvmSuppressWildcards PluginBase>
|
||||||
@Inject lateinit var compatDBHelper: CompatDBHelper
|
@Inject lateinit var compatDBHelper: CompatDBHelper
|
||||||
@Inject lateinit var repository: AppRepository
|
@Inject lateinit var repository: AppRepository
|
||||||
|
@Inject lateinit var dateUtil: DateUtil
|
||||||
@Inject lateinit var staticInjector: StaticInjector// TODO avoid , here fake only to initialize
|
@Inject lateinit var staticInjector: StaticInjector// TODO avoid , here fake only to initialize
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
|
@ -63,8 +69,9 @@ class MainApp : DaggerApplication() {
|
||||||
gitRemote = null
|
gitRemote = null
|
||||||
commitHash = null
|
commitHash = null
|
||||||
}
|
}
|
||||||
disposable.add(repository.runTransaction(VersionChangeTransaction(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE, gitRemote, commitHash)).subscribe())
|
disposable += repository.runTransaction(VersionChangeTransaction(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE, gitRemote, commitHash)).subscribe()
|
||||||
disposable.add(compatDBHelper.dbChangeDisposable())
|
disposable += repository.runTransaction(InsertTherapyEventIfNewTransaction(timestamp = dateUtil._now(), type = TherapyEvent.Type.NOTE, note = getString(info.nightscout.androidaps.core.R.string.androidaps_start).toString() + " - " + Build.MANUFACTURER + " " + Build.MODEL, glucoseUnit = TherapyEvent.GlucoseUnit.MGDL)).subscribe()
|
||||||
|
disposable += compatDBHelper.dbChangeDisposable()
|
||||||
registerActivityLifecycleCallbacks(activityMonitor)
|
registerActivityLifecycleCallbacks(activityMonitor)
|
||||||
JodaTimeAndroid.init(this)
|
JodaTimeAndroid.init(this)
|
||||||
aapsLogger.debug("Version: " + BuildConfig.VERSION_NAME)
|
aapsLogger.debug("Version: " + BuildConfig.VERSION_NAME)
|
||||||
|
@ -78,8 +85,7 @@ class MainApp : DaggerApplication() {
|
||||||
// Register all tabs in app here
|
// Register all tabs in app here
|
||||||
pluginStore.plugins = plugins
|
pluginStore.plugins = plugins
|
||||||
configBuilderPlugin.initialize()
|
configBuilderPlugin.initialize()
|
||||||
nsUpload.uploadAppStart()
|
keepAliveManager.setAlarm(this)
|
||||||
Thread { keepAliveManager.setAlarm(this) }.start()
|
|
||||||
doMigrations()
|
doMigrations()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ import info.nightscout.androidaps.databinding.DialogCareBinding
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
|
||||||
import info.nightscout.androidaps.utils.HtmlHelper
|
import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
|
@ -43,7 +42,6 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
@Inject lateinit var ctx: Context
|
@Inject lateinit var ctx: Context
|
||||||
@Inject lateinit var resourceHelper: ResourceHelper
|
@Inject lateinit var resourceHelper: ResourceHelper
|
||||||
@Inject lateinit var profileFunction: ProfileFunction
|
@Inject lateinit var profileFunction: ProfileFunction
|
||||||
@Inject lateinit var nsUpload: NSUpload
|
|
||||||
@Inject lateinit var translator: Translator
|
@Inject lateinit var translator: Translator
|
||||||
@Inject lateinit var uel: UserEntryLogger
|
@Inject lateinit var uel: UserEntryLogger
|
||||||
@Inject lateinit var repository: AppRepository
|
@Inject lateinit var repository: AppRepository
|
||||||
|
@ -224,11 +222,11 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.showConfirmation(activity, resourceHelper.gs(event), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
|
OKDialog.showConfirmation(activity, resourceHelper.gs(event), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
|
||||||
disposable += repository.runTransactionForResult(InsertTherapyEventIfNewTransaction(therapyEvent)).subscribe({ result ->
|
disposable += repository.runTransactionForResult(InsertTherapyEventIfNewTransaction(therapyEvent))
|
||||||
result.inserted.forEach { nsUpload.uploadEvent(it) }
|
.subscribe(
|
||||||
}, {
|
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted therapy event $it") } },
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
{ aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it) }
|
||||||
})
|
)
|
||||||
valuesWithUnit.add(0, ValueWithUnit(eventTime, Units.Timestamp, eventTimeChanged))
|
valuesWithUnit.add(0, ValueWithUnit(eventTime, Units.Timestamp, eventTimeChanged))
|
||||||
valuesWithUnit.add(1, ValueWithUnit(therapyEvent.type.text, Units.TherapyEvent))
|
valuesWithUnit.add(1, ValueWithUnit(therapyEvent.type.text, Units.TherapyEvent))
|
||||||
uel.log(Action.CAREPORTAL, notes, valuesWithUnit)
|
uel.log(Action.CAREPORTAL, notes, valuesWithUnit)
|
||||||
|
|
|
@ -22,7 +22,6 @@ import info.nightscout.androidaps.interfaces.Constraint
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.queue.Callback
|
import info.nightscout.androidaps.queue.Callback
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
import info.nightscout.androidaps.utils.HtmlHelper
|
import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
|
@ -41,7 +40,6 @@ class FillDialog : DialogFragmentWithDate() {
|
||||||
@Inject lateinit var constraintChecker: ConstraintChecker
|
@Inject lateinit var constraintChecker: ConstraintChecker
|
||||||
@Inject lateinit var resourceHelper: ResourceHelper
|
@Inject lateinit var resourceHelper: ResourceHelper
|
||||||
@Inject lateinit var ctx: Context
|
@Inject lateinit var ctx: Context
|
||||||
@Inject lateinit var nsUpload: NSUpload
|
|
||||||
@Inject lateinit var commandQueue: CommandQueueProvider
|
@Inject lateinit var commandQueue: CommandQueueProvider
|
||||||
@Inject lateinit var activePlugin: ActivePluginProvider
|
@Inject lateinit var activePlugin: ActivePluginProvider
|
||||||
@Inject lateinit var uel: UserEntryLogger
|
@Inject lateinit var uel: UserEntryLogger
|
||||||
|
@ -147,11 +145,10 @@ class FillDialog : DialogFragmentWithDate() {
|
||||||
type = TherapyEvent.Type.CANNULA_CHANGE,
|
type = TherapyEvent.Type.CANNULA_CHANGE,
|
||||||
note = notes,
|
note = notes,
|
||||||
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL
|
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL
|
||||||
)).subscribe({ result ->
|
)).subscribe(
|
||||||
result.inserted.forEach { nsUpload.uploadEvent(it) }
|
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted therapy event $it") } },
|
||||||
}, {
|
{ aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it) }
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if (insulinChange) {
|
if (insulinChange) {
|
||||||
// add a second for case of both checked
|
// add a second for case of both checked
|
||||||
|
@ -161,11 +158,10 @@ class FillDialog : DialogFragmentWithDate() {
|
||||||
type = TherapyEvent.Type.INSULIN_CHANGE,
|
type = TherapyEvent.Type.INSULIN_CHANGE,
|
||||||
note = notes,
|
note = notes,
|
||||||
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL
|
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL
|
||||||
)).subscribe({ result ->
|
)).subscribe(
|
||||||
result.inserted.forEach { nsUpload.uploadEvent(it) }
|
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted therapy event $it") } },
|
||||||
}, {
|
{ aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it) }
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}, null)
|
}, null)
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,14 +217,10 @@ class InsulinDialog : DialogFragmentWithDate() {
|
||||||
)
|
)
|
||||||
if (recordOnlyChecked) {
|
if (recordOnlyChecked) {
|
||||||
disposable += repository.runTransactionForResult(detailedBolusInfo.insertBolusTransaction())
|
disposable += repository.runTransactionForResult(detailedBolusInfo.insertBolusTransaction())
|
||||||
.subscribe({ result ->
|
.subscribe(
|
||||||
result.inserted.forEach {
|
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it") } },
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it")
|
{ aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it) }
|
||||||
nsUpload.uploadBolusRecord(it, detailedBolusInfo.createTherapyEvent(), null)
|
)
|
||||||
}
|
|
||||||
}, {
|
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
|
|
|
@ -152,23 +152,15 @@ class TreatmentDialog : DialogFragmentWithDate() {
|
||||||
)
|
)
|
||||||
if (recordOnlyChecked) {
|
if (recordOnlyChecked) {
|
||||||
disposable += repository.runTransactionForResult(detailedBolusInfo.insertBolusTransaction())
|
disposable += repository.runTransactionForResult(detailedBolusInfo.insertBolusTransaction())
|
||||||
.subscribe({ result ->
|
.subscribe(
|
||||||
result.inserted.forEach {
|
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it") } },
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it")
|
{ aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it) }
|
||||||
nsUpload.uploadBolusRecord(it, detailedBolusInfo.createTherapyEvent(), null)
|
)
|
||||||
}
|
|
||||||
}, {
|
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it)
|
|
||||||
})
|
|
||||||
disposable += repository.runTransactionForResult(detailedBolusInfo.insertCarbsTransaction())
|
disposable += repository.runTransactionForResult(detailedBolusInfo.insertCarbsTransaction())
|
||||||
.subscribe({ result ->
|
.subscribe(
|
||||||
result.inserted.forEach {
|
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it") } },
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it")
|
{ aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) }
|
||||||
nsUpload.uploadCarbsRecord(it, detailedBolusInfo.createTherapyEvent())
|
)
|
||||||
}
|
|
||||||
}, {
|
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import info.nightscout.androidaps.data.Profile
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult
|
import info.nightscout.androidaps.data.PumpEnactResult
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.database.entities.TherapyEvent
|
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction
|
||||||
import info.nightscout.androidaps.database.transactions.InsertTherapyEventIfNewTransaction
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventIfNewTransaction
|
||||||
import info.nightscout.androidaps.events.EventAcceptOpenLoopChange
|
import info.nightscout.androidaps.events.EventAcceptOpenLoopChange
|
||||||
import info.nightscout.androidaps.events.EventAutosensCalculationFinished
|
import info.nightscout.androidaps.events.EventAutosensCalculationFinished
|
||||||
|
@ -334,7 +335,7 @@ open class LoopPlugin @Inject constructor(
|
||||||
rxBus.send(EventNewNotification(carbReqLocal))
|
rxBus.send(EventNewNotification(carbReqLocal))
|
||||||
}
|
}
|
||||||
if (sp.getBoolean(R.string.key_ns_create_announcements_from_carbs_req, false)) {
|
if (sp.getBoolean(R.string.key_ns_create_announcements_from_carbs_req, false)) {
|
||||||
nsUpload.uploadError(resultAfterConstraints.carbsRequiredText)
|
disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(resultAfterConstraints.carbsRequiredText)).subscribe()
|
||||||
}
|
}
|
||||||
if (sp.getBoolean(R.string.key_enable_carbs_required_alert_local, true) && sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true)) {
|
if (sp.getBoolean(R.string.key_enable_carbs_required_alert_local, true) && sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true)) {
|
||||||
val intentAction5m = Intent(context, CarbSuggestionReceiver::class.java)
|
val intentAction5m = Intent(context, CarbSuggestionReceiver::class.java)
|
||||||
|
@ -658,11 +659,10 @@ open class LoopPlugin @Inject constructor(
|
||||||
duration = T.mins(durationInMinutes.toLong()).msecs(),
|
duration = T.mins(durationInMinutes.toLong()).msecs(),
|
||||||
enteredBy = "openaps://" + "AndroidAPS",
|
enteredBy = "openaps://" + "AndroidAPS",
|
||||||
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL
|
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL
|
||||||
)).subscribe({ result ->
|
)).subscribe(
|
||||||
result.inserted.forEach { nsUpload.uploadEvent(it) }
|
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted therapy event $it") } },
|
||||||
}, {
|
{ aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it) }
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -25,7 +25,6 @@ import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||||
|
@ -48,7 +47,6 @@ class FoodFragment : DaggerFragment() {
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
@Inject lateinit var aapsLogger: AAPSLogger
|
||||||
@Inject lateinit var resourceHelper: ResourceHelper
|
@Inject lateinit var resourceHelper: ResourceHelper
|
||||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||||
@Inject lateinit var nsUpload: NSUpload
|
|
||||||
@Inject lateinit var repository: AppRepository
|
@Inject lateinit var repository: AppRepository
|
||||||
@Inject lateinit var uel: UserEntryLogger
|
@Inject lateinit var uel: UserEntryLogger
|
||||||
|
|
||||||
|
@ -200,8 +198,10 @@ class FoodFragment : DaggerFragment() {
|
||||||
|
|
||||||
private fun filterData() {
|
private fun filterData() {
|
||||||
val textFilter = binding.filter.text.toString()
|
val textFilter = binding.filter.text.toString()
|
||||||
val categoryFilter = binding.category.selectedItem?.toString() ?: resourceHelper.gs(R.string.none)
|
val categoryFilter = binding.category.selectedItem?.toString()
|
||||||
val subcategoryFilter = binding.subcategory.selectedItem?.toString() ?: resourceHelper.gs(R.string.none)
|
?: resourceHelper.gs(R.string.none)
|
||||||
|
val subcategoryFilter = binding.subcategory.selectedItem?.toString()
|
||||||
|
?: resourceHelper.gs(R.string.none)
|
||||||
val newFiltered = ArrayList<Food>()
|
val newFiltered = ArrayList<Food>()
|
||||||
for (f in unfiltered) {
|
for (f in unfiltered) {
|
||||||
if (f.category == null || f.subCategory == null) continue
|
if (f.category == null || f.subCategory == null) continue
|
||||||
|
@ -252,14 +252,10 @@ class FoodFragment : DaggerFragment() {
|
||||||
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord) + "\n" + food.name, {
|
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord) + "\n" + food.name, {
|
||||||
uel.log(Action.FOOD_REMOVED, food.name)
|
uel.log(Action.FOOD_REMOVED, food.name)
|
||||||
disposable += repository.runTransactionForResult(InvalidateFoodTransaction(food.id))
|
disposable += repository.runTransactionForResult(InvalidateFoodTransaction(food.id))
|
||||||
.subscribe({
|
.subscribe(
|
||||||
val id = food.interfaceIDs.nightscoutId
|
{ aapsLogger.error(LTag.DATABASE, "Invalidated food $it") },
|
||||||
if (NSUpload.isIdValid(id)) nsUpload.removeFoodFromNS(id)
|
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating food", it) }
|
||||||
// no create at the moment
|
)
|
||||||
// else uploadQueue.removeID("dbAdd", food.timestamp.toString())
|
|
||||||
}, {
|
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while invalidating food", it)
|
|
||||||
})
|
|
||||||
}, null)
|
}, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,12 @@ package info.nightscout.androidaps.plugins.general.nsclient
|
||||||
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.database.entities.GlucoseValue
|
import info.nightscout.androidaps.database.entities.*
|
||||||
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
import info.nightscout.androidaps.interfaces.DataSyncSelector
|
import info.nightscout.androidaps.interfaces.DataSyncSelector
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
|
||||||
import info.nightscout.androidaps.utils.extensions.toJson
|
import info.nightscout.androidaps.utils.extensions.toJson
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -17,7 +15,6 @@ import javax.inject.Inject
|
||||||
class DataSyncSelectorImplementation @Inject constructor(
|
class DataSyncSelectorImplementation @Inject constructor(
|
||||||
private val sp: SP,
|
private val sp: SP,
|
||||||
private val aapsLogger: AAPSLogger,
|
private val aapsLogger: AAPSLogger,
|
||||||
private val dateUtil: DateUtil,
|
|
||||||
private val profileFunction: ProfileFunction,
|
private val profileFunction: ProfileFunction,
|
||||||
private val nsClientPlugin: NSClientPlugin,
|
private val nsClientPlugin: NSClientPlugin,
|
||||||
private val activePlugin: ActivePluginProvider,
|
private val activePlugin: ActivePluginProvider,
|
||||||
|
@ -25,30 +22,142 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
) : DataSyncSelector {
|
) : DataSyncSelector {
|
||||||
|
|
||||||
override fun resetToNextFullSync() {
|
override fun resetToNextFullSync() {
|
||||||
sp.remove(R.string.key_ns_temporary_target_last_sync)
|
sp.remove(R.string.key_ns_temporary_target_last_synced_id)
|
||||||
sp.remove(R.string.key_ns_glucose_value_last_sync)
|
sp.remove(R.string.key_ns_glucose_value_last_synced_id)
|
||||||
|
sp.remove(R.string.key_ns_food_last_synced_id)
|
||||||
|
sp.remove(R.string.key_ns_bolus_last_synced_id)
|
||||||
|
sp.remove(R.string.key_ns_carbs_last_synced_id)
|
||||||
|
sp.remove(R.string.key_ns_bolus_calculator_result_last_synced_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun confirmTempTargetsTimestamp(lastSynced: Long) {
|
override fun confirmLastBolusIdIfGreater(lastSynced: Long) {
|
||||||
aapsLogger.debug(LTag.NSCLIENT, "Setting TT data sync from $lastSynced")
|
if (lastSynced > sp.getLong(R.string.key_ns_bolus_last_synced_id, 0)) {
|
||||||
sp.putLong(R.string.key_ns_temporary_target_last_sync, lastSynced)
|
aapsLogger.debug(LTag.NSCLIENT, "Setting Bolus data sync from $lastSynced")
|
||||||
|
sp.putLong(R.string.key_ns_bolus_last_synced_id, lastSynced)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun confirmTempTargetsTimestampIfGreater(lastSynced: Long) {
|
// Prepared for v3 (returns all modified after)
|
||||||
if (lastSynced > sp.getLong(R.string.key_ns_temporary_target_last_sync, 0))
|
override fun changedBoluses(): List<Bolus> {
|
||||||
confirmTempTargetsTimestamp(lastSynced)
|
val startId = sp.getLong(R.string.key_ns_bolus_last_synced_id, 0)
|
||||||
|
return appRepository.getModifiedBolusesDataFromId(startId).blockingGet().also {
|
||||||
|
aapsLogger.debug(LTag.NSCLIENT, "Loading Bolus data for sync from $startId. Records ${it.size}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun processChangedBolusesCompat(): Boolean {
|
||||||
|
val startId = sp.getLong(R.string.key_ns_bolus_last_synced_id, 0)
|
||||||
|
appRepository.getNextSyncElementBolus(startId).blockingGet()?.let { bolus ->
|
||||||
|
aapsLogger.info(LTag.DATABASE, "Loading Bolus data Start: $startId ID: ${bolus.first.id} HistoryID: ${bolus.second} ")
|
||||||
|
when {
|
||||||
|
// removed and not uploaded yet = ignore
|
||||||
|
!bolus.first.isValid && bolus.first.interfaceIDs.nightscoutId == null -> Any()
|
||||||
|
// removed and already uploaded = send for removal
|
||||||
|
!bolus.first.isValid && bolus.first.interfaceIDs.nightscoutId != null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbRemove("treatments", bolus.first.interfaceIDs.nightscoutId, DataSyncSelector.PairBolus(bolus.first, bolus.second))
|
||||||
|
// existing without nsId = create new
|
||||||
|
bolus.first.isValid && bolus.first.interfaceIDs.nightscoutId == null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbAdd("treatments", bolus.first.toJson(), DataSyncSelector.PairBolus(bolus.first, bolus.second))
|
||||||
|
// existing with nsId = update
|
||||||
|
bolus.first.isValid && bolus.first.interfaceIDs.nightscoutId != null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolus.first.interfaceIDs.nightscoutId, bolus.first.toJson(), DataSyncSelector.PairBolus(bolus.first, bolus.second))
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun confirmLastCarbsIdIfGreater(lastSynced: Long) {
|
||||||
|
if (lastSynced > sp.getLong(R.string.key_ns_carbs_last_synced_id, 0)) {
|
||||||
|
aapsLogger.debug(LTag.NSCLIENT, "Setting Carbs data sync from $lastSynced")
|
||||||
|
sp.putLong(R.string.key_ns_carbs_last_synced_id, lastSynced)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepared for v3 (returns all modified after)
|
||||||
|
override fun changedCarbs(): List<Carbs> {
|
||||||
|
val startId = sp.getLong(R.string.key_ns_carbs_last_synced_id, 0)
|
||||||
|
return appRepository.getModifiedCarbsDataFromId(startId).blockingGet().also {
|
||||||
|
aapsLogger.debug(LTag.NSCLIENT, "Loading Carbs data for sync from $startId. Records ${it.size}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun processChangedCarbsCompat(): Boolean {
|
||||||
|
val startId = sp.getLong(R.string.key_ns_carbs_last_synced_id, 0)
|
||||||
|
appRepository.getNextSyncElementCarbs(startId).blockingGet()?.let { carb ->
|
||||||
|
aapsLogger.info(LTag.DATABASE, "Loading Carbs data Start: $startId ID: ${carb.first.id} HistoryID: ${carb.second} ")
|
||||||
|
when {
|
||||||
|
// removed and not uploaded yet = ignore
|
||||||
|
!carb.first.isValid && carb.first.interfaceIDs.nightscoutId == null -> Any()
|
||||||
|
// removed and already uploaded = send for removal
|
||||||
|
!carb.first.isValid && carb.first.interfaceIDs.nightscoutId != null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbRemove("treatments", carb.first.interfaceIDs.nightscoutId, DataSyncSelector.PairCarbs(carb.first, carb.second))
|
||||||
|
// existing without nsId = create new
|
||||||
|
carb.first.isValid && carb.first.interfaceIDs.nightscoutId == null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbAdd("treatments", carb.first.toJson(), DataSyncSelector.PairCarbs(carb.first, carb.second))
|
||||||
|
// existing with nsId = update
|
||||||
|
carb.first.isValid && carb.first.interfaceIDs.nightscoutId != null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", carb.first.interfaceIDs.nightscoutId, carb.first.toJson(), DataSyncSelector.PairCarbs(carb.first, carb.second))
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun confirmLastBolusCalculatorResultsIdIfGreater(lastSynced: Long) {
|
||||||
|
if (lastSynced > sp.getLong(R.string.key_ns_bolus_calculator_result_last_synced_id, 0)) {
|
||||||
|
aapsLogger.debug(LTag.NSCLIENT, "Setting BolusCalculatorResult data sync from $lastSynced")
|
||||||
|
sp.putLong(R.string.key_ns_bolus_calculator_result_last_synced_id, lastSynced)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepared for v3 (returns all modified after)
|
||||||
|
override fun changedBolusCalculatorResults(): List<BolusCalculatorResult> {
|
||||||
|
val startId = sp.getLong(R.string.key_ns_bolus_calculator_result_last_synced_id, 0)
|
||||||
|
return appRepository.getModifiedBolusCalculatorResultsDataFromId(startId).blockingGet().also {
|
||||||
|
aapsLogger.debug(LTag.NSCLIENT, "Loading BolusCalculatorResult data for sync from $startId. Records ${it.size}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun processChangedBolusCalculatorResultsCompat(): Boolean {
|
||||||
|
val startId = sp.getLong(R.string.key_ns_bolus_calculator_result_last_synced_id, 0)
|
||||||
|
appRepository.getNextSyncElementBolusCalculatorResult(startId).blockingGet()?.let { bolusCalculatorResult ->
|
||||||
|
aapsLogger.info(LTag.DATABASE, "Loading BolusCalculatorResult data Start: $startId ID: ${bolusCalculatorResult.first.id} HistoryID: ${bolusCalculatorResult.second} ")
|
||||||
|
when {
|
||||||
|
// removed and not uploaded yet = ignore
|
||||||
|
!bolusCalculatorResult.first.isValid && bolusCalculatorResult.first.interfaceIDs.nightscoutId == null -> Any()
|
||||||
|
// removed and already uploaded = send for removal
|
||||||
|
!bolusCalculatorResult.first.isValid && bolusCalculatorResult.first.interfaceIDs.nightscoutId != null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbRemove("treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second))
|
||||||
|
// existing without nsId = create new
|
||||||
|
bolusCalculatorResult.first.isValid && bolusCalculatorResult.first.interfaceIDs.nightscoutId == null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbAdd("treatments", bolusCalculatorResult.first.toJson(), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second))
|
||||||
|
// existing with nsId = update
|
||||||
|
bolusCalculatorResult.first.isValid && bolusCalculatorResult.first.interfaceIDs.nightscoutId != null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, bolusCalculatorResult.first.toJson(), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second))
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun confirmLastTempTargetsIdIfGreater(lastSynced: Long) {
|
||||||
|
if (lastSynced > sp.getLong(R.string.key_ns_temporary_target_last_synced_id, 0)) {
|
||||||
|
aapsLogger.debug(LTag.NSCLIENT, "Setting TemporaryTarget data sync from $lastSynced")
|
||||||
|
sp.putLong(R.string.key_ns_temporary_target_last_synced_id, lastSynced)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepared for v3 (returns all modified after)
|
// Prepared for v3 (returns all modified after)
|
||||||
override fun changedTempTargets(): List<TemporaryTarget> {
|
override fun changedTempTargets(): List<TemporaryTarget> {
|
||||||
val startId = sp.getLong(R.string.key_ns_temporary_target_last_sync, 0)
|
val startId = sp.getLong(R.string.key_ns_temporary_target_last_synced_id, 0)
|
||||||
return appRepository.getModifiedTemporaryTargetsDataFromId(startId).blockingGet().also {
|
return appRepository.getModifiedTemporaryTargetsDataFromId(startId).blockingGet().also {
|
||||||
aapsLogger.debug(LTag.NSCLIENT, "Loading TT data for sync from $startId. Records ${it.size}")
|
aapsLogger.debug(LTag.NSCLIENT, "Loading TemporaryTarget data for sync from $startId. Records ${it.size}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processChangedTempTargetsCompat(): Boolean {
|
override fun processChangedTempTargetsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_temporary_target_last_sync, 0)
|
val startId = sp.getLong(R.string.key_ns_temporary_target_last_synced_id, 0)
|
||||||
appRepository.getNextSyncElementTemporaryTarget(startId).blockingGet()?.let { tt ->
|
appRepository.getNextSyncElementTemporaryTarget(startId).blockingGet()?.let { tt ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading TemporaryTarget data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading TemporaryTarget data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second} ")
|
||||||
when {
|
when {
|
||||||
|
@ -69,26 +178,60 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun confirmLastGlucoseValueId(lastSynced: Long) {
|
override fun confirmLastFoodIdIfGreater(lastSynced: Long) {
|
||||||
aapsLogger.debug(LTag.NSCLIENT, "Setting GlucoseValue data sync from $lastSynced")
|
if (lastSynced > sp.getLong(R.string.key_ns_food_last_synced_id, 0)) {
|
||||||
sp.putLong(R.string.key_ns_glucose_value_last_sync, lastSynced)
|
aapsLogger.debug(LTag.NSCLIENT, "Setting Food data sync from $lastSynced")
|
||||||
|
sp.putLong(R.string.key_ns_food_last_synced_id, lastSynced)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepared for v3 (returns all modified after)
|
||||||
|
override fun changedFoods(): List<Food> {
|
||||||
|
val startId = sp.getLong(R.string.key_ns_food_last_synced_id, 0)
|
||||||
|
return appRepository.getModifiedFoodDataFromId(startId).blockingGet().also {
|
||||||
|
aapsLogger.debug(LTag.NSCLIENT, "Loading Food data for sync from $startId. Records ${it.size}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun processChangedFoodsCompat(): Boolean {
|
||||||
|
val startId = sp.getLong(R.string.key_ns_food_last_synced_id, 0)
|
||||||
|
appRepository.getNextSyncElementFood(startId).blockingGet()?.let { tt ->
|
||||||
|
aapsLogger.info(LTag.DATABASE, "Loading Food data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second} ")
|
||||||
|
when {
|
||||||
|
// removed and not uploaded yet = ignore
|
||||||
|
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null -> Any()
|
||||||
|
// removed and already uploaded = send for removal
|
||||||
|
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbRemove("food", tt.first.interfaceIDs.nightscoutId, DataSyncSelector.PairFood(tt.first, tt.second))
|
||||||
|
// existing without nsId = create new
|
||||||
|
tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbAdd("food", tt.first.toJson(profileFunction.getUnits()), DataSyncSelector.PairFood(tt.first, tt.second))
|
||||||
|
// existing with nsId = update
|
||||||
|
tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbUpdate("food", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(profileFunction.getUnits()), DataSyncSelector.PairFood(tt.first, tt.second))
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun confirmLastGlucoseValueIdIfGreater(lastSynced: Long) {
|
override fun confirmLastGlucoseValueIdIfGreater(lastSynced: Long) {
|
||||||
if (lastSynced > sp.getLong(R.string.key_ns_glucose_value_last_sync, 0))
|
if (lastSynced > sp.getLong(R.string.key_ns_glucose_value_last_synced_id, 0)) {
|
||||||
confirmLastGlucoseValueId(lastSynced)
|
aapsLogger.debug(LTag.NSCLIENT, "Setting GlucoseValue data sync from $lastSynced")
|
||||||
|
sp.putLong(R.string.key_ns_glucose_value_last_synced_id, lastSynced)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepared for v3 (returns all modified after)
|
// Prepared for v3 (returns all modified after)
|
||||||
override fun changedGlucoseValues(): List<GlucoseValue> {
|
override fun changedGlucoseValues(): List<GlucoseValue> {
|
||||||
val startId = sp.getLong(R.string.key_ns_glucose_value_last_sync, 0)
|
val startId = sp.getLong(R.string.key_ns_glucose_value_last_synced_id, 0)
|
||||||
return appRepository.getModifiedBgReadingsDataFromId(startId).blockingGet().also {
|
return appRepository.getModifiedBgReadingsDataFromId(startId).blockingGet().also {
|
||||||
aapsLogger.debug(LTag.NSCLIENT, "Loading GlucoseValue data for sync from $startId . Records ${it.size}")
|
aapsLogger.debug(LTag.NSCLIENT, "Loading GlucoseValue data for sync from $startId . Records ${it.size}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processChangedGlucoseValuesCompat(): Boolean {
|
override fun processChangedGlucoseValuesCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_glucose_value_last_sync, 0)
|
val startId = sp.getLong(R.string.key_ns_glucose_value_last_synced_id, 0)
|
||||||
appRepository.getNextSyncElementGlucoseValue(startId).blockingGet()?.let { gv ->
|
appRepository.getNextSyncElementGlucoseValue(startId).blockingGet()?.let { gv ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading GlucoseValue data Start: $startId ID: ${gv.first.id} HistoryID: ${gv.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading GlucoseValue data Start: $startId ID: ${gv.first.id} HistoryID: ${gv.second} ")
|
||||||
if (activePlugin.activeBgSource.uploadToNs(gv.first)) {
|
if (activePlugin.activeBgSource.uploadToNs(gv.first)) {
|
||||||
|
@ -111,4 +254,41 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun confirmLastTherapyEventIdIfGreater(lastSynced: Long) {
|
||||||
|
if (lastSynced > sp.getLong(R.string.key_ns_therapy_event_last_synced_id, 0)) {
|
||||||
|
aapsLogger.debug(LTag.NSCLIENT, "Setting TherapyEvents data sync from $lastSynced")
|
||||||
|
sp.putLong(R.string.key_ns_therapy_event_last_synced_id, lastSynced)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepared for v3 (returns all modified after)
|
||||||
|
override fun changedTherapyEvents(): List<TherapyEvent> {
|
||||||
|
val startId = sp.getLong(R.string.key_ns_therapy_event_last_synced_id, 0)
|
||||||
|
return appRepository.getModifiedTherapyEventDataFromId(startId).blockingGet().also {
|
||||||
|
aapsLogger.debug(LTag.NSCLIENT, "Loading TherapyEvents data for sync from $startId. Records ${it.size}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun processChangedTherapyEventsCompat(): Boolean {
|
||||||
|
val startId = sp.getLong(R.string.key_ns_therapy_event_last_synced_id, 0)
|
||||||
|
appRepository.getNextSyncElementTherapyEvent(startId).blockingGet()?.let { tt ->
|
||||||
|
aapsLogger.info(LTag.DATABASE, "Loading TherapyEvents data Start: $startId ID: ${tt.first.id} HistoryID: ${tt.second} ")
|
||||||
|
when {
|
||||||
|
// removed and not uploaded yet = ignore
|
||||||
|
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null -> Any()
|
||||||
|
// removed and already uploaded = send for removal
|
||||||
|
!tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbRemove("treatments", tt.first.interfaceIDs.nightscoutId, DataSyncSelector.PairTherapyEvent(tt.first, tt.second))
|
||||||
|
// existing without nsId = create new
|
||||||
|
tt.first.isValid && tt.first.interfaceIDs.nightscoutId == null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbAdd("treatments", tt.first.toJson(), DataSyncSelector.PairTherapyEvent(tt.first, tt.second))
|
||||||
|
// existing with nsId = update
|
||||||
|
tt.first.isValid && tt.first.interfaceIDs.nightscoutId != null ->
|
||||||
|
nsClientPlugin.nsClientService?.dbUpdate("treatments", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(), DataSyncSelector.PairTherapyEvent(tt.first, tt.second))
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,14 @@ import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.database.AppRepository;
|
import info.nightscout.androidaps.database.AppRepository;
|
||||||
|
import info.nightscout.androidaps.database.entities.Carbs;
|
||||||
|
import info.nightscout.androidaps.database.transactions.UpdateNsIdBolusCalculatorResultTransaction;
|
||||||
|
import info.nightscout.androidaps.database.transactions.UpdateNsIdBolusTransaction;
|
||||||
|
import info.nightscout.androidaps.database.transactions.UpdateNsIdCarbsTransaction;
|
||||||
|
import info.nightscout.androidaps.database.transactions.UpdateNsIdFoodTransaction;
|
||||||
import info.nightscout.androidaps.database.transactions.UpdateNsIdGlucoseValueTransaction;
|
import info.nightscout.androidaps.database.transactions.UpdateNsIdGlucoseValueTransaction;
|
||||||
import info.nightscout.androidaps.database.transactions.UpdateNsIdTemporaryTargetTransaction;
|
import info.nightscout.androidaps.database.transactions.UpdateNsIdTemporaryTargetTransaction;
|
||||||
|
import info.nightscout.androidaps.database.transactions.UpdateNsIdTherapyEventTransaction;
|
||||||
import info.nightscout.androidaps.db.DbRequest;
|
import info.nightscout.androidaps.db.DbRequest;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
||||||
|
@ -231,8 +237,8 @@ public class NSClientService extends DaggerService {
|
||||||
result -> aapsLogger.debug(LTag.DATABASE, "Updated ns id of temporary target " + pair.getValue()),
|
result -> aapsLogger.debug(LTag.DATABASE, "Updated ns id of temporary target " + pair.getValue()),
|
||||||
error -> aapsLogger.error(LTag.DATABASE, "Updated ns id of temporary target failed")
|
error -> aapsLogger.error(LTag.DATABASE, "Updated ns id of temporary target failed")
|
||||||
));
|
));
|
||||||
dataSyncSelector.confirmTempTargetsTimestampIfGreater(pair.getUpdateRecordId());
|
dataSyncSelector.confirmLastTempTargetsIdIfGreater(pair.getUpdateRecordId());
|
||||||
rxBus.send(new EventNSClientNewLog("DBADD", "Acked " + pair.getValue().getInterfaceIDs().getNightscoutId()));
|
rxBus.send(new EventNSClientNewLog("DBADD", "Acked TemporaryTarget " + pair.getValue().getInterfaceIDs().getNightscoutId()));
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedTempTargetsCompat();
|
dataSyncSelector.processChangedTempTargetsCompat();
|
||||||
return;
|
return;
|
||||||
|
@ -248,11 +254,91 @@ public class NSClientService extends DaggerService {
|
||||||
error -> aapsLogger.error(LTag.DATABASE, "Updated ns id of glucose value failed", error)
|
error -> aapsLogger.error(LTag.DATABASE, "Updated ns id of glucose value failed", error)
|
||||||
));
|
));
|
||||||
dataSyncSelector.confirmLastGlucoseValueIdIfGreater(pair.getUpdateRecordId());
|
dataSyncSelector.confirmLastGlucoseValueIdIfGreater(pair.getUpdateRecordId());
|
||||||
rxBus.send(new EventNSClientNewLog("DBADD", "Acked " + pair.getValue().getInterfaceIDs().getNightscoutId()));
|
rxBus.send(new EventNSClientNewLog("DBADD", "Acked GlucoseValue " + pair.getValue().getInterfaceIDs().getNightscoutId()));
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedGlucoseValuesCompat();
|
dataSyncSelector.processChangedGlucoseValuesCompat();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (ack.getOriginalObject() instanceof DataSyncSelector.PairFood) {
|
||||||
|
DataSyncSelector.PairFood pair = (DataSyncSelector.PairFood) ack.getOriginalObject();
|
||||||
|
pair.getValue().getInterfaceIDs().setNightscoutId(ack.getId());
|
||||||
|
|
||||||
|
disposable.add(repository.runTransactionForResult(new UpdateNsIdFoodTransaction(pair.getValue()))
|
||||||
|
.observeOn(aapsSchedulers.getIo())
|
||||||
|
.subscribe(
|
||||||
|
result -> aapsLogger.debug(LTag.DATABASE, "Updated ns id of food " + pair.getValue()),
|
||||||
|
error -> aapsLogger.error(LTag.DATABASE, "Updated ns id of food failed", error)
|
||||||
|
));
|
||||||
|
dataSyncSelector.confirmLastFoodIdIfGreater(pair.getUpdateRecordId());
|
||||||
|
rxBus.send(new EventNSClientNewLog("DBADD", "Acked Food " + pair.getValue().getInterfaceIDs().getNightscoutId()));
|
||||||
|
// Send new if waiting
|
||||||
|
dataSyncSelector.processChangedFoodsCompat();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ack.getOriginalObject() instanceof DataSyncSelector.PairTherapyEvent) {
|
||||||
|
DataSyncSelector.PairTherapyEvent pair = (DataSyncSelector.PairTherapyEvent) ack.getOriginalObject();
|
||||||
|
pair.getValue().getInterfaceIDs().setNightscoutId(ack.getId());
|
||||||
|
|
||||||
|
disposable.add(repository.runTransactionForResult(new UpdateNsIdTherapyEventTransaction(pair.getValue()))
|
||||||
|
.observeOn(aapsSchedulers.getIo())
|
||||||
|
.subscribe(
|
||||||
|
result -> aapsLogger.debug(LTag.DATABASE, "Updated ns id of therapy event " + pair.getValue()),
|
||||||
|
error -> aapsLogger.error(LTag.DATABASE, "Updated ns id of therapy event failed", error)
|
||||||
|
));
|
||||||
|
dataSyncSelector.confirmLastTherapyEventIdIfGreater(pair.getUpdateRecordId());
|
||||||
|
rxBus.send(new EventNSClientNewLog("DBADD", "Acked TherapyEvent " + pair.getValue().getInterfaceIDs().getNightscoutId()));
|
||||||
|
// Send new if waiting
|
||||||
|
dataSyncSelector.processChangedTherapyEventsCompat();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ack.getOriginalObject() instanceof DataSyncSelector.PairBolus) {
|
||||||
|
DataSyncSelector.PairBolus pair = (DataSyncSelector.PairBolus) ack.getOriginalObject();
|
||||||
|
pair.getValue().getInterfaceIDs().setNightscoutId(ack.getId());
|
||||||
|
|
||||||
|
disposable.add(repository.runTransactionForResult(new UpdateNsIdBolusTransaction(pair.getValue()))
|
||||||
|
.observeOn(aapsSchedulers.getIo())
|
||||||
|
.subscribe(
|
||||||
|
result -> aapsLogger.debug(LTag.DATABASE, "Updated ns id of bolus " + pair.getValue()),
|
||||||
|
error -> aapsLogger.error(LTag.DATABASE, "Updated ns id of bolus failed", error)
|
||||||
|
));
|
||||||
|
dataSyncSelector.confirmLastBolusIdIfGreater(pair.getUpdateRecordId());
|
||||||
|
rxBus.send(new EventNSClientNewLog("DBADD", "Acked Bolus " + pair.getValue().getInterfaceIDs().getNightscoutId()));
|
||||||
|
// Send new if waiting
|
||||||
|
dataSyncSelector.processChangedBolusesCompat();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ack.getOriginalObject() instanceof DataSyncSelector.PairCarbs) {
|
||||||
|
DataSyncSelector.PairCarbs pair = (DataSyncSelector.PairCarbs) ack.getOriginalObject();
|
||||||
|
pair.getValue().getInterfaceIDs().setNightscoutId(ack.getId());
|
||||||
|
|
||||||
|
disposable.add(repository.runTransactionForResult(new UpdateNsIdCarbsTransaction(pair.getValue()))
|
||||||
|
.observeOn(aapsSchedulers.getIo())
|
||||||
|
.subscribe(
|
||||||
|
result -> aapsLogger.debug(LTag.DATABASE, "Updated ns id of carbs " + pair.getValue()),
|
||||||
|
error -> aapsLogger.error(LTag.DATABASE, "Updated ns id of carbs failed", error)
|
||||||
|
));
|
||||||
|
dataSyncSelector.confirmLastCarbsIdIfGreater(pair.getUpdateRecordId());
|
||||||
|
rxBus.send(new EventNSClientNewLog("DBADD", "Acked Carbs" + pair.getValue().getInterfaceIDs().getNightscoutId()));
|
||||||
|
// Send new if waiting
|
||||||
|
dataSyncSelector.processChangedCarbsCompat();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ack.getOriginalObject() instanceof DataSyncSelector.PairBolusCalculatorResult) {
|
||||||
|
DataSyncSelector.PairBolusCalculatorResult pair = (DataSyncSelector.PairBolusCalculatorResult) ack.getOriginalObject();
|
||||||
|
pair.getValue().getInterfaceIDs().setNightscoutId(ack.getId());
|
||||||
|
|
||||||
|
disposable.add(repository.runTransactionForResult(new UpdateNsIdBolusCalculatorResultTransaction(pair.getValue()))
|
||||||
|
.observeOn(aapsSchedulers.getIo())
|
||||||
|
.subscribe(
|
||||||
|
result -> aapsLogger.debug(LTag.DATABASE, "Updated ns id of BolusCalculatorResult " + pair.getValue()),
|
||||||
|
error -> aapsLogger.error(LTag.DATABASE, "Updated ns id of BolusCalculatorResult failed", error)
|
||||||
|
));
|
||||||
|
dataSyncSelector.confirmLastBolusCalculatorResultsIdIfGreater(pair.getUpdateRecordId());
|
||||||
|
rxBus.send(new EventNSClientNewLog("DBADD", "Acked BolusCalculatorResult" + pair.getValue().getInterfaceIDs().getNightscoutId()));
|
||||||
|
// Send new if waiting
|
||||||
|
dataSyncSelector.processChangedBolusCalculatorResultsCompat();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// old way
|
// old way
|
||||||
if (ack.nsClientID != null) {
|
if (ack.nsClientID != null) {
|
||||||
uploadQueue.removeByNsClientIdIfExists(ack.json);
|
uploadQueue.removeByNsClientIdIfExists(ack.json);
|
||||||
|
@ -267,8 +353,8 @@ public class NSClientService extends DaggerService {
|
||||||
// new room way
|
// new room way
|
||||||
if (ack.getOriginalObject() instanceof DataSyncSelector.PairTemporaryTarget) {
|
if (ack.getOriginalObject() instanceof DataSyncSelector.PairTemporaryTarget) {
|
||||||
DataSyncSelector.PairTemporaryTarget pair = (DataSyncSelector.PairTemporaryTarget) ack.getOriginalObject();
|
DataSyncSelector.PairTemporaryTarget pair = (DataSyncSelector.PairTemporaryTarget) ack.getOriginalObject();
|
||||||
dataSyncSelector.confirmTempTargetsTimestampIfGreater(pair.getUpdateRecordId());
|
dataSyncSelector.confirmLastTempTargetsIdIfGreater(pair.getUpdateRecordId());
|
||||||
rxBus.send(new EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked " + ack.get_id()));
|
rxBus.send(new EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked TemporaryTarget" + ack.get_id()));
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedTempTargetsCompat();
|
dataSyncSelector.processChangedTempTargetsCompat();
|
||||||
return;
|
return;
|
||||||
|
@ -276,11 +362,51 @@ public class NSClientService extends DaggerService {
|
||||||
if (ack.getOriginalObject() instanceof DataSyncSelector.PairGlucoseValue) {
|
if (ack.getOriginalObject() instanceof DataSyncSelector.PairGlucoseValue) {
|
||||||
DataSyncSelector.PairGlucoseValue pair = (DataSyncSelector.PairGlucoseValue) ack.getOriginalObject();
|
DataSyncSelector.PairGlucoseValue pair = (DataSyncSelector.PairGlucoseValue) ack.getOriginalObject();
|
||||||
dataSyncSelector.confirmLastGlucoseValueIdIfGreater(pair.getUpdateRecordId());
|
dataSyncSelector.confirmLastGlucoseValueIdIfGreater(pair.getUpdateRecordId());
|
||||||
rxBus.send(new EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked " + ack.get_id()));
|
rxBus.send(new EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked GlucoseValue " + ack.get_id()));
|
||||||
// Send new if waiting
|
// Send new if waiting
|
||||||
dataSyncSelector.processChangedGlucoseValuesCompat();
|
dataSyncSelector.processChangedGlucoseValuesCompat();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (ack.getOriginalObject() instanceof DataSyncSelector.PairFood) {
|
||||||
|
DataSyncSelector.PairFood pair = (DataSyncSelector.PairFood) ack.getOriginalObject();
|
||||||
|
dataSyncSelector.confirmLastFoodIdIfGreater(pair.getUpdateRecordId());
|
||||||
|
rxBus.send(new EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked Food " + ack.get_id()));
|
||||||
|
// Send new if waiting
|
||||||
|
dataSyncSelector.processChangedFoodsCompat();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ack.getOriginalObject() instanceof DataSyncSelector.PairTherapyEvent) {
|
||||||
|
DataSyncSelector.PairTherapyEvent pair = (DataSyncSelector.PairTherapyEvent) ack.getOriginalObject();
|
||||||
|
dataSyncSelector.confirmLastTherapyEventIdIfGreater(pair.getUpdateRecordId());
|
||||||
|
rxBus.send(new EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked TherapyEvent " + ack.get_id()));
|
||||||
|
// Send new if waiting
|
||||||
|
dataSyncSelector.processChangedTherapyEventsCompat();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ack.getOriginalObject() instanceof DataSyncSelector.PairBolus) {
|
||||||
|
DataSyncSelector.PairBolus pair = (DataSyncSelector.PairBolus) ack.getOriginalObject();
|
||||||
|
dataSyncSelector.confirmLastBolusIdIfGreater(pair.getUpdateRecordId());
|
||||||
|
rxBus.send(new EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked Bolus " + ack.get_id()));
|
||||||
|
// Send new if waiting
|
||||||
|
dataSyncSelector.processChangedBolusesCompat();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ack.getOriginalObject() instanceof DataSyncSelector.PairCarbs) {
|
||||||
|
DataSyncSelector.PairCarbs pair = (DataSyncSelector.PairCarbs) ack.getOriginalObject();
|
||||||
|
dataSyncSelector.confirmLastCarbsIdIfGreater(pair.getUpdateRecordId());
|
||||||
|
rxBus.send(new EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked Carbs " + ack.get_id()));
|
||||||
|
// Send new if waiting
|
||||||
|
dataSyncSelector.processChangedCarbsCompat();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ack.getOriginalObject() instanceof DataSyncSelector.PairBolusCalculatorResult) {
|
||||||
|
DataSyncSelector.PairBolusCalculatorResult pair = (DataSyncSelector.PairBolusCalculatorResult) ack.getOriginalObject();
|
||||||
|
dataSyncSelector.confirmLastBolusCalculatorResultsIdIfGreater(pair.getUpdateRecordId());
|
||||||
|
rxBus.send(new EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked BolusCalculatorResult " + ack.get_id()));
|
||||||
|
// Send new if waiting
|
||||||
|
dataSyncSelector.processChangedBolusCalculatorResultsCompat();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// old way
|
// old way
|
||||||
if (ack.getResult()) {
|
if (ack.getResult()) {
|
||||||
uploadQueue.removeByMongoId(ack.getAction(), ack.get_id());
|
uploadQueue.removeByMongoId(ack.getAction(), ack.get_id());
|
||||||
|
@ -767,7 +893,7 @@ public class NSClientService extends DaggerService {
|
||||||
message.put("_id", _id);
|
message.put("_id", _id);
|
||||||
message.put("data", data);
|
message.put("data", data);
|
||||||
mSocket.emit("dbUpdate", message, new NSUpdateAck("dbUpdate", _id, aapsLogger, rxBus, originalObject));
|
mSocket.emit("dbUpdate", message, new NSUpdateAck("dbUpdate", _id, aapsLogger, rxBus, originalObject));
|
||||||
rxBus.send(new EventNSClientNewLog("DBUPDATE " + collection, "Sent " + _id));
|
rxBus.send(new EventNSClientNewLog("DBUPDATE " + collection, "Sent " + originalObject.getClass().getSimpleName() + " " + _id));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
aapsLogger.error("Unhandled exception", e);
|
aapsLogger.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
@ -793,7 +919,7 @@ public class NSClientService extends DaggerService {
|
||||||
message.put("collection", collection);
|
message.put("collection", collection);
|
||||||
message.put("_id", _id);
|
message.put("_id", _id);
|
||||||
mSocket.emit("dbRemove", message, new NSUpdateAck("dbRemove", _id, aapsLogger, rxBus, originalObject));
|
mSocket.emit("dbRemove", message, new NSUpdateAck("dbRemove", _id, aapsLogger, rxBus, originalObject));
|
||||||
rxBus.send(new EventNSClientNewLog("DBREMOVE " + collection, "Sent " + _id));
|
rxBus.send(new EventNSClientNewLog("DBREMOVE " + collection, "Sent " + originalObject.getClass().getSimpleName() + " " + _id));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
aapsLogger.error("Unhandled exception", e);
|
aapsLogger.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
@ -819,7 +945,7 @@ public class NSClientService extends DaggerService {
|
||||||
message.put("collection", collection);
|
message.put("collection", collection);
|
||||||
message.put("data", data);
|
message.put("data", data);
|
||||||
mSocket.emit("dbAdd", message, new NSAddAck(aapsLogger, rxBus, originalObject));
|
mSocket.emit("dbAdd", message, new NSAddAck(aapsLogger, rxBus, originalObject));
|
||||||
rxBus.send(new EventNSClientNewLog("DBADD " + collection, "Sent " + data));
|
rxBus.send(new EventNSClientNewLog("DBADD " + collection, "Sent " + originalObject.getClass().getSimpleName() + " " + data));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
aapsLogger.error("Unhandled exception", e);
|
aapsLogger.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
@ -843,8 +969,14 @@ public class NSClientService extends DaggerService {
|
||||||
aapsLogger.debug(LTag.NSCLIENT, "Skipping resend by lastAckTime: " + ((System.currentTimeMillis() - lastAckTime) / 1000L) + " sec");
|
aapsLogger.debug(LTag.NSCLIENT, "Skipping resend by lastAckTime: " + ((System.currentTimeMillis() - lastAckTime) / 1000L) + " sec");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (dataSyncSelector.processChangedGlucoseValuesCompat()) return;
|
|
||||||
if (dataSyncSelector.processChangedTempTargetsCompat()) return;
|
dataSyncSelector.processChangedBolusesCompat();
|
||||||
|
dataSyncSelector.processChangedCarbsCompat();
|
||||||
|
dataSyncSelector.processChangedBolusCalculatorResultsCompat();
|
||||||
|
dataSyncSelector.processChangedGlucoseValuesCompat();
|
||||||
|
dataSyncSelector.processChangedTempTargetsCompat();
|
||||||
|
dataSyncSelector.processChangedFoodsCompat();
|
||||||
|
dataSyncSelector.processChangedTherapyEventsCompat();
|
||||||
|
|
||||||
if (uploadQueue.size() == 0)
|
if (uploadQueue.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -85,7 +85,6 @@ class DexcomPlugin @Inject constructor(
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
@Inject lateinit var aapsLogger: AAPSLogger
|
||||||
@Inject lateinit var injector: HasAndroidInjector
|
@Inject lateinit var injector: HasAndroidInjector
|
||||||
@Inject lateinit var dexcomPlugin: DexcomPlugin
|
@Inject lateinit var dexcomPlugin: DexcomPlugin
|
||||||
@Inject lateinit var nsUpload: NSUpload
|
|
||||||
@Inject lateinit var sp: SP
|
@Inject lateinit var sp: SP
|
||||||
@Inject lateinit var dataWorker: DataWorker
|
@Inject lateinit var dataWorker: DataWorker
|
||||||
@Inject lateinit var broadcastToXDrip: XDripBroadcast
|
@Inject lateinit var broadcastToXDrip: XDripBroadcast
|
||||||
|
@ -157,18 +156,8 @@ class DexcomPlugin @Inject constructor(
|
||||||
broadcastToXDrip(it)
|
broadcastToXDrip(it)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Updated bg $it")
|
aapsLogger.debug(LTag.DATABASE, "Updated bg $it")
|
||||||
}
|
}
|
||||||
result.sensorInsertionsInserted.forEach {
|
result.sensorInsertionsInserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted sensor insertion $it") }
|
||||||
if (sp.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
result.calibrationsInserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted calibration $it") }
|
||||||
nsUpload.uploadEvent(it)
|
|
||||||
}
|
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted sensor insertion $it")
|
|
||||||
}
|
|
||||||
result.calibrationsInserted.forEach {
|
|
||||||
if (sp.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
|
||||||
nsUpload.uploadEvent(it)
|
|
||||||
}
|
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted calibration $it")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
aapsLogger.error("Error while processing intent from Dexcom App", e)
|
aapsLogger.error("Error while processing intent from Dexcom App", e)
|
||||||
|
|
|
@ -16,7 +16,6 @@ import info.nightscout.androidaps.interfaces.PluginDescription
|
||||||
import info.nightscout.androidaps.interfaces.PluginType
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.receivers.DataWorker
|
import info.nightscout.androidaps.receivers.DataWorker
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.XDripBroadcast
|
import info.nightscout.androidaps.utils.XDripBroadcast
|
||||||
|
@ -58,7 +57,6 @@ class EversensePlugin @Inject constructor(
|
||||||
@Inject lateinit var eversensePlugin: EversensePlugin
|
@Inject lateinit var eversensePlugin: EversensePlugin
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
@Inject lateinit var aapsLogger: AAPSLogger
|
||||||
@Inject lateinit var dateUtil: DateUtil
|
@Inject lateinit var dateUtil: DateUtil
|
||||||
@Inject lateinit var nsUpload: NSUpload
|
|
||||||
@Inject lateinit var dataWorker: DataWorker
|
@Inject lateinit var dataWorker: DataWorker
|
||||||
@Inject lateinit var repository: AppRepository
|
@Inject lateinit var repository: AppRepository
|
||||||
@Inject lateinit var broadcastToXDrip: XDripBroadcast
|
@Inject lateinit var broadcastToXDrip: XDripBroadcast
|
||||||
|
@ -147,10 +145,7 @@ class EversensePlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
.also { result ->
|
.also { result ->
|
||||||
result.inserted.forEach {
|
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted therapy event $it") }
|
||||||
nsUpload.uploadEvent(it)
|
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted therapy event $it")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ class NSClientSourcePlugin @Inject constructor(
|
||||||
override fun doWork(): Result {
|
override fun doWork(): Result {
|
||||||
var ret = Result.success()
|
var ret = Result.success()
|
||||||
|
|
||||||
if (!nsClientSourcePlugin.isEnabled() && !sp.getBoolean(R.string.key_ns_autobackfill, true) && !dexcomPlugin.isEnabled()) return Result.failure()
|
if (!nsClientSourcePlugin.isEnabled() && !sp.getBoolean(R.string.key_ns_autobackfill, true) && !dexcomPlugin.isEnabled()) return Result.success()
|
||||||
|
|
||||||
val sgvs = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
|
val sgvs = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
|
||||||
?: return Result.failure()
|
?: return Result.failure()
|
||||||
|
|
|
@ -14,7 +14,6 @@ import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult
|
import info.nightscout.androidaps.data.PumpEnactResult
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry
|
|
||||||
import info.nightscout.androidaps.dialogs.BolusProgressDialog
|
import info.nightscout.androidaps.dialogs.BolusProgressDialog
|
||||||
import info.nightscout.androidaps.events.EventBolusRequested
|
import info.nightscout.androidaps.events.EventBolusRequested
|
||||||
import info.nightscout.androidaps.events.EventNewBasalProfile
|
import info.nightscout.androidaps.events.EventNewBasalProfile
|
||||||
|
@ -25,7 +24,6 @@ import info.nightscout.androidaps.interfaces.Constraint
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
|
@ -206,14 +204,10 @@ open class CommandQueue @Inject constructor(
|
||||||
|| detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp > dateUtil._now()
|
|| detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp > dateUtil._now()
|
||||||
) {
|
) {
|
||||||
disposable += repository.runTransactionForResult(detailedBolusInfo.insertCarbsTransaction())
|
disposable += repository.runTransactionForResult(detailedBolusInfo.insertCarbsTransaction())
|
||||||
.subscribe({ result ->
|
.subscribe(
|
||||||
result.inserted.forEach {
|
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it") } },
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it")
|
{ aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) }
|
||||||
nsUpload.uploadCarbsRecord(it, detailedBolusInfo.createTherapyEvent())
|
)
|
||||||
}
|
|
||||||
}, {
|
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it)
|
|
||||||
})
|
|
||||||
// Do not process carbs anymore
|
// Do not process carbs anymore
|
||||||
detailedBolusInfo.carbs = 0.0
|
detailedBolusInfo.carbs = 0.0
|
||||||
// if no insulin just exit
|
// if no insulin just exit
|
||||||
|
|
|
@ -2,11 +2,14 @@ package info.nightscout.androidaps.utils
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
@ -19,9 +22,11 @@ class HardLimits @Inject constructor(
|
||||||
private val sp: SP,
|
private val sp: SP,
|
||||||
private val resourceHelper: ResourceHelper,
|
private val resourceHelper: ResourceHelper,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val nsUpload: NSUpload
|
private val repository: AppRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val CHILD = 0
|
private const val CHILD = 0
|
||||||
|
@ -88,7 +93,7 @@ class HardLimits @Inject constructor(
|
||||||
msg += ".\n"
|
msg += ".\n"
|
||||||
msg += String.format(resourceHelper.gs(R.string.valuelimitedto), value, newValue)
|
msg += String.format(resourceHelper.gs(R.string.valuelimitedto), value, newValue)
|
||||||
aapsLogger.error(msg)
|
aapsLogger.error(msg)
|
||||||
nsUpload.uploadError(msg)
|
disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(msg)).subscribe()
|
||||||
ToastUtils.showToastInUiThread(context, rxBus, msg, R.raw.error)
|
ToastUtils.showToastInUiThread(context, rxBus, msg, R.raw.error)
|
||||||
}
|
}
|
||||||
return newValue
|
return newValue
|
||||||
|
|
|
@ -3,12 +3,13 @@ package info.nightscout.androidaps.utils
|
||||||
import info.nightscout.androidaps.Config
|
import info.nightscout.androidaps.Config
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
|
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||||
|
@ -16,6 +17,8 @@ import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicato
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
@ -34,10 +37,12 @@ class LocalAlertUtils @Inject constructor(
|
||||||
private val iobCobCalculatorPlugin: IobCobCalculatorPlugin,
|
private val iobCobCalculatorPlugin: IobCobCalculatorPlugin,
|
||||||
private val smsCommunicatorPlugin: SmsCommunicatorPlugin,
|
private val smsCommunicatorPlugin: SmsCommunicatorPlugin,
|
||||||
private val config: Config,
|
private val config: Config,
|
||||||
private val nsUpload: NSUpload,
|
private val repository: AppRepository,
|
||||||
private val dateUtil: DateUtil
|
private val dateUtil: DateUtil
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
private fun missedReadingsThreshold(): Long {
|
private fun missedReadingsThreshold(): Long {
|
||||||
return T.mins(sp.getInt(R.string.key_missed_bg_readings_threshold_minutes, Constants.DEFAULT_MISSED_BG_READINGS_THRESHOLD_MINUTES).toLong()).msecs()
|
return T.mins(sp.getInt(R.string.key_missed_bg_readings_threshold_minutes, Constants.DEFAULT_MISSED_BG_READINGS_THRESHOLD_MINUTES).toLong()).msecs()
|
||||||
}
|
}
|
||||||
|
@ -55,7 +60,7 @@ class LocalAlertUtils @Inject constructor(
|
||||||
sp.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold())
|
sp.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold())
|
||||||
rxBus.send(EventNewNotification(Notification(Notification.PUMP_UNREACHABLE, resourceHelper.gs(R.string.pump_unreachable), Notification.URGENT).also { it.soundId = R.raw.alarm }))
|
rxBus.send(EventNewNotification(Notification(Notification.PUMP_UNREACHABLE, resourceHelper.gs(R.string.pump_unreachable), Notification.URGENT).also { it.soundId = R.raw.alarm }))
|
||||||
if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true))
|
if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true))
|
||||||
nsUpload.uploadError(resourceHelper.gs(R.string.pump_unreachable))
|
disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(resourceHelper.gs(R.string.pump_unreachable))).subscribe()
|
||||||
}
|
}
|
||||||
if (sp.getBoolean(R.string.key_smscommunicator_report_pump_ureachable, true))
|
if (sp.getBoolean(R.string.key_smscommunicator_report_pump_ureachable, true))
|
||||||
smsCommunicatorPlugin.sendNotificationToAllNumbers(resourceHelper.gs(R.string.pump_unreachable))
|
smsCommunicatorPlugin.sendNotificationToAllNumbers(resourceHelper.gs(R.string.pump_unreachable))
|
||||||
|
@ -113,7 +118,7 @@ class LocalAlertUtils @Inject constructor(
|
||||||
sp.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold())
|
sp.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold())
|
||||||
rxBus.send(EventNewNotification(n))
|
rxBus.send(EventNewNotification(n))
|
||||||
if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) {
|
if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) {
|
||||||
nsUpload.uploadError(n.text)
|
n.text?.let { disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(it)).subscribe() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -425,14 +425,10 @@ class BolusWizard @Inject constructor(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
disposable += repository.runTransactionForResult(InsertOrUpdateBolusCalculatorResultTransaction(bolusCalculatorResult!!))
|
disposable += repository.runTransactionForResult(InsertOrUpdateBolusCalculatorResultTransaction(bolusCalculatorResult!!))
|
||||||
.subscribe({ result ->
|
.subscribe(
|
||||||
result.inserted.forEach { inserted ->
|
{ result -> result.inserted.forEach { inserted -> aapsLogger.debug(LTag.DATABASE, "Inserted bolusCalculatorResult $inserted") } },
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted bolusCalculatorResult $inserted")
|
{ aapsLogger.error(LTag.DATABASE, "Error while saving bolusCalculatorResult", it) }
|
||||||
nsUpload.uploadBolusCalc(this)
|
)
|
||||||
}
|
|
||||||
}, {
|
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving meal link", it)
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (useAlarm && carbs > 0 && carbTime > 0) {
|
if (useAlarm && carbs > 0 && carbTime > 0) {
|
||||||
|
|
|
@ -33,8 +33,16 @@
|
||||||
<string name="key_protection_settings" translatable="false">protection</string>
|
<string name="key_protection_settings" translatable="false">protection</string>
|
||||||
<string name="key_absorption_category_settings" translatable="false">absorption_category_settings</string>
|
<string name="key_absorption_category_settings" translatable="false">absorption_category_settings</string>
|
||||||
<string name="key_insulin_oref_peak_settings" translatable="false">insulin_oref_peak_settings</string>
|
<string name="key_insulin_oref_peak_settings" translatable="false">insulin_oref_peak_settings</string>
|
||||||
<string name="key_ns_temporary_target_last_sync" translatable="false">ns_temporary_target_last_sync</string>
|
<string name="key_ns_temporary_target_last_synced_id" translatable="false">ns_temporary_target_last_sync</string>
|
||||||
<string name="key_ns_glucose_value_last_sync" translatable="false">ns_glucose_value_last_sync</string>
|
<string name="key_ns_glucose_value_last_synced_id" translatable="false">ns_glucose_value_last_sync</string>
|
||||||
|
<string name="key_ns_food_last_synced_id" translatable="false">ns_food_last_sync</string>
|
||||||
|
<string name="key_ns_therapy_event_last_synced_id" translatable="false">ns_therapy_event_last_sync</string>
|
||||||
|
<string name="key_smscommunicator_remotebolusmindistance" translatable="false">smscommunicator_remotebolusmindistance</string>
|
||||||
|
<string name="key_openapsama_bolussnooze_dia_divisor" translatable="false">bolussnooze_dia_divisor</string>
|
||||||
|
<string name="key_openapsama_autosens_adjusttargets" translatable="false">autosens_adjust_targets</string>
|
||||||
|
<string name="key_ns_bolus_calculator_result_last_synced_id" translatable="false">ns_bolus_calculator_result_last_synced_id</string>
|
||||||
|
<string name="key_ns_carbs_last_synced_id" translatable="false">ns_carbs_last_synced_id</string>
|
||||||
|
<string name="key_ns_bolus_last_synced_id" translatable="false">ns_bolus_last_synced_id</string>
|
||||||
|
|
||||||
<string name="treatmentssafety_title">Treatments safety</string>
|
<string name="treatmentssafety_title">Treatments safety</string>
|
||||||
<string name="treatmentssafety_maxbolus_title">Max allowed bolus [U]</string>
|
<string name="treatmentssafety_maxbolus_title">Max allowed bolus [U]</string>
|
||||||
|
@ -228,7 +236,6 @@
|
||||||
<string name="smscommunicator_stoppedsms">SMS Remote Service stopped. To reactivate it, use AAPS on master smartphone.</string>
|
<string name="smscommunicator_stoppedsms">SMS Remote Service stopped. To reactivate it, use AAPS on master smartphone.</string>
|
||||||
<string name="smscommunicator_calibrationreplywithcode">To send calibration %1$.2f reply with code %2$s</string>
|
<string name="smscommunicator_calibrationreplywithcode">To send calibration %1$.2f reply with code %2$s</string>
|
||||||
<string name="smscommunicator_bolusfailed">Bolus failed</string>
|
<string name="smscommunicator_bolusfailed">Bolus failed</string>
|
||||||
<string name="key_smscommunicator_remotebolusmindistance" translatable="false">smscommunicator_remotebolusmindistance</string>
|
|
||||||
<string name="smscommunicator_remotebolusmindistance_summary">Minimum number of minutes that must elapse between one remote bolus and the next</string>
|
<string name="smscommunicator_remotebolusmindistance_summary">Minimum number of minutes that must elapse between one remote bolus and the next</string>
|
||||||
<string name="smscommunicator_remotebolusmindistance">How many minutes must elapse, at least, between one bolus and the next</string>
|
<string name="smscommunicator_remotebolusmindistance">How many minutes must elapse, at least, between one bolus and the next</string>
|
||||||
<string name="smscommunicator_remotebolusmindistance_caveat">For your safety, to edit this preference you need to add at least 2 phone numbers.</string>
|
<string name="smscommunicator_remotebolusmindistance_caveat">For your safety, to edit this preference you need to add at least 2 phone numbers.</string>
|
||||||
|
@ -341,10 +348,8 @@
|
||||||
<string name="openapsama_current_basal_safety_multiplier_summary">Default value: 4 This is the other half of the key OpenAPS safety caps, and the other half of “3x max daily; 4x current” of the safety caps. This means your basal, regardless of max basal set on your pump, cannot be any higher than this number times the current level of your basal. This is to prevent people from getting into dangerous territory by setting excessively high max basals before understanding how the algorithm works. Again, the default is 4x; most people will never need to adjust this and are instead more likely to need to adjust other settings if they feel like they are “running into” this safety cap.</string>
|
<string name="openapsama_current_basal_safety_multiplier_summary">Default value: 4 This is the other half of the key OpenAPS safety caps, and the other half of “3x max daily; 4x current” of the safety caps. This means your basal, regardless of max basal set on your pump, cannot be any higher than this number times the current level of your basal. This is to prevent people from getting into dangerous territory by setting excessively high max basals before understanding how the algorithm works. Again, the default is 4x; most people will never need to adjust this and are instead more likely to need to adjust other settings if they feel like they are “running into” this safety cap.</string>
|
||||||
<string name="openapsama_autosens_max_summary">Default value: 1.2\nThis is a multiplier cap for autosens (and soon autotune) to set a 20%% max limit on how high the autosens ratio can be, which in turn determines how high autosens can adjust basals, how low it can adjust ISF, and how low it can set the BG target.</string>
|
<string name="openapsama_autosens_max_summary">Default value: 1.2\nThis is a multiplier cap for autosens (and soon autotune) to set a 20%% max limit on how high the autosens ratio can be, which in turn determines how high autosens can adjust basals, how low it can adjust ISF, and how low it can set the BG target.</string>
|
||||||
<string name="openapsama_autosens_min_summary">Default value: 0.7\nThe other side of the autosens safety limits, putting a cap on how low autosens can adjust basals, and how high it can adjust ISF and BG targets.</string>
|
<string name="openapsama_autosens_min_summary">Default value: 0.7\nThe other side of the autosens safety limits, putting a cap on how low autosens can adjust basals, and how high it can adjust ISF and BG targets.</string>
|
||||||
<string name="key_openapsama_autosens_adjusttargets" translatable="false">autosens_adjust_targets</string>
|
|
||||||
<string name="openapsama_autosens_adjusttargets">Autosens adjust targets, too</string>
|
<string name="openapsama_autosens_adjusttargets">Autosens adjust targets, too</string>
|
||||||
<string name="openapsama_autosens_adjusttargets_summary">Default value: true\nThis is used to allow autosens to adjust BG targets, in addition to ISF and basals.</string>
|
<string name="openapsama_autosens_adjusttargets_summary">Default value: true\nThis is used to allow autosens to adjust BG targets, in addition to ISF and basals.</string>
|
||||||
<string name="key_openapsama_bolussnooze_dia_divisor" translatable="false">bolussnooze_dia_divisor</string>
|
|
||||||
<string name="openapsama_bolussnooze_dia_divisor_summary">Default value: 2\nBolus snooze is enacted after you do a meal bolus, so the loop won’t counteract with low temps when you’ve just eaten. The example here and default is 2; so a 3 hour DIA means that bolus snooze will be gradually phased out over 1.5 hours (3DIA/2).</string>
|
<string name="openapsama_bolussnooze_dia_divisor_summary">Default value: 2\nBolus snooze is enacted after you do a meal bolus, so the loop won’t counteract with low temps when you’ve just eaten. The example here and default is 2; so a 3 hour DIA means that bolus snooze will be gradually phased out over 1.5 hours (3DIA/2).</string>
|
||||||
<string name="openapsama_min_5m_carbimpact" translatable="false">min_5m_carbimpact</string>
|
<string name="openapsama_min_5m_carbimpact" translatable="false">min_5m_carbimpact</string>
|
||||||
<string name="openapsama_min_5m_carbimpact_summary">Default value: 3.0 (AMA) or 8.0 (SMB). This is a setting for default carb absorption impact per 5 minutes. The default is an expected 3mg/dl/5min. This affects how fast COB are decayed, and how much carb absorption is assumed in calculating future predicted BG, when BG is falling more than expected, or not rising as much as expected.</string>
|
<string name="openapsama_min_5m_carbimpact_summary">Default value: 3.0 (AMA) or 8.0 (SMB). This is a setting for default carb absorption impact per 5 minutes. The default is an expected 3mg/dl/5min. This affects how fast COB are decayed, and how much carb absorption is assumed in calculating future predicted BG, when BG is falling more than expected, or not rising as much as expected.</string>
|
||||||
|
@ -1130,5 +1135,4 @@
|
||||||
<string name="profile_carbs_ratio_value">Profile carbs ratio value</string>
|
<string name="profile_carbs_ratio_value">Profile carbs ratio value</string>
|
||||||
<string name="full_sync">Full sync</string>
|
<string name="full_sync">Full sync</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -5,17 +5,20 @@ import androidx.annotation.DrawableRes
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.automation.R
|
import info.nightscout.androidaps.automation.R
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult
|
import info.nightscout.androidaps.data.PumpEnactResult
|
||||||
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview
|
import info.nightscout.androidaps.events.EventRefreshOverview
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputString
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputString
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement
|
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder
|
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationUserMessage
|
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationUserMessage
|
||||||
import info.nightscout.androidaps.queue.Callback
|
import info.nightscout.androidaps.queue.Callback
|
||||||
import info.nightscout.androidaps.utils.JsonHelper
|
import info.nightscout.androidaps.utils.JsonHelper
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -23,7 +26,9 @@ class ActionNotification(injector: HasAndroidInjector) : Action(injector) {
|
||||||
|
|
||||||
@Inject lateinit var resourceHelper: ResourceHelper
|
@Inject lateinit var resourceHelper: ResourceHelper
|
||||||
@Inject lateinit var rxBus: RxBusWrapper
|
@Inject lateinit var rxBus: RxBusWrapper
|
||||||
@Inject lateinit var nsUpload: NSUpload
|
@Inject lateinit var repository: AppRepository
|
||||||
|
|
||||||
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
var text = InputString()
|
var text = InputString()
|
||||||
|
|
||||||
|
@ -34,7 +39,7 @@ class ActionNotification(injector: HasAndroidInjector) : Action(injector) {
|
||||||
override fun doAction(callback: Callback) {
|
override fun doAction(callback: Callback) {
|
||||||
val notification = NotificationUserMessage(text.value)
|
val notification = NotificationUserMessage(text.value)
|
||||||
rxBus.send(EventNewNotification(notification))
|
rxBus.send(EventNewNotification(notification))
|
||||||
nsUpload.uploadError(text.value)
|
disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(text.value)).subscribe()
|
||||||
rxBus.send(EventRefreshOverview("ActionNotification"))
|
rxBus.send(EventRefreshOverview("ActionNotification"))
|
||||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
|
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.TestBase
|
import info.nightscout.androidaps.TestBase
|
||||||
import info.nightscout.androidaps.automation.R
|
import info.nightscout.androidaps.automation.R
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult
|
import info.nightscout.androidaps.data.PumpEnactResult
|
||||||
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputString
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputString
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
|
@ -27,7 +29,7 @@ class ActionNotificationTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var rxBus: RxBusWrapper
|
@Mock lateinit var rxBus: RxBusWrapper
|
||||||
@Mock lateinit var nsUpload: NSUpload
|
@Mock lateinit var repository: AppRepository
|
||||||
|
|
||||||
private lateinit var sut: ActionNotification
|
private lateinit var sut: ActionNotification
|
||||||
var injector: HasAndroidInjector = HasAndroidInjector {
|
var injector: HasAndroidInjector = HasAndroidInjector {
|
||||||
|
@ -35,7 +37,6 @@ class ActionNotificationTest : TestBase() {
|
||||||
if (it is ActionNotification) {
|
if (it is ActionNotification) {
|
||||||
it.resourceHelper = resourceHelper
|
it.resourceHelper = resourceHelper
|
||||||
it.rxBus = rxBus
|
it.rxBus = rxBus
|
||||||
it.nsUpload = nsUpload
|
|
||||||
}
|
}
|
||||||
if (it is PumpEnactResult) {
|
if (it is PumpEnactResult) {
|
||||||
it.resourceHelper = resourceHelper
|
it.resourceHelper = resourceHelper
|
||||||
|
@ -72,7 +73,7 @@ class ActionNotificationTest : TestBase() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Mockito.verify(rxBus, Mockito.times(2)).send(anyObject())
|
Mockito.verify(rxBus, Mockito.times(2)).send(anyObject())
|
||||||
Mockito.verify(nsUpload, Mockito.times(1)).uploadError(anyObject())
|
Mockito.verify(repository, Mockito.times(1)).runTransaction(anyObject() as InsertTherapyEventAnnouncementTransaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
|
|
|
@ -5,14 +5,20 @@ import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.annotation.RawRes
|
import androidx.annotation.RawRes
|
||||||
import info.nightscout.androidaps.core.R
|
import info.nightscout.androidaps.core.R
|
||||||
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction
|
||||||
import info.nightscout.androidaps.dialogs.ErrorDialog
|
import info.nightscout.androidaps.dialogs.ErrorDialog
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ErrorHelperActivity : DialogAppCompatActivity() {
|
class ErrorHelperActivity : DialogAppCompatActivity() {
|
||||||
@Inject lateinit var sp : SP
|
|
||||||
@Inject lateinit var nsUpload: NSUpload
|
@Inject lateinit var sp: SP
|
||||||
|
@Inject lateinit var repository: AppRepository
|
||||||
|
|
||||||
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
@ -24,17 +30,17 @@ class ErrorHelperActivity : DialogAppCompatActivity() {
|
||||||
errorDialog.title = intent.getStringExtra(TITLE)
|
errorDialog.title = intent.getStringExtra(TITLE)
|
||||||
errorDialog.show(supportFragmentManager, "Error")
|
errorDialog.show(supportFragmentManager, "Error")
|
||||||
|
|
||||||
if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) {
|
if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true))
|
||||||
nsUpload.uploadError(intent.getStringExtra(STATUS))
|
disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(intent.getStringExtra(STATUS))).subscribe()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
const val SOUND_ID = "soundId"
|
const val SOUND_ID = "soundId"
|
||||||
const val STATUS = "status"
|
const val STATUS = "status"
|
||||||
const val TITLE = "title"
|
const val TITLE = "title"
|
||||||
|
|
||||||
fun runAlarm(ctx: Context, status: String, title : String, @RawRes soundId: Int = 0) {
|
fun runAlarm(ctx: Context, status: String, title: String, @RawRes soundId: Int = 0) {
|
||||||
val i = Intent(ctx, ErrorHelperActivity::class.java)
|
val i = Intent(ctx, ErrorHelperActivity::class.java)
|
||||||
i.putExtra(SOUND_ID, soundId)
|
i.putExtra(SOUND_ID, soundId)
|
||||||
i.putExtra(STATUS, status)
|
i.putExtra(STATUS, status)
|
||||||
|
|
|
@ -1,24 +1,51 @@
|
||||||
package info.nightscout.androidaps.interfaces
|
package info.nightscout.androidaps.interfaces
|
||||||
|
|
||||||
import info.nightscout.androidaps.database.entities.GlucoseValue
|
import info.nightscout.androidaps.database.entities.*
|
||||||
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
|
||||||
|
|
||||||
interface DataSyncSelector {
|
interface DataSyncSelector {
|
||||||
|
|
||||||
data class PairTemporaryTarget(val value: TemporaryTarget, val updateRecordId: Long)
|
data class PairTemporaryTarget(val value: TemporaryTarget, val updateRecordId: Long)
|
||||||
data class PairGlucoseValue(val value: GlucoseValue, val updateRecordId: Long)
|
data class PairGlucoseValue(val value: GlucoseValue, val updateRecordId: Long)
|
||||||
|
data class PairTherapyEvent(val value: TherapyEvent, val updateRecordId: Long)
|
||||||
|
data class PairFood(val value: Food, val updateRecordId: Long)
|
||||||
|
data class PairBolus(val value: Bolus, val updateRecordId: Long)
|
||||||
|
data class PairCarbs(val value: Carbs, val updateRecordId: Long)
|
||||||
|
data class PairBolusCalculatorResult(val value: BolusCalculatorResult, val updateRecordId: Long)
|
||||||
|
|
||||||
fun resetToNextFullSync()
|
fun resetToNextFullSync()
|
||||||
|
|
||||||
fun confirmTempTargetsTimestamp(lastSynced: Long)
|
fun confirmLastBolusIdIfGreater(lastSynced: Long)
|
||||||
fun confirmTempTargetsTimestampIfGreater(lastSynced: Long)
|
fun changedBoluses() : List<Bolus>
|
||||||
|
// Until NS v3
|
||||||
|
fun processChangedBolusesCompat(): Boolean
|
||||||
|
|
||||||
|
fun confirmLastCarbsIdIfGreater(lastSynced: Long)
|
||||||
|
fun changedCarbs() : List<Carbs>
|
||||||
|
// Until NS v3
|
||||||
|
fun processChangedCarbsCompat(): Boolean
|
||||||
|
|
||||||
|
fun confirmLastBolusCalculatorResultsIdIfGreater(lastSynced: Long)
|
||||||
|
fun changedBolusCalculatorResults() : List<BolusCalculatorResult>
|
||||||
|
// Until NS v3
|
||||||
|
fun processChangedBolusCalculatorResultsCompat(): Boolean
|
||||||
|
|
||||||
|
fun confirmLastTempTargetsIdIfGreater(lastSynced: Long)
|
||||||
fun changedTempTargets() : List<TemporaryTarget>
|
fun changedTempTargets() : List<TemporaryTarget>
|
||||||
// Until NS v3
|
// Until NS v3
|
||||||
fun processChangedTempTargetsCompat(): Boolean
|
fun processChangedTempTargetsCompat(): Boolean
|
||||||
|
|
||||||
fun confirmLastGlucoseValueId(lastSynced: Long)
|
|
||||||
fun confirmLastGlucoseValueIdIfGreater(lastSynced: Long)
|
fun confirmLastGlucoseValueIdIfGreater(lastSynced: Long)
|
||||||
fun changedGlucoseValues() : List<GlucoseValue>
|
fun changedGlucoseValues() : List<GlucoseValue>
|
||||||
// Until NS v3
|
// Until NS v3
|
||||||
fun processChangedGlucoseValuesCompat(): Boolean
|
fun processChangedGlucoseValuesCompat(): Boolean
|
||||||
|
|
||||||
|
fun confirmLastTherapyEventIdIfGreater(lastSynced: Long)
|
||||||
|
fun changedTherapyEvents() : List<TherapyEvent>
|
||||||
|
// Until NS v3
|
||||||
|
fun processChangedTherapyEventsCompat(): Boolean
|
||||||
|
|
||||||
|
fun confirmLastFoodIdIfGreater(lastSynced: Long)
|
||||||
|
fun changedFoods() : List<Food>
|
||||||
|
// Until NS v3
|
||||||
|
fun processChangedFoodsCompat(): Boolean
|
||||||
}
|
}
|
|
@ -23,8 +23,6 @@ import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.database.entities.Bolus;
|
import info.nightscout.androidaps.database.entities.Bolus;
|
||||||
import info.nightscout.androidaps.database.entities.BolusCalculatorResult;
|
import info.nightscout.androidaps.database.entities.BolusCalculatorResult;
|
||||||
import info.nightscout.androidaps.database.entities.Carbs;
|
import info.nightscout.androidaps.database.entities.Carbs;
|
||||||
import info.nightscout.androidaps.database.entities.GlucoseValue;
|
|
||||||
import info.nightscout.androidaps.database.entities.TemporaryTarget;
|
|
||||||
import info.nightscout.androidaps.database.entities.TherapyEvent;
|
import info.nightscout.androidaps.database.entities.TherapyEvent;
|
||||||
import info.nightscout.androidaps.db.DbRequest;
|
import info.nightscout.androidaps.db.DbRequest;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
|
@ -33,7 +31,6 @@ import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.interfaces.IobCobCalculatorInterface;
|
import info.nightscout.androidaps.interfaces.IobCobCalculatorInterface;
|
||||||
import info.nightscout.androidaps.interfaces.LoopInterface;
|
import info.nightscout.androidaps.interfaces.LoopInterface;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileStore;
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.interfaces.UploadQueueInterface;
|
import info.nightscout.androidaps.interfaces.UploadQueueInterface;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
|
@ -43,9 +40,6 @@ import info.nightscout.androidaps.plugins.aps.loop.DeviceStatus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.RunningConfiguration;
|
import info.nightscout.androidaps.plugins.configBuilder.RunningConfiguration;
|
||||||
import info.nightscout.androidaps.receivers.ReceiverStatusStore;
|
import info.nightscout.androidaps.receivers.ReceiverStatusStore;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.JsonHelper;
|
|
||||||
import info.nightscout.androidaps.utils.T;
|
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,29 +49,21 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
public class NSUpload {
|
public class NSUpload {
|
||||||
|
|
||||||
private final AAPSLogger aapsLogger;
|
private final AAPSLogger aapsLogger;
|
||||||
private final ResourceHelper resourceHelper;
|
|
||||||
private final SP sp;
|
private final SP sp;
|
||||||
private final UploadQueueInterface uploadQueue;
|
private final UploadQueueInterface uploadQueue;
|
||||||
private final RunningConfiguration runningConfiguration;
|
private final RunningConfiguration runningConfiguration;
|
||||||
private final ProfileFunction profileFunction;
|
|
||||||
|
|
||||||
public static String ISVALID = "isValid";
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public NSUpload(
|
public NSUpload(
|
||||||
AAPSLogger aapsLogger,
|
AAPSLogger aapsLogger,
|
||||||
ResourceHelper resourceHelper,
|
|
||||||
SP sp,
|
SP sp,
|
||||||
UploadQueueInterface uploadQueue,
|
UploadQueueInterface uploadQueue,
|
||||||
RunningConfiguration runningConfiguration,
|
RunningConfiguration runningConfiguration
|
||||||
ProfileFunction profileFunction
|
|
||||||
) {
|
) {
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
this.resourceHelper = resourceHelper;
|
|
||||||
this.sp = sp;
|
this.sp = sp;
|
||||||
this.uploadQueue = uploadQueue;
|
this.uploadQueue = uploadQueue;
|
||||||
this.runningConfiguration = runningConfiguration;
|
this.runningConfiguration = runningConfiguration;
|
||||||
this.profileFunction = profileFunction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uploadTempBasalStartAbsolute(TemporaryBasal temporaryBasal, Double originalExtendedAmount) {
|
public void uploadTempBasalStartAbsolute(TemporaryBasal temporaryBasal, Double originalExtendedAmount) {
|
||||||
|
@ -281,79 +267,12 @@ public class NSUpload {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uploadCarbsRecord(@NonNull Carbs carbs, @NonNull TherapyEvent therapyEvent) {
|
|
||||||
try {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
data.put("eventType", therapyEvent.getType().getText());
|
|
||||||
data.put("carbs", carbs.getAmount());
|
|
||||||
data.put("created_at", DateUtil.toISOString(carbs.getTimestamp()));
|
|
||||||
data.put("date", carbs.getTimestamp());
|
|
||||||
if (carbs.getDuration() != 0)
|
|
||||||
data.put("duration", carbs.getDuration());
|
|
||||||
if (carbs.getInterfaceIDs().getPumpId() != null)
|
|
||||||
data.put("pumpId", carbs.getInterfaceIDs().getPumpId());
|
|
||||||
if (therapyEvent.getGlucose() != null)
|
|
||||||
data.put("glucose", therapyEvent.getGlucose());
|
|
||||||
if (therapyEvent.getGlucoseType() != null)
|
|
||||||
data.put("glucoseType", therapyEvent.getGlucoseType().getText());
|
|
||||||
if (therapyEvent.getNote() != null)
|
|
||||||
data.put("notes", therapyEvent.getNote());
|
|
||||||
uploadCareportalEntryToNS(data, carbs.getTimestamp());
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void uploadBolusRecord(@NonNull Bolus bolus, @NonNull TherapyEvent therapyEvent, @Nullable BolusCalculatorResult bolusCalculatorResult) {
|
|
||||||
try {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
data.put("eventType", therapyEvent.getType().getText());
|
|
||||||
data.put("insulin", bolus.getAmount());
|
|
||||||
data.put("created_at", DateUtil.toISOString(bolus.getTimestamp()));
|
|
||||||
data.put("date", bolus.getTimestamp());
|
|
||||||
data.put("isSMB", bolus.getType() == Bolus.Type.SMB);
|
|
||||||
if (bolus.getInterfaceIDs().getPumpId() != null)
|
|
||||||
data.put("pumpId", bolus.getInterfaceIDs().getPumpId());
|
|
||||||
if (therapyEvent.getGlucose() != null)
|
|
||||||
data.put("glucose", therapyEvent.getGlucose());
|
|
||||||
if (therapyEvent.getGlucoseType() != null)
|
|
||||||
data.put("glucoseType", therapyEvent.getGlucoseType().getText());
|
|
||||||
if (bolusCalculatorResult != null)
|
|
||||||
data.put("bolusCalculatorResult", new Gson().toJson(bolusCalculatorResult));
|
|
||||||
if (therapyEvent.getNote() != null)
|
|
||||||
data.put("notes", therapyEvent.getNote());
|
|
||||||
uploadCareportalEntryToNS(data, bolus.getTimestamp());
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void uploadBolusCalc(@NonNull DetailedBolusInfo detailedBolusInfo) {
|
|
||||||
try {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
data.put("eventType", detailedBolusInfo.getEventType().toDBbEventType().getText());
|
|
||||||
data.put("created_at", DateUtil.toISOString(detailedBolusInfo.timestamp));
|
|
||||||
data.put("date", detailedBolusInfo.timestamp);
|
|
||||||
if (detailedBolusInfo.getMgdlGlucose() != null) {
|
|
||||||
data.put("glucose", detailedBolusInfo.getMgdlGlucose());
|
|
||||||
data.put("units", Constants.MGDL);
|
|
||||||
}
|
|
||||||
if (detailedBolusInfo.getGlucoseType() != null)
|
|
||||||
data.put("glucoseType", detailedBolusInfo.getGlucoseType().getText());
|
|
||||||
if (detailedBolusInfo.getBolusCalculatorResult() != null)
|
|
||||||
data.put("bolusCalculatorResult", new Gson().toJson(detailedBolusInfo.getBolusCalculatorResult()));
|
|
||||||
if (detailedBolusInfo.getNotes() != null)
|
|
||||||
data.put("notes", detailedBolusInfo.getNotes());
|
|
||||||
uploadCareportalEntryToNS(data, detailedBolusInfo.timestamp);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void uploadProfileSwitch(ProfileSwitch profileSwitch, long nsClientId) {
|
public void uploadProfileSwitch(ProfileSwitch profileSwitch, long nsClientId) {
|
||||||
try {
|
try {
|
||||||
JSONObject data = getJson(profileSwitch);
|
JSONObject data = getJson(profileSwitch);
|
||||||
uploadCareportalEntryToNS(data, nsClientId);
|
DbRequest dbr = new DbRequest("dbAdd", "treatments", data, nsClientId);
|
||||||
|
aapsLogger.debug("Prepared: " + dbr.log());
|
||||||
|
uploadQueue.add(dbr);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
aapsLogger.error("Unhandled exception", e);
|
aapsLogger.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
@ -388,133 +307,17 @@ public class NSUpload {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uploadCareportalEntryToNS(JSONObject data, long nsClientId) {
|
// TODO replace with setting isValid = false
|
||||||
try {
|
|
||||||
if (data.has("preBolus") && data.has("carbs")) {
|
|
||||||
JSONObject prebolus = new JSONObject();
|
|
||||||
prebolus.put("carbs", data.get("carbs"));
|
|
||||||
data.remove("carbs");
|
|
||||||
prebolus.put("eventType", data.get("eventType"));
|
|
||||||
if (data.has("enteredBy")) prebolus.put("enteredBy", data.get("enteredBy"));
|
|
||||||
if (data.has("notes")) prebolus.put("notes", data.get("notes"));
|
|
||||||
long mills = DateUtil.fromISODateString(data.getString("created_at")).getTime();
|
|
||||||
Date preBolusDate = new Date(mills + data.getInt("preBolus") * 60000L + 1000L);
|
|
||||||
prebolus.put("created_at", DateUtil.toISOString(preBolusDate));
|
|
||||||
uploadCareportalEntryToNS(prebolus, preBolusDate.getTime());
|
|
||||||
}
|
|
||||||
DbRequest dbr = new DbRequest("dbAdd", "treatments", data, nsClientId);
|
|
||||||
aapsLogger.debug("Prepared: " + dbr.log());
|
|
||||||
uploadQueue.add(dbr);
|
|
||||||
} catch (Exception e) {
|
|
||||||
aapsLogger.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO replace with seting isValid = false
|
|
||||||
public void removeCareportalEntryFromNS(String _id) {
|
public void removeCareportalEntryFromNS(String _id) {
|
||||||
uploadQueue.add(new DbRequest("dbRemove", "treatments", _id, System.currentTimeMillis()));
|
uploadQueue.add(new DbRequest("dbRemove", "treatments", _id, System.currentTimeMillis()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uploadError(String error) {
|
|
||||||
uploadError(error, new Date());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void uploadError(String error, Date date) {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
try {
|
|
||||||
data.put("eventType", "Announcement");
|
|
||||||
data.put("created_at", DateUtil.toISOString(date));
|
|
||||||
data.put("enteredBy", sp.getString("careportal_enteredby", "AndroidAPS"));
|
|
||||||
data.put("notes", error);
|
|
||||||
data.put("isAnnouncement", true);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
aapsLogger.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
uploadQueue.add(new DbRequest("dbAdd", "treatments", data, date.getTime()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void uploadAppStart() {
|
|
||||||
if (sp.getBoolean(R.string.key_ns_logappstartedevent, true)) {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
try {
|
|
||||||
data.put("eventType", "Note");
|
|
||||||
data.put("created_at", DateUtil.toISOString(new Date()));
|
|
||||||
data.put("notes", resourceHelper.gs(R.string.androidaps_start) + " - " + Build.MANUFACTURER + " " + Build.MODEL);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
aapsLogger.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
uploadQueue.add(new DbRequest("dbAdd", "treatments", data, System.currentTimeMillis()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void uploadProfileStore(JSONObject profileStore) {
|
public void uploadProfileStore(JSONObject profileStore) {
|
||||||
if (sp.getBoolean(R.string.key_ns_uploadlocalprofile, false)) {
|
if (sp.getBoolean(R.string.key_ns_uploadlocalprofile, false)) {
|
||||||
uploadQueue.add(new DbRequest("dbAdd", "profile", profileStore, System.currentTimeMillis()));
|
uploadQueue.add(new DbRequest("dbAdd", "profile", profileStore, System.currentTimeMillis()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uploadEvent(String careportalEvent, long time, @Nullable String notes) {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
try {
|
|
||||||
data.put("eventType", careportalEvent);
|
|
||||||
data.put("created_at", DateUtil.toISOString(time));
|
|
||||||
data.put("enteredBy", sp.getString("careportal_enteredby", "AndroidAPS"));
|
|
||||||
data.put("units", profileFunction.getUnits());
|
|
||||||
if (notes != null) {
|
|
||||||
data.put("notes", notes);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
aapsLogger.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
uploadQueue.add(new DbRequest("dbAdd", "treatments", data, time));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void uploadEvent(TherapyEvent event) {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
try {
|
|
||||||
data.put("eventType", event.getType().getText());
|
|
||||||
data.put("created_at", event.getTimestamp());
|
|
||||||
data.put("enteredBy", event.getEnteredBy());
|
|
||||||
if (event.getGlucoseUnit() == TherapyEvent.GlucoseUnit.MGDL)
|
|
||||||
data.put("units", Constants.MGDL);
|
|
||||||
else data.put("units", Constants.MMOL);
|
|
||||||
if (event.getDuration() != 0) data.put("duration", T.msecs(event.getDuration()).mins());
|
|
||||||
if (event.getNote() != null) data.put("notes", event.getNote());
|
|
||||||
if (event.getGlucose() != null) data.put("glucose", event.getGlucose());
|
|
||||||
if (event.getGlucoseType() != null)
|
|
||||||
data.put("glucoseType", event.getGlucoseType().getText());
|
|
||||||
} catch (JSONException e) {
|
|
||||||
aapsLogger.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
uploadQueue.add(new DbRequest("dbAdd", "treatments", data, event.getTimestamp()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeFoodFromNS(String _id) {
|
|
||||||
try {
|
|
||||||
uploadQueue.add(new DbRequest("dbRemove", "food", _id, System.currentTimeMillis()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
aapsLogger.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createNSTreatment(JSONObject data, ProfileStore profileStore, ProfileFunction profileFunction, long eventTime) {
|
|
||||||
if (JsonHelper.safeGetString(data, "eventType", "").equals(TherapyEvent.Type.PROFILE_SWITCH.getText())) {
|
|
||||||
ProfileSwitch profileSwitch = profileFunction.prepareProfileSwitch(
|
|
||||||
profileStore,
|
|
||||||
JsonHelper.safeGetString(data, "profile"),
|
|
||||||
JsonHelper.safeGetInt(data, "duration"),
|
|
||||||
JsonHelper.safeGetInt(data, "percentage"),
|
|
||||||
JsonHelper.safeGetInt(data, "timeshift"),
|
|
||||||
eventTime
|
|
||||||
);
|
|
||||||
uploadProfileSwitch(profileSwitch, eventTime);
|
|
||||||
} else {
|
|
||||||
uploadCareportalEntryToNS(data, eventTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isIdValid(String _id) {
|
public static boolean isIdValid(String _id) {
|
||||||
if (_id == null)
|
if (_id == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package info.nightscout.androidaps.utils.extensions
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import info.nightscout.androidaps.Constants
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||||
|
import info.nightscout.androidaps.database.entities.BolusCalculatorResult
|
||||||
|
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
import org.json.JSONException
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
fun BolusCalculatorResult.toJson(): JSONObject =
|
||||||
|
JSONObject()
|
||||||
|
.put("eventType", TherapyEvent.Type.BOLUS_WIZARD)
|
||||||
|
.put("created_at", DateUtil.toISOString(timestamp))
|
||||||
|
.put("bolusCalculatorResult", Gson().toJson(this))
|
||||||
|
.put("date", timestamp).also {
|
||||||
|
if (glucoseValue != null) {
|
||||||
|
it.put("glucose", glucoseValue)
|
||||||
|
it.put("units", Constants.MGDL)
|
||||||
|
}
|
||||||
|
if (note != null) it.put("notes", note)
|
||||||
|
if (interfaceIDs.nightscoutId != null) it.put("_id", interfaceIDs.nightscoutId)
|
||||||
|
}
|
|
@ -1,12 +1,31 @@
|
||||||
package info.nightscout.androidaps.utils.extensions
|
package info.nightscout.androidaps.utils.extensions
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import info.nightscout.androidaps.Constants
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||||
import info.nightscout.androidaps.data.Iob
|
import info.nightscout.androidaps.data.Iob
|
||||||
import info.nightscout.androidaps.database.entities.Bolus
|
import info.nightscout.androidaps.database.entities.Bolus
|
||||||
|
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface
|
import info.nightscout.androidaps.interfaces.InsulinInterface
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
import org.json.JSONException
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
fun Bolus.iobCalc(activePlugin: ActivePluginProvider, time: Long, dia: Double): Iob {
|
fun Bolus.iobCalc(activePlugin: ActivePluginProvider, time: Long, dia: Double): Iob {
|
||||||
if (!isValid) return Iob()
|
if (!isValid) return Iob()
|
||||||
val insulinInterface: InsulinInterface = activePlugin.activeInsulin
|
val insulinInterface: InsulinInterface = activePlugin.activeInsulin
|
||||||
return insulinInterface.iobCalcForTreatment(this, time, dia)
|
return insulinInterface.iobCalcForTreatment(this, time, dia)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Bolus.toJson(): JSONObject =
|
||||||
|
JSONObject()
|
||||||
|
.put("eventType", if (type == Bolus.Type.SMB) TherapyEvent.Type.CORRECTION_BOLUS else TherapyEvent.Type.MEAL_BOLUS)
|
||||||
|
.put("insulin", amount)
|
||||||
|
.put("created_at", DateUtil.toISOString(timestamp))
|
||||||
|
.put("date", timestamp)
|
||||||
|
.put("isSMB", type == Bolus.Type.SMB).also {
|
||||||
|
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
|
||||||
|
if (interfaceIDs.nightscoutId != null) it.put("_id", interfaceIDs.nightscoutId)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package info.nightscout.androidaps.utils.extensions
|
package info.nightscout.androidaps.utils.extensions
|
||||||
|
|
||||||
import info.nightscout.androidaps.database.entities.Carbs
|
import info.nightscout.androidaps.database.entities.Carbs
|
||||||
|
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
|
import org.json.JSONObject
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
fun Carbs.expandCarbs(): List<Carbs> =
|
fun Carbs.expandCarbs(): List<Carbs> =
|
||||||
|
@ -24,3 +27,14 @@ fun Carbs.expandCarbs(): List<Carbs> =
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Carbs.toJson(): JSONObject =
|
||||||
|
JSONObject()
|
||||||
|
.put("eventType", if (amount < 12) TherapyEvent.Type.CARBS_CORRECTION else TherapyEvent.Type.MEAL_BOLUS)
|
||||||
|
.put("carbs", amount)
|
||||||
|
.put("created_at", DateUtil.toISOString(timestamp))
|
||||||
|
.put("date", timestamp).also {
|
||||||
|
if (duration != 0L) it.put("duration", duration)
|
||||||
|
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
|
||||||
|
if (interfaceIDs.nightscoutId != null) it.put("_id", interfaceIDs.nightscoutId)
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package info.nightscout.androidaps.utils.extensions
|
package info.nightscout.androidaps.utils.extensions
|
||||||
|
|
||||||
import info.nightscout.androidaps.database.entities.Food
|
import info.nightscout.androidaps.database.entities.Food
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.utils.JsonHelper
|
import info.nightscout.androidaps.utils.JsonHelper
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
@ -18,7 +17,7 @@ fun foodFromJson(jsonObject: JSONObject): Food? {
|
||||||
val protein = JsonHelper.safeGetIntAllowNull(jsonObject, "protein")
|
val protein = JsonHelper.safeGetIntAllowNull(jsonObject, "protein")
|
||||||
val fat = JsonHelper.safeGetIntAllowNull(jsonObject, "fat")
|
val fat = JsonHelper.safeGetIntAllowNull(jsonObject, "fat")
|
||||||
val id = JsonHelper.safeGetStringAllowNull(jsonObject, "_id", null) ?: return null
|
val id = JsonHelper.safeGetStringAllowNull(jsonObject, "_id", null) ?: return null
|
||||||
val isValid = JsonHelper.safeGetBoolean(jsonObject, NSUpload.ISVALID, true)
|
val isValid = JsonHelper.safeGetBoolean(jsonObject, "isValid", true)
|
||||||
|
|
||||||
val food = Food(
|
val food = Food(
|
||||||
name = name,
|
name = name,
|
||||||
|
@ -38,3 +37,22 @@ fun foodFromJson(jsonObject: JSONObject): Food? {
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Food.toJson(units: String): JSONObject =
|
||||||
|
JSONObject()
|
||||||
|
.put("type", "food")
|
||||||
|
.put("name", name)
|
||||||
|
.put("category", category)
|
||||||
|
.put("subcategory", subCategory)
|
||||||
|
.put("unit", unit)
|
||||||
|
.put("portion", portion)
|
||||||
|
.put("carbs", carbs)
|
||||||
|
.put("gi", gi)
|
||||||
|
.put("energy", energy)
|
||||||
|
.put("protein", protein)
|
||||||
|
.put("fat", fat)
|
||||||
|
.put("isValid", isValid).also {
|
||||||
|
if (interfaceIDs.nightscoutId != null) it
|
||||||
|
.put("_id", interfaceIDs.nightscoutId)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,13 @@ import info.nightscout.androidaps.database.entities.GlucoseValue
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
fun GlucoseValue.toJson() : JSONObject =
|
fun GlucoseValue.toJson(): JSONObject =
|
||||||
JSONObject()
|
JSONObject()
|
||||||
.put("device", sourceSensor.text)
|
.put("device", sourceSensor.text)
|
||||||
.put("date", timestamp)
|
.put("date", timestamp)
|
||||||
.put("dateString", DateUtil.toISOString(timestamp))
|
.put("dateString", DateUtil.toISOString(timestamp))
|
||||||
.put("sgv", value)
|
.put("sgv", value)
|
||||||
.put("direction", trendArrow.text)
|
.put("direction", trendArrow.text)
|
||||||
.put("type", "sgv")
|
.put("type", "sgv").also {
|
||||||
.put("NSCLIENT_ID", System.currentTimeMillis()) // Fake to be accepted by WS
|
if (interfaceIDs.nightscoutId != null) it.put("_id", interfaceIDs.nightscoutId)
|
||||||
|
}
|
||||||
|
|
|
@ -103,4 +103,5 @@ fun TemporaryTarget.toJson(units: String): JSONObject =
|
||||||
.put("targetBottom", Profile.fromMgdlToUnits(lowTarget, units))
|
.put("targetBottom", Profile.fromMgdlToUnits(lowTarget, units))
|
||||||
.put("targetTop", Profile.fromMgdlToUnits(highTarget, units))
|
.put("targetTop", Profile.fromMgdlToUnits(highTarget, units))
|
||||||
.put("units", units)
|
.put("units", units)
|
||||||
|
if (interfaceIDs.nightscoutId != null) it.put("_id", interfaceIDs.nightscoutId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package info.nightscout.androidaps.utils.extensions
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.core.R
|
import info.nightscout.androidaps.core.R
|
||||||
import info.nightscout.androidaps.database.entities.TherapyEvent
|
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg
|
import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.JsonHelper
|
import info.nightscout.androidaps.utils.JsonHelper
|
||||||
|
@ -57,7 +56,7 @@ fun therapyEventFromNsIdForInvalidating(nsId: String): TherapyEvent =
|
||||||
JSONObject()
|
JSONObject()
|
||||||
.put("mills", 1)
|
.put("mills", 1)
|
||||||
.put("_id", nsId)
|
.put("_id", nsId)
|
||||||
.put(NSUpload.ISVALID, false)
|
.put("isValid", false)
|
||||||
)!!
|
)!!
|
||||||
|
|
||||||
fun therapyEventFromJson(jsonObject: JSONObject): TherapyEvent? {
|
fun therapyEventFromJson(jsonObject: JSONObject): TherapyEvent? {
|
||||||
|
@ -70,7 +69,7 @@ fun therapyEventFromJson(jsonObject: JSONObject): TherapyEvent? {
|
||||||
val enteredBy = JsonHelper.safeGetStringAllowNull(jsonObject, "enteredBy", null)
|
val enteredBy = JsonHelper.safeGetStringAllowNull(jsonObject, "enteredBy", null)
|
||||||
val note = JsonHelper.safeGetStringAllowNull(jsonObject, "notes", null)
|
val note = JsonHelper.safeGetStringAllowNull(jsonObject, "notes", null)
|
||||||
val id = JsonHelper.safeGetStringAllowNull(jsonObject, "_id", null) ?: return null
|
val id = JsonHelper.safeGetStringAllowNull(jsonObject, "_id", null) ?: return null
|
||||||
val isValid = JsonHelper.safeGetBoolean(jsonObject, NSUpload.ISVALID, true)
|
val isValid = JsonHelper.safeGetBoolean(jsonObject, "isValid", true)
|
||||||
|
|
||||||
val te = TherapyEvent(
|
val te = TherapyEvent(
|
||||||
timestamp = timestamp,
|
timestamp = timestamp,
|
||||||
|
@ -87,6 +86,21 @@ fun therapyEventFromJson(jsonObject: JSONObject): TherapyEvent? {
|
||||||
return te
|
return te
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun TherapyEvent.toJson(): JSONObject =
|
||||||
|
JSONObject()
|
||||||
|
.put("eventType", type.text)
|
||||||
|
.put("created_at", timestamp)
|
||||||
|
.put("enteredBy", enteredBy)
|
||||||
|
.put("units", if (glucoseUnit == TherapyEvent.GlucoseUnit.MGDL) Constants.MGDL else Constants.MMOL)
|
||||||
|
.also {
|
||||||
|
if (duration != 0L) it.put("duration", T.msecs(duration).mins())
|
||||||
|
if (note != null) it.put("notes", note)
|
||||||
|
if (glucose != null) it.put("glucose", glucose)
|
||||||
|
if (glucoseType != null) it.put("glucoseType", glucoseType!!.text)
|
||||||
|
if (interfaceIDs.nightscoutId != null) it.put("_id", interfaceIDs.nightscoutId)
|
||||||
|
if (type == TherapyEvent.Type.ANNOUNCEMENT) it.put("isAnnouncement", true)
|
||||||
|
}
|
||||||
|
|
||||||
fun isEvent5minBack(list: List<TherapyEvent>, time: Long): Boolean {
|
fun isEvent5minBack(list: List<TherapyEvent>, time: Long): Boolean {
|
||||||
for (i in list.indices) {
|
for (i in list.indices) {
|
||||||
val event = list[i]
|
val event = list[i]
|
||||||
|
|
|
@ -38,6 +38,8 @@ import info.nightscout.androidaps.danar.comm.MsgStatusTempBasal;
|
||||||
import info.nightscout.androidaps.danar.services.AbstractDanaRExecutionService;
|
import info.nightscout.androidaps.danar.services.AbstractDanaRExecutionService;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.database.AppRepository;
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.dialogs.BolusProgressDialog;
|
import info.nightscout.androidaps.dialogs.BolusProgressDialog;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
|
@ -50,13 +52,13 @@ import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.queue.commands.Command;
|
import info.nightscout.androidaps.queue.commands.Command;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.T;
|
import info.nightscout.androidaps.utils.T;
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
||||||
@Inject AAPSLogger aapsLogger;
|
@Inject AAPSLogger aapsLogger;
|
||||||
|
@ -70,8 +72,9 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
||||||
@Inject MessageHashTableRKorean messageHashTableRKorean;
|
@Inject MessageHashTableRKorean messageHashTableRKorean;
|
||||||
@Inject ActivePluginProvider activePlugin;
|
@Inject ActivePluginProvider activePlugin;
|
||||||
@Inject ProfileFunction profileFunction;
|
@Inject ProfileFunction profileFunction;
|
||||||
@Inject NSUpload nsUpload;
|
@Inject AppRepository repository;
|
||||||
@Inject DateUtil dateUtil;
|
|
||||||
|
private final CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
public DanaRKoreanExecutionService() {
|
public DanaRKoreanExecutionService() {
|
||||||
}
|
}
|
||||||
|
@ -199,7 +202,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
||||||
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
|
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
|
||||||
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT);
|
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT);
|
||||||
rxBus.send(new EventNewNotification(reportFail));
|
rxBus.send(new EventNewNotification(reportFail));
|
||||||
nsUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaPump.getDailyTotalUnits() + "/" + danaPump.getMaxDailyTotalUnits() + "U");
|
disposable.add(repository.runTransaction(new InsertTherapyEventAnnouncementTransaction(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaPump.getDailyTotalUnits() + "/" + danaPump.getMaxDailyTotalUnits() + "U")).subscribe());
|
||||||
lastApproachingDailyLimit = System.currentTimeMillis();
|
lastApproachingDailyLimit = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,8 @@ import info.nightscout.androidaps.danar.comm.MsgStatusBasic;
|
||||||
import info.nightscout.androidaps.danar.services.AbstractDanaRExecutionService;
|
import info.nightscout.androidaps.danar.services.AbstractDanaRExecutionService;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.database.AppRepository;
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.dialogs.BolusProgressDialog;
|
import info.nightscout.androidaps.dialogs.BolusProgressDialog;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
|
@ -66,7 +68,6 @@ import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||||
|
@ -77,6 +78,7 @@ import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.T;
|
import info.nightscout.androidaps.utils.T;
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
||||||
@Inject HasAndroidInjector injector;
|
@Inject HasAndroidInjector injector;
|
||||||
|
@ -96,11 +98,12 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
||||||
@Inject DetailedBolusInfoStorage detailedBolusInfoStorage;
|
@Inject DetailedBolusInfoStorage detailedBolusInfoStorage;
|
||||||
@Inject ActivePluginProvider activePluginProvider;
|
@Inject ActivePluginProvider activePluginProvider;
|
||||||
@Inject ProfileFunction profileFunction;
|
@Inject ProfileFunction profileFunction;
|
||||||
@Inject NSUpload nsUpload;
|
@Inject AppRepository repository;
|
||||||
@Inject SP sp;
|
@Inject SP sp;
|
||||||
@Inject DateUtil dateUtil;
|
@Inject DateUtil dateUtil;
|
||||||
|
|
||||||
private long lastHistoryFetched = 0;
|
private long lastHistoryFetched = 0;
|
||||||
|
private final CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
public DanaRv2ExecutionService() {
|
public DanaRv2ExecutionService() {
|
||||||
}
|
}
|
||||||
|
@ -248,7 +251,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
||||||
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
|
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
|
||||||
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT);
|
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT);
|
||||||
rxBus.send(new EventNewNotification(reportFail));
|
rxBus.send(new EventNewNotification(reportFail));
|
||||||
nsUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaPump.getDailyTotalUnits() + "/" + danaPump.getMaxDailyTotalUnits() + "U");
|
disposable.add(repository.runTransaction(new InsertTherapyEventAnnouncementTransaction(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaPump.getDailyTotalUnits() + "/" + danaPump.getMaxDailyTotalUnits() + "U")).subscribe());
|
||||||
lastApproachingDailyLimit = System.currentTimeMillis();
|
lastApproachingDailyLimit = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import info.nightscout.androidaps.dana.DanaPump;
|
||||||
import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.androidaps.danaRv2.DanaRv2Plugin;
|
import info.nightscout.androidaps.danaRv2.DanaRv2Plugin;
|
||||||
import info.nightscout.androidaps.danar.DanaRPlugin;
|
import info.nightscout.androidaps.danar.DanaRPlugin;
|
||||||
|
import info.nightscout.androidaps.database.AppRepository;
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
|
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
|
||||||
import info.nightscout.androidaps.interfaces.ConfigBuilderInterface;
|
import info.nightscout.androidaps.interfaces.ConfigBuilderInterface;
|
||||||
|
@ -30,6 +31,7 @@ import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInf
|
||||||
import info.nightscout.androidaps.utils.CRC;
|
import info.nightscout.androidaps.utils.CRC;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 00 01 02 03 04 05 06
|
* 00 01 02 03 04 05 06
|
||||||
|
@ -51,10 +53,12 @@ public class MessageBase {
|
||||||
@Inject public CommandQueueProvider commandQueue;
|
@Inject public CommandQueueProvider commandQueue;
|
||||||
@Inject public DetailedBolusInfoStorage detailedBolusInfoStorage;
|
@Inject public DetailedBolusInfoStorage detailedBolusInfoStorage;
|
||||||
@Inject public ConstraintChecker constraintChecker;
|
@Inject public ConstraintChecker constraintChecker;
|
||||||
@Inject public NSUpload nsUpload;
|
@Inject public AppRepository repository;
|
||||||
@Inject public DatabaseHelperInterface databaseHelper;
|
@Inject public DatabaseHelperInterface databaseHelper;
|
||||||
HasAndroidInjector injector;
|
HasAndroidInjector injector;
|
||||||
|
|
||||||
|
final CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
public byte[] buffer = new byte[512];
|
public byte[] buffer = new byte[512];
|
||||||
private int position = 6;
|
private int position = 6;
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,10 @@ package info.nightscout.androidaps.danar.comm
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.danar.R
|
import info.nightscout.androidaps.danar.R
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress
|
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress
|
||||||
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
|
|
||||||
class MsgError(
|
class MsgError(
|
||||||
injector: HasAndroidInjector
|
injector: HasAndroidInjector
|
||||||
|
@ -34,6 +36,6 @@ class MsgError(
|
||||||
failed = false
|
failed = false
|
||||||
}
|
}
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Error detected: $errorString")
|
aapsLogger.debug(LTag.PUMPCOMM, "Error detected: $errorString")
|
||||||
nsUpload.uploadError(errorString)
|
disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(errorString)).subscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -45,6 +45,8 @@ import info.nightscout.androidaps.danar.comm.MsgStatusBolusExtended;
|
||||||
import info.nightscout.androidaps.danar.comm.MsgStatusTempBasal;
|
import info.nightscout.androidaps.danar.comm.MsgStatusTempBasal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.database.AppRepository;
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.dialogs.BolusProgressDialog;
|
import info.nightscout.androidaps.dialogs.BolusProgressDialog;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
|
@ -57,7 +59,6 @@ import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||||
|
@ -66,6 +67,7 @@ import info.nightscout.androidaps.queue.commands.Command;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
||||||
@Inject AAPSLogger aapsLogger;
|
@Inject AAPSLogger aapsLogger;
|
||||||
|
@ -79,10 +81,12 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
||||||
@Inject MessageHashTableR messageHashTableR;
|
@Inject MessageHashTableR messageHashTableR;
|
||||||
@Inject ActivePluginProvider activePlugin;
|
@Inject ActivePluginProvider activePlugin;
|
||||||
@Inject ProfileFunction profileFunction;
|
@Inject ProfileFunction profileFunction;
|
||||||
@Inject NSUpload nsUpload;
|
@Inject AppRepository repository;
|
||||||
@Inject SP sp;
|
@Inject SP sp;
|
||||||
@Inject HasAndroidInjector injector;
|
@Inject HasAndroidInjector injector;
|
||||||
|
|
||||||
|
private final CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
public DanaRExecutionService() {
|
public DanaRExecutionService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +215,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
||||||
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
|
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
|
||||||
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT);
|
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT);
|
||||||
rxBus.send(new EventNewNotification(reportFail));
|
rxBus.send(new EventNewNotification(reportFail));
|
||||||
nsUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaPump.getDailyTotalUnits() + "/" + danaPump.getMaxDailyTotalUnits() + "U");
|
disposable.add(repository.runTransaction(new InsertTherapyEventAnnouncementTransaction(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaPump.getDailyTotalUnits() + "/" + danaPump.getMaxDailyTotalUnits() + "U")).subscribe());
|
||||||
lastApproachingDailyLimit = System.currentTimeMillis();
|
lastApproachingDailyLimit = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
|
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
@ -38,7 +37,6 @@ open class DanaRS_Packet_APS_History_Events(
|
||||||
@Inject lateinit var danaPump: DanaPump
|
@Inject lateinit var danaPump: DanaPump
|
||||||
@Inject lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
|
@Inject lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
|
||||||
@Inject lateinit var sp: SP
|
@Inject lateinit var sp: SP
|
||||||
@Inject lateinit var nsUpload: NSUpload
|
|
||||||
@Inject lateinit var repository: AppRepository
|
@Inject lateinit var repository: AppRepository
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
|
@ -188,11 +186,10 @@ open class DanaRS_Packet_APS_History_Events(
|
||||||
type = TherapyEvent.Type.INSULIN_CHANGE,
|
type = TherapyEvent.Type.INSULIN_CHANGE,
|
||||||
note = resourceHelper.gs(R.string.danarspump),
|
note = resourceHelper.gs(R.string.danarspump),
|
||||||
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL
|
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL
|
||||||
)).subscribe({ result ->
|
)).subscribe(
|
||||||
result.inserted.forEach { nsUpload.uploadEvent(it) }
|
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted therapy event $it") } },
|
||||||
}, {
|
{ aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it) }
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
)
|
||||||
})
|
|
||||||
status = "REFILL " + dateUtil.timeString(datetime)
|
status = "REFILL " + dateUtil.timeString(datetime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,11 +223,10 @@ open class DanaRS_Packet_APS_History_Events(
|
||||||
type = TherapyEvent.Type.CANNULA_CHANGE,
|
type = TherapyEvent.Type.CANNULA_CHANGE,
|
||||||
note = resourceHelper.gs(R.string.danarspump),
|
note = resourceHelper.gs(R.string.danarspump),
|
||||||
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL
|
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL
|
||||||
)).subscribe({ result ->
|
)).subscribe(
|
||||||
result.inserted.forEach { nsUpload.uploadEvent(it) }
|
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted therapy event $it") } },
|
||||||
}, {
|
{ aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it) }
|
||||||
aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it)
|
)
|
||||||
})
|
|
||||||
status = "PRIMECANNULA " + dateUtil.timeString(datetime)
|
status = "PRIMECANNULA " + dateUtil.timeString(datetime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,16 @@ package info.nightscout.androidaps.danars.comm
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.danars.R
|
import info.nightscout.androidaps.danars.R
|
||||||
|
import info.nightscout.androidaps.danars.encryption.BleEncryption
|
||||||
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||||
import info.nightscout.androidaps.danars.encryption.BleEncryption
|
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class DanaRS_Packet_Notify_Alarm(
|
class DanaRS_Packet_Notify_Alarm(
|
||||||
|
@ -17,7 +20,9 @@ class DanaRS_Packet_Notify_Alarm(
|
||||||
|
|
||||||
@Inject lateinit var rxBus: RxBusWrapper
|
@Inject lateinit var rxBus: RxBusWrapper
|
||||||
@Inject lateinit var resourceHelper: ResourceHelper
|
@Inject lateinit var resourceHelper: ResourceHelper
|
||||||
@Inject lateinit var nsUpload: NSUpload
|
@Inject lateinit var repository: AppRepository
|
||||||
|
|
||||||
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
type = BleEncryption.DANAR_PACKET__TYPE_NOTIFY
|
type = BleEncryption.DANAR_PACKET__TYPE_NOTIFY
|
||||||
|
@ -64,7 +69,7 @@ class DanaRS_Packet_Notify_Alarm(
|
||||||
}
|
}
|
||||||
val notification = Notification(Notification.USER_MESSAGE, errorString, Notification.URGENT)
|
val notification = Notification(Notification.USER_MESSAGE, errorString, Notification.URGENT)
|
||||||
rxBus.send(EventNewNotification(notification))
|
rxBus.send(EventNewNotification(notification))
|
||||||
nsUpload.uploadError(errorString)
|
disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(errorString)).subscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getFriendlyName(): String {
|
override fun getFriendlyName(): String {
|
||||||
|
|
|
@ -16,11 +16,12 @@ import info.nightscout.androidaps.danars.comm.DanaRS_Packet
|
||||||
import info.nightscout.androidaps.danars.comm.DanaRS_Packet_Etc_Keep_Connection
|
import info.nightscout.androidaps.danars.comm.DanaRS_Packet_Etc_Keep_Connection
|
||||||
import info.nightscout.androidaps.danars.encryption.BleEncryption
|
import info.nightscout.androidaps.danars.encryption.BleEncryption
|
||||||
import info.nightscout.androidaps.danars.events.EventDanaRSPairingSuccess
|
import info.nightscout.androidaps.danars.events.EventDanaRSPairingSuccess
|
||||||
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged
|
import info.nightscout.androidaps.events.EventPumpStatusChanged
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
|
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||||
|
@ -31,6 +32,8 @@ import info.nightscout.androidaps.utils.extensions.notify
|
||||||
import info.nightscout.androidaps.utils.extensions.waitMillis
|
import info.nightscout.androidaps.utils.extensions.waitMillis
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.ScheduledFuture
|
import java.util.concurrent.ScheduledFuture
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -48,7 +51,7 @@ class BLEComm @Inject internal constructor(
|
||||||
private val danaPump: DanaPump,
|
private val danaPump: DanaPump,
|
||||||
private val danaRSPlugin: DanaRSPlugin,
|
private val danaRSPlugin: DanaRSPlugin,
|
||||||
private val bleEncryption: BleEncryption,
|
private val bleEncryption: BleEncryption,
|
||||||
private val nsUpload: NSUpload
|
private val repository: AppRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -61,6 +64,8 @@ class BLEComm @Inject internal constructor(
|
||||||
private const val PACKET_END_BYTE = 0x5A.toByte()
|
private const val PACKET_END_BYTE = 0x5A.toByte()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
private var scheduledDisconnection: ScheduledFuture<*>? = null
|
private var scheduledDisconnection: ScheduledFuture<*>? = null
|
||||||
private var processedMessage: DanaRS_Packet? = null
|
private var processedMessage: DanaRS_Packet? = null
|
||||||
private val mSendQueue = ArrayList<ByteArray>()
|
private val mSendQueue = ArrayList<ByteArray>()
|
||||||
|
@ -488,7 +493,7 @@ class BLEComm @Inject internal constructor(
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (PUMP)" + " " + DanaRS_Packet.toHexString(decryptedBuffer))
|
aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK (PUMP)" + " " + DanaRS_Packet.toHexString(decryptedBuffer))
|
||||||
mSendQueue.clear()
|
mSendQueue.clear()
|
||||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.pumperror)))
|
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, resourceHelper.gs(R.string.pumperror)))
|
||||||
nsUpload.uploadError(resourceHelper.gs(R.string.pumperror))
|
disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(resourceHelper.gs(R.string.pumperror))).subscribe()
|
||||||
val n = Notification(Notification.PUMP_ERROR, resourceHelper.gs(R.string.pumperror), Notification.URGENT)
|
val n = Notification(Notification.PUMP_ERROR, resourceHelper.gs(R.string.pumperror), Notification.URGENT)
|
||||||
rxBus.send(EventNewNotification(n))
|
rxBus.send(EventNewNotification(n))
|
||||||
// response BUSY: error status
|
// response BUSY: error status
|
||||||
|
|
|
@ -18,6 +18,8 @@ import info.nightscout.androidaps.danars.R
|
||||||
import info.nightscout.androidaps.danars.comm.*
|
import info.nightscout.androidaps.danars.comm.*
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult
|
import info.nightscout.androidaps.data.PumpEnactResult
|
||||||
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction
|
||||||
import info.nightscout.androidaps.db.Treatment
|
import info.nightscout.androidaps.db.Treatment
|
||||||
import info.nightscout.androidaps.dialogs.BolusProgressDialog
|
import info.nightscout.androidaps.dialogs.BolusProgressDialog
|
||||||
import info.nightscout.androidaps.events.EventAppExit
|
import info.nightscout.androidaps.events.EventAppExit
|
||||||
|
@ -31,7 +33,6 @@ import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress
|
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||||
|
@ -45,6 +46,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import org.joda.time.DateTimeZone
|
import org.joda.time.DateTimeZone
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
@ -71,7 +73,7 @@ class DanaRSService : DaggerService() {
|
||||||
@Inject lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
|
@Inject lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
|
||||||
@Inject lateinit var bleComm: BLEComm
|
@Inject lateinit var bleComm: BLEComm
|
||||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||||
@Inject lateinit var nsUpload: NSUpload
|
@Inject lateinit var repository: AppRepository
|
||||||
@Inject lateinit var dateUtil: DateUtil
|
@Inject lateinit var dateUtil: DateUtil
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
|
@ -180,9 +182,11 @@ class DanaRSService : DaggerService() {
|
||||||
danaPump.usingUTC -> {
|
danaPump.usingUTC -> {
|
||||||
sendMessage(DanaRS_Packet_Option_Set_Pump_UTC_And_TimeZone(injector, DateUtil.now(), offset))
|
sendMessage(DanaRS_Packet_Option_Set_Pump_UTC_And_TimeZone(injector, DateUtil.now(), offset))
|
||||||
}
|
}
|
||||||
|
|
||||||
danaPump.protocol >= 6 -> { // can set seconds
|
danaPump.protocol >= 6 -> { // can set seconds
|
||||||
sendMessage(DanaRS_Packet_Option_Set_Pump_Time(injector, DateUtil.now()))
|
sendMessage(DanaRS_Packet_Option_Set_Pump_Time(injector, DateUtil.now()))
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
waitForWholeMinute() // Dana can set only whole minute
|
waitForWholeMinute() // Dana can set only whole minute
|
||||||
// add 10sec to be sure we are over minute (will be cut off anyway)
|
// add 10sec to be sure we are over minute (will be cut off anyway)
|
||||||
|
@ -204,7 +208,7 @@ class DanaRSService : DaggerService() {
|
||||||
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
|
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
|
||||||
val reportFail = Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT)
|
val reportFail = Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT)
|
||||||
rxBus.send(EventNewNotification(reportFail))
|
rxBus.send(EventNewNotification(reportFail))
|
||||||
nsUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaPump.dailyTotalUnits + "/" + danaPump.maxDailyTotalUnits + "U")
|
disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaPump.dailyTotalUnits + "/" + danaPump.maxDailyTotalUnits + "U")).subscribe()
|
||||||
lastApproachingDailyLimit = System.currentTimeMillis()
|
lastApproachingDailyLimit = System.currentTimeMillis()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ open class AppRepository @Inject internal constructor(
|
||||||
Maybe.just(nextIdElement to nextIdElement.id)
|
Maybe.just(nextIdElement to nextIdElement.id)
|
||||||
} else {
|
} else {
|
||||||
database.glucoseValueDao.getCurrentFromHistoric(nextIdElemReferenceId)
|
database.glucoseValueDao.getCurrentFromHistoric(nextIdElemReferenceId)
|
||||||
.map { it to nextIdElement.id}
|
.map { it to nextIdElement.id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ open class AppRepository @Inject internal constructor(
|
||||||
Maybe.just(nextIdElement to nextIdElement.id)
|
Maybe.just(nextIdElement to nextIdElement.id)
|
||||||
} else {
|
} else {
|
||||||
database.temporaryTargetDao.getCurrentFromHistoric(nextIdElemReferenceId)
|
database.temporaryTargetDao.getCurrentFromHistoric(nextIdElemReferenceId)
|
||||||
.map { it to nextIdElement.id}
|
.map { it to nextIdElement.id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +161,29 @@ open class AppRepository @Inject internal constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
// THERAPY EVENT
|
// THERAPY EVENT
|
||||||
|
/*
|
||||||
|
* returns a Pair of the next entity to sync and the ID of the "update".
|
||||||
|
* The update id might either be the entry id itself if it is a new entry - or the id
|
||||||
|
* of the update ("historic") entry. The sync counter should be incremented to that id if it was synced successfully.
|
||||||
|
*
|
||||||
|
* It is a Maybe as there might be no next element.
|
||||||
|
* */
|
||||||
|
fun getNextSyncElementTherapyEvent(id: Long): Maybe<Pair<TherapyEvent, Long>> =
|
||||||
|
database.therapyEventDao.getNextModifiedOrNewAfter(id)
|
||||||
|
.flatMap { nextIdElement ->
|
||||||
|
val nextIdElemReferenceId = nextIdElement.referenceId
|
||||||
|
if (nextIdElemReferenceId == null) {
|
||||||
|
Maybe.just(nextIdElement to nextIdElement.id)
|
||||||
|
} else {
|
||||||
|
database.therapyEventDao.getCurrentFromHistoric(nextIdElemReferenceId)
|
||||||
|
.map { it to nextIdElement.id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getModifiedTherapyEventDataFromId(lastId: Long): Single<List<TherapyEvent>> =
|
||||||
|
database.therapyEventDao.getModifiedFrom(lastId)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
fun getTherapyEventDataFromTime(timestamp: Long, ascending: Boolean): Single<List<TherapyEvent>> =
|
fun getTherapyEventDataFromTime(timestamp: Long, ascending: Boolean): Single<List<TherapyEvent>> =
|
||||||
database.therapyEventDao.getTherapyEventDataFromTime(timestamp)
|
database.therapyEventDao.getTherapyEventDataFromTime(timestamp)
|
||||||
.map { if (!ascending) it.reversed() else it }
|
.map { if (!ascending) it.reversed() else it }
|
||||||
|
@ -200,6 +223,29 @@ open class AppRepository @Inject internal constructor(
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
// FOOD
|
// FOOD
|
||||||
|
/*
|
||||||
|
* returns a Pair of the next entity to sync and the ID of the "update".
|
||||||
|
* The update id might either be the entry id itself if it is a new entry - or the id
|
||||||
|
* of the update ("historic") entry. The sync counter should be incremented to that id if it was synced successfully.
|
||||||
|
*
|
||||||
|
* It is a Maybe as there might be no next element.
|
||||||
|
* */
|
||||||
|
fun getNextSyncElementFood(id: Long): Maybe<Pair<Food, Long>> =
|
||||||
|
database.foodDao.getNextModifiedOrNewAfter(id)
|
||||||
|
.flatMap { nextIdElement ->
|
||||||
|
val nextIdElemReferenceId = nextIdElement.referenceId
|
||||||
|
if (nextIdElemReferenceId == null) {
|
||||||
|
Maybe.just(nextIdElement to nextIdElement.id)
|
||||||
|
} else {
|
||||||
|
database.foodDao.getCurrentFromHistoric(nextIdElemReferenceId)
|
||||||
|
.map { it to nextIdElement.id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getModifiedFoodDataFromId(lastId: Long): Single<List<Food>> =
|
||||||
|
database.foodDao.getModifiedFrom(lastId)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
fun getFoodData(): Single<List<Food>> =
|
fun getFoodData(): Single<List<Food>> =
|
||||||
database.foodDao.getFoodData()
|
database.foodDao.getFoodData()
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
@ -208,6 +254,29 @@ open class AppRepository @Inject internal constructor(
|
||||||
database.foodDao.deleteAllEntries()
|
database.foodDao.deleteAllEntries()
|
||||||
|
|
||||||
// BOLUS
|
// BOLUS
|
||||||
|
/*
|
||||||
|
* returns a Pair of the next entity to sync and the ID of the "update".
|
||||||
|
* The update id might either be the entry id itself if it is a new entry - or the id
|
||||||
|
* of the update ("historic") entry. The sync counter should be incremented to that id if it was synced successfully.
|
||||||
|
*
|
||||||
|
* It is a Maybe as there might be no next element.
|
||||||
|
* */
|
||||||
|
fun getNextSyncElementBolus(id: Long): Maybe<Pair<Bolus, Long>> =
|
||||||
|
database.bolusDao.getNextModifiedOrNewAfter(id)
|
||||||
|
.flatMap { nextIdElement ->
|
||||||
|
val nextIdElemReferenceId = nextIdElement.referenceId
|
||||||
|
if (nextIdElemReferenceId == null) {
|
||||||
|
Maybe.just(nextIdElement to nextIdElement.id)
|
||||||
|
} else {
|
||||||
|
database.bolusDao.getCurrentFromHistoric(nextIdElemReferenceId)
|
||||||
|
.map { it to nextIdElement.id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getModifiedBolusesDataFromId(lastId: Long): Single<List<Bolus>> =
|
||||||
|
database.bolusDao.getModifiedFrom(lastId)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
fun getBolusesDataFromTime(timestamp: Long, ascending: Boolean): Single<List<Bolus>> =
|
fun getBolusesDataFromTime(timestamp: Long, ascending: Boolean): Single<List<Bolus>> =
|
||||||
database.bolusDao.getBolusesFromTime(timestamp)
|
database.bolusDao.getBolusesFromTime(timestamp)
|
||||||
.map { if (!ascending) it.reversed() else it }
|
.map { if (!ascending) it.reversed() else it }
|
||||||
|
@ -222,6 +291,29 @@ open class AppRepository @Inject internal constructor(
|
||||||
database.bolusDao.deleteAllEntries()
|
database.bolusDao.deleteAllEntries()
|
||||||
|
|
||||||
// CARBS
|
// CARBS
|
||||||
|
/*
|
||||||
|
* returns a Pair of the next entity to sync and the ID of the "update".
|
||||||
|
* The update id might either be the entry id itself if it is a new entry - or the id
|
||||||
|
* of the update ("historic") entry. The sync counter should be incremented to that id if it was synced successfully.
|
||||||
|
*
|
||||||
|
* It is a Maybe as there might be no next element.
|
||||||
|
* */
|
||||||
|
fun getNextSyncElementCarbs(id: Long): Maybe<Pair<Carbs, Long>> =
|
||||||
|
database.carbsDao.getNextModifiedOrNewAfter(id)
|
||||||
|
.flatMap { nextIdElement ->
|
||||||
|
val nextIdElemReferenceId = nextIdElement.referenceId
|
||||||
|
if (nextIdElemReferenceId == null) {
|
||||||
|
Maybe.just(nextIdElement to nextIdElement.id)
|
||||||
|
} else {
|
||||||
|
database.carbsDao.getCurrentFromHistoric(nextIdElemReferenceId)
|
||||||
|
.map { it to nextIdElement.id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getModifiedCarbsDataFromId(lastId: Long): Single<List<Carbs>> =
|
||||||
|
database.carbsDao.getModifiedFrom(lastId)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
fun getCarbsDataFromTime(timestamp: Long, ascending: Boolean): Single<List<Carbs>> =
|
fun getCarbsDataFromTime(timestamp: Long, ascending: Boolean): Single<List<Carbs>> =
|
||||||
database.carbsDao.getCarbsFromTime(timestamp)
|
database.carbsDao.getCarbsFromTime(timestamp)
|
||||||
.map { if (!ascending) it.reversed() else it }
|
.map { if (!ascending) it.reversed() else it }
|
||||||
|
@ -235,7 +327,30 @@ open class AppRepository @Inject internal constructor(
|
||||||
fun deleteAllCarbs() =
|
fun deleteAllCarbs() =
|
||||||
database.carbsDao.deleteAllEntries()
|
database.carbsDao.deleteAllEntries()
|
||||||
|
|
||||||
// CARBS
|
// BOLUS CALCULATOR RESULT
|
||||||
|
/*
|
||||||
|
* returns a Pair of the next entity to sync and the ID of the "update".
|
||||||
|
* The update id might either be the entry id itself if it is a new entry - or the id
|
||||||
|
* of the update ("historic") entry. The sync counter should be incremented to that id if it was synced successfully.
|
||||||
|
*
|
||||||
|
* It is a Maybe as there might be no next element.
|
||||||
|
* */
|
||||||
|
fun getNextSyncElementBolusCalculatorResult(id: Long): Maybe<Pair<BolusCalculatorResult, Long>> =
|
||||||
|
database.bolusCalculatorResultDao.getNextModifiedOrNewAfter(id)
|
||||||
|
.flatMap { nextIdElement ->
|
||||||
|
val nextIdElemReferenceId = nextIdElement.referenceId
|
||||||
|
if (nextIdElemReferenceId == null) {
|
||||||
|
Maybe.just(nextIdElement to nextIdElement.id)
|
||||||
|
} else {
|
||||||
|
database.bolusCalculatorResultDao.getCurrentFromHistoric(nextIdElemReferenceId)
|
||||||
|
.map { it to nextIdElement.id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getModifiedBolusCalculatorResultsDataFromId(lastId: Long): Single<List<BolusCalculatorResult>> =
|
||||||
|
database.bolusCalculatorResultDao.getModifiedFrom(lastId)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
fun getBolusCalculatorResultsDataFromTime(timestamp: Long, ascending: Boolean): Single<List<BolusCalculatorResult>> =
|
fun getBolusCalculatorResultsDataFromTime(timestamp: Long, ascending: Boolean): Single<List<BolusCalculatorResult>> =
|
||||||
database.bolusCalculatorResultDao.getBolusCalculatorResultsFromTime(timestamp)
|
database.bolusCalculatorResultDao.getBolusCalculatorResultsFromTime(timestamp)
|
||||||
.map { if (!ascending) it.reversed() else it }
|
.map { if (!ascending) it.reversed() else it }
|
||||||
|
|
|
@ -4,6 +4,7 @@ import androidx.room.Dao
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import info.nightscout.androidaps.database.TABLE_BOLUS_CALCULATOR_RESULTS
|
import info.nightscout.androidaps.database.TABLE_BOLUS_CALCULATOR_RESULTS
|
||||||
import info.nightscout.androidaps.database.entities.BolusCalculatorResult
|
import info.nightscout.androidaps.database.entities.BolusCalculatorResult
|
||||||
|
import io.reactivex.Maybe
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
|
@ -22,4 +23,15 @@ internal interface BolusCalculatorResultDao : TraceableDao<BolusCalculatorResult
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
||||||
fun getBolusCalculatorResultsIncludingInvalidFromTime(timestamp: Long): Single<List<BolusCalculatorResult>>
|
fun getBolusCalculatorResultsIncludingInvalidFromTime(timestamp: Long): Single<List<BolusCalculatorResult>>
|
||||||
|
|
||||||
|
// This query will be used with v3 to get all changed records
|
||||||
|
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE id > :id) ORDER BY id ASC")
|
||||||
|
fun getModifiedFrom(id: Long): Single<List<BolusCalculatorResult>>
|
||||||
|
|
||||||
|
// for WS we need 1 record only
|
||||||
|
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE id > :id ORDER BY id ASC limit 1")
|
||||||
|
fun getNextModifiedOrNewAfter(id: Long): Maybe<BolusCalculatorResult>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE id = :referenceId")
|
||||||
|
fun getCurrentFromHistoric(referenceId: Long): Maybe<BolusCalculatorResult>
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ import androidx.room.Dao
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import info.nightscout.androidaps.database.TABLE_BOLUSES
|
import info.nightscout.androidaps.database.TABLE_BOLUSES
|
||||||
import info.nightscout.androidaps.database.entities.Bolus
|
import info.nightscout.androidaps.database.entities.Bolus
|
||||||
|
import io.reactivex.Maybe
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
|
@ -21,4 +22,15 @@ internal interface BolusDao : TraceableDao<Bolus> {
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
@Query("SELECT * FROM $TABLE_BOLUSES WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
||||||
fun getBolusesIncludingInvalidFromTime(timestamp: Long): Single<List<Bolus>>
|
fun getBolusesIncludingInvalidFromTime(timestamp: Long): Single<List<Bolus>>
|
||||||
|
|
||||||
|
// This query will be used with v3 to get all changed records
|
||||||
|
@Query("SELECT * FROM $TABLE_BOLUSES WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_BOLUSES WHERE id > :id) ORDER BY id ASC")
|
||||||
|
fun getModifiedFrom(id: Long): Single<List<Bolus>>
|
||||||
|
|
||||||
|
// for WS we need 1 record only
|
||||||
|
@Query("SELECT * FROM $TABLE_BOLUSES WHERE id > :id ORDER BY id ASC limit 1")
|
||||||
|
fun getNextModifiedOrNewAfter(id: Long): Maybe<Bolus>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM $TABLE_BOLUSES WHERE id = :referenceId")
|
||||||
|
fun getCurrentFromHistoric(referenceId: Long): Maybe<Bolus>
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ import androidx.room.Dao
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import info.nightscout.androidaps.database.TABLE_CARBS
|
import info.nightscout.androidaps.database.TABLE_CARBS
|
||||||
import info.nightscout.androidaps.database.entities.Carbs
|
import info.nightscout.androidaps.database.entities.Carbs
|
||||||
|
import io.reactivex.Maybe
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
|
@ -21,4 +22,15 @@ internal interface CarbsDao : TraceableDao<Carbs> {
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_CARBS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
@Query("SELECT * FROM $TABLE_CARBS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
||||||
fun getCarbsIncludingInvalidFromTime(timestamp: Long): Single<List<Carbs>>
|
fun getCarbsIncludingInvalidFromTime(timestamp: Long): Single<List<Carbs>>
|
||||||
|
|
||||||
|
// This query will be used with v3 to get all changed records
|
||||||
|
@Query("SELECT * FROM $TABLE_CARBS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_CARBS WHERE id > :id) ORDER BY id ASC")
|
||||||
|
fun getModifiedFrom(id: Long): Single<List<Carbs>>
|
||||||
|
|
||||||
|
// for WS we need 1 record only
|
||||||
|
@Query("SELECT * FROM $TABLE_CARBS WHERE id > :id ORDER BY id ASC limit 1")
|
||||||
|
fun getNextModifiedOrNewAfter(id: Long): Maybe<Carbs>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM $TABLE_CARBS WHERE id = :referenceId")
|
||||||
|
fun getCurrentFromHistoric(referenceId: Long): Maybe<Carbs>
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ import androidx.room.Dao
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import info.nightscout.androidaps.database.TABLE_FOODS
|
import info.nightscout.androidaps.database.TABLE_FOODS
|
||||||
import info.nightscout.androidaps.database.entities.Food
|
import info.nightscout.androidaps.database.entities.Food
|
||||||
|
import io.reactivex.Maybe
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
|
@ -22,4 +23,14 @@ internal interface FoodDao : TraceableDao<Food> {
|
||||||
@Query("SELECT * FROM $TABLE_FOODS WHERE isValid = 1 AND referenceId IS NULL ORDER BY id DESC")
|
@Query("SELECT * FROM $TABLE_FOODS WHERE isValid = 1 AND referenceId IS NULL ORDER BY id DESC")
|
||||||
fun getFoodData(): Single<List<Food>>
|
fun getFoodData(): Single<List<Food>>
|
||||||
|
|
||||||
|
// This query will be used with v3 to get all changed records
|
||||||
|
@Query("SELECT * FROM $TABLE_FOODS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_FOODS WHERE id > :id) ORDER BY id ASC")
|
||||||
|
fun getModifiedFrom(id: Long): Single<List<Food>>
|
||||||
|
|
||||||
|
// for WS we need 1 record only
|
||||||
|
@Query("SELECT * FROM $TABLE_FOODS WHERE id > :id ORDER BY id ASC limit 1")
|
||||||
|
fun getNextModifiedOrNewAfter(id: Long): Maybe<Food>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM $TABLE_FOODS WHERE id = :referenceId")
|
||||||
|
fun getCurrentFromHistoric(referenceId: Long): Maybe<Food>
|
||||||
}
|
}
|
|
@ -42,4 +42,15 @@ internal interface TherapyEventDao : TraceableDao<TherapyEvent> {
|
||||||
|
|
||||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE timestamp >= :from AND timestamp <= :to AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE timestamp >= :from AND timestamp <= :to AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||||
fun compatGetTherapyEventDataFromToTime(from: Long, to: Long): Single<List<TherapyEvent>>
|
fun compatGetTherapyEventDataFromToTime(from: Long, to: Long): Single<List<TherapyEvent>>
|
||||||
|
|
||||||
|
// This query will be used with v3 to get all changed records
|
||||||
|
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_THERAPY_EVENTS WHERE id > :id) ORDER BY id ASC")
|
||||||
|
fun getModifiedFrom(id: Long): Single<List<TherapyEvent>>
|
||||||
|
|
||||||
|
// for WS we need 1 record only
|
||||||
|
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE id > :id ORDER BY id ASC limit 1")
|
||||||
|
fun getNextModifiedOrNewAfter(id: Long): Maybe<TherapyEvent>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE id = :referenceId")
|
||||||
|
fun getCurrentFromHistoric(referenceId: Long): Maybe<TherapyEvent>
|
||||||
}
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package info.nightscout.androidaps.database.transactions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||||
|
|
||||||
|
class InsertTherapyEventAnnouncementTransaction(
|
||||||
|
val therapyEvent: TherapyEvent
|
||||||
|
) : Transaction<InsertTherapyEventAnnouncementTransaction.TransactionResult>() {
|
||||||
|
|
||||||
|
constructor(error: String) :
|
||||||
|
this(TherapyEvent(timestamp = System.currentTimeMillis(), type = TherapyEvent.Type.ANNOUNCEMENT, duration = 0, note = error, enteredBy = "AndroidAPS", glucose = null, glucoseType = null, glucoseUnit = TherapyEvent.GlucoseUnit.MGDL))
|
||||||
|
|
||||||
|
override fun run(): TransactionResult {
|
||||||
|
val result = TransactionResult()
|
||||||
|
database.therapyEventDao.insertNewEntry(therapyEvent)
|
||||||
|
result.inserted.add(therapyEvent)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
class TransactionResult {
|
||||||
|
|
||||||
|
val inserted = mutableListOf<TherapyEvent>()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package info.nightscout.androidaps.database.transactions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.database.entities.BolusCalculatorResult
|
||||||
|
|
||||||
|
class UpdateNsIdBolusCalculatorResultTransaction(val bolusCalculatorResult: BolusCalculatorResult) : Transaction<Unit>() {
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
val current = database.bolusCalculatorResultDao.findById(bolusCalculatorResult.id)
|
||||||
|
if (current != null && current.interfaceIDs.nightscoutId != bolusCalculatorResult.interfaceIDs.nightscoutId)
|
||||||
|
database.bolusCalculatorResultDao.updateExistingEntry(bolusCalculatorResult)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package info.nightscout.androidaps.database.transactions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.database.entities.Bolus
|
||||||
|
|
||||||
|
class UpdateNsIdBolusTransaction(val bolus: Bolus) : Transaction<Unit>() {
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
val current = database.bolusDao.findById(bolus.id)
|
||||||
|
if (current != null && current.interfaceIDs.nightscoutId != bolus.interfaceIDs.nightscoutId)
|
||||||
|
database.bolusDao.updateExistingEntry(bolus)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package info.nightscout.androidaps.database.transactions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.database.entities.Carbs
|
||||||
|
|
||||||
|
class UpdateNsIdCarbsTransaction(val carbs: Carbs) : Transaction<Unit>() {
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
val current = database.carbsDao.findById(carbs.id)
|
||||||
|
if (current != null && current.interfaceIDs.nightscoutId != carbs.interfaceIDs.nightscoutId)
|
||||||
|
database.carbsDao.updateExistingEntry(carbs)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package info.nightscout.androidaps.database.transactions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.database.entities.Food
|
||||||
|
|
||||||
|
class UpdateNsIdFoodTransaction(val food: Food) : Transaction<Unit>() {
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
val current = database.foodDao.findById(food.id)
|
||||||
|
if (current != null && current.interfaceIDs.nightscoutId != food.interfaceIDs.nightscoutId)
|
||||||
|
database.foodDao.updateExistingEntry(food)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package info.nightscout.androidaps.database.transactions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||||
|
|
||||||
|
class UpdateNsIdTherapyEventTransaction(val therapyEvent: TherapyEvent) : Transaction<Unit>() {
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
val current = database.therapyEventDao.findById(therapyEvent.id)
|
||||||
|
if (current != null && current.interfaceIDs.nightscoutId != therapyEvent.interfaceIDs.nightscoutId)
|
||||||
|
database.therapyEventDao.updateExistingEntry(therapyEvent)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1558,7 +1558,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
if (repository.getTherapyEventByTimestamp(TherapyEvent.Type.NOTE, date) != null) return;
|
if (repository.getTherapyEventByTimestamp(TherapyEvent.Type.NOTE, date) != null) return;
|
||||||
disposable.add(repository.runTransactionForResult(new InsertTherapyEventIfNewTransaction(date, TherapyEvent.Type.NOTE, 0, note, sp.getString("careportal_enteredby", "AndroidAPS"), null, null, TherapyEvent.GlucoseUnit.MGDL))
|
disposable.add(repository.runTransactionForResult(new InsertTherapyEventIfNewTransaction(date, TherapyEvent.Type.NOTE, 0, note, sp.getString("careportal_enteredby", "AndroidAPS"), null, null, TherapyEvent.GlucoseUnit.MGDL))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
result -> result.getInserted().forEach(nsUpload::uploadEvent),
|
result -> result.getInserted().forEach(event -> aapsLogger.debug(LTag.DATABASE, "Inserted therapy event " + event)),
|
||||||
error -> aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", error)
|
error -> aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", error)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -1580,7 +1580,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
if (repository.getTherapyEventByTimestamp(event, date) != null) return;
|
if (repository.getTherapyEventByTimestamp(event, date) != null) return;
|
||||||
disposable.add(repository.runTransactionForResult(new InsertTherapyEventIfNewTransaction(date, event, 0, null, sp.getString("careportal_enteredby", "AndroidAPS"), null, null, TherapyEvent.GlucoseUnit.MGDL))
|
disposable.add(repository.runTransactionForResult(new InsertTherapyEventIfNewTransaction(date, event, 0, null, sp.getString("careportal_enteredby", "AndroidAPS"), null, null, TherapyEvent.GlucoseUnit.MGDL))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
result -> result.getInserted().forEach(nsUpload::uploadEvent),
|
result -> result.getInserted().forEach(record -> aapsLogger.debug(LTag.DATABASE, "Inserted therapy event " + record)),
|
||||||
error -> aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", error)
|
error -> aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", error)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
||||||
|
@ -77,7 +76,6 @@ public class MedtronicHistoryData {
|
||||||
private final AAPSLogger aapsLogger;
|
private final AAPSLogger aapsLogger;
|
||||||
private final SP sp;
|
private final SP sp;
|
||||||
private final ActivePluginProvider activePlugin;
|
private final ActivePluginProvider activePlugin;
|
||||||
private final NSUpload nsUpload;
|
|
||||||
private final MedtronicUtil medtronicUtil;
|
private final MedtronicUtil medtronicUtil;
|
||||||
private final MedtronicPumpHistoryDecoder medtronicPumpHistoryDecoder;
|
private final MedtronicPumpHistoryDecoder medtronicPumpHistoryDecoder;
|
||||||
private final MedtronicPumpStatus medtronicPumpStatus;
|
private final MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
@ -112,7 +110,6 @@ public class MedtronicHistoryData {
|
||||||
AAPSLogger aapsLogger,
|
AAPSLogger aapsLogger,
|
||||||
SP sp,
|
SP sp,
|
||||||
ActivePluginProvider activePlugin,
|
ActivePluginProvider activePlugin,
|
||||||
NSUpload nsUpload,
|
|
||||||
MedtronicUtil medtronicUtil,
|
MedtronicUtil medtronicUtil,
|
||||||
MedtronicPumpHistoryDecoder medtronicPumpHistoryDecoder,
|
MedtronicPumpHistoryDecoder medtronicPumpHistoryDecoder,
|
||||||
MedtronicPumpStatus medtronicPumpStatus,
|
MedtronicPumpStatus medtronicPumpStatus,
|
||||||
|
@ -125,7 +122,6 @@ public class MedtronicHistoryData {
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
this.sp = sp;
|
this.sp = sp;
|
||||||
this.activePlugin = activePlugin;
|
this.activePlugin = activePlugin;
|
||||||
this.nsUpload = nsUpload;
|
|
||||||
this.medtronicUtil = medtronicUtil;
|
this.medtronicUtil = medtronicUtil;
|
||||||
this.medtronicPumpHistoryDecoder = medtronicPumpHistoryDecoder;
|
this.medtronicPumpHistoryDecoder = medtronicPumpHistoryDecoder;
|
||||||
this.medtronicPumpStatus = medtronicPumpStatus;
|
this.medtronicPumpStatus = medtronicPumpStatus;
|
||||||
|
@ -593,7 +589,7 @@ public class MedtronicHistoryData {
|
||||||
event, 0, null, sp.getString("careportal_enteredby", "AndroidAPS"),
|
event, 0, null, sp.getString("careportal_enteredby", "AndroidAPS"),
|
||||||
null, null, TherapyEvent.GlucoseUnit.MGDL))
|
null, null, TherapyEvent.GlucoseUnit.MGDL))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
result -> result.getInserted().forEach(nsUpload::uploadEvent),
|
result -> result.getInserted().forEach(record -> aapsLogger.debug(LTag.DATABASE, "Inserted therapy event " + record)),
|
||||||
error -> aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", error)
|
error -> aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", error)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.eros;
|
package info.nightscout.androidaps.plugins.pump.omnipod.eros;
|
||||||
|
|
||||||
|
import static info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.OmnipodConstants.BASAL_STEP_DURATION;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -31,7 +33,8 @@ import info.nightscout.androidaps.activities.ErrorHelperActivity;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.database.entities.Bolus;
|
import info.nightscout.androidaps.database.AppRepository;
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
@ -52,7 +55,6 @@ import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
||||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||||
|
@ -108,8 +110,6 @@ import info.nightscout.androidaps.utils.rx.AapsSchedulers;
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
import static info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.OmnipodConstants.BASAL_STEP_DURATION;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by andy on 23.04.18.
|
* Created by andy on 23.04.18.
|
||||||
*
|
*
|
||||||
|
@ -141,8 +141,9 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
||||||
private final PumpDescription pumpDescription;
|
private final PumpDescription pumpDescription;
|
||||||
private final ServiceConnection serviceConnection;
|
private final ServiceConnection serviceConnection;
|
||||||
private final PumpType pumpType = PumpType.OMNIPOD_EROS;
|
private final PumpType pumpType = PumpType.OMNIPOD_EROS;
|
||||||
private final CompositeDisposable disposables = new CompositeDisposable();
|
private final AppRepository repository;
|
||||||
private final NSUpload nsUpload;
|
|
||||||
|
private final CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
// variables for handling statuses and history
|
// variables for handling statuses and history
|
||||||
private boolean firstRun = true;
|
private boolean firstRun = true;
|
||||||
|
@ -177,7 +178,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
||||||
RileyLinkUtil rileyLinkUtil,
|
RileyLinkUtil rileyLinkUtil,
|
||||||
OmnipodAlertUtil omnipodAlertUtil,
|
OmnipodAlertUtil omnipodAlertUtil,
|
||||||
ProfileFunction profileFunction,
|
ProfileFunction profileFunction,
|
||||||
NSUpload nsUpload
|
AppRepository repository
|
||||||
) {
|
) {
|
||||||
super(new PluginDescription() //
|
super(new PluginDescription() //
|
||||||
.mainType(PluginType.PUMP) //
|
.mainType(PluginType.PUMP) //
|
||||||
|
@ -204,7 +205,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
||||||
this.rileyLinkUtil = rileyLinkUtil;
|
this.rileyLinkUtil = rileyLinkUtil;
|
||||||
this.omnipodAlertUtil = omnipodAlertUtil;
|
this.omnipodAlertUtil = omnipodAlertUtil;
|
||||||
this.profileFunction = profileFunction;
|
this.profileFunction = profileFunction;
|
||||||
this.nsUpload = nsUpload;
|
this.repository = repository;
|
||||||
|
|
||||||
pumpDescription = new PumpDescription(pumpType);
|
pumpDescription = new PumpDescription(pumpType);
|
||||||
|
|
||||||
|
@ -283,32 +284,32 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
||||||
Intent intent = new Intent(context, RileyLinkOmnipodService.class);
|
Intent intent = new Intent(context, RileyLinkOmnipodService.class);
|
||||||
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
disposables.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventAppExit.class)
|
.toObservable(EventAppExit.class)
|
||||||
.observeOn(aapsSchedulers.getIo())
|
.observeOn(aapsSchedulers.getIo())
|
||||||
.subscribe(event -> context.unbindService(serviceConnection), fabricPrivacy::logException)
|
.subscribe(event -> context.unbindService(serviceConnection), fabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
disposables.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventOmnipodErosTbrChanged.class)
|
.toObservable(EventOmnipodErosTbrChanged.class)
|
||||||
.observeOn(aapsSchedulers.getIo())
|
.observeOn(aapsSchedulers.getIo())
|
||||||
.subscribe(event -> handleCancelledTbr(), fabricPrivacy::logException)
|
.subscribe(event -> handleCancelledTbr(), fabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
disposables.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventOmnipodErosUncertainTbrRecovered.class)
|
.toObservable(EventOmnipodErosUncertainTbrRecovered.class)
|
||||||
.observeOn(aapsSchedulers.getIo())
|
.observeOn(aapsSchedulers.getIo())
|
||||||
.subscribe(event -> handleUncertainTbrRecovery(), fabricPrivacy::logException)
|
.subscribe(event -> handleUncertainTbrRecovery(), fabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
disposables.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventOmnipodErosActiveAlertsChanged.class)
|
.toObservable(EventOmnipodErosActiveAlertsChanged.class)
|
||||||
.observeOn(aapsSchedulers.getIo())
|
.observeOn(aapsSchedulers.getIo())
|
||||||
.subscribe(event -> handleActivePodAlerts(), fabricPrivacy::logException)
|
.subscribe(event -> handleActivePodAlerts(), fabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
disposables.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventOmnipodErosFaultEventChanged.class)
|
.toObservable(EventOmnipodErosFaultEventChanged.class)
|
||||||
.observeOn(aapsSchedulers.getIo())
|
.observeOn(aapsSchedulers.getIo())
|
||||||
.subscribe(event -> handlePodFaultEvent(), fabricPrivacy::logException)
|
.subscribe(event -> handlePodFaultEvent(), fabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
disposables.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventPreferenceChange.class)
|
.toObservable(EventPreferenceChange.class)
|
||||||
.observeOn(aapsSchedulers.getIo())
|
.observeOn(aapsSchedulers.getIo())
|
||||||
.subscribe(event -> {
|
.subscribe(event -> {
|
||||||
|
@ -337,7 +338,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
||||||
}
|
}
|
||||||
}, fabricPrivacy::logException)
|
}, fabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
disposables.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventAppInitialized.class)
|
.toObservable(EventAppInitialized.class)
|
||||||
.observeOn(aapsSchedulers.getIo())
|
.observeOn(aapsSchedulers.getIo())
|
||||||
.subscribe(event -> {
|
.subscribe(event -> {
|
||||||
|
@ -407,7 +408,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
||||||
String notificationText = resourceHelper.gq(R.plurals.omnipod_common_pod_alerts, activeAlerts.size(), alerts);
|
String notificationText = resourceHelper.gq(R.plurals.omnipod_common_pod_alerts, activeAlerts.size(), alerts);
|
||||||
Notification notification = new Notification(Notification.OMNIPOD_POD_ALERTS, notificationText, Notification.URGENT);
|
Notification notification = new Notification(Notification.OMNIPOD_POD_ALERTS, notificationText, Notification.URGENT);
|
||||||
rxBus.send(new EventNewNotification(notification));
|
rxBus.send(new EventNewNotification(notification));
|
||||||
nsUpload.uploadError(notificationText);
|
disposable.add(repository.runTransaction(new InsertTherapyEventAnnouncementTransaction(notificationText)).subscribe());
|
||||||
|
|
||||||
if (aapsOmnipodErosManager.isAutomaticallyAcknowledgeAlertsEnabled() && !getCommandQueue().isCustomCommandInQueue(CommandAcknowledgeAlerts.class)) {
|
if (aapsOmnipodErosManager.isAutomaticallyAcknowledgeAlertsEnabled() && !getCommandQueue().isCustomCommandInQueue(CommandAcknowledgeAlerts.class)) {
|
||||||
queueAcknowledgeAlertsCommand();
|
queueAcknowledgeAlertsCommand();
|
||||||
|
@ -419,7 +420,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
||||||
private void handlePodFaultEvent() {
|
private void handlePodFaultEvent() {
|
||||||
if (podStateManager.isPodFaulted()) {
|
if (podStateManager.isPodFaulted()) {
|
||||||
String notificationText = resourceHelper.gs(R.string.omnipod_common_pod_status_pod_fault_description, podStateManager.getFaultEventCode().getValue(), podStateManager.getFaultEventCode().name());
|
String notificationText = resourceHelper.gs(R.string.omnipod_common_pod_status_pod_fault_description, podStateManager.getFaultEventCode().getValue(), podStateManager.getFaultEventCode().name());
|
||||||
nsUpload.uploadError(notificationText);
|
disposable.add(repository.runTransaction(new InsertTherapyEventAnnouncementTransaction(notificationText)).subscribe());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,7 +433,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
||||||
|
|
||||||
context.unbindService(serviceConnection);
|
context.unbindService(serviceConnection);
|
||||||
|
|
||||||
disposables.clear();
|
disposable.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queueAcknowledgeAlertsCommand() {
|
private void queueAcknowledgeAlertsCommand() {
|
||||||
|
|
|
@ -31,7 +31,6 @@ import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
||||||
|
@ -103,7 +102,6 @@ public class AapsOmnipodErosManager {
|
||||||
private final OmnipodManager delegate;
|
private final OmnipodManager delegate;
|
||||||
private final DatabaseHelperInterface databaseHelper;
|
private final DatabaseHelperInterface databaseHelper;
|
||||||
private final OmnipodAlertUtil omnipodAlertUtil;
|
private final OmnipodAlertUtil omnipodAlertUtil;
|
||||||
private final NSUpload nsUpload;
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final AppRepository repository;
|
private final AppRepository repository;
|
||||||
|
|
||||||
|
@ -137,7 +135,6 @@ public class AapsOmnipodErosManager {
|
||||||
ActivePluginProvider activePlugin,
|
ActivePluginProvider activePlugin,
|
||||||
DatabaseHelperInterface databaseHelper,
|
DatabaseHelperInterface databaseHelper,
|
||||||
OmnipodAlertUtil omnipodAlertUtil,
|
OmnipodAlertUtil omnipodAlertUtil,
|
||||||
NSUpload nsUpload,
|
|
||||||
Context context,
|
Context context,
|
||||||
AppRepository repository) {
|
AppRepository repository) {
|
||||||
|
|
||||||
|
@ -151,7 +148,6 @@ public class AapsOmnipodErosManager {
|
||||||
this.activePlugin = activePlugin;
|
this.activePlugin = activePlugin;
|
||||||
this.databaseHelper = databaseHelper;
|
this.databaseHelper = databaseHelper;
|
||||||
this.omnipodAlertUtil = omnipodAlertUtil;
|
this.omnipodAlertUtil = omnipodAlertUtil;
|
||||||
this.nsUpload = nsUpload;
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
|
|
||||||
|
@ -1007,7 +1003,7 @@ public class AapsOmnipodErosManager {
|
||||||
if (repository.getTherapyEventByTimestamp(event, date) != null) return;
|
if (repository.getTherapyEventByTimestamp(event, date) != null) return;
|
||||||
disposable.add(repository.runTransactionForResult(new InsertTherapyEventIfNewTransaction(date, event, 0, null, sp.getString("careportal_enteredby", "AndroidAPS"), null, null, TherapyEvent.GlucoseUnit.MGDL))
|
disposable.add(repository.runTransactionForResult(new InsertTherapyEventIfNewTransaction(date, event, 0, null, sp.getString("careportal_enteredby", "AndroidAPS"), null, null, TherapyEvent.GlucoseUnit.MGDL))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
result -> result.getInserted().forEach(nsUpload::uploadEvent),
|
result -> result.getInserted().forEach(record -> aapsLogger.debug(LTag.DATABASE, "Inserted therapy event " + record)),
|
||||||
error -> aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", error)
|
error -> aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", error)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue