Merge pull request #462 from Philoul/meallink_VWU_v2
Remove dana dependency
This commit is contained in:
commit
ec9efefb93
10 changed files with 261 additions and 25 deletions
|
@ -15,7 +15,6 @@ import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||||
import info.nightscout.androidaps.databinding.TreatmentsUserEntryFragmentBinding
|
import info.nightscout.androidaps.databinding.TreatmentsUserEntryFragmentBinding
|
||||||
import info.nightscout.androidaps.databinding.TreatmentsUserEntryItemBinding
|
import info.nightscout.androidaps.databinding.TreatmentsUserEntryItemBinding
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange
|
import info.nightscout.androidaps.events.EventPreferenceChange
|
||||||
import info.nightscout.androidaps.extensions.colorId
|
|
||||||
import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface
|
import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
|
@ -25,7 +24,7 @@ import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
import info.nightscout.androidaps.utils.Translator
|
import info.nightscout.androidaps.utils.Translator
|
||||||
import info.nightscout.androidaps.utils.UserEntryPresentationHelper
|
import info.nightscout.androidaps.utils.userEntry.UserEntryPresentationHelper
|
||||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
|
|
|
@ -9,6 +9,7 @@ import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.TestBase
|
import info.nightscout.androidaps.TestBase
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.interfaces.*
|
import info.nightscout.androidaps.interfaces.*
|
||||||
|
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.RunningConfiguration
|
import info.nightscout.androidaps.plugins.configBuilder.RunningConfiguration
|
||||||
|
@ -30,7 +31,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
import org.powermock.modules.junit4.PowerMockRunner
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
@RunWith(PowerMockRunner::class)
|
@RunWith(PowerMockRunner::class)
|
||||||
@PrepareForTest(ConstraintChecker::class, ReceiverStatusStore::class, RunningConfiguration::class)
|
@PrepareForTest(ConstraintChecker::class, ReceiverStatusStore::class, RunningConfiguration::class, UserEntryLogger::class)
|
||||||
class LoopPluginTest : TestBase() {
|
class LoopPluginTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
|
@ -48,6 +49,7 @@ class LoopPluginTest : TestBase() {
|
||||||
@Mock lateinit var receiverStatusStore: ReceiverStatusStore
|
@Mock lateinit var receiverStatusStore: ReceiverStatusStore
|
||||||
@Mock lateinit var notificationManager: NotificationManager
|
@Mock lateinit var notificationManager: NotificationManager
|
||||||
@Mock lateinit var repository: AppRepository
|
@Mock lateinit var repository: AppRepository
|
||||||
|
@Mock lateinit var uel:UserEntryLogger
|
||||||
@Mock lateinit var dateUtil: DateUtil
|
@Mock lateinit var dateUtil: DateUtil
|
||||||
@Mock lateinit var runningConfiguration: RunningConfiguration
|
@Mock lateinit var runningConfiguration: RunningConfiguration
|
||||||
|
|
||||||
|
@ -56,7 +58,7 @@ class LoopPluginTest : TestBase() {
|
||||||
val injector = HasAndroidInjector { AndroidInjector { } }
|
val injector = HasAndroidInjector { AndroidInjector { } }
|
||||||
@Before fun prepareMock() {
|
@Before fun prepareMock() {
|
||||||
|
|
||||||
loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, Config(), constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, virtualPumpPlugin, iobCobCalculator, receiverStatusStore, fabricPrivacy, dateUtil, repository, runningConfiguration)
|
loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, Config(), constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, virtualPumpPlugin, iobCobCalculator, receiverStatusStore, fabricPrivacy, dateUtil, uel, repository, runningConfiguration)
|
||||||
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin)
|
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin)
|
||||||
`when`(context.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(notificationManager)
|
`when`(context.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(notificationManager)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||||
import info.nightscout.androidaps.database.transactions.UserEntryTransaction
|
import info.nightscout.androidaps.database.transactions.UserEntryTransaction
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
|
import info.nightscout.androidaps.utils.userEntry.UserEntryMapper
|
||||||
|
import info.nightscout.androidaps.utils.userEntry.ValueWithUnitMapper
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import io.reactivex.rxkotlin.subscribeBy
|
import io.reactivex.rxkotlin.subscribeBy
|
||||||
|
@ -40,4 +42,11 @@ class UserEntryLogger @Inject constructor(
|
||||||
onComplete = { aapsLogger.debug("USER ENTRY: $action $source $note $filteredValues") }
|
onComplete = { aapsLogger.debug("USER ENTRY: $action $source $note $filteredValues") }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun log(action: UserEntryMapper.Action, source: UserEntryMapper.Sources, note: String? ="", vararg listvalues: ValueWithUnitMapper?) = log(action.db, source.db, note, listvalues.toList().map {it?.db()})
|
||||||
|
|
||||||
|
fun log(action: UserEntryMapper.Action, source: UserEntryMapper.Sources, vararg listvalues: ValueWithUnitMapper?) = log(action.db, source.db, "", listvalues.toList().map {it?.db()})
|
||||||
|
|
||||||
|
fun log(action: UserEntryMapper.Action, source: UserEntryMapper.Sources, note: String? ="", listvalues: List<ValueWithUnitMapper?> = listOf()) = log(action.db, source.db, note, listvalues.map {it?.db()})
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,10 +3,7 @@ package info.nightscout.androidaps.plugins.general.maintenance.formats
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.core.R
|
import info.nightscout.androidaps.core.R
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry
|
import info.nightscout.androidaps.database.entities.UserEntry
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.utils.userEntry.UserEntryPresentationHelper
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
|
||||||
import info.nightscout.androidaps.utils.Translator
|
|
||||||
import info.nightscout.androidaps.utils.UserEntryPresentationHelper
|
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.storage.Storage
|
import info.nightscout.androidaps.utils.storage.Storage
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -18,9 +15,6 @@ import javax.inject.Singleton
|
||||||
@Singleton
|
@Singleton
|
||||||
class ClassicPrefsFormat @Inject constructor(
|
class ClassicPrefsFormat @Inject constructor(
|
||||||
private var resourceHelper: ResourceHelper,
|
private var resourceHelper: ResourceHelper,
|
||||||
private var dateUtil: DateUtil,
|
|
||||||
private var translator: Translator,
|
|
||||||
private var profileFunction: ProfileFunction,
|
|
||||||
private var userEntryPresentationHelper: UserEntryPresentationHelper,
|
private var userEntryPresentationHelper: UserEntryPresentationHelper,
|
||||||
private var storage: Storage
|
private var storage: Storage
|
||||||
) : PrefsFormat {
|
) : PrefsFormat {
|
||||||
|
|
|
@ -0,0 +1,139 @@
|
||||||
|
package info.nightscout.androidaps.utils.userEntry
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.database.entities.UserEntry
|
||||||
|
|
||||||
|
class UserEntryMapper {
|
||||||
|
enum class Action (val db: UserEntry.Action) {
|
||||||
|
BOLUS (UserEntry.Action.BOLUS),
|
||||||
|
SMB (UserEntry.Action.SMB),
|
||||||
|
BOLUS_ADVISOR (UserEntry.Action.BOLUS_ADVISOR),
|
||||||
|
EXTENDED_BOLUS (UserEntry.Action.EXTENDED_BOLUS),
|
||||||
|
SUPERBOLUS_TBR (UserEntry.Action.SUPERBOLUS_TBR),
|
||||||
|
CARBS (UserEntry.Action.CARBS),
|
||||||
|
EXTENDED_CARBS (UserEntry.Action.EXTENDED_CARBS),
|
||||||
|
TEMP_BASAL (UserEntry.Action.TEMP_BASAL),
|
||||||
|
TT (UserEntry.Action.TT),
|
||||||
|
NEW_PROFILE (UserEntry.Action.NEW_PROFILE),
|
||||||
|
CLONE_PROFILE (UserEntry.Action.CLONE_PROFILE),
|
||||||
|
STORE_PROFILE (UserEntry.Action.STORE_PROFILE),
|
||||||
|
PROFILE_SWITCH (UserEntry.Action.PROFILE_SWITCH),
|
||||||
|
PROFILE_SWITCH_CLONED (UserEntry.Action.PROFILE_SWITCH_CLONED),
|
||||||
|
CLOSED_LOOP_MODE (UserEntry.Action.CLOSED_LOOP_MODE),
|
||||||
|
LGS_LOOP_MODE (UserEntry.Action.LGS_LOOP_MODE),
|
||||||
|
OPEN_LOOP_MODE (UserEntry.Action.OPEN_LOOP_MODE),
|
||||||
|
LOOP_DISABLED (UserEntry.Action.LOOP_DISABLED),
|
||||||
|
LOOP_ENABLED (UserEntry.Action.LOOP_ENABLED),
|
||||||
|
RECONNECT (UserEntry.Action.RECONNECT),
|
||||||
|
DISCONNECT (UserEntry.Action.DISCONNECT),
|
||||||
|
RESUME (UserEntry.Action.RESUME),
|
||||||
|
SUSPEND (UserEntry.Action.SUSPEND),
|
||||||
|
HW_PUMP_ALLOWED (UserEntry.Action.HW_PUMP_ALLOWED),
|
||||||
|
CLEAR_PAIRING_KEYS (UserEntry.Action.CLEAR_PAIRING_KEYS),
|
||||||
|
ACCEPTS_TEMP_BASAL (UserEntry.Action.ACCEPTS_TEMP_BASAL),
|
||||||
|
CANCEL_TEMP_BASAL (UserEntry.Action.CANCEL_TEMP_BASAL),
|
||||||
|
CANCEL_EXTENDED_BOLUS (UserEntry.Action.CANCEL_EXTENDED_BOLUS),
|
||||||
|
CANCEL_TT (UserEntry.Action.CANCEL_TT),
|
||||||
|
CAREPORTAL (UserEntry.Action.CAREPORTAL),
|
||||||
|
SITE_CHANGE (UserEntry.Action.SITE_CHANGE),
|
||||||
|
RESERVOIR_CHANGE (UserEntry.Action.RESERVOIR_CHANGE),
|
||||||
|
CALIBRATION (UserEntry.Action.CALIBRATION),
|
||||||
|
PRIME_BOLUS (UserEntry.Action.PRIME_BOLUS),
|
||||||
|
TREATMENT (UserEntry.Action.TREATMENT),
|
||||||
|
CAREPORTAL_NS_REFRESH (UserEntry.Action.CAREPORTAL_NS_REFRESH),
|
||||||
|
PROFILE_SWITCH_NS_REFRESH (UserEntry.Action.PROFILE_SWITCH_NS_REFRESH),
|
||||||
|
TREATMENTS_NS_REFRESH (UserEntry.Action.TREATMENTS_NS_REFRESH),
|
||||||
|
TT_NS_REFRESH (UserEntry.Action.TT_NS_REFRESH),
|
||||||
|
AUTOMATION_REMOVED (UserEntry.Action.AUTOMATION_REMOVED),
|
||||||
|
BG_REMOVED (UserEntry.Action.BG_REMOVED),
|
||||||
|
CAREPORTAL_REMOVED (UserEntry.Action.CAREPORTAL_REMOVED),
|
||||||
|
EXTENDED_BOLUS_REMOVED (UserEntry.Action.EXTENDED_BOLUS_REMOVED),
|
||||||
|
FOOD_REMOVED (UserEntry.Action.FOOD_REMOVED),
|
||||||
|
PROFILE_REMOVED (UserEntry.Action.PROFILE_REMOVED),
|
||||||
|
PROFILE_SWITCH_REMOVED (UserEntry.Action.PROFILE_SWITCH_REMOVED),
|
||||||
|
RESTART_EVENTS_REMOVED (UserEntry.Action.RESTART_EVENTS_REMOVED),
|
||||||
|
TREATMENT_REMOVED (UserEntry.Action.TREATMENT_REMOVED),
|
||||||
|
BOLUS_REMOVED (UserEntry.Action.BOLUS_REMOVED),
|
||||||
|
CARBS_REMOVED (UserEntry.Action.CARBS_REMOVED),
|
||||||
|
TEMP_BASAL_REMOVED (UserEntry.Action.TEMP_BASAL_REMOVED),
|
||||||
|
TT_REMOVED (UserEntry.Action.TT_REMOVED),
|
||||||
|
NS_PAUSED (UserEntry.Action.NS_PAUSED),
|
||||||
|
NS_RESUME (UserEntry.Action.NS_RESUME),
|
||||||
|
NS_QUEUE_CLEARED (UserEntry.Action.NS_QUEUE_CLEARED),
|
||||||
|
NS_SETTINGS_COPIED (UserEntry.Action.NS_SETTINGS_COPIED),
|
||||||
|
ERROR_DIALOG_OK (UserEntry.Action.ERROR_DIALOG_OK),
|
||||||
|
ERROR_DIALOG_MUTE (UserEntry.Action.ERROR_DIALOG_MUTE),
|
||||||
|
ERROR_DIALOG_MUTE_5MIN (UserEntry.Action.ERROR_DIALOG_MUTE_5MIN),
|
||||||
|
OBJECTIVE_STARTED (UserEntry.Action.OBJECTIVE_STARTED),
|
||||||
|
OBJECTIVE_UNSTARTED (UserEntry.Action.OBJECTIVE_UNSTARTED),
|
||||||
|
OBJECTIVES_SKIPPED (UserEntry.Action.OBJECTIVES_SKIPPED),
|
||||||
|
STAT_RESET (UserEntry.Action.STAT_RESET),
|
||||||
|
DELETE_LOGS (UserEntry.Action.DELETE_LOGS),
|
||||||
|
DELETE_FUTURE_TREATMENTS (UserEntry.Action.DELETE_FUTURE_TREATMENTS),
|
||||||
|
EXPORT_SETTINGS (UserEntry.Action.EXPORT_SETTINGS),
|
||||||
|
IMPORT_SETTINGS (UserEntry.Action.IMPORT_SETTINGS),
|
||||||
|
RESET_DATABASES (UserEntry.Action.RESET_DATABASES),
|
||||||
|
EXPORT_DATABASES (UserEntry.Action.EXPORT_DATABASES),
|
||||||
|
IMPORT_DATABASES (UserEntry.Action.IMPORT_DATABASES),
|
||||||
|
OTP_EXPORT (UserEntry.Action.OTP_EXPORT),
|
||||||
|
OTP_RESET (UserEntry.Action.OTP_RESET),
|
||||||
|
STOP_SMS (UserEntry.Action.STOP_SMS),
|
||||||
|
FOOD (UserEntry.Action.FOOD),
|
||||||
|
EXPORT_CSV (UserEntry.Action.EXPORT_CSV),
|
||||||
|
UNKNOWN (UserEntry.Action.UNKNOWN)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Sources (val db: UserEntry.Sources) {
|
||||||
|
TreatmentDialog (UserEntry.Sources.TreatmentDialog),
|
||||||
|
InsulinDialog (UserEntry.Sources.InsulinDialog),
|
||||||
|
CarbDialog (UserEntry.Sources.CarbDialog),
|
||||||
|
WizardDialog (UserEntry.Sources.WizardDialog),
|
||||||
|
QuickWizard (UserEntry.Sources.QuickWizard),
|
||||||
|
ExtendedBolusDialog (UserEntry.Sources.ExtendedBolusDialog),
|
||||||
|
TTDialog (UserEntry.Sources.TTDialog),
|
||||||
|
ProfileSwitchDialog (UserEntry.Sources.ProfileSwitchDialog),
|
||||||
|
LoopDialog (UserEntry.Sources.LoopDialog),
|
||||||
|
TempBasalDialog (UserEntry.Sources.TempBasalDialog),
|
||||||
|
CalibrationDialog (UserEntry.Sources.CalibrationDialog),
|
||||||
|
FillDialog (UserEntry.Sources.FillDialog),
|
||||||
|
BgCheck (UserEntry.Sources.BgCheck),
|
||||||
|
SensorInsert (UserEntry.Sources.SensorInsert),
|
||||||
|
BatteryChange (UserEntry.Sources.BatteryChange),
|
||||||
|
Note (UserEntry.Sources.Note),
|
||||||
|
Exercise (UserEntry.Sources.Exercise),
|
||||||
|
Question (UserEntry.Sources.Question),
|
||||||
|
Announcement (UserEntry.Sources.Announcement),
|
||||||
|
Actions (UserEntry.Sources.Actions),
|
||||||
|
Automation (UserEntry.Sources.Automation),
|
||||||
|
BG (UserEntry.Sources.BG),
|
||||||
|
LocalProfile (UserEntry.Sources.LocalProfile),
|
||||||
|
Loop (UserEntry.Sources.Loop),
|
||||||
|
Maintenance (UserEntry.Sources.Maintenance),
|
||||||
|
NSClient (UserEntry.Sources.NSClient),
|
||||||
|
NSProfile (UserEntry.Sources.NSProfile),
|
||||||
|
Objectives (UserEntry.Sources.Objectives),
|
||||||
|
Pump (UserEntry.Sources.Pump),
|
||||||
|
Dana (UserEntry.Sources.Dana),
|
||||||
|
DanaR (UserEntry.Sources.DanaR),
|
||||||
|
DanaRC (UserEntry.Sources.DanaRC),
|
||||||
|
DanaRv2 (UserEntry.Sources.DanaRv2),
|
||||||
|
DanaRS (UserEntry.Sources.DanaRS),
|
||||||
|
Insight (UserEntry.Sources.Insight),
|
||||||
|
Combo (UserEntry.Sources.Combo),
|
||||||
|
Medtronic (UserEntry.Sources.Medtronic),
|
||||||
|
Omnipod (UserEntry.Sources.Omnipod),
|
||||||
|
OmnipodEros (UserEntry.Sources.OmnipodEros),
|
||||||
|
OmnipodDash (UserEntry.Sources.OmnipodDash),
|
||||||
|
MDI (UserEntry.Sources.MDI),
|
||||||
|
VirtualPump (UserEntry.Sources.VirtualPump),
|
||||||
|
SMS (UserEntry.Sources.SMS),
|
||||||
|
Treatments (UserEntry.Sources.Treatments),
|
||||||
|
Wear (UserEntry.Sources.Wear),
|
||||||
|
Food (UserEntry.Sources.Food),
|
||||||
|
ConfigBuilder (UserEntry.Sources.ConfigBuilder),
|
||||||
|
Overview (UserEntry.Sources.Overview),
|
||||||
|
Stats (UserEntry.Sources.Stats),
|
||||||
|
Unknown(UserEntry.Sources.Unknown)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps.utils
|
package info.nightscout.androidaps.utils.userEntry
|
||||||
|
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
import dagger.Reusable
|
import dagger.Reusable
|
||||||
|
@ -10,6 +10,10 @@ import info.nightscout.androidaps.database.entities.UserEntry.ColorGroup
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||||
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
|
import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
|
import info.nightscout.androidaps.utils.Translator
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
package info.nightscout.androidaps.utils.userEntry
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import info.nightscout.androidaps.Constants
|
||||||
|
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
||||||
|
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||||
|
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
||||||
|
|
||||||
|
sealed class ValueWithUnitMapper { //I use a sealed class because of StringResource that containts a listOf as second parameter
|
||||||
|
|
||||||
|
object UNKNOWN : ValueWithUnitMapper() // formerly None used as fallback
|
||||||
|
|
||||||
|
data class SimpleString(val value: String) : ValueWithUnitMapper() // formerly one usage of None
|
||||||
|
|
||||||
|
data class SimpleInt(val value: Int) : ValueWithUnitMapper() // formerly one usage of None
|
||||||
|
|
||||||
|
data class Mgdl(val value: Double) : ValueWithUnitMapper()
|
||||||
|
|
||||||
|
data class Mmoll(val value: Double) : ValueWithUnitMapper()
|
||||||
|
|
||||||
|
data class Timestamp(val value: Long) : ValueWithUnitMapper()
|
||||||
|
|
||||||
|
data class Insulin(val value: Double) : ValueWithUnitMapper()
|
||||||
|
|
||||||
|
data class UnitPerHour(val value: Double) : ValueWithUnitMapper()
|
||||||
|
|
||||||
|
data class Gram(val value: Int) : ValueWithUnitMapper()
|
||||||
|
|
||||||
|
data class Minute(val value: Int) : ValueWithUnitMapper()
|
||||||
|
|
||||||
|
data class Hour(val value: Int) : ValueWithUnitMapper()
|
||||||
|
|
||||||
|
data class Percent(val value: Int) : ValueWithUnitMapper()
|
||||||
|
|
||||||
|
data class TherapyEventType(val value: TherapyEvent.Type) : ValueWithUnitMapper()
|
||||||
|
|
||||||
|
data class TherapyEventMeterType(val value: TherapyEvent.MeterType) : ValueWithUnitMapper()
|
||||||
|
|
||||||
|
data class TherapyEventTTReason(val value: TemporaryTarget.Reason) : ValueWithUnitMapper()
|
||||||
|
|
||||||
|
data class StringResource(@StringRes val value: Int, val params: List<ValueWithUnitMapper> = listOf()) : ValueWithUnitMapper()
|
||||||
|
|
||||||
|
fun db(): ValueWithUnit? {
|
||||||
|
return when(this) {
|
||||||
|
is Gram -> ValueWithUnit.Gram(this.value)
|
||||||
|
is Hour -> ValueWithUnit.Hour(this.value)
|
||||||
|
is Insulin -> ValueWithUnit.Insulin(this.value)
|
||||||
|
is Mgdl -> ValueWithUnit.Mgdl(this.value)
|
||||||
|
is Minute -> ValueWithUnit.Minute(this.value)
|
||||||
|
is Mmoll -> ValueWithUnit.Mmoll(this.value)
|
||||||
|
is Percent -> ValueWithUnit.Percent(this.value)
|
||||||
|
is SimpleInt -> ValueWithUnit.SimpleInt(this.value)
|
||||||
|
is SimpleString -> ValueWithUnit.SimpleString(this.value)
|
||||||
|
is StringResource -> ValueWithUnit.StringResource(this.value, this.params.map {it.db()}.filterNotNull())
|
||||||
|
is TherapyEventMeterType -> ValueWithUnit.TherapyEventMeterType(this.value)
|
||||||
|
is TherapyEventTTReason -> ValueWithUnit.TherapyEventTTReason(this.value)
|
||||||
|
is TherapyEventType -> ValueWithUnit.TherapyEventType(this.value)
|
||||||
|
is Timestamp -> ValueWithUnit.Timestamp(this.value)
|
||||||
|
is UnitPerHour -> ValueWithUnit.UnitPerHour(this.value)
|
||||||
|
UNKNOWN -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun value(): Any? {
|
||||||
|
return when(this) {
|
||||||
|
is Gram -> this.value
|
||||||
|
is Hour -> this.value
|
||||||
|
is Insulin -> this.value
|
||||||
|
is Mgdl -> this.value
|
||||||
|
is Minute -> this.value
|
||||||
|
is Mmoll -> this.value
|
||||||
|
is Percent -> this.value
|
||||||
|
is SimpleInt -> this.value
|
||||||
|
is SimpleString -> this.value
|
||||||
|
is StringResource -> this.value
|
||||||
|
is TherapyEventMeterType -> this.value
|
||||||
|
is TherapyEventTTReason -> this.value
|
||||||
|
is TherapyEventType -> this.value
|
||||||
|
is Timestamp -> this.value
|
||||||
|
is UnitPerHour -> this.value
|
||||||
|
UNKNOWN -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
const val MGDL = Constants.MGDL
|
||||||
|
const val MMOL = Constants.MMOL
|
||||||
|
|
||||||
|
fun fromGlucoseUnit(value: Double, string: String): ValueWithUnitMapper? = when (string) {
|
||||||
|
MGDL, "mgdl" -> Mgdl(value)
|
||||||
|
MMOL, "mmol/l" -> Mmoll(value)
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.general.maintenance.formats
|
package info.nightscout.androidaps.plugins.general.maintenance.formats
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBase
|
import info.nightscout.androidaps.TestBase
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.utils.userEntry.UserEntryPresentationHelper
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
|
||||||
import info.nightscout.androidaps.utils.Translator
|
|
||||||
import info.nightscout.androidaps.utils.UserEntryPresentationHelper
|
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
@ -16,13 +13,10 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@RunWith(PowerMockRunner::class)
|
@RunWith(PowerMockRunner::class)
|
||||||
@PrepareForTest(File::class, Translator::class)
|
@PrepareForTest(File::class, UserEntryPresentationHelper::class)
|
||||||
class ClassicPrefsFormatTest : TestBase() {
|
class ClassicPrefsFormatTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var dateUtil: DateUtil
|
|
||||||
@Mock lateinit var translator: Translator
|
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
|
||||||
@Mock lateinit var userEntryPresentationHelper: UserEntryPresentationHelper
|
@Mock lateinit var userEntryPresentationHelper: UserEntryPresentationHelper
|
||||||
@Mock lateinit var file: MockedFile
|
@Mock lateinit var file: MockedFile
|
||||||
|
|
||||||
|
@ -30,7 +24,7 @@ class ClassicPrefsFormatTest : TestBase() {
|
||||||
fun preferenceLoadingTest() {
|
fun preferenceLoadingTest() {
|
||||||
val test = "key1::val1\nkeyB::valB"
|
val test = "key1::val1\nkeyB::valB"
|
||||||
|
|
||||||
val classicFormat = ClassicPrefsFormat(resourceHelper, dateUtil, translator, profileFunction, userEntryPresentationHelper, SingleStringStorage(test))
|
val classicFormat = ClassicPrefsFormat(resourceHelper, userEntryPresentationHelper, SingleStringStorage(test))
|
||||||
val prefs = classicFormat.loadPreferences(getMockedFile(), "")
|
val prefs = classicFormat.loadPreferences(getMockedFile(), "")
|
||||||
|
|
||||||
Assert.assertEquals(prefs.values.size, 2)
|
Assert.assertEquals(prefs.values.size, 2)
|
||||||
|
@ -42,7 +36,7 @@ class ClassicPrefsFormatTest : TestBase() {
|
||||||
@Test
|
@Test
|
||||||
fun preferenceSavingTest() {
|
fun preferenceSavingTest() {
|
||||||
val storage = SingleStringStorage("")
|
val storage = SingleStringStorage("")
|
||||||
val classicFormat = ClassicPrefsFormat(resourceHelper, dateUtil, translator, profileFunction, userEntryPresentationHelper, storage)
|
val classicFormat = ClassicPrefsFormat(resourceHelper, userEntryPresentationHelper, storage)
|
||||||
val prefs = Prefs(
|
val prefs = Prefs(
|
||||||
mapOf(
|
mapOf(
|
||||||
"key1" to "A",
|
"key1" to "A",
|
||||||
|
|
|
@ -17,5 +17,4 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':core')
|
implementation project(':core')
|
||||||
implementation project(':database')
|
|
||||||
}
|
}
|
|
@ -10,8 +10,6 @@ import android.view.ViewGroup
|
||||||
import dagger.android.support.DaggerFragment
|
import dagger.android.support.DaggerFragment
|
||||||
import info.nightscout.androidaps.activities.TDDStatsActivity
|
import info.nightscout.androidaps.activities.TDDStatsActivity
|
||||||
import info.nightscout.androidaps.dana.databinding.DanarFragmentBinding
|
import info.nightscout.androidaps.dana.databinding.DanarFragmentBinding
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
|
||||||
import info.nightscout.androidaps.dialogs.ProfileViewerDialog
|
import info.nightscout.androidaps.dialogs.ProfileViewerDialog
|
||||||
import info.nightscout.androidaps.events.EventExtendedBolusChange
|
import info.nightscout.androidaps.events.EventExtendedBolusChange
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged
|
import info.nightscout.androidaps.events.EventInitializationChanged
|
||||||
|
@ -29,6 +27,8 @@ import info.nightscout.androidaps.queue.events.EventQueueChanged
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
|
import info.nightscout.androidaps.utils.userEntry.UserEntryMapper.Action
|
||||||
|
import info.nightscout.androidaps.utils.userEntry.UserEntryMapper.Sources
|
||||||
import info.nightscout.androidaps.utils.WarnColors
|
import info.nightscout.androidaps.utils.WarnColors
|
||||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||||
import info.nightscout.androidaps.extensions.toVisibility
|
import info.nightscout.androidaps.extensions.toVisibility
|
||||||
|
|
Loading…
Reference in a new issue