Merge remote-tracking branch 'Nightscout/dev' into UserEntryImprovement

This commit is contained in:
Philoul 2021-03-23 15:42:03 +01:00
commit ac3baab3f3
71 changed files with 243 additions and 359 deletions

View file

@ -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)))

View file

@ -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
}

View file

@ -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)
}
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}
}

View file

@ -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)
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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))

View file

@ -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)
}
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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()
}
}

View file

@ -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

View file

@ -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

View file

@ -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<CharSequence> = 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
}

View file

@ -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

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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()
}
}

View file

@ -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()
}
}

View file

@ -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;

View file

@ -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)

View file

@ -1,16 +1,16 @@
package info.nightscout.androidaps.plugins.general.automation.elements
import android.widget.LinearLayout
import java.util.*
class LayoutBuilder {
var mElements = ArrayList<Element>()
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
}

View file

@ -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
}

View file

@ -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)
}
}

View file

@ -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)

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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)
}

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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)

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}
}

View file

@ -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)
}

View file

@ -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())

View file

@ -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)
}

View file

@ -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())
}

View file

@ -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())
}

View file

@ -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())
}

View file

@ -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())
}

View file

@ -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
}
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}
}

View file

@ -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)

View file

@ -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())

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)

View file

@ -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)
}

View file

@ -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)

View file

@ -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)

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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
}
}
}

View file

@ -39,6 +39,7 @@ open class DatabaseModule {
private val migration6to7 = object : Migration(6, 7) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXISTS foods (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `version` INTEGER NOT NULL, `dateCreated` INTEGER NOT NULL, `isValid` INTEGER NOT NULL, `referenceId` INTEGER, `name` TEXT NOT NULL, `category` TEXT, `subCategory` TEXT, `portion` REAL NOT NULL, `carbs` INTEGER NOT NULL, `fat` INTEGER, `protein` INTEGER, `energy` INTEGER, `unit` TEXT NOT NULL, `gi` INTEGER, `nightscoutSystemId` TEXT, `nightscoutId` TEXT, `pumpType` TEXT, `pumpSerial` TEXT, `pumpId` INTEGER, `startId` INTEGER, `endId` INTEGER, FOREIGN KEY(`referenceId`) REFERENCES `foods`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )")
database.execSQL("CREATE INDEX IF NOT EXISTS `index_foods_referenceId` ON `foods` (`referenceId`)")
}
}
}

View file

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl = https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionUrl = https://services.gradle.org/distributions/gradle-6.8.2-all.zip