diff --git a/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt b/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt index c029b01af2..7bc1205ebc 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt @@ -38,20 +38,20 @@ class CarbTimer @Inject constructor( // Bg under 180 mgdl and dropping by 15 mgdl list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { list.add(TriggerBg(injector, 180.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, -15.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, -8.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add(TriggerDelta(injector, InputDelta(resourceHelper, -15.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add(TriggerDelta(injector, InputDelta(resourceHelper, -8.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) }) // Bg under 160 mgdl and dropping by 9 mgdl list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { list.add(TriggerBg(injector, 160.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, -9.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, -5.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add(TriggerDelta(injector, InputDelta(resourceHelper, -9.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add(TriggerDelta(injector, InputDelta(resourceHelper, -5.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) }) // Bg under 145 mgdl and dropping list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { list.add(TriggerBg(injector, 145.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add(TriggerDelta(injector, InputDelta(resourceHelper, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add(TriggerDelta(injector, InputDelta(resourceHelper, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) }) } actions.add(ActionAlarm(injector, resourceHelper.gs(R.string.time_to_eat))) diff --git a/automation/src/main/java/info/nightscout/androidaps/automation/di/AutomationModule.kt b/automation/src/main/java/info/nightscout/androidaps/automation/di/AutomationModule.kt index 723338631a..2fd51b4088 100644 --- a/automation/src/main/java/info/nightscout/androidaps/automation/di/AutomationModule.kt +++ b/automation/src/main/java/info/nightscout/androidaps/automation/di/AutomationModule.kt @@ -44,27 +44,4 @@ abstract class AutomationModule { @ContributesAndroidInjector abstract fun actionStartTempTargetInjector(): ActionStartTempTarget @ContributesAndroidInjector abstract fun actionStopTempTargetInjector(): ActionStopTempTarget @ContributesAndroidInjector abstract fun actionDummyInjector(): ActionDummy - - @ContributesAndroidInjector abstract fun elementInjector(): Element - @ContributesAndroidInjector abstract fun inputBgInjector(): InputBg - @ContributesAndroidInjector abstract fun inputButtonInjector(): InputButton - @ContributesAndroidInjector abstract fun comparatorInjector(): Comparator - @ContributesAndroidInjector abstract fun comparatorConnectInjector(): ComparatorConnect - @ContributesAndroidInjector abstract fun comparatorExistsInjector(): ComparatorExists - @ContributesAndroidInjector abstract fun inputDateTimeInjector(): InputDateTime - @ContributesAndroidInjector abstract fun inputDeltaInjector(): InputDelta - @ContributesAndroidInjector abstract fun inputDoubleInjector(): InputDouble - @ContributesAndroidInjector abstract fun inputDropdownMenuInjector(): InputDropdownMenu - @ContributesAndroidInjector abstract fun inputDurationInjector(): InputDuration - @ContributesAndroidInjector abstract fun inputInsulinInjector(): InputInsulin - @ContributesAndroidInjector abstract fun inputLocationModeInjector(): InputLocationMode - @ContributesAndroidInjector abstract fun inputPercentInjector(): InputPercent - @ContributesAndroidInjector abstract fun inputProfileNameInjector(): InputProfileName - @ContributesAndroidInjector abstract fun inputStringInjector(): InputString - @ContributesAndroidInjector abstract fun inputTempTargetInjector(): InputTempTarget - @ContributesAndroidInjector abstract fun inputTimeRangeInjector(): InputTimeRange - @ContributesAndroidInjector abstract fun inputTimeInjector(): InputTime - @ContributesAndroidInjector abstract fun inputWeekDayInjector(): InputWeekDay - @ContributesAndroidInjector abstract fun labelWithElementInjector(): LabelWithElement - @ContributesAndroidInjector abstract fun staticLabelInjector(): StaticLabel } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt index e483912af6..8e012f2771 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt @@ -26,10 +26,10 @@ class ActionAlarm(injector: HasAndroidInjector) : Action(injector) { @Inject lateinit var context: Context @Inject lateinit var timerUtil: TimerUtil - var text = InputString(injector) + var text = InputString() constructor(injector: HasAndroidInjector, text: String) : this(injector) { - this.text = InputString(injector, text) + this.text = InputString(text) } override fun friendlyName(): Int = R.string.alarm @@ -62,7 +62,7 @@ class ActionAlarm(injector: HasAndroidInjector) : Action(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(LabelWithElement(injector, resourceHelper.gs(R.string.alarm_short), "", text)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.alarm_short), "", text)) .build(root) } } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt index d0712688aa..92bb748abd 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt @@ -22,7 +22,7 @@ class ActionLoopSuspend(injector: HasAndroidInjector) : Action(injector) { @Inject lateinit var loopPlugin: LoopInterface @Inject lateinit var rxBus: RxBusWrapper - var minutes = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES) + var minutes = InputDuration(30, InputDuration.TimeUnit.MINUTES) override fun friendlyName(): Int = R.string.suspendloop override fun shortDescription(): String = resourceHelper.gs(R.string.suspendloopforXmin, minutes.getMinutes()) @@ -56,7 +56,7 @@ class ActionLoopSuspend(injector: HasAndroidInjector) : Action(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(LabelWithElement(injector, resourceHelper.gs(R.string.duration_min_label), "", minutes)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.duration_min_label), "", minutes)) .build(root) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt index fdf6d7177f..9913f55531 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotification.kt @@ -25,7 +25,7 @@ class ActionNotification(injector: HasAndroidInjector) : Action(injector) { @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var nsUpload: NSUpload - var text = InputString(injector) + var text = InputString() override fun friendlyName(): Int = R.string.notification override fun shortDescription(): String = resourceHelper.gs(R.string.notification_message, text.value) @@ -57,7 +57,7 @@ class ActionNotification(injector: HasAndroidInjector) : Action(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(LabelWithElement(injector, resourceHelper.gs(R.string.message_short), "", text)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.message_short), "", text)) .build(root) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.kt index eb36b44bb5..de4f6e769f 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.kt @@ -23,7 +23,7 @@ class ActionProfileSwitch(injector: HasAndroidInjector) : Action(injector) { @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var profileFunction: ProfileFunction - var inputProfileName: InputProfileName = InputProfileName(injector, "") + var inputProfileName: InputProfileName = InputProfileName(resourceHelper, activePlugin, "") override fun friendlyName(): Int = R.string.profilename override fun shortDescription(): String = resourceHelper.gs(R.string.changengetoprofilename, inputProfileName.value) @@ -59,7 +59,7 @@ class ActionProfileSwitch(injector: HasAndroidInjector) : Action(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(LabelWithElement(injector, resourceHelper.gs(R.string.profilename), "", inputProfileName)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.profilename), "", inputProfileName)) .build(root) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt index b1a7787744..689fcd945f 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt @@ -22,8 +22,8 @@ class ActionProfileSwitchPercent(injector: HasAndroidInjector) : Action(injector @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var activePlugin: ActivePluginProvider - var pct = InputPercent(injector) - var duration = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES) + var pct = InputPercent() + var duration = InputDuration(30, InputDuration.TimeUnit.MINUTES) override fun friendlyName(): Int = R.string.profilepercentage override fun shortDescription(): String = @@ -43,8 +43,8 @@ class ActionProfileSwitchPercent(injector: HasAndroidInjector) : Action(injector override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(LabelWithElement(injector, resourceHelper.gs(R.string.percent_u), "", pct)) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.duration_min_label), "", duration)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.percent_u), "", pct)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.duration_min_label), "", duration)) .build(root) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMS.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMS.kt index 22c3b134d7..82bf9cc55b 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMS.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMS.kt @@ -19,7 +19,7 @@ class ActionSendSMS(injector: HasAndroidInjector) : Action(injector) { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var smsCommunicatorPlugin: SmsCommunicatorInterface - var text = InputString(injector) + var text = InputString() override fun friendlyName(): Int = R.string.sendsmsactiondescription override fun shortDescription(): String = resourceHelper.gs(R.string.sendsmsactionlabel, text.value) @@ -50,7 +50,7 @@ class ActionSendSMS(injector: HasAndroidInjector) : Action(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(LabelWithElement(injector, resourceHelper.gs(R.string.sendsmsactiontext), "", text)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.sendsmsactiontext), "", text)) .build(root) } } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt index 6779f8c3e2..7bebe4ac6c 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.kt @@ -11,6 +11,7 @@ import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.general.automation.elements.ComparatorExists import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration @@ -37,11 +38,12 @@ class ActionStartTempTarget(injector: HasAndroidInjector) : Action(injector) { @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var repository: AppRepository @Inject lateinit var nsUpload: NSUpload + @Inject lateinit var profileFunction: ProfileFunction private val disposable = CompositeDisposable() - var value = InputTempTarget(injector) - var duration = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES) + var value = InputTempTarget(profileFunction) + var duration = InputDuration(30, InputDuration.TimeUnit.MINUTES) init { precondition = TriggerTempTarget(injector, ComparatorExists.Compare.NOT_EXISTS) @@ -66,8 +68,8 @@ class ActionStartTempTarget(injector: HasAndroidInjector) : Action(injector) { override fun generateDialog(root: LinearLayout) { val unitResId = if (value.units == Constants.MGDL) R.string.mgdl else R.string.mmol LayoutBuilder() - .add(LabelWithElement(injector, resourceHelper.gs(R.string.careportal_temporarytarget) + "\n[" + resourceHelper.gs(unitResId) + "]", "", value)) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.duration_min_label), "", duration)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.careportal_temporarytarget) + "\n[" + resourceHelper.gs(unitResId) + "]", "", value)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.duration_min_label), "", duration)) .build(root) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Comparator.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Comparator.kt index 7baedc1fd9..97f80e4460 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Comparator.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Comparator.kt @@ -6,14 +6,10 @@ import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner import androidx.annotation.StringRes -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.resources.ResourceHelper -import java.util.* -import javax.inject.Inject -class Comparator(injector: HasAndroidInjector) : Element(injector) { - @Inject lateinit var resourceHelper: ResourceHelper +class Comparator(private val resourceHelper: ResourceHelper) : Element() { enum class Compare { IS_LESSER, @@ -56,7 +52,7 @@ class Comparator(injector: HasAndroidInjector) : Element(injector) { } } - constructor(injector: HasAndroidInjector, value: Compare) : this(injector) { + constructor(resourceHelper: ResourceHelper, value: Compare) : this(resourceHelper) { this.value = value } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnect.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnect.kt index 4ca9f48afb..d27b0c4ee5 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnect.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnect.kt @@ -6,14 +6,10 @@ import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner import androidx.annotation.StringRes -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.resources.ResourceHelper -import java.util.* -import javax.inject.Inject -class ComparatorConnect(injector: HasAndroidInjector) : Element(injector) { - @Inject lateinit var resourceHelper: ResourceHelper +class ComparatorConnect(private val resourceHelper: ResourceHelper) : Element() { enum class Compare { ON_CONNECT, ON_DISCONNECT; @@ -33,7 +29,7 @@ class ComparatorConnect(injector: HasAndroidInjector) : Element(injector) { } } - constructor(injector: HasAndroidInjector, value: Compare) : this(injector) { + constructor(resourceHelper: ResourceHelper, value: Compare) : this(resourceHelper) { this.value = value } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExists.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExists.kt index 2d7f6adf1a..9337dd93fb 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExists.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExists.kt @@ -6,14 +6,10 @@ import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner import androidx.annotation.StringRes -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.resources.ResourceHelper -import java.util.* -import javax.inject.Inject -class ComparatorExists(injector: HasAndroidInjector) : Element(injector) { - @Inject lateinit var resourceHelper: ResourceHelper +class ComparatorExists(private val resourceHelper: ResourceHelper, var value: Compare = Compare.EXISTS) : Element() { enum class Compare { EXISTS, NOT_EXISTS; @@ -33,12 +29,6 @@ class ComparatorExists(injector: HasAndroidInjector) : Element(injector) { } } - constructor(injector: HasAndroidInjector, value: Compare) : this(injector) { - this.value = value - } - - var value = Compare.EXISTS - override fun addToLayout(root: LinearLayout) { val spinner = Spinner(root.context) val spinnerArrayAdapter = ArrayAdapter(root.context, R.layout.spinner_centered, Compare.labels(resourceHelper)) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.kt index e8c3e6580c..9a3e17e9b1 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.kt @@ -1,13 +1,9 @@ package info.nightscout.androidaps.plugins.general.automation.elements import android.widget.LinearLayout -import dagger.android.HasAndroidInjector -abstract class Element(val injector: HasAndroidInjector) { +abstract class Element { abstract fun addToLayout(root: LinearLayout) - init { - injector.androidInjector().inject(this) - } } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt index 045211f92e..5feb6323c1 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt @@ -1,16 +1,13 @@ package info.nightscout.androidaps.plugins.general.automation.elements import android.widget.LinearLayout -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.utils.ui.NumberPicker import java.text.DecimalFormat -import javax.inject.Inject -class InputBg(injector: HasAndroidInjector) : Element(injector) { - @Inject lateinit var profileFunction: ProfileFunction +class InputBg(profileFunction: ProfileFunction) : Element() { var units = Constants.MGDL var value = 0.0 @@ -19,7 +16,7 @@ class InputBg(injector: HasAndroidInjector) : Element(injector) { private var step = 0.0 private var decimalFormat: DecimalFormat? = null - constructor(injector: HasAndroidInjector, value: Double, units: String) : this(injector) { + constructor(profileFunction: ProfileFunction, value: Double, units: String) : this(profileFunction) { setUnits(units) this.value = value } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputButton.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputButton.kt index dd4bd9b5d6..cd9773fd69 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputButton.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputButton.kt @@ -2,13 +2,12 @@ package info.nightscout.androidaps.plugins.general.automation.elements import android.widget.Button import android.widget.LinearLayout -import dagger.android.HasAndroidInjector -class InputButton(injector: HasAndroidInjector) : Element(injector) { +class InputButton() : Element() { var text: String? = null var runnable: Runnable? = null - constructor(injector: HasAndroidInjector, text: String, runnable: Runnable) : this(injector) { + constructor(text: String, runnable: Runnable) : this() { this.text = text this.runnable = runnable } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDateTime.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDateTime.kt index 95bd31e8fa..c78b8e5e3c 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDateTime.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDateTime.kt @@ -2,29 +2,17 @@ package info.nightscout.androidaps.plugins.general.automation.elements import android.app.DatePickerDialog import android.app.TimePickerDialog -import android.content.Context import android.graphics.Typeface import android.text.format.DateFormat import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TextView -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.resources.ResourceHelper import java.util.* -import javax.inject.Inject -class InputDateTime(injector: HasAndroidInjector) : Element(injector) { - @Inject lateinit var resourceHelper: ResourceHelper - @Inject lateinit var context: Context - @Inject lateinit var dateUtil: DateUtil - - var value: Long = DateUtil.now() - - @Suppress("unused") constructor(injector: HasAndroidInjector, value: Long) : this(injector) { - this.value = value - } +class InputDateTime(private val resourceHelper: ResourceHelper, private val dateUtil: DateUtil, var value: Long = DateUtil.now()) : Element() { override fun addToLayout(root: LinearLayout) { val label = TextView(root.context) @@ -74,7 +62,7 @@ class InputDateTime(injector: HasAndroidInjector) : Element(injector) { TimePickerDialog(it, timeSetListener, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), - DateFormat.is24HourFormat(context) + DateFormat.is24HourFormat(it) ).show() } } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDelta.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDelta.kt index ee6886bf58..365de3c2dd 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDelta.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDelta.kt @@ -7,16 +7,12 @@ import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner import androidx.annotation.StringRes -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.ui.NumberPicker import info.nightscout.androidaps.utils.resources.ResourceHelper import java.text.DecimalFormat -import java.util.* -import javax.inject.Inject -class InputDelta(injector: HasAndroidInjector) : Element(injector) { - @Inject lateinit var resourceHelper: ResourceHelper +class InputDelta(private val resourceHelper: ResourceHelper) : Element() { enum class DeltaType { DELTA, SHORT_AVERAGE, LONG_AVERAGE; @@ -46,7 +42,7 @@ class InputDelta(injector: HasAndroidInjector) : Element(injector) { private var decimalFormat: DecimalFormat? = null var deltaType: DeltaType = DeltaType.DELTA - constructor(injector: HasAndroidInjector, value: Double, minValue: Double, maxValue: Double, step: Double, decimalFormat: DecimalFormat, deltaType: DeltaType) : this(injector) { + constructor(resourceHelper: ResourceHelper, value: Double, minValue: Double, maxValue: Double, step: Double, decimalFormat: DecimalFormat, deltaType: DeltaType) : this(resourceHelper) { this.value = value this.minValue = minValue this.maxValue = maxValue @@ -55,7 +51,7 @@ class InputDelta(injector: HasAndroidInjector) : Element(injector) { this.deltaType = deltaType } - constructor(injector: HasAndroidInjector, inputDelta: InputDelta) : this(injector) { + constructor(resourceHelper: ResourceHelper, inputDelta: InputDelta) : this(resourceHelper) { value = inputDelta.value minValue = inputDelta.minValue maxValue = inputDelta.maxValue diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.kt index c788f31c43..d6f975fa78 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.kt @@ -1,12 +1,11 @@ package info.nightscout.androidaps.plugins.general.automation.elements import android.widget.LinearLayout -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.ui.NumberPicker import java.text.DecimalFormat -class InputDouble(injector: HasAndroidInjector) : Element(injector) { +class InputDouble() : Element() { var value = 0.0 private var minValue = 0.0 private var maxValue = 0.0 @@ -14,7 +13,7 @@ class InputDouble(injector: HasAndroidInjector) : Element(injector) { private var decimalFormat: DecimalFormat? = null private var numberPicker: NumberPicker? = null - constructor(injector: HasAndroidInjector, value: Double, minValue: Double, maxValue: Double, step: Double, decimalFormat: DecimalFormat) : this(injector) { + constructor(value: Double, minValue: Double, maxValue: Double, step: Double, decimalFormat: DecimalFormat) : this() { this.value = value this.minValue = minValue this.maxValue = maxValue @@ -22,7 +21,7 @@ class InputDouble(injector: HasAndroidInjector) : Element(injector) { this.decimalFormat = decimalFormat } - constructor(injector: HasAndroidInjector, inputDouble: InputDouble) : this(injector) { + constructor(inputDouble: InputDouble) : this() { this.value = inputDouble.value this.minValue = inputDouble.minValue this.maxValue = inputDouble.maxValue diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDropdownMenu.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDropdownMenu.kt index 47c967d1a4..c2e7e21544 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDropdownMenu.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDropdownMenu.kt @@ -6,23 +6,21 @@ import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.resources.ResourceHelper import java.util.* -import javax.inject.Inject -class InputDropdownMenu(injector: HasAndroidInjector) : Element(injector) { - @Inject lateinit var resourceHelper: ResourceHelper +class InputDropdownMenu(private val resourceHelper: ResourceHelper) : Element() { private var itemList: ArrayList = ArrayList() var value: String = "" - constructor(injector: HasAndroidInjector, name: String) : this(injector) { + constructor(resourceHelper: ResourceHelper, name: String) : this(resourceHelper) { value = name } - @Suppress("unused") constructor(injector: HasAndroidInjector, another: InputDropdownMenu) : this(injector) { + @Suppress("unused") + constructor(resourceHelper: ResourceHelper, another: InputDropdownMenu) : this(resourceHelper) { value = another.value } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.kt index 8c77d9e0ca..1ae61ced9a 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.kt @@ -1,27 +1,22 @@ package info.nightscout.androidaps.plugins.general.automation.elements import android.widget.LinearLayout -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.ui.MinutesNumberPicker import info.nightscout.androidaps.utils.ui.NumberPicker import java.text.DecimalFormat -class InputDuration(injector: HasAndroidInjector) : Element(injector) { +class InputDuration( + var value: Int = 0, + var unit: TimeUnit = TimeUnit.MINUTES, +) : Element() { + enum class TimeUnit { MINUTES, HOURS } - constructor(injector: HasAndroidInjector, value: Int, unit: TimeUnit) : this(injector) { - this.unit = unit - this.value = value - } - - var unit: TimeUnit = TimeUnit.MINUTES - var value: Int = 0 - override fun addToLayout(root: LinearLayout) { - val numberPicker : NumberPicker + val numberPicker: NumberPicker if (unit == TimeUnit.MINUTES) { numberPicker = MinutesNumberPicker(root.context, null) numberPicker.setParams(value.toDouble(), 5.0, 24 * 60.0, 10.0, DecimalFormat("0"), false, root.findViewById(R.id.ok)) @@ -34,7 +29,7 @@ class InputDuration(injector: HasAndroidInjector) : Element(injector) { } fun duplicate(): InputDuration { - val i = InputDuration(injector) + val i = InputDuration() i.unit = unit i.value = value return i diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulin.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulin.kt index d27640836e..038449f6eb 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulin.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulin.kt @@ -1,15 +1,14 @@ package info.nightscout.androidaps.plugins.general.automation.elements import android.widget.LinearLayout -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.ui.NumberPicker import java.text.DecimalFormat -class InputInsulin(injector: HasAndroidInjector) : Element(injector) { +class InputInsulin() : Element() { var value = 0.0 - constructor(injector: HasAndroidInjector, another: InputInsulin) : this(injector) { + constructor(another: InputInsulin) : this() { value = another.value } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputLocationMode.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputLocationMode.kt index 75ec60b68b..2174da6425 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputLocationMode.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputLocationMode.kt @@ -6,14 +6,10 @@ import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner import androidx.annotation.StringRes -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.resources.ResourceHelper -import java.util.* -import javax.inject.Inject -class InputLocationMode(injector: HasAndroidInjector) : Element(injector) { - @Inject lateinit var resourceHelper: ResourceHelper +class InputLocationMode(private val resourceHelper: ResourceHelper) : Element() { enum class Mode { INSIDE, OUTSIDE, GOING_IN, GOING_OUT; @@ -46,7 +42,7 @@ class InputLocationMode(injector: HasAndroidInjector) : Element(injector) { var value: Mode = Mode.INSIDE - constructor(injector: HasAndroidInjector, value: InputLocationMode.Mode) : this(injector) { + constructor(resourceHelper: ResourceHelper, value: InputLocationMode.Mode) : this(resourceHelper) { 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/androidaps/plugins/general/automation/elements/InputPercent.kt index 5c87028760..ffb27badfe 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercent.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercent.kt @@ -1,15 +1,15 @@ package info.nightscout.androidaps.plugins.general.automation.elements import android.widget.LinearLayout -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.ui.NumberPicker import java.text.DecimalFormat -class InputPercent(injector: HasAndroidInjector) : Element(injector) { +class InputPercent() : Element() { + var value: Double = 100.0 - constructor(injector: HasAndroidInjector, value: Double) : this(injector) { + constructor(value: Double) : this() { this.value = value } @@ -22,6 +22,7 @@ class InputPercent(injector: HasAndroidInjector) : Element(injector) { } companion object { + const val MIN = 70.0 const val MAX = 130.0 } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileName.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileName.kt index a582c268b5..36e9e5e763 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileName.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileName.kt @@ -6,21 +6,13 @@ import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.LinearLayout import android.widget.Spinner -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.utils.resources.ResourceHelper -import javax.inject.Inject -class InputProfileName(injector: HasAndroidInjector) : Element(injector) { - @Inject lateinit var resourceHelper: ResourceHelper - @Inject lateinit var activePlugin: ActivePluginProvider +class InputProfileName(private val resourceHelper: ResourceHelper, private val activePlugin: ActivePluginProvider, val name: String = "") : Element() { - var value: String = "" - - constructor(injector: HasAndroidInjector, name: String) : this(injector) { - value = name - } + var value: String = name override fun addToLayout(root: LinearLayout) { val profileStore = activePlugin.activeProfileInterface.profile ?: return diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputString.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputString.kt index 0af3e88318..7ef46bd7a9 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputString.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputString.kt @@ -5,21 +5,15 @@ import android.text.TextWatcher import android.view.ViewGroup import android.widget.EditText import android.widget.LinearLayout -import dagger.android.HasAndroidInjector -class InputString(injector: HasAndroidInjector) : Element(injector) { - var textWatcher: TextWatcher = object : TextWatcher { +class InputString(var value: String = "") : Element() { + private val textWatcher: TextWatcher = object : TextWatcher { override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {} override fun afterTextChanged(s: Editable) { value = s.toString() } } - var value = "" - - constructor(injector: HasAndroidInjector, value: String) : this(injector) { - this.value = value - } override fun addToLayout(root: LinearLayout) { val editText = EditText(root.context) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.kt index 1fd1abbc3c..ca35e232df 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.kt @@ -1,34 +1,31 @@ package info.nightscout.androidaps.plugins.general.automation.elements import android.widget.LinearLayout -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.utils.ui.NumberPicker import java.text.DecimalFormat -import javax.inject.Inject -class InputTempTarget(injector: HasAndroidInjector) : Element(injector) { - var units = Constants.MGDL +class InputTempTarget(profileFunction: ProfileFunction) : Element() { + var units: String = Constants.MGDL var value = 0.0 - @Inject lateinit var profileFunction: ProfileFunction init { units = profileFunction.getUnits() value = if (units == Constants.MMOL) 6.0 else 110.0 } - constructor(injector: HasAndroidInjector, inputTempTarget: InputTempTarget) : this(injector) { + constructor(profileFunction: ProfileFunction, inputTempTarget: InputTempTarget) : this(profileFunction) { value = inputTempTarget.value units = inputTempTarget.units } override fun addToLayout(root: LinearLayout) { - var minValue: Double - var maxValue: Double - var step: Double - var decimalFormat: DecimalFormat? + val minValue: Double + val maxValue: Double + val step: Double + val decimalFormat: DecimalFormat? if (units == Constants.MMOL) { // mmol minValue = Constants.MIN_TT_MMOL maxValue = Constants.MAX_TT_MMOL diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTime.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTime.kt index ec0f8af85c..aee207cf5a 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTime.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTime.kt @@ -1,25 +1,19 @@ package info.nightscout.androidaps.plugins.general.automation.elements import android.app.TimePickerDialog -import android.content.Context import android.graphics.Typeface import android.text.format.DateFormat import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TextView -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.MidnightTime import info.nightscout.androidaps.utils.resources.ResourceHelper import java.util.* -import javax.inject.Inject -class InputTime(injector: HasAndroidInjector) : Element(injector) { - @Inject lateinit var resourceHelper: ResourceHelper - @Inject lateinit var context: Context - @Inject lateinit var dateUtil: DateUtil +class InputTime(private val resourceHelper: ResourceHelper, private val dateUtil: DateUtil) : Element() { var value: Int = getMinSinceMidnight(DateUtil.now()) @@ -40,7 +34,7 @@ class InputTime(injector: HasAndroidInjector) : Element(injector) { TimePickerDialog(it, startTimeSetListener, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), - DateFormat.is24HourFormat(context) + DateFormat.is24HourFormat(it) ).show() } } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTimeRange.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTimeRange.kt index 9a1a6f4ecd..8e5ffd0a8e 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTimeRange.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTimeRange.kt @@ -1,25 +1,19 @@ package info.nightscout.androidaps.plugins.general.automation.elements import android.app.TimePickerDialog -import android.content.Context import android.graphics.Typeface import android.text.format.DateFormat import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TextView -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.MidnightTime import info.nightscout.androidaps.utils.resources.ResourceHelper import java.util.* -import javax.inject.Inject -class InputTimeRange(injector: HasAndroidInjector) : Element(injector) { - @Inject lateinit var resourceHelper: ResourceHelper - @Inject lateinit var context: Context - @Inject lateinit var dateUtil: DateUtil +class InputTimeRange(private val resourceHelper: ResourceHelper, private val dateUtil: DateUtil) : Element() { var start: Int = getMinSinceMidnight(DateUtil.now()) var end: Int = getMinSinceMidnight(DateUtil.now()) @@ -44,7 +38,7 @@ class InputTimeRange(injector: HasAndroidInjector) : Element(injector) { TimePickerDialog(it, startTimeSetListener, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), - DateFormat.is24HourFormat(context) + DateFormat.is24HourFormat(it) ).show() } } @@ -61,7 +55,7 @@ class InputTimeRange(injector: HasAndroidInjector) : Element(injector) { TimePickerDialog(it, endTimeSetListener, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), - DateFormat.is24HourFormat(context) + DateFormat.is24HourFormat(it) ).show() } } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt index 57dd962b9e..359e252f97 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputWeekDay.kt @@ -7,7 +7,7 @@ import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.utils.ui.WeekdayPicker import java.util.* -class InputWeekDay(injector: HasAndroidInjector) : Element(injector) { +class InputWeekDay : Element() { enum class DayOfWeek { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY; diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.kt index cb2a3ffc0a..4ea68104f3 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.kt @@ -5,22 +5,14 @@ import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TableLayout import android.widget.TextView -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.utils.resources.ResourceHelper -import javax.inject.Inject -class LabelWithElement(injector: HasAndroidInjector) : Element(injector) { - @Inject lateinit var resourceHelper: ResourceHelper - - var element: Element? = null - var textPre: String = "" - var textPost: String = "" - - constructor(injector: HasAndroidInjector, textPre: String, textPost: String, element: Element) : this(injector) { - this.textPre = textPre - this.textPost = textPost - this.element = element - } +class LabelWithElement( + private val resourceHelper: ResourceHelper, + var textPre: String = "", + var textPost: String = "", + var element: Element? = null, +) : Element() { override fun addToLayout(root: LinearLayout) { // container layout val layout = LinearLayout(root.context) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilder.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilder.kt index a23467ea3d..0bf18e383d 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilder.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilder.kt @@ -1,16 +1,16 @@ package info.nightscout.androidaps.plugins.general.automation.elements import android.widget.LinearLayout -import java.util.* class LayoutBuilder { + var mElements = ArrayList() fun add(element: Element): LayoutBuilder { mElements.add(element) return this } - fun add(element: Element, condition: Boolean): LayoutBuilder { + fun maybeAdd(element: Element, condition: Boolean): LayoutBuilder { if (condition) mElements.add(element) return this } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabel.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabel.kt index 2f7b4bcc25..96320c2cd1 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabel.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/StaticLabel.kt @@ -9,18 +9,17 @@ import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger import info.nightscout.androidaps.utils.resources.ResourceHelper import javax.inject.Inject -class StaticLabel(injector: HasAndroidInjector) : Element(injector) { - @Inject lateinit var resourceHelper: ResourceHelper +class StaticLabel(private val resourceHelper: ResourceHelper) : Element() { var label = "" var trigger: Trigger? = null - constructor(injector: HasAndroidInjector, label: String, trigger: Trigger) : this(injector) { + constructor(resourceHelper: ResourceHelper, label: String, trigger: Trigger) : this(resourceHelper) { this.label = label this.trigger = trigger } - constructor(injector: HasAndroidInjector, resourceId: Int, trigger: Trigger) : this(injector) { + constructor(resourceHelper: ResourceHelper, resourceId: Int, trigger: Trigger) : this(resourceHelper) { label = resourceHelper.gs(resourceId) this.trigger = trigger } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValue.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValue.kt index d45f2220d6..d0d50fe418 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValue.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValue.kt @@ -20,13 +20,13 @@ class TriggerAutosensValue(injector: HasAndroidInjector) : Trigger(injector) { private val maxValue = (sp.getDouble(R.string.key_openapsama_autosens_max, 1.2) * 100).toInt() private val step = 1.0 private val decimalFormat = DecimalFormat("1") - var autosens: InputDouble = InputDouble(injector, 100.0, minValue.toDouble(), maxValue.toDouble(), step, decimalFormat) + var autosens: InputDouble = InputDouble(100.0, minValue.toDouble(), maxValue.toDouble(), step, decimalFormat) - var comparator: Comparator = Comparator(injector) + var comparator: Comparator = Comparator(resourceHelper) private constructor(injector: HasAndroidInjector, triggerAutosensValue: TriggerAutosensValue) : this(injector) { - autosens = InputDouble(injector, triggerAutosensValue.autosens) - comparator = Comparator(injector, triggerAutosensValue.comparator.value) + autosens = InputDouble(triggerAutosensValue.autosens) + comparator = Comparator(resourceHelper, triggerAutosensValue.comparator.value) } override fun shouldRun(): Boolean { @@ -74,9 +74,9 @@ class TriggerAutosensValue(injector: HasAndroidInjector) : Trigger(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.autosenslabel, this)) + .add(StaticLabel(resourceHelper, R.string.autosenslabel, this)) .add(comparator) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.autosenslabel) + ": ", "", autosens)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.autosenslabel) + ": ", "", autosens)) .build(root) } } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDevice.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDevice.kt index 35299bbbcd..4b75a476e3 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDevice.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBTDevice.kt @@ -22,11 +22,11 @@ class TriggerBTDevice(injector: HasAndroidInjector) : Trigger(injector) { @Inject lateinit var context: Context @Inject lateinit var automationPlugin: AutomationPlugin - var btDevice = InputDropdownMenu(injector, "") - var comparator: ComparatorConnect = ComparatorConnect(injector) + var btDevice = InputDropdownMenu(resourceHelper, "") + var comparator: ComparatorConnect = ComparatorConnect(resourceHelper) private constructor(injector: HasAndroidInjector, triggerBTDevice: TriggerBTDevice) : this(injector) { - comparator = ComparatorConnect(injector, triggerBTDevice.comparator.value) + comparator = ComparatorConnect(resourceHelper, triggerBTDevice.comparator.value) btDevice.value = triggerBTDevice.btDevice.value } @@ -69,7 +69,7 @@ class TriggerBTDevice(injector: HasAndroidInjector) : Trigger(injector) { val pairedDevices = devicesPaired() btDevice.setList(pairedDevices) LayoutBuilder() - .add(StaticLabel(injector, R.string.btdevice, this)) + .add(StaticLabel(resourceHelper, R.string.btdevice, this)) .add(btDevice) .add(comparator) .build(root) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.kt index 373cfdd3c7..b4d9d6d10b 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.kt @@ -17,17 +17,17 @@ import info.nightscout.androidaps.utils.JsonHelper import org.json.JSONObject class TriggerBg(injector: HasAndroidInjector) : Trigger(injector) { - var bg = InputBg(injector) - var comparator = Comparator(injector) + var bg = InputBg(profileFunction) + var comparator = Comparator(resourceHelper) constructor(injector: HasAndroidInjector, value: Double, units: String, compare: Comparator.Compare) : this(injector) { - bg = InputBg(injector, value, units) - comparator = Comparator(injector, compare) + bg = InputBg(profileFunction, value, units) + comparator = Comparator(resourceHelper, compare) } constructor(injector: HasAndroidInjector, triggerBg: TriggerBg) : this(injector) { - bg = InputBg(injector, triggerBg.bg.value, triggerBg.bg.units) - comparator = Comparator(injector, triggerBg.comparator.value) + bg = InputBg(profileFunction, triggerBg.bg.value, triggerBg.bg.units) + comparator = Comparator(resourceHelper, triggerBg.comparator.value) } fun setUnits(units: String): TriggerBg { @@ -97,9 +97,9 @@ class TriggerBg(injector: HasAndroidInjector) : Trigger(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.glucose, this)) + .add(StaticLabel(resourceHelper, R.string.glucose, this)) .add(comparator) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.glucose_u, bg.units), "", bg)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.glucose_u, bg.units), "", bg)) .build(root) } } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt index 24297f98ab..723da22bd4 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt @@ -16,12 +16,12 @@ import info.nightscout.androidaps.utils.JsonHelper.safeGetString import org.json.JSONObject class TriggerBolusAgo(injector: HasAndroidInjector) : Trigger(injector) { - var minutesAgo: InputDuration = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES) - var comparator: Comparator = Comparator(injector) + var minutesAgo: InputDuration = InputDuration( 30, InputDuration.TimeUnit.MINUTES) + var comparator: Comparator = Comparator(resourceHelper) private constructor(injector: HasAndroidInjector, triggerBolusAgo: TriggerBolusAgo) : this(injector) { - minutesAgo = InputDuration(injector, triggerBolusAgo.minutesAgo.value, InputDuration.TimeUnit.MINUTES) - comparator = Comparator(injector, triggerBolusAgo.comparator.value) + minutesAgo = InputDuration(triggerBolusAgo.minutesAgo.value, InputDuration.TimeUnit.MINUTES) + comparator = Comparator(resourceHelper, triggerBolusAgo.comparator.value) } fun setValue(value: Int): TriggerBolusAgo { @@ -83,9 +83,9 @@ class TriggerBolusAgo(injector: HasAndroidInjector) : Trigger(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.lastboluslabel, this)) + .add(StaticLabel(resourceHelper, R.string.lastboluslabel, this)) .add(comparator) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.lastboluslabel) + ": ", "", minutesAgo)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.lastboluslabel) + ": ", "", minutesAgo)) .build(root) } } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.kt index 90305a6178..a87ea5691f 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.kt @@ -18,12 +18,12 @@ import java.text.DecimalFormat class TriggerCOB(injector: HasAndroidInjector) : Trigger(injector) { private val minValue = 0 private val maxValue = sp.getInt(R.string.key_treatmentssafety_maxcarbs, 48) - var cob: InputDouble = InputDouble(injector, 0.0, minValue.toDouble(), maxValue.toDouble(), 1.0, DecimalFormat("1")) - var comparator: Comparator = Comparator(injector) + var cob: InputDouble = InputDouble(0.0, minValue.toDouble(), maxValue.toDouble(), 1.0, DecimalFormat("1")) + var comparator: Comparator = Comparator(resourceHelper) private constructor(injector: HasAndroidInjector, triggerCOB: TriggerCOB) : this(injector) { - cob = InputDouble(injector, triggerCOB.cob) - comparator = Comparator(injector, triggerCOB.comparator.value) + cob = InputDouble(triggerCOB.cob) + comparator = Comparator(resourceHelper, triggerCOB.comparator.value) } fun setValue(value:Double) : TriggerCOB { @@ -83,9 +83,9 @@ class TriggerCOB(injector: HasAndroidInjector) : Trigger(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.triggercoblabel, this)) + .add(StaticLabel(resourceHelper, R.string.triggercoblabel, this)) .add(comparator) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.triggercoblabel) + ": ", "", cob)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.triggercoblabel) + ": ", "", cob)) .build(root) } } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.kt index b422d52ace..35d23fe43d 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.kt @@ -21,8 +21,8 @@ import java.text.DecimalFormat class TriggerDelta(injector: HasAndroidInjector) : Trigger(injector) { var units: String = Constants.MGDL - var delta: InputDelta = InputDelta(injector) - var comparator: Comparator = Comparator(injector) + var delta: InputDelta = InputDelta(resourceHelper) + var comparator: Comparator = Comparator(resourceHelper) companion object { private const val MMOL_MAX = 4.0 @@ -31,8 +31,8 @@ class TriggerDelta(injector: HasAndroidInjector) : Trigger(injector) { init { units = profileFunction.getUnits() - delta = if (units == Constants.MMOL) InputDelta(injector, 0.0, (-MMOL_MAX), MMOL_MAX, 0.1, DecimalFormat("0.1"), DeltaType.DELTA) - else InputDelta(injector, 0.0, (-MGDL_MAX), MGDL_MAX, 1.0, DecimalFormat("1"), DeltaType.DELTA) + delta = if (units == Constants.MMOL) InputDelta(resourceHelper, 0.0, (-MMOL_MAX), MMOL_MAX, 0.1, DecimalFormat("0.1"), DeltaType.DELTA) + else InputDelta(resourceHelper, 0.0, (-MGDL_MAX), MGDL_MAX, 1.0, DecimalFormat("1"), DeltaType.DELTA) } constructor(injector: HasAndroidInjector, inputDelta: InputDelta, units: String, comparator: Comparator.Compare) : this(injector) { @@ -43,8 +43,8 @@ class TriggerDelta(injector: HasAndroidInjector) : Trigger(injector) { private constructor(injector: HasAndroidInjector, triggerDelta: TriggerDelta) : this(injector) { units = triggerDelta.units - delta = InputDelta(injector, triggerDelta.delta) - comparator = Comparator(injector, triggerDelta.comparator.value) + delta = InputDelta(resourceHelper, triggerDelta.delta) + comparator = Comparator(resourceHelper, triggerDelta.comparator.value) } fun units(units: String): TriggerDelta { @@ -103,8 +103,8 @@ class TriggerDelta(injector: HasAndroidInjector) : Trigger(injector) { val type = DeltaType.valueOf(JsonHelper.safeGetString(d, "deltaType", "")) val value = JsonHelper.safeGetDouble(d, "value") delta = - if (units == Constants.MMOL) InputDelta(injector, value, (-MMOL_MAX), MMOL_MAX, 0.1, DecimalFormat("0.1"), type) - else InputDelta(injector, value, (-MGDL_MAX), MGDL_MAX, 1.0, DecimalFormat("1"), type) + if (units == Constants.MMOL) InputDelta(resourceHelper, value, (-MMOL_MAX), MMOL_MAX, 0.1, DecimalFormat("0.1"), type) + else InputDelta(resourceHelper, value, (-MGDL_MAX), MGDL_MAX, 1.0, DecimalFormat("1"), type) comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")!!)) return this } @@ -120,9 +120,9 @@ class TriggerDelta(injector: HasAndroidInjector) : Trigger(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.deltalabel, this)) + .add(StaticLabel(resourceHelper, R.string.deltalabel, this)) .add(comparator) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.deltalabel_u, units) + ": ", "", delta)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.deltalabel_u, units) + ": ", "", delta)) .build(root) } } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIob.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIob.kt index e6d42c94bb..ca009ee794 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIob.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIob.kt @@ -15,12 +15,12 @@ import info.nightscout.androidaps.utils.JsonHelper import org.json.JSONObject class TriggerIob(injector: HasAndroidInjector) : Trigger(injector) { - var insulin = InputInsulin(injector) - var comparator: Comparator = Comparator(injector) + var insulin = InputInsulin() + var comparator: Comparator = Comparator(resourceHelper) constructor(injector: HasAndroidInjector, triggerIob: TriggerIob) : this(injector) { - insulin = InputInsulin(injector, triggerIob.insulin) - comparator = Comparator(injector, triggerIob.comparator.value) + insulin = InputInsulin(triggerIob.insulin) + comparator = Comparator(resourceHelper, triggerIob.comparator.value) } fun setValue(value: Double): TriggerIob { @@ -72,9 +72,9 @@ class TriggerIob(injector: HasAndroidInjector) : Trigger(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.iob, this)) + .add(StaticLabel(resourceHelper, R.string.iob, this)) .add(comparator) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.iob_u), "", insulin)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.iob_u), "", insulin)) .build(root) } } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.kt index 5cb460e523..bc7614cd80 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.kt @@ -12,11 +12,11 @@ import org.json.JSONObject import java.text.DecimalFormat class TriggerLocation(injector: HasAndroidInjector) : Trigger(injector) { - var latitude = InputDouble(injector, 0.0, -90.0, +90.0, 0.000001, DecimalFormat("0.000000")) - var longitude = InputDouble(injector, 0.0, -180.0, +180.0, 0.000001, DecimalFormat("0.000000")) - var distance = InputDouble(injector, 200.0, 0.0, 100000.0, 10.0, DecimalFormat("0")) - var modeSelected = InputLocationMode(injector) - var name: InputString = InputString(injector) + var latitude = InputDouble(0.0, -90.0, +90.0, 0.000001, DecimalFormat("0.000000")) + var longitude = InputDouble(0.0, -180.0, +180.0, 0.000001, DecimalFormat("0.000000")) + var distance = InputDouble(200.0, 0.0, 100000.0, 10.0, DecimalFormat("0")) + var modeSelected = InputLocationMode(resourceHelper) + var name: InputString = InputString() var lastMode = InputLocationMode.Mode.INSIDE private val buttonAction = Runnable { @@ -28,10 +28,10 @@ class TriggerLocation(injector: HasAndroidInjector) : Trigger(injector) { } private constructor(injector: HasAndroidInjector, triggerLocation: TriggerLocation) : this(injector) { - latitude = InputDouble(injector, triggerLocation.latitude) - longitude = InputDouble(injector, triggerLocation.longitude) - distance = InputDouble(injector, triggerLocation.distance) - modeSelected = InputLocationMode(injector, triggerLocation.modeSelected.value) + latitude = InputDouble(triggerLocation.latitude) + longitude = InputDouble(triggerLocation.longitude) + distance = InputDouble(triggerLocation.distance) + modeSelected = InputLocationMode(resourceHelper, triggerLocation.modeSelected.value) if (modeSelected.value == InputLocationMode.Mode.GOING_OUT) lastMode = InputLocationMode.Mode.OUTSIDE name = triggerLocation.name @@ -91,13 +91,13 @@ class TriggerLocation(injector: HasAndroidInjector) : Trigger(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.location, this)) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.name_short), "", name)) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.latitude_short), "", latitude)) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.longitude_short), "", longitude)) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.distance_short), "", distance)) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.location_mode), "", modeSelected)) - .add(InputButton(injector, resourceHelper.gs(R.string.currentlocation), buttonAction), locationDataContainer.lastLocation != null) + .add(StaticLabel(resourceHelper, R.string.location, this)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.name_short), "", name)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.latitude_short), "", latitude)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.longitude_short), "", longitude)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.distance_short), "", distance)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.location_mode), "", modeSelected)) + .maybeAdd(InputButton(resourceHelper.gs(R.string.currentlocation), buttonAction), locationDataContainer.lastLocation != null) .build(root) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercent.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercent.kt index 792b7c077c..1996ec623d 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercent.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercent.kt @@ -14,17 +14,17 @@ import info.nightscout.androidaps.utils.JsonHelper import org.json.JSONObject class TriggerProfilePercent(injector: HasAndroidInjector) : Trigger(injector) { - var pct = InputPercent(injector) - var comparator = Comparator(injector) + var pct = InputPercent() + var comparator = Comparator(resourceHelper) constructor(injector: HasAndroidInjector, value: Double, compare: Comparator.Compare) : this(injector) { - pct = InputPercent(injector, value) - comparator = Comparator(injector, compare) + pct = InputPercent( value) + comparator = Comparator(resourceHelper, compare) } constructor(injector: HasAndroidInjector, triggerProfilePercent: TriggerProfilePercent) : this(injector) { - pct = InputPercent(injector, triggerProfilePercent.pct.value) - comparator = Comparator(injector, triggerProfilePercent.comparator.value) + pct = InputPercent(triggerProfilePercent.pct.value) + comparator = Comparator(resourceHelper, triggerProfilePercent.comparator.value) } fun setValue(value: Double): TriggerProfilePercent { @@ -83,9 +83,9 @@ class TriggerProfilePercent(injector: HasAndroidInjector) : Trigger(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.profilepercentage, this)) + .add(StaticLabel(resourceHelper, R.string.profilepercentage, this)) .add(comparator) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.percent_u), "", pct)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.percent_u), "", pct)) .build(root) } } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnection.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnection.kt index 6de37135c6..3fecec8ff6 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnection.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnection.kt @@ -16,18 +16,18 @@ import info.nightscout.androidaps.utils.JsonHelper.safeGetString import org.json.JSONObject class TriggerPumpLastConnection(injector: HasAndroidInjector) : Trigger(injector) { - var minutesAgo = InputDuration(injector) - var comparator = Comparator(injector) + var minutesAgo = InputDuration() + var comparator = Comparator(resourceHelper) @Suppress("unused") constructor(injector: HasAndroidInjector, value: Int, unit: InputDuration.TimeUnit, compare: Comparator.Compare) : this(injector) { - minutesAgo = InputDuration(injector, value, unit) - comparator = Comparator(injector, compare) + minutesAgo = InputDuration(value, unit) + comparator = Comparator(resourceHelper, compare) } constructor(injector: HasAndroidInjector, triggerPumpLastConnection: TriggerPumpLastConnection) : this(injector) { - minutesAgo = InputDuration(injector, triggerPumpLastConnection.minutesAgo.value, triggerPumpLastConnection.minutesAgo.unit) - comparator = Comparator(injector, triggerPumpLastConnection.comparator.value) + minutesAgo = InputDuration(triggerPumpLastConnection.minutesAgo.value, triggerPumpLastConnection.minutesAgo.unit) + comparator = Comparator(resourceHelper, triggerPumpLastConnection.comparator.value) } fun setValue(value: Int): TriggerPumpLastConnection { @@ -84,9 +84,9 @@ class TriggerPumpLastConnection(injector: HasAndroidInjector) : Trigger(injector override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.automation_trigger_pump_last_connection_label, this)) + .add(StaticLabel(resourceHelper, R.string.automation_trigger_pump_last_connection_label, this)) .add(comparator) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.automation_trigger_pump_last_connection_description) + ": ", "", minutesAgo)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.automation_trigger_pump_last_connection_description) + ": ", "", minutesAgo)) .build(root) } } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTime.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTime.kt index eae526554c..4d15d779e5 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTime.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTime.kt @@ -20,8 +20,8 @@ import javax.inject.Inject class TriggerRecurringTime(injector: HasAndroidInjector) : Trigger(injector) { @Inject lateinit var dateUtil: DateUtil - val days = InputWeekDay(injector) - val time = InputTime(injector) + val days = InputWeekDay() + val time = InputTime(resourceHelper, dateUtil) constructor(injector: HasAndroidInjector, triggerRecurringTime: TriggerRecurringTime) : this(injector) { this.time.value = triggerRecurringTime.time.value @@ -100,7 +100,7 @@ class TriggerRecurringTime(injector: HasAndroidInjector) : Trigger(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.recurringTime, this)) + .add(StaticLabel(resourceHelper, R.string.recurringTime, this)) .add(days) .add(time) .build(root) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt index e2b339268a..8302608a47 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt @@ -20,14 +20,14 @@ class TriggerTempTarget(injector: HasAndroidInjector) : Trigger(injector) { @Inject lateinit var repository: AppRepository @Inject lateinit var dateUtil: DateUtil - var comparator = ComparatorExists(injector) + var comparator = ComparatorExists(resourceHelper) constructor(injector: HasAndroidInjector, compare: ComparatorExists.Compare) : this(injector) { - comparator = ComparatorExists(injector, compare) + comparator = ComparatorExists(resourceHelper, compare) } constructor(injector: HasAndroidInjector, triggerTempTarget: TriggerTempTarget) : this(injector) { - comparator = ComparatorExists(injector, triggerTempTarget.comparator.value) + comparator = ComparatorExists(resourceHelper, triggerTempTarget.comparator.value) } fun comparator(comparator: ComparatorExists.Compare): TriggerTempTarget { @@ -75,7 +75,7 @@ class TriggerTempTarget(injector: HasAndroidInjector) : Trigger(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.careportal_temporarytarget, this)) + .add(StaticLabel(resourceHelper, R.string.careportal_temporarytarget, this)) .add(comparator) .build(root) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.kt index f0f310df03..722d50abe2 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.general.automation.triggers +import android.content.Context import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector @@ -17,7 +18,7 @@ import javax.inject.Inject class TriggerTime(injector: HasAndroidInjector) : Trigger(injector) { @Inject lateinit var dateUtil: DateUtil - var time = InputDateTime(injector) + var time = InputDateTime(resourceHelper, dateUtil) constructor(injector: HasAndroidInjector, runAt: Long) : this(injector) { this.time.value = runAt @@ -68,7 +69,7 @@ class TriggerTime(injector: HasAndroidInjector) : Trigger(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.time, this)) + .add(StaticLabel(resourceHelper, R.string.time, this)) .add(time) .build(root) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRange.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRange.kt index 24a3268552..ff183bee41 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRange.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRange.kt @@ -21,7 +21,7 @@ class TriggerTimeRange(injector: HasAndroidInjector) : Trigger(injector) { @Inject lateinit var dateUtil: DateUtil // in minutes since midnight 60 means 1AM - var range = InputTimeRange(injector) + var range = InputTimeRange(resourceHelper, dateUtil) constructor(injector: HasAndroidInjector, start: Int, end: Int) : this(injector) { range.start = start @@ -84,7 +84,7 @@ class TriggerTimeRange(injector: HasAndroidInjector) : Trigger(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.time_range, this)) + .add(StaticLabel(resourceHelper, R.string.time_range, this)) .add(range) .build(root) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsid.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsid.kt index df44fc2853..316d1d1aab 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsid.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsid.kt @@ -18,17 +18,17 @@ import javax.inject.Inject class TriggerWifiSsid(injector: HasAndroidInjector) : Trigger(injector) { @Inject lateinit var receiverStatusStore: ReceiverStatusStore - var ssid = InputString(injector) - var comparator = Comparator(injector) + var ssid = InputString() + var comparator = Comparator(resourceHelper) @Suppress("unused") constructor(injector: HasAndroidInjector, ssid: String, compare: Comparator.Compare) : this(injector) { - this.ssid = InputString(injector, ssid) - comparator = Comparator(injector, compare) + this.ssid = InputString(ssid) + comparator = Comparator(resourceHelper, compare) } constructor(injector: HasAndroidInjector, triggerWifiSsid: TriggerWifiSsid) : this(injector) { - this.ssid = InputString(injector, triggerWifiSsid.ssid.value) - comparator = Comparator(injector, triggerWifiSsid.comparator.value) + this.ssid = InputString(triggerWifiSsid.ssid.value) + comparator = Comparator(resourceHelper, triggerWifiSsid.comparator.value) } fun setValue(ssid: String): TriggerWifiSsid { @@ -83,9 +83,9 @@ class TriggerWifiSsid(injector: HasAndroidInjector) : Trigger(injector) { override fun generateDialog(root: LinearLayout) { LayoutBuilder() - .add(StaticLabel(injector, R.string.ns_wifi_ssids, this)) + .add(StaticLabel(resourceHelper, R.string.ns_wifi_ssids, this)) .add(comparator) - .add(LabelWithElement(injector, resourceHelper.gs(R.string.ns_wifi_ssids) + ": ", "", ssid)) + .add(LabelWithElement(resourceHelper, resourceHelper.gs(R.string.ns_wifi_ssids) + ": ", "", ssid)) .build(root) } } \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarmTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarmTest.kt index 104826fda3..1639de19bb 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarmTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarmTest.kt @@ -60,7 +60,7 @@ class ActionAlarmTest : TestBase() { } @Test fun shortDescriptionTest() { - sut.text = InputString(injector, "Asd") + sut.text = InputString("Asd") Assert.assertEquals("Alarm: %s", sut.shortDescription()) } @@ -81,12 +81,12 @@ class ActionAlarmTest : TestBase() { } @Test fun toJSONTest() { - sut.text = InputString(injector, "Asd") + sut.text = InputString("Asd") Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionAlarm\"}", sut.toJSON()) } @Test fun fromJSONTest() { - sut.text = InputString(injector, "Asd") + sut.text = InputString("Asd") sut.fromJSON("{\"text\":\"Asd\"}") Assert.assertEquals("Asd", sut.text.value) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspendTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspendTest.kt index bb21e9a89f..7ee31d1d16 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspendTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspendTest.kt @@ -31,7 +31,7 @@ class ActionLoopSuspendTest : ActionsTestBase() { } @Test fun shortDescriptionTest() { - sut.minutes = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES) + sut.minutes = InputDuration(30, InputDuration.TimeUnit.MINUTES) Assert.assertEquals("Suspend loop for %d min", sut.shortDescription()) } @@ -41,7 +41,7 @@ class ActionLoopSuspendTest : ActionsTestBase() { @Test fun doActionTest() { `when`(loopPlugin.isSuspended).thenReturn(false) - sut.minutes = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES) + sut.minutes = InputDuration(30, InputDuration.TimeUnit.MINUTES) sut.doAction(object : Callback() { override fun run() {} }) @@ -57,7 +57,7 @@ class ActionLoopSuspendTest : ActionsTestBase() { @Test fun applyTest() { val a = ActionLoopSuspend(injector) - a.minutes = InputDuration(injector, 20, InputDuration.TimeUnit.MINUTES) + a.minutes = InputDuration(20, InputDuration.TimeUnit.MINUTES) val b = ActionLoopSuspend(injector) b.apply(a) Assert.assertEquals(20, b.minutes.getMinutes().toLong()) diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt index 1055cc0eae..68e446a922 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt @@ -57,7 +57,7 @@ class ActionNotificationTest : TestBase() { } @Test fun shortDescriptionTest() { - sut.text = InputString(injector, "Asd") + sut.text = InputString("Asd") Assert.assertEquals("Notification: %s", sut.shortDescription()) } @@ -80,12 +80,12 @@ class ActionNotificationTest : TestBase() { } @Test fun toJSONTest() { - sut.text = InputString(injector, "Asd") + sut.text = InputString("Asd") Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionNotification\"}", sut.toJSON()) } @Test fun fromJSONTest() { - sut.text = InputString(injector, "Asd") + sut.text = InputString("Asd") sut.fromJSON("{\"text\":\"Asd\"}") Assert.assertEquals("Asd", sut.text.value) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercentTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercentTest.kt index 53b252ff3b..f5d54e4343 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercentTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercentTest.kt @@ -32,8 +32,8 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() { } @Test fun shortDescriptionTest() { - sut.pct = InputPercent(injector, 100.0) - sut.duration = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES) + sut.pct = InputPercent(100.0) + sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES) Assert.assertNull(sut.shortDescription()) // not mocked } @@ -42,8 +42,8 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() { } @Test fun doActionTest() { - sut.pct = InputPercent(injector, 110.0) - sut.duration = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES) + sut.pct = InputPercent(110.0) + sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES) sut.doAction(object : Callback() { override fun run() { Assert.assertTrue(result.success) @@ -57,8 +57,8 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() { } @Test fun toJSONTest() { - sut.pct = InputPercent(injector, 100.0) - sut.duration = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES) + 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()) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchTest.kt index f87a288b4b..3c5defd684 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchTest.kt @@ -44,7 +44,7 @@ class ActionProfileSwitchTest : ActionsTestBase() { @Test fun doAction() { //Empty input `when`(profileFunction.getProfileName()).thenReturn("Test") - sut.inputProfileName = InputProfileName(injector, "") + sut.inputProfileName = InputProfileName(resourceHelper, activePlugin, "") sut.doAction(object : Callback() { override fun run() { Assert.assertFalse(result.success) @@ -53,7 +53,7 @@ class ActionProfileSwitchTest : ActionsTestBase() { //Not initialized profileStore `when`(profileFunction.getProfile()).thenReturn(null) - sut.inputProfileName = InputProfileName(injector, "someProfile") + sut.inputProfileName = InputProfileName(resourceHelper, activePlugin, "someProfile") sut.doAction(object : Callback() { override fun run() { Assert.assertFalse(result.success) @@ -63,7 +63,7 @@ class ActionProfileSwitchTest : ActionsTestBase() { //profile already set `when`(profileFunction.getProfile()).thenReturn(validProfile) `when`(profileFunction.getProfileName()).thenReturn("Test") - sut.inputProfileName = InputProfileName(injector, "Test") + sut.inputProfileName = InputProfileName(resourceHelper, activePlugin, "Test") sut.doAction(object : Callback() { override fun run() { Assert.assertTrue(result.success) @@ -73,7 +73,7 @@ class ActionProfileSwitchTest : ActionsTestBase() { // profile doesn't exists `when`(profileFunction.getProfileName()).thenReturn("Active") - sut.inputProfileName = InputProfileName(injector, "Test") + sut.inputProfileName = InputProfileName(resourceHelper, activePlugin, "Test") sut.doAction(object : Callback() { override fun run() { Assert.assertFalse(result.success) @@ -83,7 +83,7 @@ class ActionProfileSwitchTest : ActionsTestBase() { // do profile switch `when`(profileFunction.getProfileName()).thenReturn("Test") - sut.inputProfileName = InputProfileName(injector, TESTPROFILENAME) + sut.inputProfileName = InputProfileName(resourceHelper, activePlugin, TESTPROFILENAME) sut.doAction(object : Callback() { override fun run() { Assert.assertTrue(result.success) @@ -98,7 +98,7 @@ class ActionProfileSwitchTest : ActionsTestBase() { } @Test fun toJSONTest() { - sut.inputProfileName = InputProfileName(injector, "Test") + sut.inputProfileName = InputProfileName(resourceHelper, activePlugin, "Test") Assert.assertEquals(stringJson, sut.toJSON()) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMSTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMSTest.kt index db8ead7126..476aabd460 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMSTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionSendSMSTest.kt @@ -40,7 +40,7 @@ class ActionSendSMSTest : ActionsTestBase() { @Test fun doActionTest() { `when`(smsCommunicatorPlugin.sendNotificationToAllNumbers(anyString())).thenReturn(true) - sut.text = InputString(injector, "Asd") + sut.text = InputString("Asd") sut.doAction(object : Callback() { override fun run() { Assert.assertTrue(result.success) @@ -53,7 +53,7 @@ class ActionSendSMSTest : ActionsTestBase() { } @Test fun toJSONTest() { - sut.text = InputString(injector, "Asd") + sut.text = InputString("Asd") Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionSendSMS\"}", sut.toJSON()) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt index 54866e5815..98f3b03e0a 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt @@ -35,9 +35,9 @@ class ActionStartTempTargetTest : ActionsTestBase() { } @Test fun shortDescriptionTest() { - sut.value = InputTempTarget(injector) + sut.value = InputTempTarget(profileFunction) sut.value.value = 100.0 - sut.duration = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES) + sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES) Assert.assertEquals("Start temp target: 100mg/dl@null(Automation)", sut.shortDescription()) } @@ -94,9 +94,9 @@ class ActionStartTempTargetTest : ActionsTestBase() { } @Test fun toJSONTest() { - sut.value = InputTempTarget(injector) + sut.value = InputTempTarget(profileFunction) sut.value.value = 100.0 - sut.duration = InputDuration(injector, 30, InputDuration.TimeUnit.MINUTES) + 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()) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt index 17d8827b64..6451441f0f 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt @@ -11,12 +11,14 @@ import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget +import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Before import org.mockito.Mock import org.mockito.Mockito.`when` import org.powermock.core.classloader.annotations.PrepareForTest +import javax.inject.Inject @PrepareForTest(RxBusWrapper::class, ActionsTestBase.TestLoopPlugin::class, AppRepository::class) open class ActionsTestBase : TestBaseWithProfile() { @@ -63,6 +65,7 @@ open class ActionsTestBase : TestBaseWithProfile() { it.resourceHelper = resourceHelper it.activePlugin = activePlugin it.repository = repository + it.profileFunction = profileFunction } if (it is ActionSendSMS) { it.aapsLogger = aapsLogger @@ -110,7 +113,8 @@ open class ActionsTestBase : TestBaseWithProfile() { if (it is PumpEnactResult) { it.resourceHelper = resourceHelper } - if (it is InputTempTarget) { + if(it is Trigger) { + it.resourceHelper = resourceHelper it.profileFunction = profileFunction } } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnectTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnectTest.kt index e62a0ebc77..16db4a10c7 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnectTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnectTest.kt @@ -14,7 +14,7 @@ class ComparatorConnectTest : TriggerTestBase() { } @Test fun setValueTest() { - val c = ComparatorConnect(injector) + val c = ComparatorConnect(resourceHelper) c.value = ComparatorConnect.Compare.ON_DISCONNECT Assert.assertEquals(ComparatorConnect.Compare.ON_DISCONNECT, c.value) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt index 99d71cdeab..94a00c6833 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt @@ -14,7 +14,7 @@ class ComparatorExistsTest : TriggerTestBase() { } @Test fun setValueTest() { - val c = ComparatorExists(injector) + val c = ComparatorExists(resourceHelper) c.value = ComparatorExists.Compare.NOT_EXISTS Assert.assertEquals(ComparatorExists.Compare.NOT_EXISTS, c.value) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt index da8143e7f6..e33ade173f 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt @@ -32,7 +32,7 @@ class ComparatorTest : TriggerTestBase() { @Test fun setValueTest() { - val c: Comparator = Comparator(injector).setValue(Comparator.Compare.IS_EQUAL_OR_GREATER) + val c: Comparator = Comparator(resourceHelper).setValue(Comparator.Compare.IS_EQUAL_OR_GREATER) Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_GREATER, c.value) } } \ No newline at end of file diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt index 05b44be32a..2dd2bd6fbd 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt @@ -16,10 +16,10 @@ class InputBgTest : TriggerTestBase() { @Test fun setValueTest() { - var i: InputBg = InputBg(injector).setUnits(Constants.MMOL).setValue(5.0) + var i: InputBg = InputBg(profileFunction).setUnits(Constants.MMOL).setValue(5.0) Assert.assertEquals(5.0, i.value, 0.01) Assert.assertEquals(InputBg.MMOL_MIN, i.minValue, 0.01) - i = InputBg(injector).setValue(100.0).setUnits(Constants.MGDL) + i = InputBg(profileFunction).setValue(100.0).setUnits(Constants.MGDL) Assert.assertEquals(100.0, i.value, 0.01) Assert.assertEquals(InputBg.MGDL_MIN, i.minValue, 0.01) Assert.assertEquals(Constants.MGDL, i.units) diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt index f52003e3f0..f1becea887 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt @@ -10,10 +10,10 @@ import org.powermock.modules.junit4.PowerMockRunner class InputDurationTest : TriggerTestBase() { @Test fun setValueTest() { - var i = InputDuration(injector, 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(injector, 5, InputDuration.TimeUnit.HOURS) + i = InputDuration(5, InputDuration.TimeUnit.HOURS) Assert.assertEquals(5, i.value) Assert.assertEquals(InputDuration.TimeUnit.HOURS, i.unit) Assert.assertEquals(5 * 60, i.getMinutes()) diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt index 97b09bfcd7..f4f8c8b770 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt @@ -10,7 +10,7 @@ import org.powermock.modules.junit4.PowerMockRunner class InputInsulinTest : TriggerTestBase() { @Test fun setValueTest() { - val i = InputInsulin(injector) + val i = InputInsulin() i.value = 5.0 Assert.assertEquals(5.0, i.value, 0.01) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt index 3367bbdfa0..1cf2e8e0df 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt @@ -10,7 +10,7 @@ import org.powermock.modules.junit4.PowerMockRunner class InputPercentTest : TriggerTestBase() { @Test fun setValueTest() { - val i = InputPercent(injector) + val i = InputPercent() i.value = 10.0 Assert.assertEquals(10.0, i.value, 0.01) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileNameTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileNameTest.kt index f4bc3d07b1..1566a3e1af 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileNameTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputProfileNameTest.kt @@ -10,7 +10,7 @@ import org.powermock.modules.junit4.PowerMockRunner class InputProfileNameTest : TriggerTestBase() { @Test fun setValue() { - val inputProfileName = InputProfileName(injector, "Test") + val inputProfileName = InputProfileName(resourceHelper, activePlugin, "Test") Assert.assertEquals("Test", inputProfileName.value) inputProfileName.value = "Test2" Assert.assertEquals("Test2", inputProfileName.value) diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt index 686cf9047b..6a8ce2d94b 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt @@ -10,7 +10,7 @@ import org.powermock.modules.junit4.PowerMockRunner class InputStringTest : TriggerTestBase() { @Test fun setValueTest() { - val i = InputString(injector) + val i = InputString() i.value = "asd" Assert.assertEquals("asd", i.value) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt index b137a8ef9b..b87722373c 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt @@ -13,7 +13,7 @@ import org.powermock.modules.junit4.PowerMockRunner class InputTempTargetTest : TriggerTestBase() { @Test fun setValueTest() { - val i = InputTempTarget(injector) + val i = InputTempTarget(profileFunction) i.units = Constants.MMOL i.value = 5.0 Assert.assertEquals(5.0, i.value, 0.01) diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElementTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElementTest.kt index f0fcaafe56..57a3f5676c 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElementTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElementTest.kt @@ -11,7 +11,7 @@ class LabelWithElementTest : TriggerTestBase() { @Test fun constructorTest() { - val l = LabelWithElement(injector, "A", "B", InputInsulin(injector)) + val l = LabelWithElement(resourceHelper, "A", "B", InputInsulin()) Assert.assertEquals("A", l.textPre) Assert.assertEquals("B", l.textPost) Assert.assertEquals(InputInsulin::class.java, l.element!!.javaClass) diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilderTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilderTest.kt index f59e84d3ad..a81b5506be 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilderTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/LayoutBuilderTest.kt @@ -15,17 +15,17 @@ class LayoutBuilderTest : TestBase() { @Test fun addTest() { val layoutBuilder = LayoutBuilder() - val inputInsulin = InputInsulin(injector) + val inputInsulin = InputInsulin() layoutBuilder.add(inputInsulin) Assert.assertEquals(1, layoutBuilder.mElements.size) } @Test fun addConditionalTest() { val layoutBuilder = LayoutBuilder() - val inputInsulin = InputInsulin(injector) - layoutBuilder.add(inputInsulin, true) + val inputInsulin = InputInsulin() + layoutBuilder.maybeAdd(inputInsulin, true) Assert.assertEquals(1, layoutBuilder.mElements.size) - layoutBuilder.add(inputInsulin, false) + layoutBuilder.maybeAdd(inputInsulin, false) Assert.assertEquals(1, layoutBuilder.mElements.size) } } \ 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 index d40b5243e3..15eaa50c5e 100644 --- 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 @@ -13,10 +13,10 @@ import org.powermock.modules.junit4.PowerMockRunner class StaticLabelTest : TriggerTestBase() { @Test fun constructor() { - var sl = StaticLabel(injector, "any", TriggerDummy(injector)) + var sl = StaticLabel(resourceHelper, "any", TriggerDummy(injector)) Assert.assertEquals("any", sl.label) `when`(resourceHelper.gs(R.string.pumplimit)).thenReturn("pump limit") - sl = StaticLabel(injector, R.string.pumplimit, TriggerDummy(injector)) + sl = StaticLabel(resourceHelper, 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/TriggerTestBase.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt index 37ecd1fcf9..fe3538d319 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt @@ -79,15 +79,6 @@ open class TriggerTestBase : TestBaseWithProfile() { if (it is TriggerWifiSsid) { it.receiverStatusStore = receiverStatusStore } - if (it is InputBg) { - it.profileFunction = profileFunction - } - if (it is InputTempTarget) { - it.profileFunction = profileFunction - } - if (it is StaticLabel) { - it.resourceHelper = resourceHelper - } } }