diff --git a/.gitignore b/.gitignore index affd38763c..74eb164a98 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ .gradle /local.properties .DS_Store -app/jacoco.exec +*/jacoco.exec /build /captures *.apk diff --git a/app/build.gradle b/app/build.gradle index 2d81b4f539..959dd342da 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,23 +1,18 @@ -buildscript { - repositories { - maven { url "https://plugins.gradle.org/m2/" } // jacoco 0.2 - } - - dependencies { - //classpath 'com.dicedmelon.gradle:jacoco-android:0.1.4' - classpath 'com.hiya:jacoco-android:0.2' - } -} apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' apply plugin: 'com.google.gms.google-services' -//apply plugin: 'jacoco-android' apply plugin: 'com.hiya.jacoco-android' apply plugin: 'com.google.firebase.crashlytics' +apply from: "${project.rootDir}/gradle/android_dependencies.gradle" + jacoco { - toolVersion = "0.8.3" + toolVersion = "0.8.6" +} + +tasks.withType(Test) { + jacoco.includeNoLocationClasses = true } repositories { @@ -109,12 +104,9 @@ tasks.matching { it instanceof Test }.all { } android { - compileSdkVersion 28 ndkVersion "21.1.6352462" defaultConfig { - minSdkVersion 26 - targetSdkVersion 28 multiDexEnabled true versionCode 1500 version "2.8.2.1-dev-b" @@ -123,37 +115,9 @@ android { buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"' buildConfigField "String", "COMMITTED", '"' + allCommitted() + '"' - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - // if you change minSdkVersion to less than 11, you need to change executeTask for wear - ndk { - moduleName "BleCommandUtil" - } - } - kotlinOptions { - jvmTarget = '1.8' - } - buildFeatures { - viewBinding true - } - lintOptions { - checkReleaseBuilds false - disable 'MissingTranslation' - disable 'ExtraTranslation' - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - debug { - testCoverageEnabled(project.hasProperty('coverage')) - } - firebaseDisable { - System.setProperty("disableFirebase", "true") - ext.enableCrashlytics = false - } } + flavorDimensions "standard" productFlavors { full { @@ -197,25 +161,8 @@ android { ] } } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - testOptions { - unitTests { - returnDefaultValues = true - includeAndroidResources = true - - all { - maxParallelForks = 10 - forkEvery = 20 - } - } - } useLibrary "org.apache.http.legacy" - } allprojects { @@ -241,27 +188,9 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - testImplementation "junit:junit:$junit_version" - testImplementation 'org.json:json:20201115' - testImplementation "org.mockito:mockito-core:${mockitoVersion}" - testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}" - testImplementation "org.powermock:powermock-module-junit4-rule-agent:${powermockVersion}" - testImplementation "org.powermock:powermock-module-junit4-rule:${powermockVersion}" - testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}" - testImplementation "joda-time:joda-time:$jodatime_version" - testImplementation('com.google.truth:truth:1.1.2') { - exclude group: "com.google.guava", module: "guava" - } - testImplementation "org.skyscreamer:jsonassert:1.5.0" - testImplementation "org.hamcrest:hamcrest-all:1.3" - - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0-alpha04' - androidTestImplementation "androidx.test.ext:junit:$androidx_junit" - androidTestImplementation "androidx.test:rules:$androidx_rules" - /* Dagger2 - We are going to use dagger.android which includes - * support for Activity and fragment injection so we need to include - * the following dependencies */ + * support for Activity and fragment injection so we need to include + * the following dependencies */ annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version" @@ -270,10 +199,11 @@ dependencies { /* Dagger2 - default dependency */ kapt "com.google.dagger:dagger-compiler:$dagger_version" - - androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' } +apply from: "${project.rootDir}/gradle/test_dependencies.gradle" + + /* // Run 'adb' shell command to clear application data of main app for 'debug' variant task clearMainAppData(type: Exec) { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cb897b727c..1abc55ecfe 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,6 +25,7 @@ + @@ -74,8 +75,12 @@ + android:excludeFromRecents="true" + android:exported="true" + android:launchMode="singleInstance" + android:permission="com.google.firebase.auth.api.gms.permission.LAUNCH_FEDERATED_SIGN_IN" + android:theme="@android:style/Theme.Translucent.NoTitleBar" + tools:replace="android:launchMode" /> = LinkedList() val unitLabel = if (units == Constants.MMOL) resourceHelper.gs(R.string.mmol) else resourceHelper.gs(R.string.mgdl) + val useAlarm = binding.alarmCheckBox.isChecked val activitySelected = binding.activityTt.isChecked if (activitySelected) @@ -192,6 +190,8 @@ class CarbsDialog : DialogFragmentWithDate() { val time = eventTime + timeOffset * 1000 * 60 if (timeOffset != 0) actions.add(resourceHelper.gs(R.string.time) + ": " + dateUtil.dateAndTimeString(time)) + if (useAlarm && carbs > 0 && timeOffset > 0) + actions.add(resourceHelper.gs(R.string.alarminxmin, timeOffset).formatColor(resourceHelper, R.color.info)) val duration = binding.duration.value.toInt() if (duration > 0) actions.add(resourceHelper.gs(R.string.duration) + ": " + duration + resourceHelper.gs(R.string.shorthour)) @@ -257,6 +257,9 @@ class CarbsDialog : DialogFragmentWithDate() { nsUpload.uploadEvent(CareportalEvent.NOTE, DateUtil.now() - 2000, resourceHelper.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset)) } } + if (useAlarm && carbs > 0 && timeOffset > 0) { + carbTimer.scheduleReminder(dateUtil._now() + T.mins(timeOffset.toLong()).msecs()) + } }, null) } } else diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt index 97a6079e4a..fe15677807 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt @@ -15,7 +15,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.HardLimits @@ -36,7 +35,7 @@ open class OpenAPSAMAPlugin @Inject constructor( private val profileFunction: ProfileFunction, private val context: Context, private val activePlugin: ActivePluginProvider, - private val treatmentsPlugin: TreatmentsPlugin, + private val treatmentsPlugin: TreatmentsInterface, private val iobCobCalculatorPlugin: IobCobCalculatorPlugin, private val hardLimits: HardLimits, private val profiler: Profiler, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt index f1245810f0..c57e427194 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt @@ -17,7 +17,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.HardLimits import info.nightscout.androidaps.utils.Profiler @@ -37,7 +36,7 @@ open class OpenAPSSMBPlugin @Inject constructor( private val profileFunction: ProfileFunction, private val context: Context, private val activePlugin: ActivePluginProvider, - private val treatmentsPlugin: TreatmentsPlugin, + private val treatmentsPlugin: TreatmentsInterface, private val iobCobCalculatorPlugin: IobCobCalculatorPlugin, private val hardLimits: HardLimits, private val profiler: Profiler, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt index f1a3dde59b..c2cbe83ff7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt @@ -13,7 +13,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.HardLimits import info.nightscout.androidaps.utils.Round @@ -38,7 +37,7 @@ class SafetyPlugin @Inject constructor( private val activePlugin: ActivePluginProvider, private val hardLimits: HardLimits, private val buildHelper: BuildHelper, - private val treatmentsPlugin: TreatmentsPlugin, + private val treatmentsPlugin: TreatmentsInterface, private val config: Config ) : PluginBase(PluginDescription() .mainType(PluginType.CONSTRAINTS) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt index c387e70f33..93411a1275 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt @@ -5,14 +5,16 @@ import android.widget.LinearLayout import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R -import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.plugins.bus.RxBusWrapper 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.LayoutBuilder import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.TimerUtil import info.nightscout.androidaps.utils.resources.ResourceHelper import org.json.JSONObject import javax.inject.Inject @@ -22,6 +24,7 @@ class ActionAlarm(injector: HasAndroidInjector) : Action(injector) { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var context: Context + @Inject lateinit var timerUtil: TimerUtil var text = InputString(injector) @@ -33,10 +36,11 @@ class ActionAlarm(injector: HasAndroidInjector) : Action(injector) { override fun shortDescription(): String = resourceHelper.gs(R.string.alarm_message, text.value) @DrawableRes override fun icon(): Int = R.drawable.ic_access_alarm_24dp - override fun isValid(): Boolean = text.value.isNotEmpty() + override fun isValid(): Boolean = true // empty alarm will show app name override fun doAction(callback: Callback) { - ErrorHelperActivity.runAlarm(context, text.value, resourceHelper.gs(R.string.alarm), R.raw.modern_alarm) + timerUtil.scheduleReminder(DateUtil.now() + T.secs(10L).msecs(), text.value.takeIf { it.isNotBlank() } + ?: resourceHelper.gs(R.string.app_name)) callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt index fce6bb41c4..def0d59a6c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt @@ -11,15 +11,15 @@ import com.google.common.base.Optional import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.TreatmentsInterface import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseTriggerDialog import info.nightscout.androidaps.plugins.general.automation.events.EventTriggerChanged import info.nightscout.androidaps.plugins.general.automation.events.EventTriggerClone import info.nightscout.androidaps.plugins.general.automation.events.EventTriggerRemove import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.services.LastLocationDataContainer import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -29,13 +29,14 @@ import javax.inject.Inject import kotlin.reflect.full.primaryConstructor abstract class Trigger(val injector: HasAndroidInjector) { + @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var sp: SP @Inject lateinit var locationDataContainer: LastLocationDataContainer - @Inject lateinit var treatmentsPlugin: TreatmentsPlugin + @Inject lateinit var treatmentsInterface: TreatmentsInterface @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin @@ -53,12 +54,13 @@ abstract class Trigger(val injector: HasAndroidInjector) { abstract fun duplicate(): Trigger companion object { + @JvmStatic fun scanForActivity(cont: Context?): AppCompatActivity? { when (cont) { - null -> return null + null -> return null is AppCompatActivity -> return cont - is ContextWrapper -> return scanForActivity(cont.baseContext) + is ContextWrapper -> return scanForActivity(cont.baseContext) else -> return null } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt index 27f736cf9a..5ff50b561c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt @@ -35,7 +35,7 @@ class TriggerBolusAgo(injector: HasAndroidInjector) : Trigger(injector) { } override fun shouldRun(): Boolean { - val lastBolusTime = treatmentsPlugin.getLastBolusTime(true) + val lastBolusTime = treatmentsInterface.getLastBolusTime(true) if (lastBolusTime == 0L) return if (comparator.value == Comparator.Compare.IS_NOT_AVAILABLE) { aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt index 26aa0c81b7..25ef553816 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt @@ -28,7 +28,7 @@ class TriggerTempTarget(injector: HasAndroidInjector) : Trigger(injector) { } override fun shouldRun(): Boolean { - val tt = treatmentsPlugin.tempTargetFromHistory + val tt = treatmentsInterface.tempTargetFromHistory if (tt == null && comparator.value == ComparatorExists.Compare.NOT_EXISTS) { aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription()) return true diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt index ecd151e426..31aa345d65 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt @@ -363,7 +363,7 @@ class OpenHumansUploader @Inject constructor( copyDisposable = Completable.fromCallable { MainApp.getDbHelper().clearOpenHumansQueue() } .andThen(Single.defer { Single.just(MainApp.getDbHelper().countOfAllRows + treatmentsPlugin.service.count()) }) .doOnSuccess { maxProgress = it } - .flatMapObservable { Observable.defer { Observable.fromIterable(treatmentsPlugin.service.treatmentData) } } + .flatMapObservable { Observable.defer { Observable.fromIterable(treatmentsPlugin.service.getTreatmentData()) } } .map { enqueueTreatment(it); increaseCounter() } .ignoreElements() .andThen(Observable.defer { Observable.fromIterable(repository.compatGetBgReadingsDataFromTime(0, true).blockingGet()) }) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index 92761bfa74..c44460c604 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -33,7 +33,6 @@ import info.nightscout.androidaps.plugins.general.smsCommunicator.events.EventSm import info.nightscout.androidaps.plugins.general.smsCommunicator.otp.OneTimePassword import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.receivers.BundleStore import info.nightscout.androidaps.receivers.DataReceiver @@ -450,7 +449,7 @@ class SmsCommunicatorPlugin @Inject constructor( private fun processTREATMENTS(divided: Array, receivedSms: Sms) { if (divided[1].toUpperCase(Locale.getDefault()) == "REFRESH") { - (activePlugin.activeTreatments as TreatmentsPlugin).service.resetTreatments() + activePlugin.activeTreatments.service.resetTreatments() rxBus.send(EventNSClientRestart()) sendSMS(Sms(receivedSms.phoneNumber, "TREATMENTS REFRESH SENT")) receivedSms.processed = true @@ -589,9 +588,10 @@ class SmsCommunicatorPlugin @Inject constructor( val finalPercentage = percentage messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction(list[pindex - 1] as String, finalPercentage) { override fun run() { - uel.log("SMS PROFILE", reply) activePlugin.activeTreatments.doProfileSwitch(store, list[pindex - 1] as String, 0, finalPercentage, 0, DateUtil.now()) - sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.profileswitchcreated))) + val replyText = resourceHelper.gs(R.string.profileswitchcreated) + sendSMS(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS PROFILE", replyText) } }) } @@ -607,17 +607,18 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() { override fun run() { - uel.log("SMS BASAL", reply) commandQueue.cancelTempBasal(true, object : Callback() { override fun run() { if (result.success) { var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalcanceled) replyText += "\n" + activePlugin.activePump.shortStatus(true) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS BASAL", replyText) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalcancelfailed) replyText += "\n" + activePlugin.activePump.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS BASAL", replyText) } } }) @@ -639,17 +640,18 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction(tempBasalPct, duration) { override fun run() { - uel.log("SMS BASAL", reply) commandQueue.tempBasalPercent(anInteger(), secondInteger(), true, profile, object : Callback() { override fun run() { if (result.success) { var replyText = if (result.isPercent) String.format(resourceHelper.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration) else String.format(resourceHelper.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration) replyText += "\n" + activePlugin.activePump.shortStatus(true) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS BASAL", replyText) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalfailed) replyText += "\n" + activePlugin.activePump.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS BASAL", replyText) } } }) @@ -672,7 +674,6 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction(tempBasal, duration) { override fun run() { - uel.log("SMS BASAL", reply) commandQueue.tempBasalAbsolute(aDouble(), secondInteger(), true, profile, object : Callback() { override fun run() { if (result.success) { @@ -680,10 +681,12 @@ class SmsCommunicatorPlugin @Inject constructor( else String.format(resourceHelper.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration) replyText += "\n" + activePlugin.activePump.shortStatus(true) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS BASAL", replyText) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalfailed) replyText += "\n" + activePlugin.activePump.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS BASAL", replyText) } } }) @@ -700,7 +703,6 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() { override fun run() { - uel.log("SMS EXTENDED", reply) commandQueue.cancelExtended(object : Callback() { override fun run() { if (result.success) { @@ -711,6 +713,7 @@ class SmsCommunicatorPlugin @Inject constructor( var replyText = resourceHelper.gs(R.string.smscommunicator_extendedcancelfailed) replyText += "\n" + activePlugin.activePump.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS EXTENDED", replyText) } } }) @@ -729,7 +732,6 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction(extended, duration) { override fun run() { - uel.log("SMS EXTENDED", reply) commandQueue.extendedBolus(aDouble(), secondInteger(), object : Callback() { override fun run() { if (result.success) { @@ -737,10 +739,12 @@ class SmsCommunicatorPlugin @Inject constructor( if (config.APS) replyText += "\n" + resourceHelper.gs(R.string.loopsuspended) replyText += "\n" + activePlugin.activePump.shortStatus(true) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS EXTENDED", replyText) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_extendedfailed) replyText += "\n" + activePlugin.activePump.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS EXTENDED", replyText) } } }) @@ -765,7 +769,6 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction(bolus) { override fun run() { - uel.log("SMS BOLUS", reply) val detailedBolusInfo = DetailedBolusInfo() detailedBolusInfo.insulin = aDouble() detailedBolusInfo.source = Source.USER @@ -810,10 +813,12 @@ class SmsCommunicatorPlugin @Inject constructor( } } sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS BOLUS", replyText) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_bolusfailed) replyText += "\n" + activePlugin.activePump.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS BOLUS", replyText) } } }) @@ -842,7 +847,6 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction(grams, time) { override fun run() { - uel.log("SMS CARBS", reply) val detailedBolusInfo = DetailedBolusInfo() detailedBolusInfo.carbs = anInteger().toDouble() detailedBolusInfo.source = Source.USER @@ -854,10 +858,12 @@ class SmsCommunicatorPlugin @Inject constructor( var replyText = String.format(resourceHelper.gs(R.string.smscommunicator_carbsset), anInteger) replyText += "\n" + activePlugin.activePump.shortStatus(true) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS CARBS", replyText) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_carbsfailed) replyText += "\n" + activePlugin.activePump.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS CARBS", replyText) } } }) @@ -866,6 +872,7 @@ class SmsCommunicatorPlugin @Inject constructor( var replyText = String.format(resourceHelper.gs(R.string.smscommunicator_carbsset), anInteger) replyText += "\n" + activePlugin.activePump.shortStatus(true) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS CARBS", replyText) } } }) @@ -883,7 +890,6 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() { override fun run() { - uel.log("SMS TARGET", reply) val units = profileFunction.getUnits() var keyDuration = 0 var defaultTargetDuration = 0 @@ -931,6 +937,7 @@ class SmsCommunicatorPlugin @Inject constructor( val ttString = if (units == Constants.MMOL) DecimalFormatter.to1Decimal(tt) else DecimalFormatter.to0Decimal(tt) val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_tt_set), ttString, ttDuration) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS TARGET", replyText) } }) } else if (isStop) { @@ -939,7 +946,6 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() { override fun run() { - uel.log("SMS TARGET", reply) val tempTarget = TempTarget() .source(Source.USER) .date(DateUtil.now()) @@ -949,6 +955,7 @@ class SmsCommunicatorPlugin @Inject constructor( activePlugin.activeTreatments.addToHistoryTempTarget(tempTarget) val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_tt_canceled)) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS TARGET", reply) } }) } else @@ -964,10 +971,10 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() { override fun run() { - uel.log("SMS SMS", reply) sp.putBoolean(R.string.key_smscommunicator_remotecommandsallowed, false) val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_stoppedsms)) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS SMS", replyText) } }) } else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat))) @@ -981,9 +988,11 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction(cal) { override fun run() { - uel.log("SMS CAL", reply) val result = xdripCalibrations.sendIntent(aDouble!!) - if (result) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_calibrationsent))) else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_calibrationfailed))) + val replyText = + if (result) resourceHelper.gs(R.string.smscommunicator_calibrationsent) else resourceHelper.gs(R.string.smscommunicator_calibrationfailed) + sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + uel.log("SMS CAL", replyText) } }) } else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat))) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java index 15ae4409ad..354468f7aa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java @@ -41,6 +41,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpPluginBase; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -80,7 +81,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr private final ResourceHelper resourceHelper; private final ProfileFunction profileFunction; - private final TreatmentsPlugin treatmentsPlugin; + private final TreatmentsInterface treatmentsPlugin; private final info.nightscout.androidaps.utils.sharedPreferences.SP sp; private RxBusWrapper rxBus; private final CommandQueueProvider commandQueue; @@ -136,7 +137,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr RxBusWrapper rxBus, ResourceHelper resourceHelper, ProfileFunction profileFunction, - TreatmentsPlugin treatmentsPlugin, + TreatmentsInterface treatmentsPlugin, SP sp, CommandQueueProvider commandQueue, Context context diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index f5b46ffc9e..638439e728 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -49,6 +49,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpPluginBase; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -129,7 +130,6 @@ import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_erro import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoActiveTBRToCanceLException; import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator; import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil; -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.TimeChangeType; import info.nightscout.androidaps.utils.resources.ResourceHelper; @@ -141,7 +141,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, private final AAPSLogger aapsLogger; private final RxBusWrapper rxBus; private final ResourceHelper resourceHelper; - private final TreatmentsPlugin treatmentsPlugin; + private final TreatmentsInterface treatmentsPlugin; private final SP sp; private final CommandQueueProvider commandQueue; private final ProfileFunction profileFunction; @@ -203,7 +203,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, AAPSLogger aapsLogger, RxBusWrapper rxBus, ResourceHelper resourceHelper, - TreatmentsPlugin treatmentsPlugin, + TreatmentsInterface treatmentsPlugin, SP sp, CommandQueueProvider commandQueue, ProfileFunction profileFunction, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java index 49d1070b7d..a4f85e3882 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java @@ -16,6 +16,7 @@ import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; import org.json.JSONException; import org.json.JSONObject; @@ -39,6 +40,8 @@ import info.nightscout.androidaps.events.EventNsTreatment; import info.nightscout.androidaps.events.EventReloadTreatmentData; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.DatabaseHelperInterface; +import info.nightscout.androidaps.interfaces.TreatmentServiceInterface; +import info.nightscout.androidaps.interfaces.UpdateReturn; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -57,7 +60,7 @@ import io.reactivex.disposables.CompositeDisposable; * Created by mike on 24.09.2017. */ -public class TreatmentService extends OrmLiteBaseService { +public class TreatmentService extends OrmLiteBaseService implements TreatmentServiceInterface { @Inject AAPSLogger aapsLogger; @Inject FabricPrivacy fabricPrivacy; @@ -471,7 +474,7 @@ public class TreatmentService extends OrmLiteBaseService { } - public UpdateReturn createOrUpdateMedtronic(Treatment treatment, boolean fromNightScout) { + @NotNull public UpdateReturn createOrUpdateMedtronic(@NotNull Treatment treatment, boolean fromNightScout) { if (MedtronicHistoryData.doubleBolusDebug) aapsLogger.debug(LTag.DATATREATMENTS, "DoubleBolusDebug: createOrUpdateMedtronic:: originalTreatment={}, fromNightScout={}", treatment, fromNightScout); @@ -821,22 +824,4 @@ public class TreatmentService extends OrmLiteBaseService { return null; } - public class UpdateReturn { - public UpdateReturn(boolean success, boolean newRecord) { - this.success = success; - this.newRecord = newRecord; - } - - boolean newRecord; - boolean success; - - @Override - public String toString() { - return "UpdateReturn [" + - "newRecord=" + newRecord + - ", success=" + success + - ']'; - } - } - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java index dbb4846bde..41e3673493 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java @@ -46,7 +46,9 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.interfaces.ProfileStore; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.TreatmentServiceInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface; +import info.nightscout.androidaps.interfaces.UpdateReturn; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -82,7 +84,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface private final CompositeDisposable disposable = new CompositeDisposable(); - protected TreatmentService service; + protected TreatmentServiceInterface service; private IobTotal lastTreatmentCalculation; private IobTotal lastTempBasalsCalculation; @@ -180,7 +182,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface super.onStop(); } - public TreatmentService getService() { + @Override + public TreatmentServiceInterface getService() { return this.service; } @@ -620,9 +623,9 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface } public TreatmentUpdateReturn createOrUpdateMedtronic(Treatment treatment, boolean fromNightScout) { - TreatmentService.UpdateReturn resultRecord = getService().createOrUpdateMedtronic(treatment, fromNightScout); + UpdateReturn resultRecord = getService().createOrUpdateMedtronic(treatment, fromNightScout); - return new TreatmentUpdateReturn(resultRecord.success, resultRecord.newRecord); + return new TreatmentUpdateReturn(resultRecord.getSuccess(), resultRecord.getNewRecord()); } // return true if new record is created @@ -643,7 +646,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface treatment.carbs = detailedBolusInfo.carbs; treatment.mealBolus = treatment.carbs > 0; treatment.boluscalc = detailedBolusInfo.boluscalc != null ? detailedBolusInfo.boluscalc.toString() : null; - TreatmentService.UpdateReturn creatOrUpdateResult; + UpdateReturn creatOrUpdateResult; getAapsLogger().debug(medtronicPump && MedtronicHistoryData.doubleBolusDebug, LTag.DATATREATMENTS, "DoubleBolusDebug: addToHistoryTreatment::treatment={} " + treatment); @@ -652,7 +655,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface else creatOrUpdateResult = getService().createOrUpdateMedtronic(treatment, false); - boolean newRecordCreated = creatOrUpdateResult.newRecord; + boolean newRecordCreated = creatOrUpdateResult.getNewRecord(); //log.debug("Adding new Treatment record" + treatment.toString()); if (detailedBolusInfo.carbTime != 0) { @@ -673,7 +676,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface if (newRecordCreated && detailedBolusInfo.isValid) nsUpload.uploadTreatmentRecord(detailedBolusInfo); - if (!allowUpdate && !creatOrUpdateResult.success) { + if (!allowUpdate && !creatOrUpdateResult.getSuccess()) { getAapsLogger().error("Treatment could not be added to DB", new Exception()); String status = String.format(resourceHelper.gs(R.string.error_adding_treatment_message), treatment.insulin, (int) treatment.carbs, dateUtil.dateAndTimeString(treatment.date)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt index 3a46793e02..0e4f7cc200 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt @@ -64,11 +64,11 @@ class TreatmentsUserEntryFragment : DaggerFragment() { val current = entries[position] holder.binding.date.text = dateUtil.dateAndTimeAndSecondsString(current.timestamp) holder.binding.action.text = current.action - holder.binding.s.text = current.s - holder.binding.d1.text = if (current.d1 != 0.0) current.d1.toString() else "" - holder.binding.d2.text = if (current.d2 != 0.0) current.d2.toString() else "" - holder.binding.i1.text = if (current.i1 != 0) current.i1.toString() else "" - holder.binding.i1.text = if (current.i2 != 0) current.i2.toString() else "" + if (current.s != "") holder.binding.s.text = current.s else holder.binding.s.visibility = View.GONE + if (current.d1 != 0.0) holder.binding.d1.text = current.d1.toString() else holder.binding.d1.visibility = View.GONE + if (current.d2 != 0.0) holder.binding.d2.text = current.d2.toString() else holder.binding.d2.visibility = View.GONE + if (current.i1 != 0) holder.binding.i1.text = current.i1.toString() else holder.binding.i1.visibility = View.GONE + if (current.i2 != 0) holder.binding.i2.text = current.i2.toString() else holder.binding.i2.visibility = View.GONE } inner class UserEntryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt b/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt new file mode 100644 index 0000000000..c029b01af2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt @@ -0,0 +1,63 @@ +package info.nightscout.androidaps.utils + +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.Constants +import info.nightscout.androidaps.R +import info.nightscout.androidaps.plugins.general.automation.AutomationEvent +import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin +import info.nightscout.androidaps.plugins.general.automation.actions.ActionAlarm +import info.nightscout.androidaps.plugins.general.automation.elements.Comparator +import info.nightscout.androidaps.plugins.general.automation.elements.InputDelta +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBg +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDelta +import info.nightscout.androidaps.utils.resources.ResourceHelper +import java.text.DecimalFormat +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class CarbTimer @Inject constructor( + private val injector: HasAndroidInjector, + private val resourceHelper: ResourceHelper, + private val automationPlugin: AutomationPlugin, + private val timerUtil: TimerUtil +) { + + fun scheduleReminder(time: Long, text: String? = null) = + timerUtil.scheduleReminder(time, text ?: resourceHelper.gs(R.string.timetoeat)) + + fun scheduleEatReminder() { + val event = AutomationEvent(injector).apply { + title = resourceHelper.gs(R.string.bolusadvisor) + readOnly = true + systemAction = true + autoRemove = true + trigger = TriggerConnector(injector, TriggerConnector.Type.OR).apply { + + // Bg under 180 mgdl and dropping by 15 mgdl + list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { + list.add(TriggerBg(injector, 180.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) + list.add(TriggerDelta(injector, InputDelta(injector, -15.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add(TriggerDelta(injector, InputDelta(injector, -8.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + }) + // Bg under 160 mgdl and dropping by 9 mgdl + list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { + list.add(TriggerBg(injector, 160.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) + list.add(TriggerDelta(injector, InputDelta(injector, -9.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add(TriggerDelta(injector, InputDelta(injector, -5.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + }) + // Bg under 145 mgdl and dropping + list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { + list.add(TriggerBg(injector, 145.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) + list.add(TriggerDelta(injector, InputDelta(injector, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add(TriggerDelta(injector, InputDelta(injector, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + }) + } + actions.add(ActionAlarm(injector, resourceHelper.gs(R.string.time_to_eat))) + } + + automationPlugin.addIfNotExists(event) + } + +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TimerUtil.kt b/app/src/main/java/info/nightscout/androidaps/utils/TimerUtil.kt new file mode 100644 index 0000000000..b62f00df54 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/TimerUtil.kt @@ -0,0 +1,27 @@ +package info.nightscout.androidaps.utils + +import android.content.Context +import android.content.Intent +import android.provider.AlarmClock +import info.nightscout.androidaps.R +import info.nightscout.androidaps.utils.resources.ResourceHelper +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class TimerUtil @Inject constructor( + private val context: Context, + private val resourceHelper: ResourceHelper, +) { + + fun scheduleReminder(time: Long, text: String? = null) { + Intent(AlarmClock.ACTION_SET_TIMER).apply { + val length: Int = ((time - DateUtil.now()) / 1000).toInt() + flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK + putExtra(AlarmClock.EXTRA_LENGTH, length) + putExtra(AlarmClock.EXTRA_SKIP_UI, true) + putExtra(AlarmClock.EXTRA_MESSAGE, text ?: resourceHelper.gs(R.string.app_name)) + context.startActivity(this) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt index e690ce4dba..37fccabd8c 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt @@ -6,7 +6,6 @@ import android.text.Spanned import com.google.common.base.Joiner import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Config -import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.data.DetailedBolusInfo @@ -22,18 +21,10 @@ import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker -import info.nightscout.androidaps.plugins.general.automation.AutomationEvent -import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin -import info.nightscout.androidaps.plugins.general.automation.actions.ActionAlarm -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.plugins.general.automation.elements.InputDelta -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBg -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDelta -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTime import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.utils.CarbTimer import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.Round @@ -44,7 +35,6 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.json.JSONException import org.json.JSONObject -import java.text.DecimalFormat import java.util.* import javax.inject.Inject import kotlin.math.abs @@ -63,10 +53,10 @@ class BolusWizard @Inject constructor( @Inject lateinit var commandQueue: CommandQueueProvider @Inject lateinit var loopPlugin: LoopPlugin @Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin - @Inject lateinit var automationPlugin: AutomationPlugin @Inject lateinit var dateUtil: DateUtil @Inject lateinit var config: Config @Inject lateinit var uel: UserEntryLogger + @Inject lateinit var carbTimer: CarbTimer init { injector.androidInjector().inject(this) @@ -363,7 +353,7 @@ class BolusWizard @Inject constructor( if (!result.success) { ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), R.raw.boluserror) } else - scheduleEatReminder() + carbTimer.scheduleEatReminder() } }) } @@ -434,57 +424,9 @@ class BolusWizard @Inject constructor( } } if (useAlarm && carbs > 0 && carbTime > 0) { - scheduleReminder(dateUtil._now() + T.mins(carbTime.toLong()).msecs()) + carbTimer.scheduleReminder(dateUtil._now() + T.mins(carbTime.toLong()).msecs()) } } }) } - - private fun scheduleEatReminder() { - val event = AutomationEvent(injector).apply { - title = resourceHelper.gs(R.string.bolusadvisor) - readOnly = true - systemAction = true - autoRemove = true - trigger = TriggerConnector(injector, TriggerConnector.Type.OR).apply { - - // Bg under 180 mgdl and dropping by 15 mgdl - list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { - list.add(TriggerBg(injector, 180.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, -15.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, -8.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - }) - // Bg under 160 mgdl and dropping by 9 mgdl - list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { - list.add(TriggerBg(injector, 160.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, -9.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, -5.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - }) - // Bg under 145 mgdl and dropping - list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { - list.add(TriggerBg(injector, 145.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - }) - } - actions.add(ActionAlarm(injector, resourceHelper.gs(R.string.time_to_eat))) - } - - automationPlugin.addIfNotExists(event) - } - - private fun scheduleReminder(time: Long) { - val event = AutomationEvent(injector).apply { - title = resourceHelper.gs(R.string.timetoeat) - readOnly = true - systemAction = true - autoRemove = true - trigger = TriggerConnector(injector, TriggerConnector.Type.AND).apply { - list.add(TriggerTime(injector, time)) - } - actions.add(ActionAlarm(injector, resourceHelper.gs(R.string.timetoeat))) - } - - automationPlugin.addIfNotExists(event) - } -} +} \ No newline at end of file diff --git a/app/src/main/jniLibs/README.md b/app/src/main/jniLibs/README.md deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/app/src/main/jniLibs/arm64-v8a/libBleCommandUtil.so b/app/src/main/jniLibs/arm64-v8a/libBleCommandUtil.so deleted file mode 100644 index 69e283b5fe..0000000000 Binary files a/app/src/main/jniLibs/arm64-v8a/libBleCommandUtil.so and /dev/null differ diff --git a/app/src/main/jniLibs/armeabi-v7a/libBleCommandUtil.so b/app/src/main/jniLibs/armeabi-v7a/libBleCommandUtil.so deleted file mode 100644 index 0c717bc3e8..0000000000 Binary files a/app/src/main/jniLibs/armeabi-v7a/libBleCommandUtil.so and /dev/null differ diff --git a/app/src/main/jniLibs/armeabi/libBleCommandUtil.so b/app/src/main/jniLibs/armeabi/libBleCommandUtil.so deleted file mode 100644 index a51a8c7d9a..0000000000 Binary files a/app/src/main/jniLibs/armeabi/libBleCommandUtil.so and /dev/null differ diff --git a/app/src/main/jniLibs/mips/libBleCommandUtil.so b/app/src/main/jniLibs/mips/libBleCommandUtil.so deleted file mode 100644 index fcff5eb6b2..0000000000 Binary files a/app/src/main/jniLibs/mips/libBleCommandUtil.so and /dev/null differ diff --git a/app/src/main/jniLibs/mips64/libBleCommandUtil.so b/app/src/main/jniLibs/mips64/libBleCommandUtil.so deleted file mode 100644 index a8a292ea13..0000000000 Binary files a/app/src/main/jniLibs/mips64/libBleCommandUtil.so and /dev/null differ diff --git a/app/src/main/jniLibs/x86/libBleCommandUtil.so b/app/src/main/jniLibs/x86/libBleCommandUtil.so deleted file mode 100644 index 638a9def95..0000000000 Binary files a/app/src/main/jniLibs/x86/libBleCommandUtil.so and /dev/null differ diff --git a/app/src/main/jniLibs/x86_64/libBleCommandUtil.so b/app/src/main/jniLibs/x86_64/libBleCommandUtil.so deleted file mode 100644 index 94873d3732..0000000000 Binary files a/app/src/main/jniLibs/x86_64/libBleCommandUtil.so and /dev/null differ diff --git a/app/src/main/res/layout/dialog_carbs.xml b/app/src/main/res/layout/dialog_carbs.xml index 66c58a61bf..f0f306c6ff 100644 --- a/app/src/main/res/layout/dialog_carbs.xml +++ b/app/src/main/res/layout/dialog_carbs.xml @@ -75,107 +75,160 @@ - + android:paddingEnd="5dp"> - + - + - + - + - + + - + - + - + - + + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + Šipka trendu Kanyla Vstup uživatele + Použijte hodnoty pro největší jídlo, jaké obvykle jíte\n diff --git a/app/src/main/res/values-de-rDE/strings.xml b/app/src/main/res/values-de-rDE/strings.xml index 8cffc8b783..106f34a0af 100644 --- a/app/src/main/res/values-de-rDE/strings.xml +++ b/app/src/main/res/values-de-rDE/strings.xml @@ -1162,4 +1162,5 @@ Unerwartetes Verhalten. Trendpfeil Kanüle Benutzereingabe + Verwende die Werte der größten Mahlzeit, die Du normalerweise zu Dir nimmst\n diff --git a/app/src/main/res/values-fr-rFR/objectives.xml b/app/src/main/res/values-fr-rFR/objectives.xml index 288de82bbb..54809e4ba5 100644 --- a/app/src/main/res/values-fr-rFR/objectives.xml +++ b/app/src/main/res/values-fr-rFR/objectives.xml @@ -21,7 +21,7 @@ Activation de fonctionnalités supplémentaires pour l\'utilisation en journée, telles que la fonction SMB Activation de l\'automatisation Lisez le wiki et augmentez le maxIA pour que les SMBs fonctionnent correctement ! Un bon début est maxIA = moyenne des Bolus Repas + 3 x maximum débit Basal quotidien - Lisez la documentation comment l\'automatisation fonctionne. Configurez vos premières règles simples. Au lieu de mettre une action, configurez une notification. Quand vous êtes sûr que l\'automatisation est déclenchée au bon moment, remplacez la notification par une action réelle. (https://androidaps.readthedocs.io/en/latest/CROWDIN/fr/Usage/Automation.html) + Lisez la documentation comment l\'automatisation fonctionne. Configurez vos premières règles simples. Au lieu de mettre une action, configurez une notification. Quand vous êtes sûr que l\'automatisation est déclenchée au bon moment, remplacez la notification par une action réelle. (https://androidaps.readthedocs.io/fr/latest/Usage/Automation.html) Glycémie disponible sur NS Statut de la pompe disponible sur NS Activation manuelle @@ -36,7 +36,7 @@ Affichage du contenu du plugin Boucle Modification de l\'échelle du graphique par un appui long sur la courbe de glycémie Entrer - Si vous avez au moins 3 mois d\'expérience de boucle fermée avec d\'autres systèmes, vous pourriez avoir droit à un code permettant d\'ignorer les objectifs. Voir https://androidaps.readthedocs.io/en/latest/CROWDIN/fr/Usage/Objectives.html#ignorer-les-objectifs pour plus de détails. + Si vous avez au moins 3 mois d\'expérience de boucle fermée avec d\'autres systèmes, vous pourriez avoir droit à un code permettant d\'ignorer les objectifs. Voir https://androidaps.readthedocs.io/fr/latest/Usage/Objectives.html#ignorer-les-objectifs pour plus de détails. Code accepté Code invalide Prouver ses connaissances @@ -46,10 +46,10 @@ Prochain non terminé Code requis : %1$s (Sélectionnez toutes les bonnes réponses) - https://androidaps.readthedocs.io/en/latest/CROWDIN/fr/Getting-Started/FAQ.html#what-to-do-when-taking-a-shower-or-bath - https://androidaps.readthedocs.io/en/latest/CROWDIN/fr/Getting-Started/Screenshots.html#the-homescreen - https://androidaps.readthedocs.io/en/latest/CROWDIN/fr/Getting-Started/Screenshots.html#config-builder - https://androidaps.readthedocs.io/en/latest/CROWDIN/fr/Getting-Started/Screenshots.html#the-homescreen + https://androidaps.readthedocs.io/fr/latest/Getting-Started/FAQ.html#que-faire-pour-prendre-une-douche-ou-un-bain + https://androidaps.readthedocs.io/fr/latest/Getting-Started/Screenshots.html + https://androidaps.readthedocs.io/fr/latest/Configuration/Config-Builder.html + https://androidaps.readthedocs.io/fr/latest/Getting-Started/Screenshots.html Non connecté à Internet Échec de la récupération de l\'heure Exigences de l\'objectif non atteintes diff --git a/app/src/main/res/values-fr-rFR/strings.xml b/app/src/main/res/values-fr-rFR/strings.xml index b8a1ace3fd..959da11884 100644 --- a/app/src/main/res/values-fr-rFR/strings.xml +++ b/app/src/main/res/values-fr-rFR/strings.xml @@ -1162,4 +1162,5 @@ L\'ENSEMBLE DES RISQUES LIÉS À LA QUALITÉ ET À LA PERFORMANCE DU PROGRAMME S Flèche de tendance Canule Entrées utilisateur + Utilisez les valeurs qui correspondent à vos plus gros repas\n diff --git a/app/src/main/res/values-it-rIT/strings.xml b/app/src/main/res/values-it-rIT/strings.xml index ccedf44eb5..8bfdf04a07 100644 --- a/app/src/main/res/values-it-rIT/strings.xml +++ b/app/src/main/res/values-it-rIT/strings.xml @@ -1161,4 +1161,5 @@ Freccia trend Cannula Inserimento utente + Usa i valori del cibo più abbondante che mangi di solito\n diff --git a/app/src/main/res/values-iw-rIL/strings.xml b/app/src/main/res/values-iw-rIL/strings.xml index b1450e9f52..2b8d794200 100644 --- a/app/src/main/res/values-iw-rIL/strings.xml +++ b/app/src/main/res/values-iw-rIL/strings.xml @@ -180,7 +180,7 @@ שמור טעינה מחדש של הפרופיל תקשורת SMS - מספרי טלפון מותרים + מספרי טלפון מורשים + XXXXXXXXXX; + YYYYYYYYYY לאישור מתן בולוס %1$.2f יחידות יש להשיב עם הקוד %2$s למתן %1$.2f יחידות בולוס ארוחה יש להשיב עם הקוד %2$s @@ -1161,4 +1161,5 @@ חץ מגמה צינורית קלט המשתמש + השתמשו בערכים הגבוהים ביותר של מזונות שאתם אוכלים בדרך כלל\n diff --git a/app/src/main/res/values-no-rNO/strings.xml b/app/src/main/res/values-no-rNO/strings.xml index 181ac9fe55..e87337521a 100644 --- a/app/src/main/res/values-no-rNO/strings.xml +++ b/app/src/main/res/values-no-rNO/strings.xml @@ -1161,4 +1161,5 @@ Trend pil Kanyle Bruker registrering + Bruk verdiene for det største måltidet du normalt spiser\n diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 50c0176157..543467fda4 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -1161,4 +1161,5 @@ Seta de tendência Cânula Entrada de Utilizador + Utilize valores da sua maior refeição que normalmente come\n diff --git a/app/src/main/res/values-ru-rRU/strings.xml b/app/src/main/res/values-ru-rRU/strings.xml index 2e0825e547..af7bfd5b0b 100644 --- a/app/src/main/res/values-ru-rRU/strings.xml +++ b/app/src/main/res/values-ru-rRU/strings.xml @@ -1163,4 +1163,5 @@ Context | Edit Context Стрелка тренда Катетер помпы Запись пользователя + Введите максимальные значения вашего приема пищи \n diff --git a/app/src/main/res/values-sk-rSK/strings.xml b/app/src/main/res/values-sk-rSK/strings.xml index 29e570471f..9339c222f7 100644 --- a/app/src/main/res/values-sk-rSK/strings.xml +++ b/app/src/main/res/values-sk-rSK/strings.xml @@ -420,6 +420,7 @@ BAZ DEV AKT + -BGI ABS DEVSLOPE O aplikácii @@ -627,6 +628,7 @@ Automaticky doplňovať chýbajúcu glykémiu z NS SMB podané pumpou Aktivita + Vplyv na glykémiu (BGI) Citlivosť Odchýlky Aktívne sacharidy @@ -1158,4 +1160,6 @@ Vyčistiť filter Trendová šípka Kanyla + Vstup používateľa + Použite hodnoty pre najväčšie jedlo, aké obvykle jete\n diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 0b02d9a048..ecffee5c8e 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -125,69 +125,6 @@ YpsoPump - - Other (unsupported) - 512 - 712 - 515 - 715 - 522 - 722 - 523 (Fw 2.4A or lower) - 723 (Fw 2.4A or lower) - 554 (EU Fw. <= 2.6A) - 754 (EU Fw. <= 2.6A) - 554 (CA Fw. <= 2.7A) - 754 (CA Fw. <= 2.7A) - - - - @string/medtronic_pump_frequency_us_ca - @string/medtronic_pump_frequency_worldwide - - - - @string/key_medtronic_pump_frequency_us_ca - @string/key_medtronic_pump_frequency_worldwide - - - - 5 - 10 - 15 - - - - @string/medtronic_pump_encoding_4b6b_local - @string/medtronic_pump_encoding_4b6b_rileylink - - - - @string/common_on - @string/common_off - - - - @string/key_medtronic_pump_encoding_4b6b_local - @string/key_medtronic_pump_encoding_4b6b_rileylink - - - - @string/medtronic_pump_battery_no - @string/medtronic_pump_battery_alkaline - @string/medtronic_pump_battery_lithium - @string/medtronic_pump_battery_nizn - @string/medtronic_pump_battery_nimh - - - - @string/key_medtronic_pump_battery_no - @string/key_medtronic_pump_battery_alkaline - @string/key_medtronic_pump_battery_lithium - @string/key_medtronic_pump_battery_nizn - @string/key_medtronic_pump_battery_nimh - - 15 30 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index c03d4b1ce8..573c94c900 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -65,7 +65,4 @@ #2E2E2E - #FFFFFF - #BBBBBB - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0d7e5910da..9c0acd512a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1251,7 +1251,6 @@ snoozedTo snooze_dst_in24h snooze_loopdisabled - ^\\d{6} Use of Extended bolus feature will stop closed loop mode for the time of running extended bolus. Do you really want it? Closed loop disabled because of running Extended bolus \"PhoneChecker\" diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 054f8f8d23..b79d02361d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -22,16 +22,6 @@ @color/colorAccent - - - + + +