Remove dependency and create 2 classes for drivers

This commit is contained in:
Philoul 2021-04-06 23:30:16 +02:00
parent e490c2df04
commit ffa9c04496
9 changed files with 254 additions and 8 deletions

View file

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

View file

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

View file

@ -6,7 +6,7 @@ import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
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.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

View file

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

View file

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

View file

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

View file

@ -4,7 +4,7 @@ import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
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.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

View file

@ -17,5 +17,4 @@ android {
dependencies { dependencies {
implementation project(':core') implementation project(':core')
implementation project(':database')
} }

View file

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