diff --git a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt index 154a35ff49..c495fb0056 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt @@ -6,7 +6,15 @@ import android.content.SharedPreferences import android.content.SharedPreferences.OnSharedPreferenceChangeListener import android.os.Bundle import androidx.annotation.XmlRes -import androidx.preference.* +import androidx.preference.EditTextPreference +import androidx.preference.ListPreference +import androidx.preference.Preference +import androidx.preference.PreferenceCategory +import androidx.preference.PreferenceFragmentCompat +import androidx.preference.PreferenceGroup +import androidx.preference.PreferenceManager +import androidx.preference.PreferenceScreen +import androidx.preference.size import dagger.android.support.AndroidSupportInjection import info.nightscout.androidaps.R import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin @@ -20,23 +28,22 @@ import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.plugin.general.openhumans.OpenHumansUploader import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin +import info.nightscout.androidaps.plugins.aps.openAPSSMBDynamicISF.OpenAPSSMBDynamicISFPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.configBuilder.PluginStore import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin -import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin import info.nightscout.androidaps.plugins.general.autotune.AutotunePlugin import info.nightscout.androidaps.plugins.general.maintenance.MaintenancePlugin import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus -import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin import info.nightscout.androidaps.plugins.general.tidepool.TidepoolPlugin import info.nightscout.androidaps.plugins.general.wear.WearPlugin import info.nightscout.androidaps.plugins.general.xdripStatusline.StatusLinePlugin -import info.nightscout.plugins.insulin.InsulinOrefFreePeakPlugin import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin import info.nightscout.androidaps.plugins.pump.eopatch.EopatchPumpPlugin import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin @@ -45,12 +52,23 @@ import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin -import info.nightscout.androidaps.plugins.source.* +import info.nightscout.androidaps.plugins.source.AidexPlugin +import info.nightscout.androidaps.plugins.source.DexcomPlugin +import info.nightscout.androidaps.plugins.source.EversensePlugin +import info.nightscout.androidaps.plugins.source.GlimpPlugin +import info.nightscout.androidaps.plugins.source.GlunovoPlugin +import info.nightscout.androidaps.plugins.source.IntelligoPlugin +import info.nightscout.androidaps.plugins.source.PoctechPlugin +import info.nightscout.androidaps.plugins.source.TomatoPlugin import info.nightscout.androidaps.utils.alertDialogs.OKDialog.show import info.nightscout.androidaps.utils.protection.PasswordCheck -import info.nightscout.androidaps.utils.protection.ProtectionCheck.ProtectionType.* -import info.nightscout.androidaps.interfaces.ResourceHelper -import info.nightscout.androidaps.plugins.aps.openAPSSMBDynamicISF.OpenAPSSMBDynamicISFPlugin +import info.nightscout.androidaps.utils.protection.ProtectionCheck.ProtectionType.BIOMETRIC +import info.nightscout.androidaps.utils.protection.ProtectionCheck.ProtectionType.CUSTOM_PASSWORD +import info.nightscout.androidaps.utils.protection.ProtectionCheck.ProtectionType.CUSTOM_PIN +import info.nightscout.androidaps.utils.protection.ProtectionCheck.ProtectionType.NONE +import info.nightscout.automation.AutomationPlugin +import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin +import info.nightscout.plugins.insulin.InsulinOrefFreePeakPlugin import info.nightscout.shared.SafeParse import info.nightscout.shared.sharedPreferences.SP import javax.inject.Inject diff --git a/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt b/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt index 8433db9be4..d4a3145519 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt @@ -5,7 +5,6 @@ import dagger.Component import dagger.android.AndroidInjectionModule import dagger.android.AndroidInjector import info.nightscout.androidaps.MainApp -import info.nightscout.androidaps.automation.di.AutomationModule import info.nightscout.androidaps.combo.di.ComboModule import info.nightscout.androidaps.dana.di.DanaHistoryModule import info.nightscout.androidaps.dana.di.DanaModule @@ -23,6 +22,7 @@ import info.nightscout.androidaps.plugins.pump.eopatch.dagger.EopatchModule import info.nightscout.androidaps.plugins.pump.medtronic.di.MedtronicModule import info.nightscout.androidaps.plugins.pump.omnipod.dash.di.OmnipodDashModule import info.nightscout.androidaps.plugins.pump.omnipod.eros.di.OmnipodErosModule +import info.nightscout.automation.di.AutomationModule import info.nightscout.implementation.di.CommandQueueModule import info.nightscout.plugins.di.InsulinModule import info.nightscout.plugins.di.SMSCommunicatorModule diff --git a/app/src/main/java/info/nightscout/androidaps/di/FragmentsModule.kt b/app/src/main/java/info/nightscout/androidaps/di/FragmentsModule.kt index e272765167..63f422301e 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/FragmentsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/FragmentsModule.kt @@ -28,13 +28,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesFragment import info.nightscout.androidaps.plugins.constraints.objectives.activities.ObjectivesExamDialog import info.nightscout.androidaps.plugins.general.actions.ActionsFragment -import info.nightscout.androidaps.plugins.general.automation.AutomationFragment -import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseActionDialog -import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseOperationDialog -import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseTriggerDialog -import info.nightscout.androidaps.plugins.general.automation.dialogs.EditActionDialog -import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog -import info.nightscout.androidaps.plugins.general.automation.dialogs.EditTriggerDialog import info.nightscout.androidaps.plugins.general.autotune.AutotuneFragment import info.nightscout.androidaps.plugins.general.food.FoodFragment import info.nightscout.androidaps.plugins.general.maintenance.MaintenanceFragment @@ -55,7 +48,6 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesPreferencesFragment(): MyPreferenceFragment @ContributesAndroidInjector abstract fun contributesActionsFragment(): ActionsFragment - @ContributesAndroidInjector abstract fun contributesAutomationFragment(): AutomationFragment @ContributesAndroidInjector abstract fun contributesAutotuneFragment(): AutotuneFragment @ContributesAndroidInjector abstract fun contributesBGSourceFragment(): BGSourceFragment @@ -83,17 +75,11 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesVirtualPumpFragment(): VirtualPumpFragment @ContributesAndroidInjector abstract fun contributesCareDialog(): CareDialog - @ContributesAndroidInjector abstract fun contributesEditActionDialog(): EditActionDialog - @ContributesAndroidInjector abstract fun contributesEditEventDialog(): EditEventDialog - @ContributesAndroidInjector abstract fun contributesEditTriggerDialog(): EditTriggerDialog @ContributesAndroidInjector abstract fun contributesEditQuickWizardDialog(): EditQuickWizardDialog @ContributesAndroidInjector abstract fun contributesExtendedBolusDialog(): ExtendedBolusDialog @ContributesAndroidInjector abstract fun contributesFillDialog(): FillDialog - @ContributesAndroidInjector abstract fun contributesChooseActionDialog(): ChooseActionDialog - @ContributesAndroidInjector abstract fun contributesChooseTriggerDialog(): ChooseTriggerDialog - @ContributesAndroidInjector abstract fun contributesChooseOperationDialog(): ChooseOperationDialog @ContributesAndroidInjector abstract fun contributesInsulinDialog(): InsulinDialog @ContributesAndroidInjector abstract fun contributesLoopDialog(): LoopDialog @ContributesAndroidInjector abstract fun contributesObjectivesExamDialog(): ObjectivesExamDialog diff --git a/app/src/main/java/info/nightscout/androidaps/di/PluginsModule.kt b/app/src/main/java/info/nightscout/androidaps/di/PluginsModule.kt index 70fbaa5a9e..03988e828a 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/PluginsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/PluginsModule.kt @@ -24,7 +24,6 @@ import info.nightscout.androidaps.plugins.constraints.signatureVerifier.Signatur import info.nightscout.androidaps.plugins.constraints.storage.StorageConstraintPlugin import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerPlugin import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin -import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin import info.nightscout.androidaps.plugins.general.autotune.AutotunePlugin import info.nightscout.androidaps.plugins.general.dataBroadcaster.DataBroadcastPlugin import info.nightscout.androidaps.plugins.general.food.FoodPlugin @@ -32,15 +31,10 @@ import info.nightscout.androidaps.plugins.general.maintenance.MaintenancePlugin import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin -import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin import info.nightscout.androidaps.plugins.general.themes.ThemeSwitcherPlugin import info.nightscout.androidaps.plugins.general.tidepool.TidepoolPlugin import info.nightscout.androidaps.plugins.general.wear.WearPlugin import info.nightscout.androidaps.plugins.general.xdripStatusline.StatusLinePlugin -import info.nightscout.plugins.insulin.InsulinLyumjevPlugin -import info.nightscout.plugins.insulin.InsulinOrefFreePeakPlugin -import info.nightscout.plugins.insulin.InsulinOrefRapidActingPlugin -import info.nightscout.plugins.insulin.InsulinOrefUltraRapidActingPlugin import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin @@ -53,7 +47,23 @@ import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin -import info.nightscout.androidaps.plugins.source.* +import info.nightscout.androidaps.plugins.source.AidexPlugin +import info.nightscout.androidaps.plugins.source.DexcomPlugin +import info.nightscout.androidaps.plugins.source.GlimpPlugin +import info.nightscout.androidaps.plugins.source.GlunovoPlugin +import info.nightscout.androidaps.plugins.source.IntelligoPlugin +import info.nightscout.androidaps.plugins.source.MM640gPlugin +import info.nightscout.androidaps.plugins.source.NSClientSourcePlugin +import info.nightscout.androidaps.plugins.source.PoctechPlugin +import info.nightscout.androidaps.plugins.source.RandomBgPlugin +import info.nightscout.androidaps.plugins.source.TomatoPlugin +import info.nightscout.androidaps.plugins.source.XdripPlugin +import info.nightscout.automation.AutomationPlugin +import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin +import info.nightscout.plugins.insulin.InsulinLyumjevPlugin +import info.nightscout.plugins.insulin.InsulinOrefFreePeakPlugin +import info.nightscout.plugins.insulin.InsulinOrefRapidActingPlugin +import info.nightscout.plugins.insulin.InsulinOrefUltraRapidActingPlugin import javax.inject.Qualifier @Suppress("unused") diff --git a/app/src/main/java/info/nightscout/androidaps/di/ServicesModule.kt b/app/src/main/java/info/nightscout/androidaps/di/ServicesModule.kt index 9fc54fa7cf..83dcefc853 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/ServicesModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/ServicesModule.kt @@ -7,7 +7,7 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Dismiss import info.nightscout.androidaps.plugins.general.persistentNotification.DummyService import info.nightscout.androidaps.plugins.general.wear.wearintegration.DataLayerListenerServiceMobile import info.nightscout.androidaps.services.AlarmSoundService -import info.nightscout.androidaps.services.LocationService +import info.nightscout.automation.services.LocationService @Module @Suppress("unused") diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt index 452e9606e5..37e74bef84 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt @@ -16,9 +16,9 @@ import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivityNames import info.nightscout.androidaps.interfaces.CommandQueue import info.nightscout.androidaps.interfaces.Constraint +import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.ToastUtils @@ -28,7 +28,7 @@ import info.nightscout.androidaps.utils.protection.ProtectionCheck.Protection.BO import info.nightscout.shared.SafeParse import info.nightscout.shared.logging.LTag import java.text.DecimalFormat -import java.util.* +import java.util.LinkedList import javax.inject.Inject import kotlin.math.abs @@ -55,8 +55,10 @@ class ExtendedBolusDialog : DialogFragmentWithDate() { savedInstanceState.putDouble("duration", binding.duration.value) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { onCreateViewGeneral() _binding = DialogExtendedbolusBinding.inflate(inflater, container, false) return binding.root @@ -69,13 +71,17 @@ class ExtendedBolusDialog : DialogFragmentWithDate() { val maxInsulin = constraintChecker.getMaxExtendedBolusAllowed().value() val extendedStep = pumpDescription.extendedBolusStep - binding.insulin.setParams(savedInstanceState?.getDouble("insulin") - ?: extendedStep, extendedStep, maxInsulin, extendedStep, DecimalFormat("0.00"), false, binding.okcancel.ok) + binding.insulin.setParams( + savedInstanceState?.getDouble("insulin") + ?: extendedStep, extendedStep, maxInsulin, extendedStep, DecimalFormat("0.00"), false, binding.okcancel.ok + ) val extendedDurationStep = pumpDescription.extendedBolusDurationStep val extendedMaxDuration = pumpDescription.extendedBolusMaxDuration - binding.duration.setParams(savedInstanceState?.getDouble("duration") - ?: extendedDurationStep, extendedDurationStep, extendedMaxDuration, extendedDurationStep, DecimalFormat("0"), false, binding.okcancel.ok) + binding.duration.setParams( + savedInstanceState?.getDouble("duration") + ?: extendedDurationStep, extendedDurationStep, extendedMaxDuration, extendedDurationStep, DecimalFormat("0"), false, binding.okcancel.ok + ) binding.insulinLabel.labelFor = binding.insulin.editTextId binding.durationLabel.labelFor = binding.duration.editTextId } @@ -98,9 +104,11 @@ class ExtendedBolusDialog : DialogFragmentWithDate() { activity?.let { activity -> OKDialog.showConfirmation(activity, rh.gs(R.string.extended_bolus), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), { - uel.log(Action.EXTENDED_BOLUS, Sources.ExtendedBolusDialog, + uel.log( + Action.EXTENDED_BOLUS, Sources.ExtendedBolusDialog, ValueWithUnit.Insulin(insulinAfterConstraint), - ValueWithUnit.Minute(durationInMinutes)) + ValueWithUnit.Minute(durationInMinutes) + ) commandQueue.extendedBolus(insulinAfterConstraint, durationInMinutes, object : Callback() { override fun run() { if (!result.success) { @@ -115,12 +123,12 @@ class ExtendedBolusDialog : DialogFragmentWithDate() { override fun onResume() { super.onResume() - if(!queryingProtection) { + if (!queryingProtection) { queryingProtection = true activity?.let { activity -> val cancelFail = { queryingProtection = false - aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.simpleName}") ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt index f9e0848e9b..383ac76b9c 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt @@ -20,9 +20,9 @@ import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivityNames import info.nightscout.androidaps.interfaces.CommandQueue import info.nightscout.androidaps.interfaces.Constraint +import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.HtmlHelper @@ -34,7 +34,7 @@ import info.nightscout.shared.SafeParse import info.nightscout.shared.logging.LTag import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign -import java.util.* +import java.util.LinkedList import javax.inject.Inject import kotlin.math.abs @@ -62,8 +62,10 @@ class FillDialog : DialogFragmentWithDate() { savedInstanceState.putDouble("fill_insulin_amount", binding.fillInsulinamount.value) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { onCreateViewGeneral() _binding = DialogFillBinding.inflate(inflater, container, false) return binding.root @@ -74,8 +76,10 @@ class FillDialog : DialogFragmentWithDate() { val maxInsulin = constraintChecker.getMaxBolusAllowed().value() val bolusStep = activePlugin.activePump.pumpDescription.bolusStep - binding.fillInsulinamount.setParams(savedInstanceState?.getDouble("fill_insulin_amount") - ?: 0.0, 0.0, maxInsulin, bolusStep, DecimalFormatter.pumpSupportedBolusFormat(activePlugin.activePump), true, binding.okcancel.ok) + binding.fillInsulinamount.setParams( + savedInstanceState?.getDouble("fill_insulin_amount") + ?: 0.0, 0.0, maxInsulin, bolusStep, DecimalFormatter.pumpSupportedBolusFormat(activePlugin.activePump), true, binding.okcancel.ok + ) val amount1 = sp.getDouble("fill_button1", 0.3) if (amount1 > 0) { binding.fillPresetButton1.visibility = View.VISIBLE @@ -140,37 +144,45 @@ class FillDialog : DialogFragmentWithDate() { OKDialog.showConfirmation(activity, rh.gs(R.string.primefill), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), { if (insulinAfterConstraints > 0) { uel.log(Action.PRIME_BOLUS, Sources.FillDialog, - notes, - ValueWithUnit.Insulin(insulinAfterConstraints).takeIf { insulinAfterConstraints != 0.0 }) + notes, + ValueWithUnit.Insulin(insulinAfterConstraints)) requestPrimeBolus(insulinAfterConstraints, notes) } if (siteChange) { - uel.log(Action.SITE_CHANGE, Sources.FillDialog, + uel.log( + Action.SITE_CHANGE, Sources.FillDialog, notes, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, - ValueWithUnit.TherapyEventType(TherapyEvent.Type.CANNULA_CHANGE)) - disposable += repository.runTransactionForResult(InsertIfNewByTimestampTherapyEventTransaction( - timestamp = eventTime, - type = TherapyEvent.Type.CANNULA_CHANGE, - note = notes, - glucoseUnit = TherapyEvent.GlucoseUnit.MGDL - )).subscribe( + ValueWithUnit.TherapyEventType(TherapyEvent.Type.CANNULA_CHANGE) + ) + disposable += repository.runTransactionForResult( + InsertIfNewByTimestampTherapyEventTransaction( + timestamp = eventTime, + type = TherapyEvent.Type.CANNULA_CHANGE, + note = notes, + glucoseUnit = TherapyEvent.GlucoseUnit.MGDL + ) + ).subscribe( { result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted therapy event $it") } }, { aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it) } ) } if (insulinChange) { // add a second for case of both checked - uel.log(Action.RESERVOIR_CHANGE, Sources.FillDialog, + uel.log( + Action.RESERVOIR_CHANGE, Sources.FillDialog, notes, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, - ValueWithUnit.TherapyEventType(TherapyEvent.Type.INSULIN_CHANGE)) - disposable += repository.runTransactionForResult(InsertIfNewByTimestampTherapyEventTransaction( - timestamp = eventTime + 1000, - type = TherapyEvent.Type.INSULIN_CHANGE, - note = notes, - glucoseUnit = TherapyEvent.GlucoseUnit.MGDL - )).subscribe( + ValueWithUnit.TherapyEventType(TherapyEvent.Type.INSULIN_CHANGE) + ) + disposable += repository.runTransactionForResult( + InsertIfNewByTimestampTherapyEventTransaction( + timestamp = eventTime + 1000, + type = TherapyEvent.Type.INSULIN_CHANGE, + note = notes, + glucoseUnit = TherapyEvent.GlucoseUnit.MGDL + ) + ).subscribe( { result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted therapy event $it") } }, { aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it) } ) @@ -203,12 +215,12 @@ class FillDialog : DialogFragmentWithDate() { override fun onResume() { super.onResume() - if(!queryingProtection) { + if (!queryingProtection) { queryingProtection = true activity?.let { activity -> val cancelFail = { queryingProtection = false - aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.simpleName}") ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt index 0f8dafe47c..55498fbea7 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt @@ -19,11 +19,24 @@ import info.nightscout.androidaps.database.transactions.InsertAndCancelCurrentTe import info.nightscout.androidaps.databinding.DialogInsulinBinding import info.nightscout.androidaps.extensions.formatColor import info.nightscout.androidaps.extensions.toVisibility -import info.nightscout.androidaps.interfaces.* -import info.nightscout.androidaps.logging.UserEntryLogger +import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.ActivityNames +import info.nightscout.androidaps.interfaces.BolusTimer +import info.nightscout.androidaps.interfaces.CommandQueue +import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraints +import info.nightscout.androidaps.interfaces.GlucoseUnit +import info.nightscout.androidaps.interfaces.Profile +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.queue.Callback -import info.nightscout.androidaps.utils.* +import info.nightscout.androidaps.utils.DecimalFormatter +import info.nightscout.androidaps.utils.DefaultValueHelper +import info.nightscout.androidaps.utils.HtmlHelper +import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.extensions.toSignedString import info.nightscout.androidaps.utils.protection.ProtectionCheck @@ -33,7 +46,7 @@ import info.nightscout.shared.logging.LTag import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import java.text.DecimalFormat -import java.util.* +import java.util.LinkedList import java.util.concurrent.TimeUnit import javax.inject.Inject import kotlin.math.abs @@ -96,8 +109,10 @@ class InsulinDialog : DialogFragmentWithDate() { savedInstanceState.putDouble("amount", binding.amount.value) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { onCreateViewGeneral() _binding = DialogInsulinBinding.inflate(inflater, container, false) return binding.root @@ -112,17 +127,23 @@ class InsulinDialog : DialogFragmentWithDate() { } val maxInsulin = constraintChecker.getMaxBolusAllowed().value() - binding.time.setParams(savedInstanceState?.getDouble("time") - ?: 0.0, -12 * 60.0, 12 * 60.0, 5.0, DecimalFormat("0"), false, binding.okcancel.ok, textWatcher) - binding.amount.setParams(savedInstanceState?.getDouble("amount") - ?: 0.0, 0.0, maxInsulin, activePlugin.activePump.pumpDescription.bolusStep, DecimalFormatter.pumpSupportedBolusFormat(activePlugin.activePump), false, binding.okcancel.ok, textWatcher) + binding.time.setParams( + savedInstanceState?.getDouble("time") + ?: 0.0, -12 * 60.0, 12 * 60.0, 5.0, DecimalFormat("0"), false, binding.okcancel.ok, textWatcher + ) + binding.amount.setParams( + savedInstanceState?.getDouble("amount") + ?: 0.0, 0.0, maxInsulin, activePlugin.activePump.pumpDescription.bolusStep, DecimalFormatter.pumpSupportedBolusFormat(activePlugin.activePump), false, binding.okcancel.ok, textWatcher + ) val plus05Text = sp.getDouble(rh.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT).toSignedString(activePlugin.activePump) binding.plus05.text = plus05Text binding.plus05.contentDescription = rh.gs(R.string.overview_insulin_label) + " " + plus05Text binding.plus05.setOnClickListener { - binding.amount.value = max(0.0, binding.amount.value - + sp.getDouble(rh.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT)) + binding.amount.value = max( + 0.0, binding.amount.value + + sp.getDouble(rh.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT) + ) validateInputs() binding.amount.announceValue() } @@ -130,8 +151,10 @@ class InsulinDialog : DialogFragmentWithDate() { binding.plus10.text = plus10Text binding.plus10.contentDescription = rh.gs(R.string.overview_insulin_label) + " " + plus10Text binding.plus10.setOnClickListener { - binding.amount.value = max(0.0, binding.amount.value - + sp.getDouble(rh.gs(R.string.key_insulin_button_increment_2), PLUS2_DEFAULT)) + binding.amount.value = max( + 0.0, binding.amount.value + + sp.getDouble(rh.gs(R.string.key_insulin_button_increment_2), PLUS2_DEFAULT) + ) validateInputs() binding.amount.announceValue() } @@ -139,8 +162,10 @@ class InsulinDialog : DialogFragmentWithDate() { binding.plus20.text = plus20Text binding.plus20.contentDescription = rh.gs(R.string.overview_insulin_label) + " " + plus20Text binding.plus20.setOnClickListener { - binding.amount.value = max(0.0, binding.amount.value - + sp.getDouble(rh.gs(R.string.key_insulin_button_increment_3), PLUS3_DEFAULT)) + binding.amount.value = max( + 0.0, binding.amount.value + + sp.getDouble(rh.gs(R.string.key_insulin_button_increment_3), PLUS3_DEFAULT) + ) validateInputs() binding.amount.announceValue() } @@ -180,8 +205,10 @@ class InsulinDialog : DialogFragmentWithDate() { val eatingSoonTTDuration = defaultValueHelper.determineEatingSoonTTDuration() val eatingSoonTT = defaultValueHelper.determineEatingSoonTT() if (eatingSoonChecked) - actions.add(rh.gs(R.string.temp_target_short) + ": " + (DecimalFormatter.to1Decimal(eatingSoonTT) + " " + unitLabel + " (" + rh.gs(R.string.format_mins, eatingSoonTTDuration) + ")") - .formatColor(context, rh, R.attr.tempTargetConfirmation)) + actions.add( + rh.gs(R.string.temp_target_short) + ": " + (DecimalFormatter.to1Decimal(eatingSoonTT) + " " + unitLabel + " (" + rh.gs(R.string.format_mins, eatingSoonTTDuration) + ")") + .formatColor(context, rh, R.attr.tempTargetConfirmation) + ) val timeOffset = binding.time.value.toInt() val time = dateUtil.now() + T.mins(timeOffset.toLong()).msecs() @@ -196,23 +223,27 @@ class InsulinDialog : DialogFragmentWithDate() { activity?.let { activity -> OKDialog.showConfirmation(activity, rh.gs(R.string.bolus), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), { if (eatingSoonChecked) { - uel.log(Action.TT, Sources.InsulinDialog, + uel.log( + Action.TT, Sources.InsulinDialog, notes, ValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.EATING_SOON), ValueWithUnit.fromGlucoseUnit(eatingSoonTT, units.asText), - ValueWithUnit.Minute(eatingSoonTTDuration)) - disposable += repository.runTransactionForResult(InsertAndCancelCurrentTemporaryTargetTransaction( - timestamp = System.currentTimeMillis(), - duration = TimeUnit.MINUTES.toMillis(eatingSoonTTDuration.toLong()), - reason = TemporaryTarget.Reason.EATING_SOON, - lowTarget = Profile.toMgdl(eatingSoonTT, profileFunction.getUnits()), - highTarget = Profile.toMgdl(eatingSoonTT, profileFunction.getUnits()) - )).subscribe({ result -> - result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") } - result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") } - }, { - aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it) - }) + ValueWithUnit.Minute(eatingSoonTTDuration) + ) + disposable += repository.runTransactionForResult( + InsertAndCancelCurrentTemporaryTargetTransaction( + timestamp = System.currentTimeMillis(), + duration = TimeUnit.MINUTES.toMillis(eatingSoonTTDuration.toLong()), + reason = TemporaryTarget.Reason.EATING_SOON, + lowTarget = Profile.toMgdl(eatingSoonTT, profileFunction.getUnits()), + highTarget = Profile.toMgdl(eatingSoonTT, profileFunction.getUnits()) + ) + ).subscribe({ result -> + result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") } + result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") } + }, { + aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it) + }) } if (insulinAfterConstraints > 0) { val detailedBolusInfo = DetailedBolusInfo() @@ -223,10 +254,10 @@ class InsulinDialog : DialogFragmentWithDate() { detailedBolusInfo.timestamp = time if (recordOnlyChecked) { uel.log(Action.BOLUS, Sources.InsulinDialog, - rh.gs(R.string.record) + if (notes.isNotEmpty()) ": " + notes else "", - ValueWithUnit.SimpleString(rh.gsNotLocalised(R.string.record)), - ValueWithUnit.Insulin(insulinAfterConstraints), - ValueWithUnit.Minute(timeOffset).takeIf { timeOffset!= 0 }) + rh.gs(R.string.record) + if (notes.isNotEmpty()) ": $notes" else "", + ValueWithUnit.SimpleString(rh.gsNotLocalised(R.string.record)), + ValueWithUnit.Insulin(insulinAfterConstraints), + ValueWithUnit.Minute(timeOffset).takeIf { timeOffset != 0 }) disposable += repository.runTransactionForResult(detailedBolusInfo.insertBolusTransaction()) .subscribe( { result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it") } }, @@ -235,9 +266,11 @@ class InsulinDialog : DialogFragmentWithDate() { if (timeOffset == 0) bolusTimer.removeAutomationEventBolusReminder() } else { - uel.log(Action.BOLUS, Sources.InsulinDialog, + uel.log( + Action.BOLUS, Sources.InsulinDialog, notes, - ValueWithUnit.Insulin(insulinAfterConstraints)) + ValueWithUnit.Insulin(insulinAfterConstraints) + ) commandQueue.bolus(detailedBolusInfo, object : Callback() { override fun run() { if (!result.success) { @@ -260,12 +293,12 @@ class InsulinDialog : DialogFragmentWithDate() { override fun onResume() { super.onResume() - if(!queryingProtection) { + if (!queryingProtection) { queryingProtection = true activity?.let { activity -> val cancelFail = { queryingProtection = false - aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.simpleName}") ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt index d04fcb3105..8e001e348c 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt @@ -29,6 +29,7 @@ import info.nightscout.androidaps.interfaces.ActivityNames import info.nightscout.androidaps.interfaces.CommandQueue import info.nightscout.androidaps.interfaces.ConfigBuilder import info.nightscout.androidaps.interfaces.Constraint +import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginType @@ -37,7 +38,6 @@ import info.nightscout.androidaps.interfaces.PumpDescription import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.DateUtil @@ -457,7 +457,7 @@ class LoopDialog : DaggerDialogFragment() { activity?.let { activity -> val cancelFail = { queryingProtection = false - aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.simpleName}") ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt index a3e410e826..37a2aef807 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt @@ -24,7 +24,7 @@ import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.shared.logging.LTag +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.DefaultValueHelper @@ -35,14 +35,13 @@ import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.protection.ProtectionCheck.Protection.BOLUS -import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.shared.logging.LTag import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import java.text.DecimalFormat -import java.util.* +import java.util.LinkedList import java.util.concurrent.TimeUnit import javax.inject.Inject -import kotlin.collections.ArrayList class ProfileSwitchDialog : DialogFragmentWithDate() { @@ -257,7 +256,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() { activity?.let { activity -> val cancelFail = { queryingProtection = false - aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.simpleName}") ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt index 6e07438101..02db55fd02 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt @@ -12,9 +12,16 @@ import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.database.entities.ValueWithUnit import info.nightscout.androidaps.databinding.DialogTempbasalBinding import info.nightscout.androidaps.extensions.formatColor -import info.nightscout.androidaps.interfaces.* -import info.nightscout.androidaps.logging.UserEntryLogger +import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.ActivityNames +import info.nightscout.androidaps.interfaces.CommandQueue +import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraints +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.PumpDescription +import info.nightscout.androidaps.interfaces.PumpSync +import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.ToastUtils @@ -24,7 +31,7 @@ import info.nightscout.androidaps.utils.protection.ProtectionCheck.Protection.BO import info.nightscout.shared.SafeParse import info.nightscout.shared.logging.LTag import java.text.DecimalFormat -import java.util.* +import java.util.LinkedList import javax.inject.Inject import kotlin.math.abs @@ -151,7 +158,7 @@ class TempBasalDialog : DialogFragmentWithDate() { activity?.let { activity -> val cancelFail = { queryingProtection = false - aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.simpleName}") ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt index de278cb854..d445de8dcb 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt @@ -10,32 +10,32 @@ import com.google.common.base.Joiner import com.google.common.collect.Lists import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R -import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.ValueWrapper -import info.nightscout.androidaps.database.entities.ValueWithUnit import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Sources +import info.nightscout.androidaps.database.entities.ValueWithUnit import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction import info.nightscout.androidaps.database.transactions.InsertAndCancelCurrentTemporaryTargetTransaction import info.nightscout.androidaps.databinding.DialogTemptargetBinding -import info.nightscout.androidaps.interfaces.GlucoseUnit -import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.interfaces.Constraints +import info.nightscout.androidaps.interfaces.GlucoseUnit +import info.nightscout.androidaps.interfaces.Profile +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.protection.ProtectionCheck.Protection.BOLUS -import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.shared.logging.LTag import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import java.text.DecimalFormat -import java.util.* +import java.util.LinkedList import java.util.concurrent.TimeUnit import javax.inject.Inject @@ -229,7 +229,7 @@ class TempTargetDialog : DialogFragmentWithDate() { activity?.let { activity -> val cancelFail = { queryingProtection = false - aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.simpleName}") ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt index 2424be5d47..595a4026ec 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt @@ -21,9 +21,9 @@ import info.nightscout.androidaps.interfaces.ActivityNames import info.nightscout.androidaps.interfaces.CommandQueue import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Constraint +import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.HtmlHelper @@ -36,7 +36,7 @@ import info.nightscout.shared.logging.LTag import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import java.text.DecimalFormat -import java.util.* +import java.util.LinkedList import javax.inject.Inject import kotlin.math.abs @@ -212,7 +212,7 @@ class TreatmentDialog : DialogFragmentWithDate() { activity?.let { activity -> val cancelFail = { queryingProtection = false - aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.simpleName}") ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt index 7918dffd31..504f5df0bb 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt @@ -29,13 +29,23 @@ import info.nightscout.androidaps.extensions.formatColor import info.nightscout.androidaps.extensions.runOnUiThread import info.nightscout.androidaps.extensions.toVisibility import info.nightscout.androidaps.extensions.valueToUnits -import info.nightscout.androidaps.interfaces.* -import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraints -import info.nightscout.androidaps.utils.* +import info.nightscout.androidaps.interfaces.GlucoseUnit +import info.nightscout.androidaps.interfaces.IobCobCalculator +import info.nightscout.androidaps.interfaces.Profile +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.DecimalFormatter +import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.HtmlHelper +import info.nightscout.androidaps.utils.Round +import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.protection.ProtectionCheck.Protection.BOLUS -import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.wizard.BolusWizard import info.nightscout.shared.SafeParse @@ -105,7 +115,7 @@ class WizardDialog : DaggerDialogFragment() { override fun onStart() { super.onStart() dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) - aapsLogger.debug(LTag.APS, "Dialog opened: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog opened: ${this.javaClass.simpleName}") } override fun onSaveInstanceState(savedInstanceState: Bundle) { @@ -189,7 +199,7 @@ class WizardDialog : DaggerDialogFragment() { context?.let { context -> wizard?.confirmAndExecute(context) } - aapsLogger.debug(LTag.APS, "Dialog ok pressed: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog ok pressed: ${this.javaClass.simpleName}") } dismiss() } @@ -200,7 +210,7 @@ class WizardDialog : DaggerDialogFragment() { binding.iobCheckboxIcon.setOnClickListener { binding.iobCheckbox.isChecked = !binding.iobCheckbox.isChecked; processIobCheckBox(); } // cancel button binding.okcancel.cancel.setOnClickListener { - aapsLogger.debug(LTag.APS, "Dialog canceled: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog canceled: ${this.javaClass.simpleName}") dismiss() } // checkboxes @@ -512,7 +522,7 @@ class WizardDialog : DaggerDialogFragment() { activity?.let { activity -> val cancelFail = { queryingProtection = false - aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.simpleName}") ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImpl.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImpl.kt index dc79e8df30..992a18bd64 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImpl.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImpl.kt @@ -9,7 +9,13 @@ import info.nightscout.androidaps.database.entities.ProfileSwitch import info.nightscout.androidaps.database.transactions.InsertOrUpdateProfileSwitch import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged import info.nightscout.androidaps.extensions.fromConstant -import info.nightscout.androidaps.interfaces.* +import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.GlucoseUnit +import info.nightscout.androidaps.interfaces.Profile +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.ProfileStore +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.nsclient.data.DeviceStatusData import info.nightscout.androidaps.utils.DateUtil @@ -42,7 +48,7 @@ class ProfileFunctionImpl @Inject constructor( private val deviceStatusData: DeviceStatusData ) : ProfileFunction { - var cache = ConcurrentHashMap() + private var cache = ConcurrentHashMap() private val disposable = CompositeDisposable() @@ -177,7 +183,7 @@ class ProfileFunctionImpl @Inject constructor( val profileStore = activePlugin.activeProfileSource.profile ?: return false val ps = buildProfileSwitch(profileStore, profile.profileName, durationInMinutes, percentage, 0, dateUtil.now()) ?: return false val validity = ProfileSealed.PS(ps).isValid( - rh.gs(info.nightscout.androidaps.automation.R.string.careportal_profileswitch), + rh.gs(info.nightscout.automation.R.string.careportal_profileswitch), activePlugin.activePump, config, rh, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 36e03d8911..06647300df 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -76,7 +76,6 @@ import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotifi import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalResultSMB import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.constraints.bgQualityCheck.BgQualityCheckPlugin -import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewCalcProgress @@ -103,6 +102,7 @@ import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.ui.SingleClickButton import info.nightscout.androidaps.utils.ui.UIRunnable import info.nightscout.androidaps.utils.wizard.QuickWizard +import info.nightscout.automation.AutomationPlugin import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.weardata.EventData diff --git a/automation/build.gradle b/automation/build.gradle index 6c80e0f396..c938522da0 100644 --- a/automation/build.gradle +++ b/automation/build.gradle @@ -9,7 +9,7 @@ apply from: "${project.rootDir}/core/android_module_dependencies.gradle" apply from: "${project.rootDir}/core/test_dependencies.gradle" apply from: "${project.rootDir}/core/jacoco_global.gradle" android { - namespace 'info.nightscout.androidaps.automation' + namespace 'info.nightscout.automation' } dependencies { diff --git a/automation/src/main/AndroidManifest.xml b/automation/src/main/AndroidManifest.xml index 94da5bcfde..22e49c0cef 100644 --- a/automation/src/main/AndroidManifest.xml +++ b/automation/src/main/AndroidManifest.xml @@ -7,7 +7,7 @@ diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationAddAction.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationAddAction.kt deleted file mode 100644 index 867550e2f4..0000000000 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationAddAction.kt +++ /dev/null @@ -1,6 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.events - -import info.nightscout.androidaps.events.Event -import info.nightscout.androidaps.plugins.general.automation.actions.Action - -class EventAutomationAddAction(val action: Action) : Event() diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationUpdateAction.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationUpdateAction.kt deleted file mode 100644 index 3def1053ac..0000000000 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationUpdateAction.kt +++ /dev/null @@ -1,6 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.events - -import info.nightscout.androidaps.events.Event -import info.nightscout.androidaps.plugins.general.automation.actions.Action - -class EventAutomationUpdateAction(val action: Action, val position: Int) : Event() \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationUpdateTrigger.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationUpdateTrigger.kt deleted file mode 100644 index 4ba39c7461..0000000000 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationUpdateTrigger.kt +++ /dev/null @@ -1,6 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.events - -import info.nightscout.androidaps.events.Event -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector - -class EventAutomationUpdateTrigger(val trigger: TriggerConnector) : Event() diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventTriggerClone.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventTriggerClone.kt deleted file mode 100644 index 3bb996a642..0000000000 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventTriggerClone.kt +++ /dev/null @@ -1,6 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.events - -import info.nightscout.androidaps.events.Event -import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger - -class EventTriggerClone(val trigger: Trigger) : Event() \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventTriggerRemove.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventTriggerRemove.kt deleted file mode 100644 index 6c502a10f5..0000000000 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventTriggerRemove.kt +++ /dev/null @@ -1,6 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.events - -import info.nightscout.androidaps.events.Event -import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger - -class EventTriggerRemove(val trigger: Trigger) : Event() \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt b/automation/src/main/java/info/nightscout/automation/AutomationEvent.kt similarity index 86% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt rename to automation/src/main/java/info/nightscout/automation/AutomationEvent.kt index 6657204f97..9b70ea5232 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt +++ b/automation/src/main/java/info/nightscout/automation/AutomationEvent.kt @@ -1,17 +1,16 @@ -package info.nightscout.androidaps.plugins.general.automation +package info.nightscout.automation import dagger.android.HasAndroidInjector -import info.nightscout.shared.logging.AAPSLogger -import info.nightscout.androidaps.plugins.general.automation.actions.Action -import info.nightscout.androidaps.plugins.general.automation.actions.ActionDummy -import info.nightscout.androidaps.plugins.general.automation.actions.ActionStopProcessing -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.T +import info.nightscout.automation.actions.Action +import info.nightscout.automation.actions.ActionDummy +import info.nightscout.automation.actions.ActionStopProcessing +import info.nightscout.automation.triggers.TriggerConnector +import info.nightscout.automation.triggers.TriggerDummy +import info.nightscout.shared.logging.AAPSLogger import org.json.JSONArray import org.json.JSONObject -import java.util.* import javax.inject.Inject class AutomationEvent(private val injector: HasAndroidInjector) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt b/automation/src/main/java/info/nightscout/automation/AutomationFragment.kt similarity index 95% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt rename to automation/src/main/java/info/nightscout/automation/AutomationFragment.kt index dbbb566b54..4d775cf789 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt +++ b/automation/src/main/java/info/nightscout/automation/AutomationFragment.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation +package info.nightscout.automation import android.annotation.SuppressLint import android.content.Context @@ -23,19 +23,12 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import dagger.android.HasAndroidInjector import dagger.android.support.DaggerFragment -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.automation.databinding.AutomationEventItemBinding -import info.nightscout.androidaps.automation.databinding.AutomationFragmentBinding import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.extensions.toVisibility import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog -import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged -import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector import info.nightscout.androidaps.utils.ActionModeHelper import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.HtmlHelper @@ -44,6 +37,12 @@ import info.nightscout.androidaps.utils.dragHelpers.ItemTouchHelperAdapter import info.nightscout.androidaps.utils.dragHelpers.OnStartDragListener import info.nightscout.androidaps.utils.dragHelpers.SimpleItemTouchHelperCallback import info.nightscout.androidaps.utils.rx.AapsSchedulers +import info.nightscout.automation.databinding.AutomationEventItemBinding +import info.nightscout.automation.databinding.AutomationFragmentBinding +import info.nightscout.automation.dialogs.EditEventDialog +import info.nightscout.automation.events.EventAutomationDataChanged +import info.nightscout.automation.events.EventAutomationUpdateGui +import info.nightscout.automation.triggers.TriggerConnector import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import javax.inject.Inject diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt b/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt similarity index 81% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt rename to automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt index fc67a6e217..3061decaa5 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt +++ b/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation +package info.nightscout.automation import android.content.Context import android.os.Handler @@ -6,25 +6,57 @@ import android.os.HandlerThread import android.os.SystemClock import dagger.android.HasAndroidInjector import info.nightscout.androidaps.annotations.OpenForTesting -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.events.EventBTChange import info.nightscout.androidaps.events.EventChargingState -import info.nightscout.androidaps.events.EventLocationChange import info.nightscout.androidaps.events.EventNetworkChange import info.nightscout.androidaps.events.EventPreferenceChange -import info.nightscout.androidaps.interfaces.* -import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Constraints -import info.nightscout.androidaps.plugins.general.automation.actions.* -import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged -import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui -import info.nightscout.androidaps.plugins.general.automation.triggers.* +import info.nightscout.androidaps.interfaces.Loop +import info.nightscout.androidaps.interfaces.PluginBase +import info.nightscout.androidaps.interfaces.PluginDescription +import info.nightscout.androidaps.interfaces.PluginType +import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.queue.Callback -import info.nightscout.androidaps.services.LocationServiceHelper import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.rx.AapsSchedulers +import info.nightscout.automation.actions.Action +import info.nightscout.automation.actions.ActionAlarm +import info.nightscout.automation.actions.ActionCarePortalEvent +import info.nightscout.automation.actions.ActionNotification +import info.nightscout.automation.actions.ActionProfileSwitch +import info.nightscout.automation.actions.ActionProfileSwitchPercent +import info.nightscout.automation.actions.ActionRunAutotune +import info.nightscout.automation.actions.ActionSendSMS +import info.nightscout.automation.actions.ActionStartTempTarget +import info.nightscout.automation.actions.ActionStopProcessing +import info.nightscout.automation.actions.ActionStopTempTarget +import info.nightscout.automation.events.EventAutomationDataChanged +import info.nightscout.automation.events.EventAutomationUpdateGui +import info.nightscout.automation.events.EventLocationChange +import info.nightscout.automation.services.LocationServiceHelper +import info.nightscout.automation.triggers.Trigger +import info.nightscout.automation.triggers.TriggerAutosensValue +import info.nightscout.automation.triggers.TriggerBTDevice +import info.nightscout.automation.triggers.TriggerBg +import info.nightscout.automation.triggers.TriggerBolusAgo +import info.nightscout.automation.triggers.TriggerCOB +import info.nightscout.automation.triggers.TriggerConnector +import info.nightscout.automation.triggers.TriggerDelta +import info.nightscout.automation.triggers.TriggerIob +import info.nightscout.automation.triggers.TriggerLocation +import info.nightscout.automation.triggers.TriggerProfilePercent +import info.nightscout.automation.triggers.TriggerPumpLastConnection +import info.nightscout.automation.triggers.TriggerRecurringTime +import info.nightscout.automation.triggers.TriggerTempTarget +import info.nightscout.automation.triggers.TriggerTempTargetValue +import info.nightscout.automation.triggers.TriggerTime +import info.nightscout.automation.triggers.TriggerTimeRange +import info.nightscout.automation.triggers.TriggerWifiSsid import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.LTag import info.nightscout.shared.sharedPreferences.SP @@ -33,7 +65,7 @@ import io.reactivex.rxjava3.kotlin.plusAssign import org.json.JSONArray import org.json.JSONException import org.json.JSONObject -import java.util.* +import java.util.Collections import javax.inject.Inject import javax.inject.Singleton @@ -82,7 +114,7 @@ class AutomationPlugin @Inject constructor( companion object { const val event = - "{\"title\":\"Low\",\"enabled\":true,\"trigger\":\"{\\\"type\\\":\\\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector\\\",\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBg\\\\\\\",\\\\\\\"data\\\\\\\":{\\\\\\\"bg\\\\\\\":4,\\\\\\\"comparator\\\\\\\":\\\\\\\"IS_LESSER\\\\\\\",\\\\\\\"units\\\\\\\":\\\\\\\"mmol\\\\\\\"}}\\\",\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDelta\\\\\\\",\\\\\\\"data\\\\\\\":{\\\\\\\"value\\\\\\\":-0.1,\\\\\\\"units\\\\\\\":\\\\\\\"mmol\\\\\\\",\\\\\\\"deltaType\\\\\\\":\\\\\\\"DELTA\\\\\\\",\\\\\\\"comparator\\\\\\\":\\\\\\\"IS_LESSER\\\\\\\"}}\\\"]}}\",\"actions\":[\"{\\\"type\\\":\\\"info.nightscout.androidaps.plugins.general.automation.actions.ActionStartTempTarget\\\",\\\"data\\\":{\\\"value\\\":8,\\\"units\\\":\\\"mmol\\\",\\\"durationInMinutes\\\":60}}\"]}" + "{\"title\":\"Low\",\"enabled\":true,\"trigger\":\"{\\\"type\\\":\\\"TriggerConnector\\\",\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"TriggerBg\\\\\\\",\\\\\\\"data\\\\\\\":{\\\\\\\"bg\\\\\\\":4,\\\\\\\"comparator\\\\\\\":\\\\\\\"IS_LESSER\\\\\\\",\\\\\\\"units\\\\\\\":\\\\\\\"mmol\\\\\\\"}}\\\",\\\"{\\\\\\\"type\\\\\\\":\\\\\\\"TriggerDelta\\\\\\\",\\\\\\\"data\\\\\\\":{\\\\\\\"value\\\\\\\":-0.1,\\\\\\\"units\\\\\\\":\\\\\\\"mmol\\\\\\\",\\\\\\\"deltaType\\\\\\\":\\\\\\\"DELTA\\\\\\\",\\\\\\\"comparator\\\\\\\":\\\\\\\"IS_LESSER\\\\\\\"}}\\\"]}}\",\"actions\":[\"{\\\"type\\\":\\\"ActionStartTempTarget\\\",\\\"data\\\":{\\\"value\\\":8,\\\"units\\\":\\\"mmol\\\",\\\"durationInMinutes\\\":60}}\"]}" } init { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.kt b/automation/src/main/java/info/nightscout/automation/actions/Action.kt similarity index 74% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.kt rename to automation/src/main/java/info/nightscout/automation/actions/Action.kt index 5503d84d0c..0912187d79 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/Action.kt @@ -1,12 +1,12 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import android.widget.LinearLayout import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector -import info.nightscout.shared.logging.AAPSLogger -import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger -import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.triggers.Trigger +import info.nightscout.shared.logging.AAPSLogger import org.json.JSONException import org.json.JSONObject import javax.inject.Inject @@ -43,48 +43,33 @@ abstract class Action(val injector: HasAndroidInjector) { val obj = JSONObject(a.toJSON()) val type = obj.getString("type") val data = obj.getJSONObject("data") - if (type == javaClass.name) fromJSON(data.toString()) + if (type == javaClass.simpleName) fromJSON(data.toString()) } fun instantiate(obj: JSONObject): Action? { try { - val type = obj.getString("type") + var type = obj.getString("type") val data = if (obj.has("data")) obj.getJSONObject("data") else JSONObject() + // stripe off package name + val dotIndex = type.lastIndexOf('.') + if (dotIndex > 0) type = type.substring(dotIndex + 1) return when (type) { - ActionAlarm::class.java.name, // backward compatibility ActionAlarm::class.java.simpleName -> ActionAlarm(injector).fromJSON(data.toString()) - ActionCarePortalEvent::class.java.name, ActionCarePortalEvent::class.java.simpleName -> ActionCarePortalEvent(injector).fromJSON(data.toString()) - ActionDummy::class.java.name, ActionDummy::class.java.simpleName -> ActionDummy(injector).fromJSON(data.toString()) - ActionLoopDisable::class.java.name, ActionLoopDisable::class.java.simpleName -> ActionLoopDisable(injector).fromJSON(data.toString()) - ActionLoopEnable::class.java.name, ActionLoopEnable::class.java.simpleName -> ActionLoopEnable(injector).fromJSON(data.toString()) - ActionLoopResume::class.java.name, ActionLoopResume::class.java.simpleName -> ActionLoopResume(injector).fromJSON(data.toString()) - ActionLoopSuspend::class.java.name, ActionLoopSuspend::class.java.simpleName -> ActionLoopSuspend(injector).fromJSON(data.toString()) - ActionNotification::class.java.name, ActionNotification::class.java.simpleName -> ActionNotification(injector).fromJSON(data.toString()) - ActionProfileSwitch::class.java.name, ActionProfileSwitch::class.java.simpleName -> ActionProfileSwitch(injector).fromJSON(data.toString()) - ActionProfileSwitchPercent::class.java.name, ActionProfileSwitchPercent::class.java.simpleName -> ActionProfileSwitchPercent(injector).fromJSON(data.toString()) - ActionRunAutotune::class.java.name, ActionRunAutotune::class.java.simpleName -> ActionRunAutotune(injector).fromJSON(data.toString()) - ActionSendSMS::class.java.name, ActionSendSMS::class.java.simpleName -> ActionSendSMS(injector).fromJSON(data.toString()) - ActionStartTempTarget::class.java.name, ActionStartTempTarget::class.java.simpleName -> ActionStartTempTarget(injector).fromJSON(data.toString()) - ActionStopTempTarget::class.java.name, ActionStopTempTarget::class.java.simpleName -> ActionStopTempTarget(injector).fromJSON(data.toString()) else -> throw ClassNotFoundException(type) } - //val clazz = Class.forName(type).kotlin - //return (clazz.primaryConstructor?.call(injector) as Action).fromJSON(data?.toString() - // ?: "") - //return (clazz.newInstance() as Action).fromJSON(data?.toString() ?: "") } catch (e: ClassNotFoundException) { aapsLogger.error("Unhandled exception", e) } catch (e: InstantiationException) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionAlarm.kt similarity index 83% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionAlarm.kt index 4767d287a9..5b333d6865 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionAlarm.kt @@ -1,19 +1,19 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import android.content.Context import android.widget.LinearLayout import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.plugins.bus.RxBus -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.TimerUtil +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputString +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder import org.json.JSONObject import javax.inject.Inject @@ -45,7 +45,7 @@ class ActionAlarm(injector: HasAndroidInjector) : Action(injector) { override fun toJSON(): String { val data = JSONObject().put("text", text.value) return JSONObject() - .put("type", this.javaClass.name) + .put("type", this.javaClass.simpleName) .put("data", data) .toString() } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionCarePortalEvent.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionCarePortalEvent.kt similarity index 86% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionCarePortalEvent.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionCarePortalEvent.kt index 47d6679712..1eb043d055 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionCarePortalEvent.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionCarePortalEvent.kt @@ -1,9 +1,8 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import android.widget.LinearLayout import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.TherapyEvent import info.nightscout.androidaps.database.entities.UserEntry @@ -11,18 +10,19 @@ import info.nightscout.androidaps.database.entities.ValueWithUnit import info.nightscout.androidaps.database.transactions.InsertIfNewByTimestampTherapyEventTransaction import info.nightscout.androidaps.extensions.fromConstant import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.plugins.general.automation.elements.InputCarePortalMenu -import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration -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.plugins.iob.iobCobCalculator.GlucoseStatusProvider 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.automation.R +import info.nightscout.automation.elements.InputCarePortalMenu +import info.nightscout.automation.elements.InputDuration +import info.nightscout.automation.elements.InputString +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.shared.logging.LTag import info.nightscout.shared.sharedPreferences.SP import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign @@ -65,7 +65,7 @@ class ActionCarePortalEvent(injector: HasAndroidInjector) : Action(injector) { valuesWithUnit.add(ValueWithUnit.TherapyEventType(therapyEvent.type)) therapyEvent.enteredBy = enteredBy - if ( therapyEvent.type == TherapyEvent.Type.QUESTION || therapyEvent.type == TherapyEvent.Type.ANNOUNCEMENT) { + if (therapyEvent.type == TherapyEvent.Type.QUESTION || therapyEvent.type == TherapyEvent.Type.ANNOUNCEMENT) { val glucoseStatus = glucoseStatusProvider.glucoseStatusData if (glucoseStatus != null) { therapyEvent.glucose = glucoseStatus.glucose @@ -75,10 +75,10 @@ class ActionCarePortalEvent(injector: HasAndroidInjector) : Action(injector) { } } else { therapyEvent.duration = T.mins(duration.value.toLong()).msecs() - valuesWithUnit.add(ValueWithUnit.Minute(duration.value).takeIf { !duration.value.equals(0) } ) + valuesWithUnit.add(ValueWithUnit.Minute(duration.value).takeIf { !duration.value.equals(0) }) } therapyEvent.note = note.value - valuesWithUnit.add(ValueWithUnit.SimpleString(note.value).takeIf { note.value.isNotBlank() } ) + valuesWithUnit.add(ValueWithUnit.SimpleString(note.value).takeIf { note.value.isNotBlank() }) disposable += repository.runTransactionForResult(InsertIfNewByTimestampTherapyEventTransaction(therapyEvent)) .subscribe( { result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted therapy event $it") } }, @@ -93,7 +93,7 @@ class ActionCarePortalEvent(injector: HasAndroidInjector) : Action(injector) { .put("note", note.value) .put("durationInMinutes", duration.value) return JSONObject() - .put("type", this.javaClass.name) + .put("type", this.javaClass.simpleName) .put("data", data) .toString() } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionDummy.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionDummy.kt similarity index 91% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionDummy.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionDummy.kt index 2a7f591b5c..85c0ec76af 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionDummy.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionDummy.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import dagger.android.HasAndroidInjector import info.nightscout.androidaps.queue.Callback diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionLoopDisable.kt similarity index 94% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionLoopDisable.kt index 0a4866c298..2d0a2b79c3 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionLoopDisable.kt @@ -1,8 +1,7 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.database.entities.UserEntry import info.nightscout.androidaps.database.entities.UserEntry.Sources @@ -15,6 +14,7 @@ import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.R import javax.inject.Inject class ActionLoopDisable(injector: HasAndroidInjector) : Action(injector) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionLoopEnable.kt similarity index 94% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionLoopEnable.kt index e1ce21ccee..d51a12002a 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionLoopEnable.kt @@ -1,8 +1,7 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.database.entities.UserEntry import info.nightscout.androidaps.database.entities.UserEntry.Sources @@ -14,6 +13,7 @@ import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.R import javax.inject.Inject class ActionLoopEnable(injector: HasAndroidInjector) : Action(injector) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionLoopResume.kt similarity index 95% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionLoopResume.kt index c60c861d06..157dde9be8 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionLoopResume.kt @@ -1,8 +1,7 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.UserEntry @@ -11,11 +10,12 @@ import info.nightscout.androidaps.database.transactions.CancelCurrentOfflineEven import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.interfaces.ConfigBuilder import info.nightscout.androidaps.interfaces.Loop -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.automation.R +import info.nightscout.shared.logging.LTag import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import javax.inject.Inject diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionLoopSuspend.kt similarity index 86% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionLoopSuspend.kt index 1c490b4bde..89daf25063 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionLoopSuspend.kt @@ -1,9 +1,8 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import android.widget.LinearLayout import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.database.entities.UserEntry import info.nightscout.androidaps.database.entities.UserEntry.Sources @@ -12,11 +11,12 @@ import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration -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.JsonHelper +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputDuration +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder import org.json.JSONObject import javax.inject.Inject @@ -49,7 +49,7 @@ class ActionLoopSuspend(injector: HasAndroidInjector) : Action(injector) { override fun toJSON(): String { val data = JSONObject().put("minutes", minutes.getMinutes()) return JSONObject() - .put("type", this.javaClass.name) + .put("type", this.javaClass.simpleName) .put("data", data) .toString() } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionNotification.kt similarity index 85% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionNotification.kt index 63622eca2c..7b5e824458 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionNotification.kt @@ -1,21 +1,21 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import android.widget.LinearLayout import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R 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.plugins.bus.RxBus -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.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationUserMessage import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputString +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import org.json.JSONObject @@ -45,7 +45,7 @@ class ActionNotification(injector: HasAndroidInjector) : Action(injector) { override fun toJSON(): String { val data = JSONObject().put("text", text.value) return JSONObject() - .put("type", this.javaClass.name) + .put("type", this.javaClass.simpleName) .put("data", data) .toString() } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionProfileSwitch.kt similarity index 90% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionProfileSwitch.kt index 52e1048b42..eb4f1d4915 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionProfileSwitch.kt @@ -1,9 +1,8 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import android.widget.LinearLayout import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.database.entities.UserEntry import info.nightscout.androidaps.database.entities.UserEntry.Sources @@ -11,12 +10,13 @@ import info.nightscout.androidaps.database.entities.ValueWithUnit import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.plugins.general.automation.elements.InputProfileName -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.automation.R +import info.nightscout.automation.elements.InputProfileName +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder import info.nightscout.shared.logging.LTag import org.json.JSONObject import javax.inject.Inject @@ -78,7 +78,7 @@ class ActionProfileSwitch(injector: HasAndroidInjector) : Action(injector) { override fun toJSON(): String { val data = JSONObject().put("profileToSwitchTo", inputProfileName.value) return JSONObject() - .put("type", this.javaClass.name) + .put("type", this.javaClass.simpleName) .put("data", data) .toString() } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionProfileSwitchPercent.kt similarity index 82% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionProfileSwitchPercent.kt index e6863d4c1c..975fc3a871 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionProfileSwitchPercent.kt @@ -1,23 +1,23 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import android.widget.LinearLayout import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.database.entities.UserEntry import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.database.entities.ValueWithUnit import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration -import info.nightscout.androidaps.plugins.general.automation.elements.InputPercent -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.triggers.TriggerProfilePercent import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputDuration +import info.nightscout.automation.elements.InputPercent +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.triggers.TriggerProfilePercent import info.nightscout.shared.logging.LTag import org.json.JSONObject import javax.inject.Inject @@ -71,7 +71,7 @@ class ActionProfileSwitchPercent(injector: HasAndroidInjector) : Action(injector .put("percentage", pct.value) .put("durationInMinutes", duration.value) return JSONObject() - .put("type", this.javaClass.name) + .put("type", this.javaClass.simpleName) .put("data", data) .toString() } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionRunAutotune.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionRunAutotune.kt similarity index 87% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionRunAutotune.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionRunAutotune.kt index b1da120478..af98613a0d 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionRunAutotune.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionRunAutotune.kt @@ -1,21 +1,20 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import android.widget.LinearLayout import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.Autotune import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ResourceHelper -import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration -import info.nightscout.androidaps.plugins.general.automation.elements.InputProfileName -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.JsonHelper +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputDuration +import info.nightscout.automation.elements.InputProfileName +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder import info.nightscout.shared.logging.LTag import info.nightscout.shared.sharedPreferences.SP import org.json.JSONObject @@ -76,7 +75,7 @@ class ActionRunAutotune(injector: HasAndroidInjector) : Action(injector) { .put("profileToTune", inputProfileName.value) .put("tunedays", daysBack.value) return JSONObject() - .put("type", this.javaClass.name) + .put("type", this.javaClass.simpleName) .put("data", data) .toString() } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMS.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionSendSMS.kt similarity index 79% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMS.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionSendSMS.kt index cf7055c7e1..927ca86b28 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMS.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionSendSMS.kt @@ -1,15 +1,15 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import android.widget.LinearLayout import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.interfaces.SmsCommunicator -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.JsonHelper +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputString +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder import org.json.JSONObject import javax.inject.Inject @@ -33,7 +33,7 @@ class ActionSendSMS(injector: HasAndroidInjector) : Action(injector) { override fun toJSON(): String { val data = JSONObject().put("text", text.value) return JSONObject() - .put("type", this.javaClass.name) + .put("type", this.javaClass.simpleName) .put("data", data) .toString() } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionStartTempTarget.kt similarity index 89% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionStartTempTarget.kt index 6e45d702d2..985ad6b884 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionStartTempTarget.kt @@ -1,10 +1,9 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import android.widget.LinearLayout import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.TemporaryTarget @@ -18,16 +17,17 @@ import info.nightscout.androidaps.interfaces.GlucoseUnit import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.plugins.general.automation.elements.ComparatorExists -import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration -import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget -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.triggers.TriggerTempTarget import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.JsonHelper import info.nightscout.androidaps.utils.JsonHelper.safeGetDouble +import info.nightscout.automation.R +import info.nightscout.automation.elements.ComparatorExists +import info.nightscout.automation.elements.InputDuration +import info.nightscout.automation.elements.InputTempTarget +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.triggers.TriggerTempTarget import info.nightscout.shared.logging.LTag import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign @@ -93,7 +93,7 @@ class ActionStartTempTarget(injector: HasAndroidInjector) : Action(injector) { .put("units", value.units.asText) .put("durationInMinutes", duration.getMinutes()) return JSONObject() - .put("type", this.javaClass.name) + .put("type", this.javaClass.simpleName) .put("data", data) .toString() } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopProcessing.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionStopProcessing.kt similarity index 85% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopProcessing.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionStopProcessing.kt index eb437bb91c..53f613915c 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopProcessing.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionStopProcessing.kt @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import androidx.annotation.DrawableRes import com.google.gson.JsonObject import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.R import org.json.JSONObject class ActionStopProcessing(injector: HasAndroidInjector) : Action(injector) { @@ -22,7 +22,7 @@ class ActionStopProcessing(injector: HasAndroidInjector) : Action(injector) { override fun toJSON(): String { return JSONObject() - .put("type", this.javaClass.name) + .put("type", this.javaClass.simpleName) .put("data", JsonObject()) .toString() } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTarget.kt b/automation/src/main/java/info/nightscout/automation/actions/ActionStopTempTarget.kt similarity index 94% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTarget.kt rename to automation/src/main/java/info/nightscout/automation/actions/ActionStopTempTarget.kt index 53075b11e7..c921884a58 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTarget.kt +++ b/automation/src/main/java/info/nightscout/automation/actions/ActionStopTempTarget.kt @@ -1,7 +1,6 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.UserEntry @@ -10,6 +9,7 @@ import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTa import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.automation.R import info.nightscout.shared.logging.LTag import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign diff --git a/automation/src/main/java/info/nightscout/androidaps/automation/di/AutomationModule.kt b/automation/src/main/java/info/nightscout/automation/di/AutomationModule.kt similarity index 50% rename from automation/src/main/java/info/nightscout/androidaps/automation/di/AutomationModule.kt rename to automation/src/main/java/info/nightscout/automation/di/AutomationModule.kt index b889b40692..be20c322e1 100644 --- a/automation/src/main/java/info/nightscout/androidaps/automation/di/AutomationModule.kt +++ b/automation/src/main/java/info/nightscout/automation/di/AutomationModule.kt @@ -1,15 +1,62 @@ -package info.nightscout.androidaps.automation.di +package info.nightscout.automation.di import dagger.Module import dagger.android.ContributesAndroidInjector -import info.nightscout.androidaps.plugins.general.automation.AutomationEvent -import info.nightscout.androidaps.plugins.general.automation.actions.* -import info.nightscout.androidaps.plugins.general.automation.elements.* -import info.nightscout.androidaps.plugins.general.automation.triggers.* +import info.nightscout.automation.AutomationEvent +import info.nightscout.automation.AutomationFragment +import info.nightscout.automation.actions.Action +import info.nightscout.automation.actions.ActionAlarm +import info.nightscout.automation.actions.ActionCarePortalEvent +import info.nightscout.automation.actions.ActionDummy +import info.nightscout.automation.actions.ActionLoopDisable +import info.nightscout.automation.actions.ActionLoopEnable +import info.nightscout.automation.actions.ActionLoopResume +import info.nightscout.automation.actions.ActionLoopSuspend +import info.nightscout.automation.actions.ActionNotification +import info.nightscout.automation.actions.ActionProfileSwitch +import info.nightscout.automation.actions.ActionProfileSwitchPercent +import info.nightscout.automation.actions.ActionRunAutotune +import info.nightscout.automation.actions.ActionSendSMS +import info.nightscout.automation.actions.ActionStartTempTarget +import info.nightscout.automation.actions.ActionStopProcessing +import info.nightscout.automation.actions.ActionStopTempTarget +import info.nightscout.automation.dialogs.ChooseActionDialog +import info.nightscout.automation.dialogs.ChooseOperationDialog +import info.nightscout.automation.dialogs.ChooseTriggerDialog +import info.nightscout.automation.dialogs.EditActionDialog +import info.nightscout.automation.dialogs.EditEventDialog +import info.nightscout.automation.dialogs.EditTriggerDialog +import info.nightscout.automation.triggers.Trigger +import info.nightscout.automation.triggers.TriggerAutosensValue +import info.nightscout.automation.triggers.TriggerBTDevice +import info.nightscout.automation.triggers.TriggerBg +import info.nightscout.automation.triggers.TriggerBolusAgo +import info.nightscout.automation.triggers.TriggerCOB +import info.nightscout.automation.triggers.TriggerConnector +import info.nightscout.automation.triggers.TriggerDelta +import info.nightscout.automation.triggers.TriggerDummy +import info.nightscout.automation.triggers.TriggerIob +import info.nightscout.automation.triggers.TriggerLocation +import info.nightscout.automation.triggers.TriggerProfilePercent +import info.nightscout.automation.triggers.TriggerPumpLastConnection +import info.nightscout.automation.triggers.TriggerRecurringTime +import info.nightscout.automation.triggers.TriggerTempTarget +import info.nightscout.automation.triggers.TriggerTempTargetValue +import info.nightscout.automation.triggers.TriggerTime +import info.nightscout.automation.triggers.TriggerTimeRange +import info.nightscout.automation.triggers.TriggerWifiSsid @Module @Suppress("unused") abstract class AutomationModule { + + @ContributesAndroidInjector abstract fun contributesAutomationFragment(): AutomationFragment + @ContributesAndroidInjector abstract fun contributesChooseActionDialog(): ChooseActionDialog + @ContributesAndroidInjector abstract fun contributesChooseTriggerDialog(): ChooseTriggerDialog + @ContributesAndroidInjector abstract fun contributesChooseOperationDialog(): ChooseOperationDialog + @ContributesAndroidInjector abstract fun contributesEditActionDialog(): EditActionDialog + @ContributesAndroidInjector abstract fun contributesEditEventDialog(): EditEventDialog + @ContributesAndroidInjector abstract fun contributesEditTriggerDialog(): EditTriggerDialog @ContributesAndroidInjector abstract fun automationEventInjector(): AutomationEvent @ContributesAndroidInjector abstract fun triggerInjector(): Trigger diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseActionDialog.kt b/automation/src/main/java/info/nightscout/automation/dialogs/ChooseActionDialog.kt similarity index 81% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseActionDialog.kt rename to automation/src/main/java/info/nightscout/automation/dialogs/ChooseActionDialog.kt index d6ec553117..1f760c89f0 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseActionDialog.kt +++ b/automation/src/main/java/info/nightscout/automation/dialogs/ChooseActionDialog.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.dialogs +package info.nightscout.automation.dialogs import android.os.Bundle import android.view.LayoutInflater @@ -6,13 +6,13 @@ import android.view.View import android.view.ViewGroup import android.widget.RadioButton import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.databinding.AutomationDialogChooseActionBinding import info.nightscout.androidaps.dialogs.DialogFragmentWithDate import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin -import info.nightscout.androidaps.plugins.general.automation.actions.Action -import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationAddAction -import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui +import info.nightscout.automation.AutomationPlugin +import info.nightscout.automation.actions.Action +import info.nightscout.automation.databinding.AutomationDialogChooseActionBinding +import info.nightscout.automation.events.EventAutomationAddAction +import info.nightscout.automation.events.EventAutomationUpdateGui import javax.inject.Inject import kotlin.reflect.full.primaryConstructor @@ -30,8 +30,10 @@ class ChooseActionDialog : DialogFragmentWithDate() { // onDestroyView. private val binding get() = _binding!! - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { // restore checked radio button savedInstanceState?.let { bundle -> checkedIndex = bundle.getInt("checkedIndex") diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseOperationDialog.kt b/automation/src/main/java/info/nightscout/automation/dialogs/ChooseOperationDialog.kt similarity index 91% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseOperationDialog.kt rename to automation/src/main/java/info/nightscout/automation/dialogs/ChooseOperationDialog.kt index 4570c3e005..bd56e331ce 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseOperationDialog.kt +++ b/automation/src/main/java/info/nightscout/automation/dialogs/ChooseOperationDialog.kt @@ -1,14 +1,14 @@ -package info.nightscout.androidaps.plugins.general.automation.dialogs +package info.nightscout.automation.dialogs import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.RadioButton -import info.nightscout.androidaps.automation.databinding.AutomationDialogChooseOperationBinding import info.nightscout.androidaps.dialogs.DialogFragmentWithDate -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.automation.databinding.AutomationDialogChooseOperationBinding +import info.nightscout.automation.triggers.TriggerConnector import javax.inject.Inject class ChooseOperationDialog : DialogFragmentWithDate() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseTriggerDialog.kt b/automation/src/main/java/info/nightscout/automation/dialogs/ChooseTriggerDialog.kt similarity index 86% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseTriggerDialog.kt rename to automation/src/main/java/info/nightscout/automation/dialogs/ChooseTriggerDialog.kt index df8d9979a9..0bd9556d4b 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/ChooseTriggerDialog.kt +++ b/automation/src/main/java/info/nightscout/automation/dialogs/ChooseTriggerDialog.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.dialogs +package info.nightscout.automation.dialogs import android.os.Bundle import android.view.LayoutInflater @@ -6,10 +6,10 @@ import android.view.View import android.view.ViewGroup import android.widget.RadioButton import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.databinding.AutomationDialogChooseTriggerBinding import info.nightscout.androidaps.dialogs.DialogFragmentWithDate -import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin -import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger +import info.nightscout.automation.AutomationPlugin +import info.nightscout.automation.databinding.AutomationDialogChooseTriggerBinding +import info.nightscout.automation.triggers.Trigger import javax.inject.Inject import kotlin.reflect.full.primaryConstructor @@ -32,8 +32,10 @@ class ChooseTriggerDialog : DialogFragmentWithDate() { fun onClick(newTriggerObject: Trigger) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { // restore checked radio button savedInstanceState?.let { bundle -> checkedIndex = bundle.getInt("checkedIndex") diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditActionDialog.kt b/automation/src/main/java/info/nightscout/automation/dialogs/EditActionDialog.kt similarity index 78% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditActionDialog.kt rename to automation/src/main/java/info/nightscout/automation/dialogs/EditActionDialog.kt index 6f40e9c12f..0371700726 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditActionDialog.kt +++ b/automation/src/main/java/info/nightscout/automation/dialogs/EditActionDialog.kt @@ -1,16 +1,16 @@ -package info.nightscout.androidaps.plugins.general.automation.dialogs +package info.nightscout.automation.dialogs import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.databinding.AutomationDialogActionBinding import info.nightscout.androidaps.dialogs.DialogFragmentWithDate import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.plugins.general.automation.actions.Action -import info.nightscout.androidaps.plugins.general.automation.actions.ActionDummy -import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateAction +import info.nightscout.automation.actions.Action +import info.nightscout.automation.actions.ActionDummy +import info.nightscout.automation.databinding.AutomationDialogActionBinding +import info.nightscout.automation.events.EventAutomationUpdateAction import org.json.JSONObject import javax.inject.Inject @@ -28,8 +28,10 @@ class EditActionDialog : DialogFragmentWithDate() { // onDestroyView. private val binding get() = _binding!! - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { // load data from bundle (savedInstanceState ?: arguments)?.let { bundle -> actionPosition = bundle.getInt("actionPosition", -1) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.kt b/automation/src/main/java/info/nightscout/automation/dialogs/EditEventDialog.kt similarity index 82% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.kt rename to automation/src/main/java/info/nightscout/automation/dialogs/EditEventDialog.kt index cdafc9c788..7362c47a92 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditEventDialog.kt +++ b/automation/src/main/java/info/nightscout/automation/dialogs/EditEventDialog.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.dialogs +package info.nightscout.automation.dialogs import android.os.Bundle import android.view.LayoutInflater @@ -10,22 +10,22 @@ import android.widget.TextView import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.automation.databinding.AutomationDialogEventBinding import info.nightscout.androidaps.dialogs.DialogFragmentWithDate import info.nightscout.androidaps.extensions.toVisibility import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.plugins.general.automation.AutomationEvent -import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin -import info.nightscout.androidaps.plugins.general.automation.actions.Action -import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationAddAction -import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged -import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateAction -import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui -import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateTrigger import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.rx.AapsSchedulers +import info.nightscout.automation.AutomationEvent +import info.nightscout.automation.AutomationPlugin +import info.nightscout.automation.R +import info.nightscout.automation.actions.Action +import info.nightscout.automation.databinding.AutomationDialogEventBinding +import info.nightscout.automation.events.EventAutomationAddAction +import info.nightscout.automation.events.EventAutomationDataChanged +import info.nightscout.automation.events.EventAutomationUpdateAction +import info.nightscout.automation.events.EventAutomationUpdateGui +import info.nightscout.automation.events.EventAutomationUpdateTrigger import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import javax.inject.Inject @@ -50,8 +50,10 @@ class EditEventDialog : DialogFragmentWithDate() { // onDestroyView. private val binding get() = _binding!! - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { event = AutomationEvent(injector) // load data from bundle (savedInstanceState ?: arguments)?.let { bundle -> @@ -98,30 +100,30 @@ class EditEventDialog : DialogFragmentWithDate() { .toObservable(EventAutomationUpdateGui::class.java) .observeOn(aapsSchedulers.main) .subscribe({ - actionListAdapter?.notifyDataSetChanged() - showPreconditions() - }, fabricPrivacy::logException) + actionListAdapter?.notifyDataSetChanged() + showPreconditions() + }, fabricPrivacy::logException) disposable += rxBus .toObservable(EventAutomationAddAction::class.java) .observeOn(aapsSchedulers.main) .subscribe({ - event.addAction(it.action) - actionListAdapter?.notifyDataSetChanged() - }, fabricPrivacy::logException) + event.addAction(it.action) + actionListAdapter?.notifyDataSetChanged() + }, fabricPrivacy::logException) disposable += rxBus .toObservable(EventAutomationUpdateTrigger::class.java) .observeOn(aapsSchedulers.main) .subscribe({ - event.trigger = it.trigger - binding.triggerDescription.text = event.trigger.friendlyDescription() - }, fabricPrivacy::logException) + event.trigger = it.trigger + binding.triggerDescription.text = event.trigger.friendlyDescription() + }, fabricPrivacy::logException) disposable += rxBus .toObservable(EventAutomationUpdateAction::class.java) .observeOn(aapsSchedulers.main) .subscribe({ - event.actions[it.position] = it.action - actionListAdapter?.notifyDataSetChanged() - }, fabricPrivacy::logException) + event.actions[it.position] = it.action + actionListAdapter?.notifyDataSetChanged() + }, fabricPrivacy::logException) } override fun submit(): Boolean { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditTriggerDialog.kt b/automation/src/main/java/info/nightscout/automation/dialogs/EditTriggerDialog.kt similarity index 84% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditTriggerDialog.kt rename to automation/src/main/java/info/nightscout/automation/dialogs/EditTriggerDialog.kt index d6cdb53a74..e03aa29246 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/dialogs/EditTriggerDialog.kt +++ b/automation/src/main/java/info/nightscout/automation/dialogs/EditTriggerDialog.kt @@ -1,22 +1,22 @@ -package info.nightscout.androidaps.plugins.general.automation.dialogs +package info.nightscout.automation.dialogs import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.databinding.AutomationDialogEditTriggerBinding import info.nightscout.androidaps.dialogs.DialogFragmentWithDate import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateTrigger -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.general.automation.triggers.Trigger -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.rx.AapsSchedulers +import info.nightscout.automation.databinding.AutomationDialogEditTriggerBinding +import info.nightscout.automation.events.EventAutomationUpdateTrigger +import info.nightscout.automation.events.EventTriggerChanged +import info.nightscout.automation.events.EventTriggerClone +import info.nightscout.automation.events.EventTriggerRemove +import info.nightscout.automation.triggers.Trigger +import info.nightscout.automation.triggers.TriggerConnector +import info.nightscout.automation.triggers.TriggerDummy import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import org.json.JSONObject diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Comparator.kt b/automation/src/main/java/info/nightscout/automation/elements/Comparator.kt similarity index 96% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Comparator.kt rename to automation/src/main/java/info/nightscout/automation/elements/Comparator.kt index 93f3827f55..cfb63d1295 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Comparator.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/Comparator.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.view.View @@ -7,8 +7,8 @@ import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner import androidx.annotation.StringRes -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.automation.R class Comparator(private val rh: ResourceHelper) : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnect.kt b/automation/src/main/java/info/nightscout/automation/elements/ComparatorConnect.kt similarity index 94% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnect.kt rename to automation/src/main/java/info/nightscout/automation/elements/ComparatorConnect.kt index 4ce4d00a69..bf638d1548 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnect.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/ComparatorConnect.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.view.View @@ -7,8 +7,8 @@ import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner import androidx.annotation.StringRes -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.automation.R class ComparatorConnect(private val rh: ResourceHelper) : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExists.kt b/automation/src/main/java/info/nightscout/automation/elements/ComparatorExists.kt similarity index 94% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExists.kt rename to automation/src/main/java/info/nightscout/automation/elements/ComparatorExists.kt index 071388dab1..055ecc8e15 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExists.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/ComparatorExists.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.view.View @@ -7,8 +7,8 @@ import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner import androidx.annotation.StringRes -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.automation.R class ComparatorExists(private val rh: ResourceHelper, var value: Compare = Compare.EXISTS) : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.kt b/automation/src/main/java/info/nightscout/automation/elements/Element.kt similarity index 61% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.kt rename to automation/src/main/java/info/nightscout/automation/elements/Element.kt index 9a3e17e9b1..0e980bf2d6 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/Element.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.widget.LinearLayout diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt b/automation/src/main/java/info/nightscout/automation/elements/InputBg.kt similarity index 93% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputBg.kt index f54cd4aefe..ec3057b453 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputBg.kt @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.widget.LinearLayout -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.GlucoseUnit import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.utils.ui.NumberPicker +import info.nightscout.automation.R import java.text.DecimalFormat class InputBg(profileFunction: ProfileFunction) : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputButton.kt b/automation/src/main/java/info/nightscout/automation/elements/InputButton.kt similarity index 89% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputButton.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputButton.kt index aeb6919321..c51dc518c9 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputButton.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputButton.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.widget.Button diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputCarePortalMenu.kt b/automation/src/main/java/info/nightscout/automation/elements/InputCarePortalMenu.kt similarity index 96% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputCarePortalMenu.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputCarePortalMenu.kt index f0c63f6415..8f18fbf49e 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputCarePortalMenu.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputCarePortalMenu.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.view.View @@ -8,9 +8,9 @@ import android.widget.LinearLayout import android.widget.Spinner import androidx.annotation.DrawableRes import androidx.annotation.StringRes -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.entities.TherapyEvent import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.automation.R class InputCarePortalMenu(private val rh: ResourceHelper) : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDateTime.kt b/automation/src/main/java/info/nightscout/automation/elements/InputDateTime.kt similarity index 96% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDateTime.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputDateTime.kt index 54c97699af..7fd3d9d3d6 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDateTime.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputDateTime.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.content.Context import android.graphics.Typeface @@ -12,10 +12,10 @@ import androidx.fragment.app.FragmentManager import com.google.android.material.datepicker.MaterialDatePicker import com.google.android.material.timepicker.MaterialTimePicker import com.google.android.material.timepicker.TimeFormat -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.interfaces.ResourceHelper -import java.util.* +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.automation.R +import java.util.Calendar class InputDateTime(private val rh: ResourceHelper, private val dateUtil: DateUtil, var value: Long = dateUtil.now()) : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDelta.kt b/automation/src/main/java/info/nightscout/automation/elements/InputDelta.kt similarity index 96% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDelta.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputDelta.kt index 79ae4548a4..4115111e38 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDelta.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputDelta.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.view.View @@ -7,9 +7,9 @@ import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner import androidx.annotation.StringRes -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.utils.ui.NumberPicker +import info.nightscout.automation.R import java.text.DecimalFormat class InputDelta(private val rh: ResourceHelper) : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.kt b/automation/src/main/java/info/nightscout/automation/elements/InputDouble.kt similarity index 92% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputDouble.kt index 9d3e3f45c2..9c507c657e 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputDouble.kt @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.widget.LinearLayout -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.ui.NumberPicker +import info.nightscout.automation.R import java.text.DecimalFormat class InputDouble() : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDropdownMenu.kt b/automation/src/main/java/info/nightscout/automation/elements/InputDropdownMenu.kt similarity index 93% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDropdownMenu.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputDropdownMenu.kt index 6c6fc96059..f4faa23301 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDropdownMenu.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputDropdownMenu.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.view.View @@ -6,9 +6,8 @@ import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.ResourceHelper -import java.util.* +import info.nightscout.automation.R class InputDropdownMenu(private val rh: ResourceHelper) : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.kt b/automation/src/main/java/info/nightscout/automation/elements/InputDuration.kt similarity index 93% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputDuration.kt index 05dc3ef41b..ae374e37c9 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputDuration.kt @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.widget.LinearLayout -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.ui.MinutesNumberPicker import info.nightscout.androidaps.utils.ui.NumberPicker +import info.nightscout.automation.R import java.text.DecimalFormat class InputDuration( diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulin.kt b/automation/src/main/java/info/nightscout/automation/elements/InputInsulin.kt similarity index 85% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulin.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputInsulin.kt index 4b394fdcfc..c7b701026c 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulin.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputInsulin.kt @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.widget.LinearLayout -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.ui.NumberPicker +import info.nightscout.automation.R import java.text.DecimalFormat class InputInsulin() : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputLocationMode.kt b/automation/src/main/java/info/nightscout/automation/elements/InputLocationMode.kt similarity index 92% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputLocationMode.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputLocationMode.kt index 23c2167749..47f139f4c9 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputLocationMode.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputLocationMode.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.view.View @@ -7,8 +7,8 @@ import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner import androidx.annotation.StringRes -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.automation.R class InputLocationMode(private val rh: ResourceHelper) : Element() { @@ -44,7 +44,7 @@ class InputLocationMode(private val rh: ResourceHelper) : Element() { var value: Mode = Mode.INSIDE - constructor(rh: ResourceHelper, value: InputLocationMode.Mode) : this(rh) { + constructor(rh: ResourceHelper, value: Mode) : this(rh) { this.value = value } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercent.kt b/automation/src/main/java/info/nightscout/automation/elements/InputPercent.kt similarity index 86% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercent.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputPercent.kt index 91032dec63..c5809f3d20 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercent.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputPercent.kt @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.widget.LinearLayout -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.ui.NumberPicker +import info.nightscout.automation.R import java.text.DecimalFormat class InputPercent() : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileName.kt b/automation/src/main/java/info/nightscout/automation/elements/InputProfileName.kt similarity index 88% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileName.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputProfileName.kt index 9cdac1b01e..47b17fe30e 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileName.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputProfileName.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.view.View @@ -6,11 +6,11 @@ import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.automation.R -class InputProfileName(private val rh: ResourceHelper, private val activePlugin: ActivePlugin, val name: String = "", val addActive: Boolean = false) : Element() { +class InputProfileName(private val rh: ResourceHelper, private val activePlugin: ActivePlugin, val name: String = "", private val addActive: Boolean = false) : Element() { var value: String = name diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputString.kt b/automation/src/main/java/info/nightscout/automation/elements/InputString.kt similarity index 93% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputString.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputString.kt index dd24d0f993..05c08d56c4 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputString.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputString.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.text.Editable import android.text.TextWatcher diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.kt b/automation/src/main/java/info/nightscout/automation/elements/InputTempTarget.kt similarity index 93% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputTempTarget.kt index 474dda7c9c..83d33e1f65 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputTempTarget.kt @@ -1,12 +1,12 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.view.Gravity import android.widget.LinearLayout import info.nightscout.androidaps.Constants -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.GlucoseUnit import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.utils.ui.NumberPicker +import info.nightscout.automation.R import java.text.DecimalFormat class InputTempTarget(profileFunction: ProfileFunction) : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTime.kt b/automation/src/main/java/info/nightscout/automation/elements/InputTime.kt similarity index 92% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTime.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputTime.kt index 60175253ac..a8235ca852 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTime.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputTime.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.content.Context import android.graphics.Typeface @@ -11,12 +11,12 @@ import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.FragmentManager import com.google.android.material.timepicker.MaterialTimePicker import com.google.android.material.timepicker.TimeFormat -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.Profile +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.MidnightTime -import info.nightscout.androidaps.interfaces.ResourceHelper -import java.util.* +import info.nightscout.automation.R +import java.util.Calendar class InputTime(private val rh: ResourceHelper, private val dateUtil: DateUtil) : Element() { @@ -63,9 +63,9 @@ class InputTime(private val rh: ResourceHelper, private val dateUtil: DateUtil) private fun getFragmentManager(context: Context?): FragmentManager? { return when (context) { - is AppCompatActivity -> context.supportFragmentManager + is AppCompatActivity -> context.supportFragmentManager is ContextThemeWrapper -> getFragmentManager(context.baseContext) - else -> null + else -> null } } } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTimeRange.kt b/automation/src/main/java/info/nightscout/automation/elements/InputTimeRange.kt similarity index 97% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTimeRange.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputTimeRange.kt index 7a953519bb..39d0351074 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTimeRange.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputTimeRange.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.content.Context import android.graphics.Typeface @@ -12,12 +12,12 @@ import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.FragmentManager import com.google.android.material.timepicker.MaterialTimePicker import com.google.android.material.timepicker.TimeFormat -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.Profile +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.MidnightTime -import info.nightscout.androidaps.interfaces.ResourceHelper -import java.util.* +import info.nightscout.automation.R +import java.util.Calendar class InputTimeRange(private val rh: ResourceHelper, private val dateUtil: DateUtil) : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt b/automation/src/main/java/info/nightscout/automation/elements/InputWeekDay.kt similarity index 94% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt rename to automation/src/main/java/info/nightscout/automation/elements/InputWeekDay.kt index c34a53444c..4f761687e5 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/InputWeekDay.kt @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.widget.LinearLayout import androidx.annotation.StringRes -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.ui.WeekdayPicker -import java.util.* +import info.nightscout.automation.R +import java.util.Calendar class InputWeekDay : Element() { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.kt b/automation/src/main/java/info/nightscout/automation/elements/LabelWithElement.kt similarity index 93% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.kt rename to automation/src/main/java/info/nightscout/automation/elements/LabelWithElement.kt index 01ec8d00e9..4d6b72d35b 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/LabelWithElement.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.graphics.Typeface import android.view.Gravity diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilder.kt b/automation/src/main/java/info/nightscout/automation/elements/LayoutBuilder.kt similarity index 88% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilder.kt rename to automation/src/main/java/info/nightscout/automation/elements/LayoutBuilder.kt index 0c87f393d2..a7bc41cd02 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilder.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/LayoutBuilder.kt @@ -1,10 +1,9 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.content.Context -import android.view.Gravity import android.view.ViewGroup import android.widget.LinearLayout -import info.nightscout.androidaps.automation.R +import info.nightscout.automation.R class LayoutBuilder { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabel.kt b/automation/src/main/java/info/nightscout/automation/elements/StaticLabel.kt similarity index 89% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabel.kt rename to automation/src/main/java/info/nightscout/automation/elements/StaticLabel.kt index 60552f655b..03455053e4 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabel.kt +++ b/automation/src/main/java/info/nightscout/automation/elements/StaticLabel.kt @@ -1,12 +1,12 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import android.graphics.Typeface import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TextView -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.automation.R +import info.nightscout.automation.triggers.Trigger class StaticLabel(private val rh: ResourceHelper) : Element() { diff --git a/automation/src/main/java/info/nightscout/automation/events/EventAutomationAddAction.kt b/automation/src/main/java/info/nightscout/automation/events/EventAutomationAddAction.kt new file mode 100644 index 0000000000..0927b0adee --- /dev/null +++ b/automation/src/main/java/info/nightscout/automation/events/EventAutomationAddAction.kt @@ -0,0 +1,6 @@ +package info.nightscout.automation.events + +import info.nightscout.androidaps.events.Event +import info.nightscout.automation.actions.Action + +class EventAutomationAddAction(val action: Action) : Event() diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationDataChanged.kt b/automation/src/main/java/info/nightscout/automation/events/EventAutomationDataChanged.kt similarity index 57% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationDataChanged.kt rename to automation/src/main/java/info/nightscout/automation/events/EventAutomationDataChanged.kt index d017468dbb..62afbd58fb 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationDataChanged.kt +++ b/automation/src/main/java/info/nightscout/automation/events/EventAutomationDataChanged.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.events +package info.nightscout.automation.events import info.nightscout.androidaps.events.Event diff --git a/automation/src/main/java/info/nightscout/automation/events/EventAutomationUpdateAction.kt b/automation/src/main/java/info/nightscout/automation/events/EventAutomationUpdateAction.kt new file mode 100644 index 0000000000..c0a07acd0b --- /dev/null +++ b/automation/src/main/java/info/nightscout/automation/events/EventAutomationUpdateAction.kt @@ -0,0 +1,6 @@ +package info.nightscout.automation.events + +import info.nightscout.androidaps.events.Event +import info.nightscout.automation.actions.Action + +class EventAutomationUpdateAction(val action: Action, val position: Int) : Event() \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationUpdateGui.kt b/automation/src/main/java/info/nightscout/automation/events/EventAutomationUpdateGui.kt similarity index 56% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationUpdateGui.kt rename to automation/src/main/java/info/nightscout/automation/events/EventAutomationUpdateGui.kt index 1326701b93..1e8a34fcd5 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventAutomationUpdateGui.kt +++ b/automation/src/main/java/info/nightscout/automation/events/EventAutomationUpdateGui.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.events +package info.nightscout.automation.events import info.nightscout.androidaps.events.Event diff --git a/automation/src/main/java/info/nightscout/automation/events/EventAutomationUpdateTrigger.kt b/automation/src/main/java/info/nightscout/automation/events/EventAutomationUpdateTrigger.kt new file mode 100644 index 0000000000..36641921d8 --- /dev/null +++ b/automation/src/main/java/info/nightscout/automation/events/EventAutomationUpdateTrigger.kt @@ -0,0 +1,6 @@ +package info.nightscout.automation.events + +import info.nightscout.androidaps.events.Event +import info.nightscout.automation.triggers.TriggerConnector + +class EventAutomationUpdateTrigger(val trigger: TriggerConnector) : Event() diff --git a/automation/src/main/java/info/nightscout/androidaps/events/EventLocationChange.kt b/automation/src/main/java/info/nightscout/automation/events/EventLocationChange.kt similarity index 51% rename from automation/src/main/java/info/nightscout/androidaps/events/EventLocationChange.kt rename to automation/src/main/java/info/nightscout/automation/events/EventLocationChange.kt index fee6c9f800..f9b1e43dc0 100644 --- a/automation/src/main/java/info/nightscout/androidaps/events/EventLocationChange.kt +++ b/automation/src/main/java/info/nightscout/automation/events/EventLocationChange.kt @@ -1,5 +1,6 @@ -package info.nightscout.androidaps.events +package info.nightscout.automation.events import android.location.Location +import info.nightscout.androidaps.events.Event class EventLocationChange(var location: Location) : Event() diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventTriggerChanged.kt b/automation/src/main/java/info/nightscout/automation/events/EventTriggerChanged.kt similarity index 54% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventTriggerChanged.kt rename to automation/src/main/java/info/nightscout/automation/events/EventTriggerChanged.kt index 7e0eaaad45..f876df72bd 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/events/EventTriggerChanged.kt +++ b/automation/src/main/java/info/nightscout/automation/events/EventTriggerChanged.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.events +package info.nightscout.automation.events import info.nightscout.androidaps.events.Event diff --git a/automation/src/main/java/info/nightscout/automation/events/EventTriggerClone.kt b/automation/src/main/java/info/nightscout/automation/events/EventTriggerClone.kt new file mode 100644 index 0000000000..2ac79c766b --- /dev/null +++ b/automation/src/main/java/info/nightscout/automation/events/EventTriggerClone.kt @@ -0,0 +1,6 @@ +package info.nightscout.automation.events + +import info.nightscout.androidaps.events.Event +import info.nightscout.automation.triggers.Trigger + +class EventTriggerClone(val trigger: Trigger) : Event() \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/automation/events/EventTriggerRemove.kt b/automation/src/main/java/info/nightscout/automation/events/EventTriggerRemove.kt new file mode 100644 index 0000000000..e7c2415eec --- /dev/null +++ b/automation/src/main/java/info/nightscout/automation/events/EventTriggerRemove.kt @@ -0,0 +1,6 @@ +package info.nightscout.automation.events + +import info.nightscout.androidaps.events.Event +import info.nightscout.automation.triggers.Trigger + +class EventTriggerRemove(val trigger: Trigger) : Event() \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/services/LastLocationDataContainer.kt b/automation/src/main/java/info/nightscout/automation/services/LastLocationDataContainer.kt similarity index 85% rename from automation/src/main/java/info/nightscout/androidaps/services/LastLocationDataContainer.kt rename to automation/src/main/java/info/nightscout/automation/services/LastLocationDataContainer.kt index aa184ade9c..d81e60cba4 100644 --- a/automation/src/main/java/info/nightscout/androidaps/services/LastLocationDataContainer.kt +++ b/automation/src/main/java/info/nightscout/automation/services/LastLocationDataContainer.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.services +package info.nightscout.automation.services import android.location.Location import info.nightscout.androidaps.annotations.OpenForTesting @@ -8,5 +8,6 @@ import javax.inject.Singleton @OpenForTesting @Singleton class LastLocationDataContainer @Inject constructor() { + var lastLocation: Location? = null } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/services/LocationService.kt b/automation/src/main/java/info/nightscout/automation/services/LocationService.kt similarity index 87% rename from automation/src/main/java/info/nightscout/androidaps/services/LocationService.kt rename to automation/src/main/java/info/nightscout/automation/services/LocationService.kt index 4183c24932..0cad0e3e61 100644 --- a/automation/src/main/java/info/nightscout/androidaps/services/LocationService.kt +++ b/automation/src/main/java/info/nightscout/automation/services/LocationService.kt @@ -1,6 +1,6 @@ @file:Suppress("PrivatePropertyName") -package info.nightscout.androidaps.services +package info.nightscout.automation.services import android.Manifest import android.app.Notification @@ -16,16 +16,16 @@ import android.os.IBinder import androidx.core.app.ActivityCompat import com.google.android.gms.location.LocationServices import dagger.android.DaggerService -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.events.EventAppExit -import info.nightscout.androidaps.events.EventLocationChange import info.nightscout.androidaps.interfaces.NotificationHolder -import info.nightscout.shared.logging.AAPSLogger -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.rx.AapsSchedulers +import info.nightscout.automation.R +import info.nightscout.automation.events.EventLocationChange +import info.nightscout.shared.logging.AAPSLogger +import info.nightscout.shared.logging.LTag import info.nightscout.shared.sharedPreferences.SP import io.reactivex.rxjava3.disposables.CompositeDisposable import javax.inject.Inject @@ -106,7 +106,11 @@ class LocationService : DaggerService() { } // Get last location once until we get regular update - if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission( + this, + Manifest.permission.ACCESS_COARSE_LOCATION + ) == PackageManager.PERMISSION_GRANTED + ) { LocationServices.getFusedLocationProviderClient(this).lastLocation.addOnSuccessListener { lastLocationDataContainer.lastLocation = it } @@ -138,20 +142,25 @@ class LocationService : DaggerService() { } catch (ex: IllegalArgumentException) { aapsLogger.error(LTag.LOCATION, "network provider does not exist", ex) } - disposable.add(rxBus - .toObservable(EventAppExit::class.java) - .observeOn(aapsSchedulers.io) - .subscribe({ - aapsLogger.debug(LTag.LOCATION, "EventAppExit received") - stopSelf() - }, fabricPrivacy::logException) + disposable.add( + rxBus + .toObservable(EventAppExit::class.java) + .observeOn(aapsSchedulers.io) + .subscribe({ + aapsLogger.debug(LTag.LOCATION, "EventAppExit received") + stopSelf() + }, fabricPrivacy::logException) ) } override fun onDestroy() { super.onDestroy() try { - if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission( + this, + Manifest.permission.ACCESS_COARSE_LOCATION + ) != PackageManager.PERMISSION_GRANTED + ) { return } locationListener?.let { locationManager?.removeUpdates(it) } diff --git a/automation/src/main/java/info/nightscout/androidaps/services/LocationServiceHelper.kt b/automation/src/main/java/info/nightscout/automation/services/LocationServiceHelper.kt similarity index 98% rename from automation/src/main/java/info/nightscout/androidaps/services/LocationServiceHelper.kt rename to automation/src/main/java/info/nightscout/automation/services/LocationServiceHelper.kt index 8021406f76..3d0fec1cff 100644 --- a/automation/src/main/java/info/nightscout/androidaps/services/LocationServiceHelper.kt +++ b/automation/src/main/java/info/nightscout/automation/services/LocationServiceHelper.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.services +package info.nightscout.automation.services import android.content.ComponentName import android.content.Context diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt b/automation/src/main/java/info/nightscout/automation/triggers/Trigger.kt similarity index 81% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt rename to automation/src/main/java/info/nightscout/automation/triggers/Trigger.kt index 2af7f49ce0..a7340492b5 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/Trigger.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.content.Context import android.content.ContextWrapper @@ -9,21 +9,21 @@ import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.IobCobCalculator import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.shared.logging.AAPSLogger -import info.nightscout.androidaps.plugins.bus.RxBus -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.GlucoseStatusProvider -import info.nightscout.androidaps.services.LastLocationDataContainer -import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.automation.R +import info.nightscout.automation.dialogs.ChooseTriggerDialog +import info.nightscout.automation.events.EventTriggerChanged +import info.nightscout.automation.events.EventTriggerClone +import info.nightscout.automation.events.EventTriggerRemove +import info.nightscout.automation.services.LastLocationDataContainer +import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.LTag import info.nightscout.shared.sharedPreferences.SP import org.json.JSONObject @@ -80,49 +80,32 @@ abstract class Trigger(val injector: HasAndroidInjector) { fun instantiate(obj: JSONObject): Trigger { try { - val type = obj.getString("type") + var type = obj.getString("type") val data = obj.getJSONObject("data") - //val clazz = Class.forName(type).kotlin - //return (clazz.primaryConstructor?.call(injector) as Trigger).fromJSON(data?.toString() ?: "") + // stripe off package name + val dotIndex = type.lastIndexOf('.') + if (dotIndex > 0) type = type.substring(dotIndex + 1) return when (type) { - TriggerAutosensValue::class.java.name, // backward compatibility TriggerAutosensValue::class.java.simpleName -> TriggerAutosensValue(injector).fromJSON(data.toString()) - TriggerBg::class.java.name, TriggerBg::class.java.simpleName -> TriggerBg(injector).fromJSON(data.toString()) - TriggerBolusAgo::class.java.name, TriggerBolusAgo::class.java.simpleName -> TriggerBolusAgo(injector).fromJSON(data.toString()) - TriggerBTDevice::class.java.name, TriggerBTDevice::class.java.simpleName -> TriggerBTDevice(injector).fromJSON(data.toString()) - TriggerIob::class.java.name, TriggerIob::class.java.simpleName -> TriggerIob(injector).fromJSON(data.toString()) - TriggerCOB::class.java.name, TriggerCOB::class.java.simpleName -> TriggerCOB(injector).fromJSON(data.toString()) - TriggerConnector::class.java.name, TriggerConnector::class.java.simpleName -> TriggerConnector(injector).fromJSON(data.toString()) - TriggerDelta::class.java.name, TriggerDelta::class.java.simpleName -> TriggerDelta(injector).fromJSON(data.toString()) - TriggerDummy::class.java.name, TriggerDummy::class.java.simpleName -> TriggerDummy(injector).fromJSON(data.toString()) - TriggerIob::class.java.name, TriggerIob::class.java.simpleName -> TriggerIob(injector).fromJSON(data.toString()) - TriggerLocation::class.java.name, TriggerLocation::class.java.simpleName -> TriggerLocation(injector).fromJSON(data.toString()) - TriggerProfilePercent::class.java.name, TriggerProfilePercent::class.java.simpleName -> TriggerProfilePercent(injector).fromJSON(data.toString()) - TriggerPumpLastConnection::class.java.name, TriggerPumpLastConnection::class.java.simpleName -> TriggerPumpLastConnection(injector).fromJSON(data.toString()) - TriggerRecurringTime::class.java.name, TriggerRecurringTime::class.java.simpleName -> TriggerRecurringTime(injector).fromJSON(data.toString()) - TriggerTempTarget::class.java.name, TriggerTempTarget::class.java.simpleName -> TriggerTempTarget(injector).fromJSON(data.toString()) - TriggerTempTargetValue::class.java.name, TriggerTempTargetValue::class.java.simpleName -> TriggerTempTargetValue(injector).fromJSON(data.toString()) - TriggerTime::class.java.name, TriggerTime::class.java.simpleName -> TriggerTime(injector).fromJSON(data.toString()) - TriggerTimeRange::class.java.name, TriggerTimeRange::class.java.simpleName -> TriggerTimeRange(injector).fromJSON(data.toString()) - TriggerWifiSsid::class.java.name, TriggerWifiSsid::class.java.simpleName -> TriggerWifiSsid(injector).fromJSON(data.toString()) + else -> TriggerConnector(injector) } } catch (e: Exception) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValue.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerAutosensValue.kt similarity index 85% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValue.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerAutosensValue.kt index dcc896e81b..6faf32a001 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValue.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerAutosensValue.kt @@ -1,21 +1,22 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.plugins.general.automation.elements.InputDouble -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.StaticLabel import info.nightscout.androidaps.utils.JsonHelper.safeGetDouble import info.nightscout.androidaps.utils.JsonHelper.safeGetString +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputDouble +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject import java.text.DecimalFormat class TriggerAutosensValue(injector: HasAndroidInjector) : Trigger(injector) { + private val minValue = (sp.getDouble(R.string.key_openapsama_autosens_min, 0.7) * 100).toInt() private val maxValue = (sp.getDouble(R.string.key_openapsama_autosens_max, 1.2) * 100).toInt() private val step = 1.0 diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDevice.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerBTDevice.kt similarity index 86% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDevice.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerBTDevice.kt index 81d22fecf9..1b554b3d7f 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDevice.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerBTDevice.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.Manifest import android.bluetooth.BluetoothManager @@ -9,15 +9,15 @@ import android.widget.LinearLayout import androidx.core.app.ActivityCompat import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.events.EventBTChange -import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin -import info.nightscout.androidaps.plugins.general.automation.elements.ComparatorConnect -import info.nightscout.androidaps.plugins.general.automation.elements.InputDropdownMenu -import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder -import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabel import info.nightscout.androidaps.utils.JsonHelper import info.nightscout.androidaps.utils.ToastUtils +import info.nightscout.automation.AutomationPlugin +import info.nightscout.automation.R +import info.nightscout.automation.elements.ComparatorConnect +import info.nightscout.automation.elements.InputDropdownMenu +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel import info.nightscout.shared.logging.LTag import org.json.JSONObject import javax.inject.Inject diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerBg.kt similarity index 87% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerBg.kt index e386a7fa9e..8b105a4650 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerBg.kt @@ -1,19 +1,19 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.GlucoseUnit import info.nightscout.androidaps.interfaces.Profile -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.plugins.general.automation.elements.InputBg -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.StaticLabel import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputBg +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject class TriggerBg(injector: HasAndroidInjector) : Trigger(injector) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerBolusAgo.kt similarity index 86% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerBolusAgo.kt index a7e0b11ec4..f1db96fa39 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerBolusAgo.kt @@ -1,19 +1,19 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.database.entities.Bolus -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration -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.StaticLabel import info.nightscout.androidaps.utils.JsonHelper import info.nightscout.androidaps.utils.JsonHelper.safeGetString +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputDuration +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject class TriggerBolusAgo(injector: HasAndroidInjector) : Trigger(injector) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerCOB.kt similarity index 82% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerCOB.kt index 6ab853a73e..ed3f2a2009 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerCOB.kt @@ -1,17 +1,17 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.plugins.general.automation.elements.InputDouble -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.StaticLabel import info.nightscout.androidaps.utils.JsonHelper import info.nightscout.androidaps.utils.JsonHelper.safeGetDouble +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputDouble +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject import java.text.DecimalFormat @@ -48,7 +48,7 @@ class TriggerCOB(injector: HasAndroidInjector) : Trigger(injector) { false } } - if (cobInfo.displayCob != null && comparator.value.check(cobInfo.displayCob!!, cob.value)) { + if (comparator.value.check(cobInfo.displayCob!!, cob.value)) { aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription()) return true } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerConnector.kt similarity index 97% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerConnector.kt index 3a7ff9258f..abe89bd9fd 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerConnector.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.content.Context import android.graphics.Typeface @@ -9,15 +9,14 @@ import android.widget.TextView import androidx.annotation.StringRes import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseOperationDialog -import info.nightscout.androidaps.utils.JsonHelper.safeGetString import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.utils.JsonHelper.safeGetString import info.nightscout.androidaps.utils.ui.VerticalTextView +import info.nightscout.automation.R +import info.nightscout.automation.dialogs.ChooseOperationDialog +import info.nightscout.shared.logging.LTag import org.json.JSONArray import org.json.JSONObject -import java.util.* class TriggerConnector(injector: HasAndroidInjector) : Trigger(injector) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerDelta.kt similarity index 88% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerDelta.kt index 924cd08dad..5c2721d468 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerDelta.kt @@ -1,20 +1,20 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.GlucoseUnit import info.nightscout.androidaps.interfaces.Profile -import info.nightscout.shared.logging.LTag -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.elements.InputDelta.DeltaType -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.StaticLabel import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputDelta +import info.nightscout.automation.elements.InputDelta.DeltaType +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject import java.text.DecimalFormat diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDummy.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerDummy.kt similarity index 81% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDummy.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerDummy.kt index be914525ef..7fb05ae910 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDummy.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerDummy.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional import dagger.android.HasAndroidInjector @@ -15,9 +15,7 @@ class TriggerDummy(injector: HasAndroidInjector, val shouldRun: Boolean = false) throw NotImplementedError("An operation is not implemented") } - override fun fromJSON(data: String): Trigger { - throw NotImplementedError("An operation is not implemented") - } + override fun fromJSON(data: String): Trigger = TriggerDummy(injector) override fun friendlyName(): Int { throw NotImplementedError("An operation is not implemented") diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIob.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerIob.kt similarity index 81% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIob.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerIob.kt index 2717fc333d..ff78e82bdb 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIob.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerIob.kt @@ -1,19 +1,20 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.plugins.general.automation.elements.InputInsulin -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.StaticLabel import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputInsulin +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject class TriggerIob(injector: HasAndroidInjector) : Trigger(injector) { + var insulin = InputInsulin() var comparator: Comparator = Comparator(rh) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerLocation.kt similarity index 90% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerLocation.kt index 66a8213a32..1b21bfdea0 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerLocation.kt @@ -1,13 +1,19 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.location.Location import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.* import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputButton +import info.nightscout.automation.elements.InputDouble +import info.nightscout.automation.elements.InputLocationMode +import info.nightscout.automation.elements.InputString +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject import java.text.DecimalFormat @@ -47,7 +53,8 @@ class TriggerLocation(injector: HasAndroidInjector) : Trigger(injector) { if (modeSelected.value == InputLocationMode.Mode.INSIDE && calculatedDistance <= distance.value || modeSelected.value == InputLocationMode.Mode.OUTSIDE && calculatedDistance > distance.value || modeSelected.value == InputLocationMode.Mode.GOING_IN && calculatedDistance <= distance.value && lastMode == InputLocationMode.Mode.OUTSIDE || - modeSelected.value == InputLocationMode.Mode.GOING_OUT && calculatedDistance > distance.value && lastMode == InputLocationMode.Mode.INSIDE) { + modeSelected.value == InputLocationMode.Mode.GOING_OUT && calculatedDistance > distance.value && lastMode == InputLocationMode.Mode.INSIDE + ) { aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription()) lastMode = currentMode(calculatedDistance) return true diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercent.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerProfilePercent.kt similarity index 87% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercent.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerProfilePercent.kt index d57d7d02fd..13d5875101 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercent.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerProfilePercent.kt @@ -1,17 +1,17 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.ProfileSealed -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.plugins.general.automation.elements.InputPercent -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.StaticLabel import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputPercent +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject class TriggerProfilePercent(injector: HasAndroidInjector) : Trigger(injector) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnection.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerPumpLastConnection.kt similarity index 86% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnection.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerPumpLastConnection.kt index 8d3be596af..624bd34f7e 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnection.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerPumpLastConnection.kt @@ -1,17 +1,17 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration -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.StaticLabel import info.nightscout.androidaps.utils.JsonHelper.safeGetInt import info.nightscout.androidaps.utils.JsonHelper.safeGetString +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputDuration +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject class TriggerPumpLastConnection(injector: HasAndroidInjector) : Trigger(injector) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTime.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerRecurringTime.kt similarity index 88% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTime.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerRecurringTime.kt index 0ff48b9055..777caaa237 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTime.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerRecurringTime.kt @@ -1,19 +1,20 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.Profile -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.InputTime -import info.nightscout.androidaps.plugins.general.automation.elements.InputWeekDay -import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder -import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabel import info.nightscout.androidaps.utils.JsonHelper import info.nightscout.androidaps.utils.MidnightTime +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputTime +import info.nightscout.automation.elements.InputWeekDay +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject -import java.util.* +import java.util.Calendar +import java.util.Objects class TriggerRecurringTime(injector: HasAndroidInjector) : Trigger(injector) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTarget.kt similarity index 87% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTarget.kt index f89eb9896c..93840e711e 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTarget.kt @@ -1,15 +1,15 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.ValueWrapper -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.ComparatorExists -import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder -import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabel import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.automation.R +import info.nightscout.automation.elements.ComparatorExists +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject class TriggerTempTarget(injector: HasAndroidInjector) : Trigger(injector) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetValue.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTargetValue.kt similarity index 86% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetValue.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTargetValue.kt index faf6d3d115..48dad6bd83 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetValue.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTargetValue.kt @@ -1,20 +1,20 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.interfaces.GlucoseUnit import info.nightscout.androidaps.interfaces.Profile -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.plugins.general.automation.elements.InputBg -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.StaticLabel import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputBg +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject class TriggerTempTargetValue(injector: HasAndroidInjector) : Trigger(injector) { @@ -77,7 +77,7 @@ class TriggerTempTargetValue(injector: HasAndroidInjector) : Trigger(injector) { override fun friendlyName(): Int = R.string.careportal_temporarytargetvalue - override fun friendlyDescription(): String { + override fun friendlyDescription(): String { return if (comparator.value == Comparator.Compare.IS_NOT_AVAILABLE) rh.gs(R.string.notemptarget) else diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerTime.kt similarity index 84% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerTime.kt index 299b8b895d..9227168f99 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerTime.kt @@ -1,15 +1,15 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.InputDateTime -import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder -import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabel import info.nightscout.androidaps.utils.JsonHelper import info.nightscout.androidaps.utils.T +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputDateTime +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject class TriggerTime(injector: HasAndroidInjector) : Trigger(injector) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRange.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerTimeRange.kt similarity index 88% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRange.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerTimeRange.kt index ad21537299..399f079d51 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRange.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerTimeRange.kt @@ -1,16 +1,16 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.Profile -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.InputTimeRange -import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder -import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabel import info.nightscout.androidaps.utils.JsonHelper.safeGetInt import info.nightscout.androidaps.utils.MidnightTime +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputTimeRange +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject // Trigger for time range ( from 10:00AM till 13:00PM ) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsid.kt b/automation/src/main/java/info/nightscout/automation/triggers/TriggerWifiSsid.kt similarity index 85% rename from automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsid.kt rename to automation/src/main/java/info/nightscout/automation/triggers/TriggerWifiSsid.kt index 593b14d770..8431aac4d0 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsid.kt +++ b/automation/src/main/java/info/nightscout/automation/triggers/TriggerWifiSsid.kt @@ -1,17 +1,17 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.automation.R -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -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.plugins.general.automation.elements.StaticLabel import info.nightscout.androidaps.receivers.ReceiverStatusStore import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputString +import info.nightscout.automation.elements.LabelWithElement +import info.nightscout.automation.elements.LayoutBuilder +import info.nightscout.automation.elements.StaticLabel +import info.nightscout.shared.logging.LTag import org.json.JSONObject import javax.inject.Inject diff --git a/automation/src/main/res/layout/automation_dialog_action.xml b/automation/src/main/res/layout/automation_dialog_action.xml index ba6a516e70..e6a5c7db91 100644 --- a/automation/src/main/res/layout/automation_dialog_action.xml +++ b/automation/src/main/res/layout/automation_dialog_action.xml @@ -6,7 +6,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:focusableInTouchMode="true" - tools:context="info.nightscout.androidaps.plugins.general.automation.dialogs.EditActionDialog"> + tools:context="info.nightscout.automation.dialogs.EditActionDialog"> + tools:context="info.nightscout.automation.dialogs.EditEventDialog"> + tools:context="info.nightscout.automation.dialogs.ChooseOperationDialog"> + tools:context="info.nightscout.automation.dialogs.EditEventDialog"> + tools:context="info.nightscout.automation.dialogs.EditEventDialog"> + tools:context="info.nightscout.automation.dialogs.EditEventDialog"> + tools:context="info.nightscout.automation.AutomationFragment"> uninitialized(): T = null as T -} +} \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/TestBaseWithProfile.kt b/automation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt similarity index 96% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/TestBaseWithProfile.kt rename to automation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index 84cda9cefb..af1f3c622a 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/TestBaseWithProfile.kt +++ b/automation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -1,8 +1,7 @@ -package info.nightscout.androidaps.plugins.general.automation +package info.nightscout.androidaps import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.extensions.pureProfileFromJson @@ -11,11 +10,11 @@ import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileStore +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.interfaces.ResourceHelper import org.json.JSONObject import org.junit.Before import org.mockito.Mock @@ -59,4 +58,4 @@ open class TestBaseWithProfile : TestBase() { json.put("store", store) return ProfileStore(profileInjector, json, dateUtil) } -} +} \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/TestPumpPlugin.kt b/automation/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt similarity index 92% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/TestPumpPlugin.kt rename to automation/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt index 33a9e512c7..105a41ab8d 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/TestPumpPlugin.kt +++ b/automation/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt @@ -2,25 +2,26 @@ package info.nightscout.androidaps import dagger.android.HasAndroidInjector import info.nightscout.androidaps.data.DetailedBolusInfo -import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginDescription -import info.nightscout.androidaps.interfaces.PumpDescription +import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.Pump +import info.nightscout.androidaps.interfaces.PumpDescription import info.nightscout.androidaps.interfaces.PumpSync -import info.nightscout.shared.logging.AAPSLogger +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.plugins.common.ManufacturerType import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.utils.TimeChangeType -import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.shared.logging.AAPSLogger import org.json.JSONObject @Suppress("MemberVisibilityCanBePrivate") -class TestPumpPlugin(pluginDescription: PluginDescription, - aapsLogger: AAPSLogger, - rh: ResourceHelper, - injector: HasAndroidInjector +class TestPumpPlugin( + pluginDescription: PluginDescription, + aapsLogger: AAPSLogger, + rh: ResourceHelper, + injector: HasAndroidInjector ) : PluginBase( pluginDescription, aapsLogger, rh, injector ), Pump { @@ -62,8 +63,13 @@ class TestPumpPlugin(pluginDescription: PluginDescription, override val batteryLevel: Int = 0 override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult = PumpEnactResult(injector).success(true) override fun stopBolusDelivering() {} - override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult = PumpEnactResult(injector).success(true) - override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult = PumpEnactResult(injector).success(true) + override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult = PumpEnactResult( + injector + ).success(true) + + override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult = + PumpEnactResult(injector).success(true) + override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult = PumpEnactResult(injector).success(true) override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult = PumpEnactResult(injector).success(true) override fun cancelExtendedBolus(): PumpEnactResult = PumpEnactResult(injector).success(true) diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionTest.kt deleted file mode 100644 index d199e76bc2..0000000000 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionTest.kt +++ /dev/null @@ -1,14 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.actions - -import org.json.JSONObject -import org.junit.Assert -import org.junit.Test - -class ActionTest : ActionsTestBase() { - - @Test - fun instantiateTest() { - val action: Action? = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionDummy\"}")) - Assert.assertNotEquals(null, action) - } -} \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabelTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabelTest.kt deleted file mode 100644 index 1277a84251..0000000000 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabelTest.kt +++ /dev/null @@ -1,19 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.elements - -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase -import org.junit.Assert -import org.junit.Test -import org.mockito.Mockito.`when` - -class StaticLabelTest : TriggerTestBase() { - - @Test fun constructor() { - var sl = StaticLabel(rh, "any", TriggerDummy(injector)) - Assert.assertEquals("any", sl.label) - `when`(rh.gs(R.string.pumplimit)).thenReturn("pump limit") - sl = StaticLabel(rh, R.string.pumplimit, TriggerDummy(injector)) - Assert.assertEquals("pump limit", sl.label) - } -} \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/DummyTrigger.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/DummyTrigger.kt deleted file mode 100644 index feccdb7804..0000000000 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/DummyTrigger.kt +++ /dev/null @@ -1,17 +0,0 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers - -import com.google.common.base.Optional -import dagger.android.AndroidInjector -import dagger.android.HasAndroidInjector -import org.json.JSONObject - -class DummyTrigger(var result: Boolean) : Trigger(HasAndroidInjector { AndroidInjector { } }) { - - override fun shouldRun(): Boolean = result - override fun dataJSON(): JSONObject = JSONObject() - override fun fromJSON(data: String): Trigger = DummyTrigger(result) - override fun friendlyName(): Int = 0 - override fun friendlyDescription(): String = " " - override fun icon(): Optional = Optional.absent() - override fun duplicate(): Trigger = DummyTrigger(result) -} \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/AutomationEventTest.kt b/automation/src/test/java/info/nightscout/automation/AutomationEventTest.kt similarity index 84% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/AutomationEventTest.kt rename to automation/src/test/java/info/nightscout/automation/AutomationEventTest.kt index 68066c6e7b..dac65a3f52 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/AutomationEventTest.kt +++ b/automation/src/test/java/info/nightscout/automation/AutomationEventTest.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation +package info.nightscout.automation import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector @@ -7,12 +7,12 @@ import info.nightscout.androidaps.interfaces.ConfigBuilder import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.plugins.general.automation.actions.Action -import info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopEnable -import info.nightscout.androidaps.plugins.general.automation.actions.ActionStopProcessing -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnectorTest -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy +import info.nightscout.automation.actions.Action +import info.nightscout.automation.actions.ActionLoopEnable +import info.nightscout.automation.actions.ActionStopProcessing +import info.nightscout.automation.triggers.TriggerConnector +import info.nightscout.automation.triggers.TriggerConnectorTest +import info.nightscout.automation.triggers.TriggerDummy import org.json.JSONObject import org.junit.Assert import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/ComposeTriggerTest.kt b/automation/src/test/java/info/nightscout/automation/ComposeTriggerTest.kt similarity index 81% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/ComposeTriggerTest.kt rename to automation/src/test/java/info/nightscout/automation/ComposeTriggerTest.kt index 01ddca5cbe..7b30c7a594 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/ComposeTriggerTest.kt +++ b/automation/src/test/java/info/nightscout/automation/ComposeTriggerTest.kt @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.general.automation +package info.nightscout.automation import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase -import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy +import info.nightscout.automation.triggers.Trigger +import info.nightscout.automation.triggers.TriggerConnector +import info.nightscout.automation.triggers.TriggerDummy import org.junit.Assert import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarmTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionAlarmTest.kt similarity index 81% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarmTest.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionAlarmTest.kt index ebdc64227a..63cf3e0c82 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarmTest.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionAlarmTest.kt @@ -1,13 +1,13 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase -import info.nightscout.androidaps.automation.R +import info.nightscout.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.plugins.general.automation.elements.InputString +import info.nightscout.automation.elements.InputString import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.TimerUtil @@ -45,15 +45,15 @@ class ActionAlarmTest : TestBase() { @Before fun setup() { - `when`(rh.gs(R.string.ok)).thenReturn("OK") - `when`(rh.gs(R.string.alarm)).thenReturn("Alarm") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.ok)).thenReturn("OK") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.alarm)).thenReturn("Alarm") `when`(rh.gs(ArgumentMatchers.eq(R.string.alarm_message), ArgumentMatchers.anyString())).thenReturn("Alarm: %s") sut = ActionAlarm(injector) } @Test fun friendlyNameTest() { - Assert.assertEquals(R.string.alarm, sut.friendlyName()) + Assert.assertEquals(info.nightscout.androidaps.core.R.string.alarm, sut.friendlyName()) } @Test fun shortDescriptionTest() { @@ -62,7 +62,7 @@ class ActionAlarmTest : TestBase() { } @Test fun iconTest() { - Assert.assertEquals(R.drawable.ic_access_alarm_24dp, sut.icon()) + Assert.assertEquals(info.nightscout.androidaps.core.R.drawable.ic_access_alarm_24dp, sut.icon()) } @Test fun doActionTest() { @@ -79,7 +79,7 @@ class ActionAlarmTest : TestBase() { @Test fun toJSONTest() { sut.text = InputString("Asd") - Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionAlarm\"}", sut.toJSON()) + Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"ActionAlarm\"}", sut.toJSON()) } @Test fun fromJSONTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionCarePortalEventTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionCarePortalEventTest.kt similarity index 77% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionCarePortalEventTest.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionCarePortalEventTest.kt index 430ae5e11c..658218e35f 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionCarePortalEventTest.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionCarePortalEventTest.kt @@ -1,13 +1,12 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.transactions.InsertIfNewByTimestampTherapyEventTransaction import info.nightscout.androidaps.database.transactions.Transaction import info.nightscout.androidaps.interfaces.GlucoseUnit -import info.nightscout.androidaps.plugins.general.automation.elements.InputCarePortalMenu -import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration -import info.nightscout.androidaps.plugins.general.automation.elements.InputString import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.elements.InputCarePortalMenu +import info.nightscout.automation.elements.InputDuration +import info.nightscout.automation.elements.InputString import io.reactivex.rxjava3.core.Single import org.junit.Assert import org.junit.Before @@ -24,7 +23,7 @@ class ActionCarePortalEventTest : ActionsTestBase() { `when`(sp.getString(ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn("AAPS") `when`( rh.gs( - ArgumentMatchers.eq(R.string.careportal_note_message), + ArgumentMatchers.eq(info.nightscout.androidaps.core.R.string.careportal_note_message), ArgumentMatchers.anyString() ) ).thenReturn("Note : %s") @@ -41,7 +40,7 @@ class ActionCarePortalEventTest : ActionsTestBase() { } @Test fun friendlyNameTest() { - Assert.assertEquals(R.string.careportal, sut.friendlyName()) + Assert.assertEquals(info.nightscout.androidaps.core.R.string.careportal, sut.friendlyName()) } @Test fun shortDescriptionTest() { @@ -49,7 +48,7 @@ class ActionCarePortalEventTest : ActionsTestBase() { } @Test fun iconTest() { - Assert.assertEquals(R.drawable.ic_cp_note, sut.icon()) + Assert.assertEquals(info.nightscout.androidaps.core.R.drawable.ic_cp_note, sut.icon()) } @Test fun doActionTest() { @@ -66,7 +65,7 @@ class ActionCarePortalEventTest : ActionsTestBase() { @Test fun toJSONTest() { Assert.assertEquals( - "{\"data\":{\"note\":\"Asd\",\"cpEvent\":\"NOTE\",\"durationInMinutes\":5},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionCarePortalEvent\"}", + "{\"data\":{\"note\":\"Asd\",\"cpEvent\":\"NOTE\",\"durationInMinutes\":5},\"type\":\"ActionCarePortalEvent\"}", sut.toJSON() ) } diff --git a/automation/src/test/java/info/nightscout/automation/actions/ActionDummyTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionDummyTest.kt new file mode 100644 index 0000000000..7dc016bee4 --- /dev/null +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionDummyTest.kt @@ -0,0 +1,20 @@ +package info.nightscout.automation.actions + +import org.json.JSONObject +import org.junit.Assert +import org.junit.Test + +class ActionDummyTest : ActionsTestBase() { + + @Test + fun instantiateTest() { + var action: Action? = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionDummy\"}")) + Assert.assertTrue(action is ActionDummy) + + action = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"info.nightscout.automation.actions.ActionDummy\"}")) + Assert.assertTrue(action is ActionDummy) + + action = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"ActionDummy\"}")) + Assert.assertTrue(action is ActionDummy) + } +} \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisableTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionLoopDisableTest.kt similarity index 86% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisableTest.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionLoopDisableTest.kt index 17858ebea5..92c68df644 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisableTest.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionLoopDisableTest.kt @@ -1,8 +1,8 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.R import org.junit.Assert import org.junit.Before import org.junit.Test @@ -18,7 +18,7 @@ class ActionLoopDisableTest : ActionsTestBase() { fun setup() { testPumpPlugin.pumpDescription.isTempBasalCapable = true - `when`(rh.gs(R.string.disableloop)).thenReturn("Disable loop") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.disableloop)).thenReturn("Disable loop") `when`(rh.gs(R.string.alreadydisabled)).thenReturn("Disable loop") sut = ActionLoopDisable(injector) @@ -26,7 +26,7 @@ class ActionLoopDisableTest : ActionsTestBase() { @Test fun friendlyNameTest() { - Assert.assertEquals(R.string.disableloop, sut.friendlyName()) + Assert.assertEquals(info.nightscout.androidaps.core.R.string.disableloop, sut.friendlyName()) } @Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnableTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionLoopEnableTest.kt similarity index 84% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnableTest.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionLoopEnableTest.kt index 0ab4e677f2..2de25cfe10 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnableTest.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionLoopEnableTest.kt @@ -1,8 +1,8 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.R import org.junit.Assert import org.junit.Before import org.junit.Test @@ -17,14 +17,14 @@ class ActionLoopEnableTest : ActionsTestBase() { fun setup() { testPumpPlugin.pumpDescription.isTempBasalCapable = true - `when`(rh.gs(R.string.enableloop)).thenReturn("Enable loop") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.enableloop)).thenReturn("Enable loop") `when`(rh.gs(R.string.alreadyenabled)).thenReturn("Already enabled") sut = ActionLoopEnable(injector) } @Test fun friendlyNameTest() { - Assert.assertEquals(R.string.enableloop, sut.friendlyName()) + Assert.assertEquals(info.nightscout.androidaps.core.R.string.enableloop, sut.friendlyName()) } @Test fun shortDescriptionTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResumeTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionLoopResumeTest.kt similarity index 88% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResumeTest.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionLoopResumeTest.kt index 00957cab4a..ae8d4041b7 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResumeTest.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionLoopResumeTest.kt @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.transactions.CancelCurrentOfflineEventIfAnyTransaction import info.nightscout.androidaps.database.transactions.Transaction import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.R import io.reactivex.rxjava3.core.Single import org.junit.Assert import org.junit.Before @@ -18,14 +18,14 @@ class ActionLoopResumeTest : ActionsTestBase() { @Before fun setup() { - `when`(rh.gs(R.string.resumeloop)).thenReturn("Resume loop") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.resumeloop)).thenReturn("Resume loop") `when`(rh.gs(R.string.notsuspended)).thenReturn("Not suspended") sut = ActionLoopResume(injector) } @Test fun friendlyNameTest() { - Assert.assertEquals(R.string.resumeloop, sut.friendlyName()) + Assert.assertEquals(info.nightscout.androidaps.core.R.string.resumeloop, sut.friendlyName()) } @Test fun shortDescriptionTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspendTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionLoopSuspendTest.kt similarity index 85% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspendTest.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionLoopSuspendTest.kt index 2c5bddf948..b63948e44f 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspendTest.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionLoopSuspendTest.kt @@ -1,7 +1,7 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputDuration import info.nightscout.androidaps.queue.Callback import org.junit.Assert import org.junit.Before @@ -17,7 +17,7 @@ class ActionLoopSuspendTest : ActionsTestBase() { @Before fun setup() { - `when`(rh.gs(R.string.suspendloop)).thenReturn("Suspend loop") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.suspendloop)).thenReturn("Suspend loop") `when`(rh.gs(ArgumentMatchers.eq(R.string.suspendloopforXmin), ArgumentMatchers.anyInt())).thenReturn("Suspend loop for %d min") `when`(rh.gs(R.string.alreadysuspended)).thenReturn("Already suspended") @@ -25,7 +25,7 @@ class ActionLoopSuspendTest : ActionsTestBase() { } @Test fun friendlyNameTest() { - Assert.assertEquals(R.string.suspendloop, sut.friendlyName()) + Assert.assertEquals(info.nightscout.androidaps.core.R.string.suspendloop, sut.friendlyName()) } @Test fun shortDescriptionTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionNotificationTest.kt similarity index 84% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionNotificationTest.kt index 7d607b32d0..40735be08d 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionNotificationTest.kt @@ -1,15 +1,15 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase -import info.nightscout.androidaps.automation.R +import info.nightscout.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction import info.nightscout.androidaps.database.transactions.Transaction import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.plugins.general.automation.elements.InputString +import info.nightscout.automation.elements.InputString import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.interfaces.ResourceHelper import io.reactivex.rxjava3.core.Completable @@ -43,8 +43,8 @@ class ActionNotificationTest : TestBase() { @Before fun setup() { - `when`(rh.gs(R.string.ok)).thenReturn("OK") - `when`(rh.gs(R.string.notification)).thenReturn("Notification") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.ok)).thenReturn("OK") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.notification)).thenReturn("Notification") `when`( rh.gs( ArgumentMatchers.eq(R.string.notification_message), @@ -58,7 +58,7 @@ class ActionNotificationTest : TestBase() { } @Test fun friendlyNameTest() { - Assert.assertEquals(R.string.notification, sut.friendlyName()) + Assert.assertEquals(info.nightscout.androidaps.core.R.string.notification, sut.friendlyName()) } @Test fun shortDescriptionTest() { @@ -87,7 +87,7 @@ class ActionNotificationTest : TestBase() { @Test fun toJSONTest() { sut.text = InputString("Asd") Assert.assertEquals( - "{\"data\":{\"text\":\"Asd\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionNotification\"}", + "{\"data\":{\"text\":\"Asd\"},\"type\":\"ActionNotification\"}", sut.toJSON() ) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercentTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionProfileSwitchPercentTest.kt similarity index 75% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercentTest.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionProfileSwitchPercentTest.kt index 7a37cac6e0..03850393fa 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercentTest.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionProfileSwitchPercentTest.kt @@ -1,13 +1,12 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration -import info.nightscout.androidaps.plugins.general.automation.elements.InputPercent import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputDuration +import info.nightscout.automation.elements.InputPercent import org.junit.Assert import org.junit.Before import org.junit.Test -import org.mockito.ArgumentMatchers import org.mockito.Mockito import org.mockito.Mockito.`when` @@ -19,7 +18,7 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() { fun setup() { `when`(rh.gs(R.string.startprofileforever)).thenReturn("Start profile %d%%") - `when`(rh.gs(R.string.startprofile)).thenReturn("Start profile %d%% for %d min") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.startprofile)).thenReturn("Start profile %d%% for %d min") sut = ActionProfileSwitchPercent(injector) } @@ -35,7 +34,7 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() { } @Test fun iconTest() { - Assert.assertEquals(R.drawable.ic_actions_profileswitch, sut.icon()) + Assert.assertEquals(info.nightscout.androidaps.core.R.drawable.ic_actions_profileswitch, sut.icon()) } @Test fun doActionTest() { @@ -57,7 +56,7 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() { @Test fun toJSONTest() { sut.pct = InputPercent(100.0) sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES) - Assert.assertEquals("{\"data\":{\"percentage\":100,\"durationInMinutes\":30},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionProfileSwitchPercent\"}", sut.toJSON()) + Assert.assertEquals("{\"data\":{\"percentage\":100,\"durationInMinutes\":30},\"type\":\"ActionProfileSwitchPercent\"}", sut.toJSON()) } @Test fun fromJSONTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionProfileSwitchTest.kt similarity index 85% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchTest.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionProfileSwitchTest.kt index 51d36bf4f3..0bdb7fd185 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchTest.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionProfileSwitchTest.kt @@ -1,31 +1,31 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.plugins.general.automation.elements.InputProfileName import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputProfileName import org.junit.Assert import org.junit.Before import org.junit.Test import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers.anyLong import org.mockito.Mockito -import org.mockito.Mockito.`when` import org.mockito.Mockito.anyInt import org.mockito.Mockito.anyString +import org.mockito.Mockito.`when` class ActionProfileSwitchTest : ActionsTestBase() { private lateinit var sut: ActionProfileSwitch - private val stringJson = "{\"data\":{\"profileToSwitchTo\":\"Test\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionProfileSwitch\"}" + private val stringJson = "{\"data\":{\"profileToSwitchTo\":\"Test\"},\"type\":\"ActionProfileSwitch\"}" @Before fun setUp() { `when`(rh.gs(R.string.profilename)).thenReturn("Change profile to") `when`(rh.gs(ArgumentMatchers.eq(R.string.changengetoprofilename), ArgumentMatchers.anyString())).thenReturn("Change profile to %s") `when`(rh.gs(R.string.alreadyset)).thenReturn("Already set") - `when`(rh.gs(R.string.notexists)).thenReturn("not exists") - `when`(rh.gs(R.string.error_field_must_not_be_empty)).thenReturn("The field must not be empty") - `when`(rh.gs(R.string.noprofile)).thenReturn("No profile loaded from NS yet") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.notexists)).thenReturn("not exists") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.error_field_must_not_be_empty)).thenReturn("The field must not be empty") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.noprofile)).thenReturn("No profile loaded from NS yet") sut = ActionProfileSwitch(injector) } @@ -107,6 +107,6 @@ class ActionProfileSwitchTest : ActionsTestBase() { } @Test fun iconTest() { - Assert.assertEquals(R.drawable.ic_actions_profileswitch, sut.icon()) + Assert.assertEquals(info.nightscout.androidaps.core.R.drawable.ic_actions_profileswitch, sut.icon()) } } \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMSTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionSendSMSTest.kt similarity index 84% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMSTest.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionSendSMSTest.kt index d6ef7fd7a2..b41950d690 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMSTest.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionSendSMSTest.kt @@ -1,8 +1,8 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.plugins.general.automation.elements.InputString import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputString import org.junit.Assert import org.junit.Before import org.junit.Test @@ -51,7 +51,7 @@ class ActionSendSMSTest : ActionsTestBase() { @Test fun toJSONTest() { sut.text = InputString("Asd") - Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionSendSMS\"}", sut.toJSON()) + Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"ActionSendSMS\"}", sut.toJSON()) } @Test fun fromJSONTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionStartTempTargetTest.kt similarity index 86% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionStartTempTargetTest.kt index 0777e6a687..8c6d3a2e3a 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionStartTempTargetTest.kt @@ -1,13 +1,13 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.transactions.InsertAndCancelCurrentTemporaryTargetTransaction import info.nightscout.androidaps.database.transactions.Transaction import info.nightscout.androidaps.interfaces.GlucoseUnit -import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration -import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputDuration +import info.nightscout.automation.elements.InputTempTarget import io.reactivex.rxjava3.core.Single import org.junit.Assert import org.junit.Before @@ -38,12 +38,12 @@ class ActionStartTempTargetTest : ActionsTestBase() { } @Test fun iconTest() { - Assert.assertEquals(R.drawable.ic_temptarget_high, sut.icon()) + Assert.assertEquals(info.nightscout.androidaps.core.R.drawable.ic_temptarget_high, sut.icon()) } @Test fun doActionTest() { - val expectedTarget = TemporaryTarget( + val expectedTarget = TemporaryTarget( id = 0, version = 0, dateCreated = -1, @@ -92,7 +92,7 @@ class ActionStartTempTargetTest : ActionsTestBase() { sut.value = InputTempTarget(profileFunction) sut.value.value = 100.0 sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES) - Assert.assertEquals("{\"data\":{\"durationInMinutes\":30,\"units\":\"mg/dl\",\"value\":100},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionStartTempTarget\"}", sut.toJSON()) + Assert.assertEquals("{\"data\":{\"durationInMinutes\":30,\"units\":\"mg/dl\",\"value\":100},\"type\":\"ActionStartTempTarget\"}", sut.toJSON()) } @Test fun fromJSONTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopProcessingTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionStopProcessingTest.kt similarity index 89% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopProcessingTest.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionStopProcessingTest.kt index c16de7bdac..665b3e6d9e 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopProcessingTest.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionStopProcessingTest.kt @@ -1,7 +1,7 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.R import org.junit.Assert import org.junit.Before import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTargetTest.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionStopTempTargetTest.kt similarity index 95% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTargetTest.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionStopTempTargetTest.kt index 0f0e80eb8f..376a1810ea 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTargetTest.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionStopTempTargetTest.kt @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction import info.nightscout.androidaps.database.transactions.Transaction import info.nightscout.androidaps.queue.Callback +import info.nightscout.automation.R import io.reactivex.rxjava3.core.Single import org.junit.Assert import org.junit.Before diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt b/automation/src/test/java/info/nightscout/automation/actions/ActionsTestBase.kt similarity index 84% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt rename to automation/src/test/java/info/nightscout/automation/actions/ActionsTestBase.kt index dcd0e94cba..2816ef4527 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt +++ b/automation/src/test/java/info/nightscout/automation/actions/ActionsTestBase.kt @@ -1,17 +1,26 @@ -package info.nightscout.androidaps.plugins.general.automation.actions +package info.nightscout.automation.actions import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestPumpPlugin -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.database.entities.OfflineEvent -import info.nightscout.androidaps.interfaces.* -import info.nightscout.shared.logging.AAPSLogger -import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.plugins.general.automation.TestBaseWithProfile -import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger +import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.CommandQueue +import info.nightscout.androidaps.interfaces.ConfigBuilder +import info.nightscout.androidaps.interfaces.Constraint +import info.nightscout.androidaps.interfaces.GlucoseUnit +import info.nightscout.androidaps.interfaces.Loop +import info.nightscout.androidaps.interfaces.PluginBase +import info.nightscout.androidaps.interfaces.PluginDescription +import info.nightscout.androidaps.interfaces.Profile +import info.nightscout.androidaps.interfaces.ProfileSource import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.interfaces.SmsCommunicator +import info.nightscout.androidaps.logging.UserEntryLogger +import info.nightscout.automation.triggers.Trigger +import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.sharedPreferences.SP import org.junit.Before import org.mockito.Mock @@ -154,6 +163,11 @@ ActionsTestBase : TestBaseWithProfile() { if (it is Trigger) { it.rh = rh it.profileFunction = profileFunction + it.aapsLogger = aapsLogger + } + if (it is Action) { + it.rh = rh + it.aapsLogger = aapsLogger } } } @@ -166,7 +180,7 @@ ActionsTestBase : TestBaseWithProfile() { `when`(activePlugin.activeProfileSource).thenReturn(profilePlugin) `when`(profilePlugin.profile).thenReturn(getValidProfileStore()) - `when`(rh.gs(R.string.ok)).thenReturn("OK") - `when`(rh.gs(R.string.error)).thenReturn("Error") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.ok)).thenReturn("OK") + `when`(rh.gs(info.nightscout.androidaps.core.R.string.error)).thenReturn("Error") } } \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnectTest.kt b/automation/src/test/java/info/nightscout/automation/elements/ComparatorConnectTest.kt similarity index 72% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnectTest.kt rename to automation/src/test/java/info/nightscout/automation/elements/ComparatorConnectTest.kt index 045b3f30a7..cca7b80c41 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnectTest.kt +++ b/automation/src/test/java/info/nightscout/automation/elements/ComparatorConnectTest.kt @@ -1,6 +1,6 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import info.nightscout.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt b/automation/src/test/java/info/nightscout/automation/elements/ComparatorExistsTest.kt similarity index 72% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt rename to automation/src/test/java/info/nightscout/automation/elements/ComparatorExistsTest.kt index 8d5e8a487e..d0aab2680b 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt +++ b/automation/src/test/java/info/nightscout/automation/elements/ComparatorExistsTest.kt @@ -1,6 +1,6 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import info.nightscout.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt b/automation/src/test/java/info/nightscout/automation/elements/ComparatorTest.kt similarity index 89% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt rename to automation/src/test/java/info/nightscout/automation/elements/ComparatorTest.kt index 7a6532916e..b49396950a 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt +++ b/automation/src/test/java/info/nightscout/automation/elements/ComparatorTest.kt @@ -1,6 +1,6 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import info.nightscout.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt b/automation/src/test/java/info/nightscout/automation/elements/InputBgTest.kt similarity index 83% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt rename to automation/src/test/java/info/nightscout/automation/elements/InputBgTest.kt index ee20a8e851..c30f473d11 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt +++ b/automation/src/test/java/info/nightscout/automation/elements/InputBgTest.kt @@ -1,7 +1,7 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import info.nightscout.androidaps.interfaces.GlucoseUnit -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import info.nightscout.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Before import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputCarePortalEventTest.kt b/automation/src/test/java/info/nightscout/automation/elements/InputCarePortalEventTest.kt similarity index 72% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputCarePortalEventTest.kt rename to automation/src/test/java/info/nightscout/automation/elements/InputCarePortalEventTest.kt index 54c50a5825..64ea7220a9 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputCarePortalEventTest.kt +++ b/automation/src/test/java/info/nightscout/automation/elements/InputCarePortalEventTest.kt @@ -1,6 +1,6 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import info.nightscout.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt b/automation/src/test/java/info/nightscout/automation/elements/InputDurationTest.kt similarity index 70% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt rename to automation/src/test/java/info/nightscout/automation/elements/InputDurationTest.kt index 424efd6d36..cf02692df8 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt +++ b/automation/src/test/java/info/nightscout/automation/elements/InputDurationTest.kt @@ -1,13 +1,13 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import info.nightscout.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test class InputDurationTest : TriggerTestBase() { @Test fun setValueTest() { - var i = InputDuration( 5, InputDuration.TimeUnit.MINUTES) + var i = InputDuration(5, InputDuration.TimeUnit.MINUTES) Assert.assertEquals(5, i.value) Assert.assertEquals(InputDuration.TimeUnit.MINUTES, i.unit) i = InputDuration(5, InputDuration.TimeUnit.HOURS) diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt b/automation/src/test/java/info/nightscout/automation/elements/InputInsulinTest.kt similarity index 59% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt rename to automation/src/test/java/info/nightscout/automation/elements/InputInsulinTest.kt index c2b2c53ceb..00a0fea092 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt +++ b/automation/src/test/java/info/nightscout/automation/elements/InputInsulinTest.kt @@ -1,6 +1,6 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import info.nightscout.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt b/automation/src/test/java/info/nightscout/automation/elements/InputPercentTest.kt similarity index 59% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt rename to automation/src/test/java/info/nightscout/automation/elements/InputPercentTest.kt index a75c044cf7..e53295b8fc 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt +++ b/automation/src/test/java/info/nightscout/automation/elements/InputPercentTest.kt @@ -1,6 +1,6 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import info.nightscout.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileNameTest.kt b/automation/src/test/java/info/nightscout/automation/elements/InputProfileNameTest.kt similarity index 70% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileNameTest.kt rename to automation/src/test/java/info/nightscout/automation/elements/InputProfileNameTest.kt index 176672c9e1..02b0d088a9 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileNameTest.kt +++ b/automation/src/test/java/info/nightscout/automation/elements/InputProfileNameTest.kt @@ -1,6 +1,6 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import info.nightscout.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt b/automation/src/test/java/info/nightscout/automation/elements/InputStringTest.kt similarity index 59% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt rename to automation/src/test/java/info/nightscout/automation/elements/InputStringTest.kt index 7bce11b606..03d5c45934 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt +++ b/automation/src/test/java/info/nightscout/automation/elements/InputStringTest.kt @@ -1,6 +1,6 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import info.nightscout.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt b/automation/src/test/java/info/nightscout/automation/elements/InputTempTargetTest.kt similarity index 76% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt rename to automation/src/test/java/info/nightscout/automation/elements/InputTempTargetTest.kt index 6690a7a017..569a23d4b6 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt +++ b/automation/src/test/java/info/nightscout/automation/elements/InputTempTargetTest.kt @@ -1,7 +1,7 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import info.nightscout.androidaps.interfaces.GlucoseUnit -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import info.nightscout.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElementTest.kt b/automation/src/test/java/info/nightscout/automation/elements/LabelWithElementTest.kt similarity index 70% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElementTest.kt rename to automation/src/test/java/info/nightscout/automation/elements/LabelWithElementTest.kt index 32eb7379a2..d1b390de69 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElementTest.kt +++ b/automation/src/test/java/info/nightscout/automation/elements/LabelWithElementTest.kt @@ -1,6 +1,6 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase +import info.nightscout.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilderTest.kt b/automation/src/test/java/info/nightscout/automation/elements/LayoutBuilderTest.kt similarity index 92% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilderTest.kt rename to automation/src/test/java/info/nightscout/automation/elements/LayoutBuilderTest.kt index 76b1e01d42..35130ebc34 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilderTest.kt +++ b/automation/src/test/java/info/nightscout/automation/elements/LayoutBuilderTest.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.elements +package info.nightscout.automation.elements import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector diff --git a/automation/src/test/java/info/nightscout/automation/elements/StaticLabelTest.kt b/automation/src/test/java/info/nightscout/automation/elements/StaticLabelTest.kt new file mode 100644 index 0000000000..64a9058643 --- /dev/null +++ b/automation/src/test/java/info/nightscout/automation/elements/StaticLabelTest.kt @@ -0,0 +1,18 @@ +package info.nightscout.automation.elements + +import info.nightscout.automation.triggers.TriggerDummy +import info.nightscout.automation.triggers.TriggerTestBase +import org.junit.Assert +import org.junit.Test +import org.mockito.Mockito.`when` + +class StaticLabelTest : TriggerTestBase() { + + @Test fun constructor() { + var sl = StaticLabel(rh, "any", TriggerDummy(injector)) + Assert.assertEquals("any", sl.label) + `when`(rh.gs(info.nightscout.androidaps.core.R.string.pumplimit)).thenReturn("pump limit") + sl = StaticLabel(rh, info.nightscout.androidaps.core.R.string.pumplimit, TriggerDummy(injector)) + Assert.assertEquals("pump limit", sl.label) + } +} \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValueTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerAutosensValueTest.kt similarity index 90% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValueTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerAutosensValueTest.kt index ab2563b0d7..e054fd2f8c 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValueTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerAutosensValueTest.kt @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator import org.json.JSONObject import org.junit.Assert import org.junit.Before @@ -16,8 +16,8 @@ class TriggerAutosensValueTest : TriggerTestBase() { var now = 1514766900000L @Test fun shouldRunTest() { - `when`(sp.getDouble(Mockito.eq(R.string.key_openapsama_autosens_max), ArgumentMatchers.anyDouble())).thenReturn(1.2) - `when`(sp.getDouble(Mockito.eq(R.string.key_openapsama_autosens_min), ArgumentMatchers.anyDouble())).thenReturn(0.7) + `when`(sp.getDouble(Mockito.eq(info.nightscout.androidaps.core.R.string.key_openapsama_autosens_max), ArgumentMatchers.anyDouble())).thenReturn(1.2) + `when`(sp.getDouble(Mockito.eq(info.nightscout.androidaps.core.R.string.key_openapsama_autosens_min), ArgumentMatchers.anyDouble())).thenReturn(0.7) `when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(generateAutosensData()) var t = TriggerAutosensValue(injector) t.autosens.value = 110.0 diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDeviceTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerBTDeviceTest.kt similarity index 81% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDeviceTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerBTDeviceTest.kt index 4ddeded933..c717c94d4f 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDeviceTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerBTDeviceTest.kt @@ -1,8 +1,7 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.plugins.general.automation.elements.ComparatorConnect +import info.nightscout.automation.elements.ComparatorConnect import org.json.JSONObject import org.junit.Assert import org.junit.Test @@ -34,7 +33,7 @@ class TriggerBTDeviceTest : TriggerTestBase() { @Test fun icon() { - Assert.assertEquals(Optional.of(R.drawable.ic_bluetooth_white_48dp), TriggerBTDevice(injector).icon()) + Assert.assertEquals(Optional.of(info.nightscout.androidaps.core.R.drawable.ic_bluetooth_white_48dp), TriggerBTDevice(injector).icon()) } @Test fun duplicate() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBgTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerBgTest.kt similarity index 87% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBgTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerBgTest.kt index e9ee52718f..3e2565f11b 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBgTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerBgTest.kt @@ -1,16 +1,14 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.entities.GlucoseValue import info.nightscout.androidaps.interfaces.GlucoseUnit -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator +import info.nightscout.automation.elements.Comparator import org.json.JSONObject import org.junit.Assert import org.junit.Before import org.junit.Test import org.mockito.Mockito.`when` -import java.util.* class TriggerBgTest : TriggerTestBase() { @@ -78,19 +76,21 @@ class TriggerBgTest : TriggerTestBase() { @Test fun iconTest() { - Assert.assertEquals(Optional.of(R.drawable.ic_cp_bgcheck), TriggerBg(injector).icon()) + Assert.assertEquals(Optional.of(info.nightscout.androidaps.core.R.drawable.ic_cp_bgcheck), TriggerBg(injector).icon()) } private fun generateOneCurrentRecordBgData(): List { val list: MutableList = ArrayList() - list.add(GlucoseValue( - raw = 0.0, - noise = 0.0, - value = 214.0, - timestamp = now - 1, - sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, - trendArrow = GlucoseValue.TrendArrow.FLAT - )) + list.add( + GlucoseValue( + raw = 0.0, + noise = 0.0, + value = 214.0, + timestamp = now - 1, + sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, + trendArrow = GlucoseValue.TrendArrow.FLAT + ) + ) return list } } \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgoTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerBolusAgoTest.kt similarity index 93% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgoTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerBolusAgoTest.kt index 53f9e0e9c0..f2d2322a5f 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgoTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerBolusAgoTest.kt @@ -1,10 +1,9 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.database.entities.Bolus -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator +import info.nightscout.automation.elements.Comparator import io.reactivex.rxjava3.core.Single import org.json.JSONException import org.json.JSONObject @@ -95,6 +94,6 @@ class TriggerBolusAgoTest : TriggerTestBase() { } @Test fun iconTest() { - Assert.assertEquals(Optional.of(R.drawable.ic_bolus), TriggerBolusAgo(injector).icon()) + Assert.assertEquals(Optional.of(info.nightscout.androidaps.core.R.drawable.ic_bolus), TriggerBolusAgo(injector).icon()) } } \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOBTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerCOBTest.kt similarity index 90% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOBTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerCOBTest.kt index 1176417304..7e7d3634b1 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOBTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerCOBTest.kt @@ -1,9 +1,8 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo +import info.nightscout.automation.elements.Comparator import org.json.JSONObject import org.junit.Assert import org.junit.Before @@ -62,7 +61,7 @@ class TriggerCOBTest : TriggerTestBase() { } @Test fun iconTest() { - Assert.assertEquals(Optional.of(R.drawable.ic_cp_bolus_carbs), TriggerCOB(injector).icon()) + Assert.assertEquals(Optional.of(info.nightscout.androidaps.core.R.drawable.ic_cp_bolus_carbs), TriggerCOB(injector).icon()) } fun generateCobInfo(): CobInfo { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnectorTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerConnectorTest.kt similarity index 84% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnectorTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerConnectorTest.kt index f43006c6d9..388124a452 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnectorTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerConnectorTest.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import org.json.JSONException import org.json.JSONObject @@ -14,14 +14,14 @@ class TriggerConnectorTest : TriggerTestBase() { Assert.assertTrue(t.size() == 0) t.list.add(t2) Assert.assertTrue(t.size() == 1) - Assert.assertEquals(t2, t.list.get(0)) + Assert.assertEquals(t2, t.list[0]) t.list.add(t3) Assert.assertTrue(t.size() == 2) - Assert.assertEquals(t2, t.list.get(0)) - Assert.assertEquals(t3, t.list.get(1)) + Assert.assertEquals(t2, t.list[0]) + Assert.assertEquals(t3, t.list[1]) Assert.assertTrue(t.list.remove(t2)) Assert.assertTrue(t.size() == 1) - Assert.assertEquals(t3, t.list.get(0)) + Assert.assertEquals(t3, t.list[0]) Assert.assertTrue(t.shouldRun()) } @@ -74,7 +74,9 @@ class TriggerConnectorTest : TriggerTestBase() { } companion object { + const val empty = "{\"data\":{\"connectorType\":\"AND\",\"triggerList\":[]},\"type\":\"TriggerConnector\"}" - const val oneItem = "{\"data\":{\"connectorType\":\"AND\",\"triggerList\":[\"{\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[]},\\\"type\\\":\\\"TriggerConnector\\\"}\"]},\"type\":\"TriggerConnector\"}" + const val oneItem = + "{\"data\":{\"connectorType\":\"AND\",\"triggerList\":[\"{\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[]},\\\"type\\\":\\\"TriggerConnector\\\"}\"]},\"type\":\"TriggerConnector\"}" } } \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDeltaTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerDeltaTest.kt similarity index 95% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDeltaTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerDeltaTest.kt index 9f23dffbfc..cd09279d92 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDeltaTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerDeltaTest.kt @@ -1,17 +1,16 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.entities.GlucoseValue import info.nightscout.androidaps.interfaces.GlucoseUnit -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.plugins.general.automation.elements.InputDelta.DeltaType +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputDelta.DeltaType import org.json.JSONObject import org.junit.Assert import org.junit.Before import org.junit.Test import org.mockito.Mockito.`when` -import java.util.* class TriggerDeltaTest : TriggerTestBase() { diff --git a/automation/src/test/java/info/nightscout/automation/triggers/TriggerDummyTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerDummyTest.kt new file mode 100644 index 0000000000..5553062367 --- /dev/null +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerDummyTest.kt @@ -0,0 +1,21 @@ +package info.nightscout.automation.triggers + +import org.json.JSONObject +import org.junit.Assert +import org.junit.Test + +class TriggerDummyTest : TriggerTestBase() { + + @Test + fun instantiateTest() { + var trigger: Trigger? = TriggerDummy(injector).instantiate(JSONObject("{\"data\":{},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy\"}")) + Assert.assertTrue(trigger is TriggerDummy) + + trigger = TriggerDummy(injector).instantiate(JSONObject("{\"data\":{},\"type\":\"info.nightscout.automation.triggers.TriggerDummy\"}")) + Assert.assertTrue(trigger is TriggerDummy) + + trigger = TriggerDummy(injector).instantiate(JSONObject("{\"data\":{},\"type\":\"TriggerDummy\"}")) + Assert.assertTrue(trigger is TriggerDummy) + } + +} \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIobTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerIobTest.kt similarity index 94% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIobTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerIobTest.kt index cb554535e2..d5b7d746c1 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIobTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerIobTest.kt @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.IobTotal -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator import org.json.JSONObject import org.junit.Assert import org.junit.Before diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocationTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerLocationTest.kt similarity index 93% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocationTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerLocationTest.kt index 8f80672065..c2881bb524 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocationTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerLocationTest.kt @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.location.Location import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.plugins.general.automation.elements.InputLocationMode +import info.nightscout.automation.R +import info.nightscout.automation.elements.InputLocationMode import org.json.JSONException import org.json.JSONObject import org.junit.Assert @@ -87,7 +87,7 @@ class TriggerLocationTest : TriggerTestBase() { } @Test fun friendlyNameTest() { - Assert.assertEquals(R.string.location.toLong(), TriggerLocation(injector).friendlyName().toLong()) + Assert.assertEquals(R.string.location, TriggerLocation(injector).friendlyName()) } @Test fun friendlyDescriptionTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercentTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerProfilePercentTest.kt similarity index 86% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercentTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerProfilePercentTest.kt index 75d3e24238..961e624221 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercentTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerProfilePercentTest.kt @@ -1,9 +1,8 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import org.json.JSONException +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator import org.json.JSONObject import org.junit.Assert import org.junit.Before @@ -61,10 +60,10 @@ class TriggerProfilePercentTest : TriggerTestBase() { } @Test fun iconTest() { - Assert.assertEquals(Optional.of(R.drawable.ic_actions_profileswitch), TriggerProfilePercent(injector).icon()) + Assert.assertEquals(Optional.of(info.nightscout.androidaps.core.R.drawable.ic_actions_profileswitch), TriggerProfilePercent(injector).icon()) } @Test fun friendlyNameTest() { - Assert.assertEquals(R.string.profilepercentage.toLong(), TriggerProfilePercent(injector).friendlyName().toLong()) // not mocked + Assert.assertEquals(R.string.profilepercentage, TriggerProfilePercent(injector).friendlyName()) // not mocked } } \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnectionTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerPumpLastConnectionTest.kt similarity index 88% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnectionTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerPumpLastConnectionTest.kt index 1bd94e4e25..bbb6ad5173 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnectionTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerPumpLastConnectionTest.kt @@ -1,8 +1,8 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator import org.json.JSONObject import org.junit.Assert import org.junit.Before @@ -61,10 +61,10 @@ class TriggerPumpLastConnectionTest : TriggerTestBase() { } @Test fun iconTest() { - Assert.assertEquals(Optional.of(R.drawable.ic_remove), TriggerPumpLastConnection(injector).icon()) + Assert.assertEquals(Optional.of(info.nightscout.androidaps.core.R.drawable.ic_remove), TriggerPumpLastConnection(injector).icon()) } @Test fun friendlyNameTest() { - Assert.assertEquals(R.string.automation_trigger_pump_last_connection_label.toLong(), TriggerPumpLastConnection(injector).friendlyName().toLong()) + Assert.assertEquals(R.string.automation_trigger_pump_last_connection_label, TriggerPumpLastConnection(injector).friendlyName()) } } \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTimeTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerRecurringTimeTest.kt similarity index 79% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTimeTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerRecurringTimeTest.kt index e63ec3118b..20063486e6 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTimeTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerRecurringTimeTest.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import info.nightscout.androidaps.utils.MidnightTime import info.nightscout.androidaps.utils.T @@ -10,7 +10,7 @@ import org.mockito.Mockito.`when` class TriggerRecurringTimeTest : TriggerTestBase() { - var now : Long = 0L + var now: Long = 0L @Before fun mock() { now = MidnightTime.calc() + T.mins(95).msecs() // 95 min from midnight @@ -29,7 +29,8 @@ class TriggerRecurringTimeTest : TriggerTestBase() { Assert.assertTrue(t.shouldRun()) } - private var timeJson = "{\"data\":{\"WEDNESDAY\":false,\"MONDAY\":false,\"THURSDAY\":false,\"SUNDAY\":false,\"TUESDAY\":false,\"FRIDAY\":false,\"SATURDAY\":false,\"time\":4444},\"type\":\"TriggerRecurringTime\"}" + private var timeJson = + "{\"data\":{\"WEDNESDAY\":false,\"MONDAY\":false,\"THURSDAY\":false,\"SUNDAY\":false,\"TUESDAY\":false,\"FRIDAY\":false,\"SATURDAY\":false,\"time\":4444},\"type\":\"TriggerRecurringTime\"}" @Test fun toJSONTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerTempTargetTest.kt similarity index 56% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerTempTargetTest.kt index 7960208905..989f1b41ac 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerTempTargetTest.kt @@ -1,8 +1,8 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.plugins.general.automation.elements.ComparatorExists +import info.nightscout.automation.R +import info.nightscout.automation.elements.ComparatorExists import org.json.JSONObject import org.junit.Assert import org.junit.Before @@ -16,20 +16,21 @@ class TriggerTempTargetTest : TriggerTestBase() { @Before fun mock() { `when`(dateUtil.now()).thenReturn(now) } -/* - @Test fun shouldRunTest() { - `when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(null) - var t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS) - Assert.assertFalse(t.shouldRun()) - t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS) - Assert.assertTrue(t.shouldRun()) - `when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(TemporaryTarget(duration = 0, highTarget = 0.0, lowTarget = 0.0, reason = TemporaryTarget.Reason.CUSTOM, timestamp = 0)) - t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS) - Assert.assertFalse(t.shouldRun()) - t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS) - Assert.assertTrue(t.shouldRun()) - } -*/ + + /* + @Test fun shouldRunTest() { + `when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(null) + var t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS) + Assert.assertFalse(t.shouldRun()) + t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS) + Assert.assertTrue(t.shouldRun()) + `when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(TemporaryTarget(duration = 0, highTarget = 0.0, lowTarget = 0.0, reason = TemporaryTarget.Reason.CUSTOM, timestamp = 0)) + t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS) + Assert.assertFalse(t.shouldRun()) + t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS) + Assert.assertTrue(t.shouldRun()) + } + */ @Test fun copyConstructorTest() { val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS) val t1 = t.duplicate() as TriggerTempTarget diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetValueTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerTempTargetValueTest.kt similarity index 88% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetValueTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerTempTargetValueTest.kt index 6c4a09f505..fe75e777a1 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetValueTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerTempTargetValueTest.kt @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.interfaces.GlucoseUnit -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator import io.reactivex.rxjava3.core.Single import org.json.JSONObject import org.junit.Assert @@ -25,7 +25,19 @@ class TriggerTempTargetValueTest : TriggerTestBase() { @Test fun shouldRunTest() { - `when`(repository.getTemporaryTargetActiveAt(dateUtil.now())).thenReturn(Single.just(ValueWrapper.Existing(TemporaryTarget(duration = 60000, highTarget = 140.0, lowTarget = 140.0, reason = TemporaryTarget.Reason.CUSTOM, timestamp = now - 1)))) + `when`(repository.getTemporaryTargetActiveAt(dateUtil.now())).thenReturn( + Single.just( + ValueWrapper.Existing( + TemporaryTarget( + duration = 60000, + highTarget = 140.0, + lowTarget = 140.0, + reason = TemporaryTarget.Reason.CUSTOM, + timestamp = now - 1 + ) + ) + ) + ) var t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL) Assert.assertFalse(t.shouldRun()) t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL) diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerTestBase.kt similarity index 91% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerTestBase.kt index 3e289c6946..fd3c79ad7f 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerTestBase.kt @@ -1,19 +1,19 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestPumpPlugin import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.IobCobCalculator import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin -import info.nightscout.androidaps.plugins.general.automation.TestBaseWithProfile import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStore import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider import info.nightscout.androidaps.receivers.ReceiverStatusStore -import info.nightscout.androidaps.services.LastLocationDataContainer +import info.nightscout.automation.AutomationPlugin +import info.nightscout.automation.services.LastLocationDataContainer import info.nightscout.shared.sharedPreferences.SP import org.junit.Before import org.mockito.Mock diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRangeTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerTimeRangeTest.kt similarity index 85% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRangeTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerTimeRangeTest.kt index 55e31d328f..f4b2967b07 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRangeTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerTimeRangeTest.kt @@ -1,8 +1,8 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.MidnightTime +import info.nightscout.automation.R import org.json.JSONObject import org.junit.Assert import org.junit.Before @@ -57,7 +57,7 @@ class TriggerTimeRangeTest : TriggerTestBase() { } @Test fun friendlyNameTest() { - Assert.assertEquals(R.string.time_range.toLong(), TriggerTimeRange(injector).friendlyName().toLong()) + Assert.assertEquals(R.string.time_range, TriggerTimeRange(injector).friendlyName()) } @Test fun friendlyDescriptionTest() { @@ -65,6 +65,6 @@ class TriggerTimeRangeTest : TriggerTestBase() { } @Test fun iconTest() { - Assert.assertEquals(Optional.of(R.drawable.ic_access_alarm_24dp), TriggerTimeRange(injector).icon()) + Assert.assertEquals(Optional.of(info.nightscout.androidaps.core.R.drawable.ic_access_alarm_24dp), TriggerTimeRange(injector).icon()) } } \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerTimeTest.kt similarity index 84% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerTimeTest.kt index 24f7fc9932..f5c01adea5 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerTimeTest.kt @@ -1,7 +1,6 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.T import org.json.JSONException import org.json.JSONObject @@ -49,7 +48,7 @@ class TriggerTimeTest : TriggerTestBase() { } @Test fun friendlyNameTest() { - Assert.assertEquals(R.string.time.toLong(), TriggerTime(injector).friendlyName().toLong()) + Assert.assertEquals(info.nightscout.androidaps.core.R.string.time, TriggerTime(injector).friendlyName()) } @Test fun friendlyDescriptionTest() { @@ -57,6 +56,6 @@ class TriggerTimeTest : TriggerTestBase() { } @Test fun iconTest() { - Assert.assertEquals(Optional.of(R.drawable.ic_access_alarm_24dp), TriggerTime(injector).icon()) + Assert.assertEquals(Optional.of(info.nightscout.androidaps.core.R.drawable.ic_access_alarm_24dp), TriggerTime(injector).icon()) } } \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsidTest.kt b/automation/src/test/java/info/nightscout/automation/triggers/TriggerWifiSsidTest.kt similarity index 89% rename from automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsidTest.kt rename to automation/src/test/java/info/nightscout/automation/triggers/TriggerWifiSsidTest.kt index 3e7fe4549e..6a1cc6ab8b 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsidTest.kt +++ b/automation/src/test/java/info/nightscout/automation/triggers/TriggerWifiSsidTest.kt @@ -1,9 +1,9 @@ -package info.nightscout.androidaps.plugins.general.automation.triggers +package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.events.EventNetworkChange -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator +import info.nightscout.automation.R +import info.nightscout.automation.elements.Comparator import org.json.JSONException import org.json.JSONObject import org.junit.Assert @@ -65,7 +65,7 @@ class TriggerWifiSsidTest : TriggerTestBase() { } @Test fun friendlyNameTest() { - Assert.assertEquals(R.string.ns_wifi_ssids.toLong(), TriggerWifiSsid(injector).friendlyName().toLong()) + Assert.assertEquals(info.nightscout.androidaps.core.R.string.ns_wifi_ssids, TriggerWifiSsid(injector).friendlyName()) } @Test fun friendlyDescriptionTest() { diff --git a/core/src/main/java/info/nightscout/androidaps/dialogs/DialogFragmentWithDate.kt b/core/src/main/java/info/nightscout/androidaps/dialogs/DialogFragmentWithDate.kt index d034427cc9..7df6466494 100644 --- a/core/src/main/java/info/nightscout/androidaps/dialogs/DialogFragmentWithDate.kt +++ b/core/src/main/java/info/nightscout/androidaps/dialogs/DialogFragmentWithDate.kt @@ -19,7 +19,7 @@ import info.nightscout.androidaps.utils.DateUtil import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.LTag import info.nightscout.shared.sharedPreferences.SP -import java.util.* +import java.util.Calendar import java.util.concurrent.atomic.AtomicBoolean import javax.inject.Inject @@ -52,7 +52,7 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() { ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ) - aapsLogger.debug(LTag.APS, "Dialog opened: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog opened: ${this.javaClass.simpleName}") } override fun onSaveInstanceState(savedInstanceState: Bundle) { @@ -123,21 +123,21 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() { (view.findViewById(R.id.ok) as Button?)?.setOnClickListener { synchronized(okClicked) { if (okClicked.get()) { - aapsLogger.warn(LTag.UI, "guarding: ok already clicked for dialog: ${this.javaClass.name}") + aapsLogger.warn(LTag.UI, "guarding: ok already clicked for dialog: ${this.javaClass.simpleName}") } else { okClicked.set(true) if (submit()) { - aapsLogger.debug(LTag.APS, "Submit pressed for Dialog: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Submit pressed for Dialog: ${this.javaClass.simpleName}") dismiss() } else { - aapsLogger.debug(LTag.APS, "Submit returned false for Dialog: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Submit returned false for Dialog: ${this.javaClass.simpleName}") okClicked.set(false) } } } } (view.findViewById(R.id.cancel) as Button?)?.setOnClickListener { - aapsLogger.debug(LTag.APS, "Cancel pressed for dialog: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Cancel pressed for dialog: ${this.javaClass.simpleName}") dismiss() } diff --git a/implementation/src/main/java/info/nightscout/implementation/BolusTimerImpl.kt b/implementation/src/main/java/info/nightscout/implementation/BolusTimerImpl.kt index 5eca0312ae..e5a11dea26 100644 --- a/implementation/src/main/java/info/nightscout/implementation/BolusTimerImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/BolusTimerImpl.kt @@ -3,15 +3,15 @@ package info.nightscout.implementation import dagger.android.HasAndroidInjector import info.nightscout.androidaps.interfaces.BolusTimer import info.nightscout.androidaps.interfaces.GlucoseUnit -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.interfaces.ResourceHelper +import info.nightscout.automation.AutomationEvent +import info.nightscout.automation.AutomationPlugin +import info.nightscout.automation.actions.ActionAlarm +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputDelta +import info.nightscout.automation.triggers.TriggerBg +import info.nightscout.automation.triggers.TriggerConnector +import info.nightscout.automation.triggers.TriggerDelta import java.text.DecimalFormat import javax.inject.Inject import javax.inject.Singleton diff --git a/implementation/src/main/java/info/nightscout/implementation/CarbTimerImpl.kt b/implementation/src/main/java/info/nightscout/implementation/CarbTimerImpl.kt index 4dc0ce1a00..ff27d2d623 100644 --- a/implementation/src/main/java/info/nightscout/implementation/CarbTimerImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/CarbTimerImpl.kt @@ -3,16 +3,16 @@ package info.nightscout.implementation import dagger.android.HasAndroidInjector import info.nightscout.androidaps.interfaces.CarbTimer import info.nightscout.androidaps.interfaces.GlucoseUnit -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.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.elements.Comparator import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.utils.TimerUtil +import info.nightscout.automation.AutomationEvent +import info.nightscout.automation.AutomationPlugin +import info.nightscout.automation.actions.ActionAlarm +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputDelta +import info.nightscout.automation.triggers.TriggerBg +import info.nightscout.automation.triggers.TriggerConnector +import info.nightscout.automation.triggers.TriggerDelta import java.text.DecimalFormat import javax.inject.Inject import javax.inject.Singleton @@ -48,19 +48,40 @@ class CarbTimerImpl @Inject constructor( list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { list.add(TriggerBg(injector, 180.0, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER)) list.add(TriggerDelta(injector, InputDelta(rh, -15.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add(TriggerDelta(injector, InputDelta(rh, -8.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add( + TriggerDelta( + injector, + InputDelta(rh, -8.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), + GlucoseUnit.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, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER)) list.add(TriggerDelta(injector, InputDelta(rh, -9.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add(TriggerDelta(injector, InputDelta(rh, -5.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add( + TriggerDelta( + injector, + InputDelta(rh, -5.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), + GlucoseUnit.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, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER)) list.add(TriggerDelta(injector, InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add(TriggerDelta(injector, InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add( + TriggerDelta( + injector, + InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), + GlucoseUnit.MGDL, + Comparator.Compare.IS_EQUAL_OR_LESSER + ) + ) }) } actions.add(ActionAlarm(injector, rh.gs(R.string.time_to_eat))) diff --git a/implementation/src/test/java/info/nightscout/implementation/BolusTimerImplTest.kt b/implementation/src/test/java/info/nightscout/implementation/BolusTimerImplTest.kt index 78211c0604..11b81bc1c0 100644 --- a/implementation/src/test/java/info/nightscout/implementation/BolusTimerImplTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/BolusTimerImplTest.kt @@ -6,17 +6,17 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.interfaces.GlucoseUnit import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.interfaces.Constraints -import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin -import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger -import info.nightscout.androidaps.services.LocationServiceHelper import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.automation.AutomationPlugin +import info.nightscout.automation.services.LocationServiceHelper +import info.nightscout.automation.triggers.Trigger import info.nightscout.shared.sharedPreferences.SP import org.junit.Assert import org.junit.Before diff --git a/implementation/src/test/java/info/nightscout/implementation/CarbTimerImplTest.kt b/implementation/src/test/java/info/nightscout/implementation/CarbTimerImplTest.kt index be03ee5c88..60b49c4d97 100644 --- a/implementation/src/test/java/info/nightscout/implementation/CarbTimerImplTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/CarbTimerImplTest.kt @@ -6,18 +6,18 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.interfaces.GlucoseUnit import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.interfaces.Constraints -import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin -import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger -import info.nightscout.androidaps.services.LocationServiceHelper import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.TimerUtil +import info.nightscout.automation.AutomationPlugin +import info.nightscout.automation.services.LocationServiceHelper +import info.nightscout.automation.triggers.Trigger import info.nightscout.shared.sharedPreferences.SP import org.junit.Assert import org.junit.Before diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/CarbsDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/CarbsDialog.kt index 2dbe5511ad..80b4bd6561 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/CarbsDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/CarbsDialog.kt @@ -404,7 +404,7 @@ class CarbsDialog : DialogFragmentWithDate() { activity?.let { activity -> val cancelFail = { queryingProtection = false - aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.name}") + aapsLogger.debug(LTag.APS, "Dialog canceled on resume protection: ${this.javaClass.simpleName}") ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() }