make new ValueWithUnit translatable

This commit is contained in:
AdrianLxM 2021-03-25 03:23:28 +01:00
parent 8ec8bd60bc
commit d9aced595b
20 changed files with 125 additions and 77 deletions

View file

@ -223,7 +223,7 @@ class CarbsDialog : DialogFragmentWithDate() {
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.carbs), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
when {
activitySelected -> {
uel.log(Action.TT, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.ACTIVITY.text), XXXValueWithUnit.fromGlucoseUnit(activityTT, units) , XXXValueWithUnit.Minute(activityTTDuration))
uel.log(Action.TT, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.ACTIVITY), XXXValueWithUnit.fromGlucoseUnit(activityTT, units) , XXXValueWithUnit.Minute(activityTTDuration))
disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction(
timestamp = System.currentTimeMillis(),
duration = TimeUnit.MINUTES.toMillis(activityTTDuration.toLong()),
@ -239,7 +239,7 @@ class CarbsDialog : DialogFragmentWithDate() {
}
eatingSoonSelected -> {
uel.log(Action.TT, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.EATING_SOON.text), XXXValueWithUnit.fromGlucoseUnit(eatingSoonTT, units) , XXXValueWithUnit.Minute(eatingSoonTTDuration))
uel.log(Action.TT, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.EATING_SOON), XXXValueWithUnit.fromGlucoseUnit(eatingSoonTT, units) , XXXValueWithUnit.Minute(eatingSoonTTDuration))
disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction(
timestamp = System.currentTimeMillis(),
duration = TimeUnit.MINUTES.toMillis(eatingSoonTTDuration.toLong()),
@ -255,7 +255,7 @@ class CarbsDialog : DialogFragmentWithDate() {
}
hypoSelected -> {
uel.log(Action.TT, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.HYPOGLYCEMIA.text), XXXValueWithUnit.fromGlucoseUnit(hypoTT, units) , XXXValueWithUnit.Minute(hypoTTDuration))
uel.log(Action.TT, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.HYPOGLYCEMIA), XXXValueWithUnit.fromGlucoseUnit(hypoTT, units) , XXXValueWithUnit.Minute(hypoTTDuration))
disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction(
timestamp = System.currentTimeMillis(),
duration = TimeUnit.MINUTES.toMillis(hypoTTDuration.toLong()),
@ -272,7 +272,7 @@ class CarbsDialog : DialogFragmentWithDate() {
}
if (carbsAfterConstraints > 0) {
if (duration == 0) {
carbsGenerator.createCarb(carbsAfterConstraints, time, TherapyEvent.Type.CARBS_CORRECTION.text, notes)
carbsGenerator.createCarb(carbsAfterConstraints, time, TherapyEvent.Type.CARBS_CORRECTION, notes)
} else {
carbsGenerator.generateCarbs(carbsAfterConstraints, time, duration, notes)
nsUpload.uploadEvent(TherapyEvent.Type.NOTE.text, DateUtil.now() - 2000, resourceHelper.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset))

View file

@ -204,7 +204,7 @@ class CareDialog : DialogFragmentWithDate() {
therapyEvent.glucoseType = meterType
therapyEvent.glucose = binding.bg.value
valuesWithUnit.add(XXXValueWithUnit.fromGlucoseUnit(binding.bg.value.toDouble(), profileFunction.getUnits()))
valuesWithUnit.add(XXXValueWithUnit.TherapyEvent(meterType.text))
valuesWithUnit.add(XXXValueWithUnit.TherapyEventMeterType(meterType))
}
if (options == EventType.NOTE || options == EventType.EXERCISE) {
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_duration_label) + ": " + resourceHelper.gs(R.string.format_mins, binding.duration.value.toInt()))
@ -229,7 +229,7 @@ class CareDialog : DialogFragmentWithDate() {
aapsLogger.error(LTag.BGSOURCE, "Error while saving therapy event", it)
})
valuesWithUnit.add(0, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged })
valuesWithUnit.add(1, XXXValueWithUnit.TherapyEvent(therapyEvent.type.text))
valuesWithUnit.add(1, XXXValueWithUnit.TherapyEventType(therapyEvent.type))
uel.log(Action.CAREPORTAL, notes, valuesWithUnit)
}, null)
}

View file

@ -141,7 +141,7 @@ class FillDialog : DialogFragmentWithDate() {
requestPrimeBolus(insulinAfterConstraints, notes)
}
if (siteChange) {
uel.log(Action.CAREPORTAL, notes, XXXValueWithUnit.TherapyEvent(TherapyEvent.Type.CANNULA_CHANGE.text))
uel.log(Action.CAREPORTAL, notes, XXXValueWithUnit.TherapyEventType(TherapyEvent.Type.CANNULA_CHANGE))
disposable += repository.runTransactionForResult(InsertTherapyEventIfNewTransaction(
timestamp = eventTime,
type = TherapyEvent.Type.CANNULA_CHANGE,
@ -155,7 +155,7 @@ class FillDialog : DialogFragmentWithDate() {
}
if (insulinChange) {
// add a second for case of both checked
uel.log(Action.CAREPORTAL, notes, XXXValueWithUnit.TherapyEvent(TherapyEvent.Type.INSULIN_CHANGE.text))
uel.log(Action.CAREPORTAL, notes, XXXValueWithUnit.TherapyEventType(TherapyEvent.Type.INSULIN_CHANGE))
disposable += repository.runTransactionForResult(InsertTherapyEventIfNewTransaction(
timestamp = eventTime + 1000,
type = TherapyEvent.Type.INSULIN_CHANGE,

View file

@ -190,7 +190,7 @@ class InsulinDialog : DialogFragmentWithDate() {
activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.bolus), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
if (eatingSoonChecked) {
uel.log(Action.TT, notes, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.EATING_SOON.text), XXXValueWithUnit.fromGlucoseUnit(eatingSoonTT, units), XXXValueWithUnit.Minute(eatingSoonTTDuration))
uel.log(Action.TT, notes, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.EATING_SOON), XXXValueWithUnit.fromGlucoseUnit(eatingSoonTT, units), XXXValueWithUnit.Minute(eatingSoonTTDuration))
disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction(
timestamp = System.currentTimeMillis(),
duration = TimeUnit.MINUTES.toMillis(eatingSoonTTDuration.toLong()),
@ -206,7 +206,7 @@ class InsulinDialog : DialogFragmentWithDate() {
}
if (insulinAfterConstraints > 0) {
val detailedBolusInfo = DetailedBolusInfo()
detailedBolusInfo.eventType = TherapyEvent.Type.CORRECTION_BOLUS.text
detailedBolusInfo.eventType = TherapyEvent.Type.CORRECTION_BOLUS
detailedBolusInfo.insulin = insulinAfterConstraints
detailedBolusInfo.context = context
detailedBolusInfo.source = Source.USER

View file

@ -182,10 +182,10 @@ class TempTargetDialog : DialogFragmentWithDate() {
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_temporarytarget), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
val units = profileFunction.getUnits()
when(reason) {
resourceHelper.gs(R.string.eatingsoon) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.EATING_SOON.text), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration))
resourceHelper.gs(R.string.activity) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.ACTIVITY.text), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration))
resourceHelper.gs(R.string.hypo) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.HYPOGLYCEMIA.text), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration))
resourceHelper.gs(R.string.manual) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.CUSTOM.text), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration))
resourceHelper.gs(R.string.eatingsoon) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.EATING_SOON), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration))
resourceHelper.gs(R.string.activity) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.ACTIVITY), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration))
resourceHelper.gs(R.string.hypo) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.HYPOGLYCEMIA), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration))
resourceHelper.gs(R.string.manual) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.CUSTOM), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration))
resourceHelper.gs(R.string.stoptemptarget) -> uel.log(Action.CANCEL_TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged })
}
if (target == 0.0 || duration == 0) {

View file

@ -133,8 +133,8 @@ class TreatmentDialog : DialogFragmentWithDate() {
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.overview_treatment_label), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
uel.log(Action.TREATMENT, XXXValueWithUnit.Insulin(insulin ).takeIf { insulin != 0.0 }, XXXValueWithUnit.Gram(carbs).takeIf { carbs != 0 })
val detailedBolusInfo = DetailedBolusInfo()
if (insulinAfterConstraints == 0.0) detailedBolusInfo.eventType = TherapyEvent.Type.CARBS_CORRECTION.text
if (carbsAfterConstraints == 0) detailedBolusInfo.eventType = TherapyEvent.Type.CORRECTION_BOLUS.text
if (insulinAfterConstraints == 0.0) detailedBolusInfo.eventType = TherapyEvent.Type.CARBS_CORRECTION
if (carbsAfterConstraints == 0) detailedBolusInfo.eventType = TherapyEvent.Type.CORRECTION_BOLUS
detailedBolusInfo.insulin = insulinAfterConstraints
detailedBolusInfo.carbs = carbsAfterConstraints.toDouble()
detailedBolusInfo.context = context

View file

@ -596,7 +596,7 @@ open class LoopPlugin @Inject constructor(
// deliver SMB
val detailedBolusInfo = DetailedBolusInfo()
detailedBolusInfo.lastKnownBolusTime = treatmentsPlugin.lastBolusTime
detailedBolusInfo.eventType = TherapyEvent.Type.CORRECTION_BOLUS.text
detailedBolusInfo.eventType = TherapyEvent.Type.CORRECTION_BOLUS
detailedBolusInfo.insulin = request.smb
detailedBolusInfo.isSMB = true
detailedBolusInfo.source = Source.USER

View file

@ -87,7 +87,7 @@ class NSClientAddUpdateWorker(
.also { result ->
result.inserted.forEach { tt ->
uel.log(UserEntry.Action.TT_FROM_NS,
XXXValueWithUnit.TherapyEvent(tt.reason.text),
XXXValueWithUnit.TherapyEventTTReason(tt.reason),
XXXValueWithUnit.Mgdl(tt.lowTarget),
XXXValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget },
XXXValueWithUnit.Minute(tt.duration.toInt() / 60000)
@ -95,7 +95,7 @@ class NSClientAddUpdateWorker(
}
result.invalidated.forEach { tt ->
uel.log(UserEntry.Action.TT_DELETED_FROM_NS,
XXXValueWithUnit.TherapyEvent(tt.reason.text),
XXXValueWithUnit.TherapyEventTTReason(tt.reason),
XXXValueWithUnit.Mgdl(tt.lowTarget),
XXXValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget },
XXXValueWithUnit.Minute(tt.duration.toInt() / 60000)
@ -103,7 +103,7 @@ class NSClientAddUpdateWorker(
}
result.ended.forEach { tt ->
uel.log(UserEntry.Action.TT_CANCELED_FROM_NS,
XXXValueWithUnit.TherapyEvent(tt.reason.text),
XXXValueWithUnit.TherapyEventTTReason(tt.reason),
XXXValueWithUnit.Mgdl(tt.lowTarget),
XXXValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget },
XXXValueWithUnit.Minute(tt.duration.toInt() / 60000)
@ -134,14 +134,14 @@ class NSClientAddUpdateWorker(
uel.log(UserEntry.Action.CAREPORTAL_FROM_NS,
it.note ?: "",
XXXValueWithUnit.Timestamp(it.timestamp),
XXXValueWithUnit.TherapyEvent(it.type.text)
XXXValueWithUnit.TherapyEventType(it.type)
)
}
result.invalidated.forEach {
uel.log(UserEntry.Action.CAREPORTAL_DELETED_FROM_NS,
it.note ?: "",
XXXValueWithUnit.Timestamp(it.timestamp),
XXXValueWithUnit.TherapyEvent(it.type.text)
XXXValueWithUnit.TherapyEventType(it.type)
)
}
}

View file

@ -69,7 +69,7 @@ class NSClientRemoveWorker(
result.invalidated.forEach { tt ->
uel.log(
UserEntry.Action.TT_DELETED_FROM_NS,
XXXValueWithUnit.TherapyEvent(tt.reason.text),
XXXValueWithUnit.TherapyEventTTReason(tt.reason),
XXXValueWithUnit.Mgdl(tt.lowTarget),
XXXValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget },
XXXValueWithUnit.Minute(tt.duration.toInt() / 60000).takeIf { tt.duration != 0L }
@ -90,7 +90,7 @@ class NSClientRemoveWorker(
uel.log(
UserEntry.Action.CAREPORTAL_DELETED_FROM_NS, (it.note ?: ""),
XXXValueWithUnit.Timestamp(it.timestamp),
XXXValueWithUnit.TherapyEvent(it.type.text))
XXXValueWithUnit.TherapyEventType(it.type))
}
}

View file

@ -545,7 +545,7 @@ class ActionStringHandler @Inject constructor(
private fun doECarbs(carbs: Int, time: Long, duration: Int) {
if (carbs > 0) {
if (duration == 0) {
carbsGenerator.createCarb(carbs, time, TherapyEvent.Type.CARBS_CORRECTION.text, "watch")
carbsGenerator.createCarb(carbs, time, TherapyEvent.Type.CARBS_CORRECTION, "watch")
} else {
carbsGenerator.generateCarbs(carbs, time, duration, "watch eCarbs")
}

View file

@ -31,11 +31,11 @@ class CarbsGenerator @Inject constructor(
val carbTime = startTime + i * 15 * 60 * 1000
val smallCarbAmount = (1.0 * remainingCarbs / (ticks - i)).roundToInt() //on last iteration (ticks-i) is 1 -> smallCarbAmount == remainingCarbs
remainingCarbs -= smallCarbAmount.toLong()
if (smallCarbAmount > 0) createCarb(smallCarbAmount, carbTime, TherapyEvent.Type.MEAL_BOLUS.text, notes)
if (smallCarbAmount > 0) createCarb(smallCarbAmount, carbTime, TherapyEvent.Type.MEAL_BOLUS, notes)
}
}
fun createCarb(carbs: Int, time: Long, eventType: String, notes: String) {
fun createCarb(carbs: Int, time: Long, eventType: TherapyEvent.Type, notes: String) {
val carbInfo = DetailedBolusInfo()
carbInfo.date = time
carbInfo.eventType = eventType

View file

@ -197,7 +197,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
resourceHelper.gs(R.string.notes_label) + ": " + (therapyEvent.note ?: "") + "\n" +
resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(therapyEvent.timestamp)
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable {
uel.log(Action.CAREPORTAL_REMOVED, therapyEvent.note , XXXValueWithUnit.Timestamp(therapyEvent.timestamp), XXXValueWithUnit.TherapyEvent(therapyEvent.type.text))
uel.log(Action.CAREPORTAL_REMOVED, therapyEvent.note , XXXValueWithUnit.Timestamp(therapyEvent.timestamp), XXXValueWithUnit.TherapyEventType(therapyEvent.type))
disposable += repository.runTransactionForResult(InvalidateTherapyEventTransaction(therapyEvent.id))
.subscribe({
val id = therapyEvent.interfaceIDs.nightscoutId

View file

@ -197,7 +197,7 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
${dateUtil.dateAndTimeString(tempTarget.timestamp)}
""".trimIndent(),
{ _: DialogInterface?, _: Int ->
uel.log(Action.TT_REMOVED, XXXValueWithUnit.Timestamp(tempTarget.timestamp), XXXValueWithUnit.TherapyEvent(tempTarget.reason.text), XXXValueWithUnit.Mgdl(tempTarget.lowTarget), XXXValueWithUnit.Mgdl(tempTarget.highTarget).takeIf { tempTarget.lowTarget != tempTarget.highTarget }, XXXValueWithUnit.Minute(tempTarget.duration.toInt()))
uel.log(Action.TT_REMOVED, XXXValueWithUnit.Timestamp(tempTarget.timestamp), XXXValueWithUnit.TherapyEventTTReason(tempTarget.reason), XXXValueWithUnit.Mgdl(tempTarget.lowTarget), XXXValueWithUnit.Mgdl(tempTarget.highTarget).takeIf { tempTarget.lowTarget != tempTarget.highTarget }, XXXValueWithUnit.Minute(tempTarget.duration.toInt()))
disposable += repository.runTransactionForResult(InvalidateTemporaryTargetTransaction(tempTarget.id))
.subscribe({
val id = tempTarget.interfaceIDs.nightscoutId

View file

@ -340,7 +340,7 @@ class BolusWizard @Inject constructor(
val confirmMessage = confirmMessageAfterConstraints(advisor = true)
OKDialog.showConfirmation(ctx, resourceHelper.gs(R.string.boluswizard), confirmMessage, {
DetailedBolusInfo().apply {
eventType = TherapyEvent.Type.CORRECTION_BOLUS.text
eventType = TherapyEvent.Type.CORRECTION_BOLUS
insulin = insulinAfterConstraints
carbs = 0.0
context = ctx
@ -350,7 +350,7 @@ class BolusWizard @Inject constructor(
boluscalc = nsJSON()
source = Source.USER
notes = this@BolusWizard.notes
uel.log(Action.BOLUS_ADVISOR, notes, XXXValueWithUnit.TherapyEvent(eventType), XXXValueWithUnit.Insulin(insulinAfterConstraints))
uel.log(Action.BOLUS_ADVISOR, notes, XXXValueWithUnit.TherapyEventType(eventType), XXXValueWithUnit.Insulin(insulinAfterConstraints))
if (insulin > 0) {
commandQueue.bolus(this, object : Callback() {
override fun run() {
@ -404,7 +404,7 @@ class BolusWizard @Inject constructor(
}
}
DetailedBolusInfo().apply {
eventType = TherapyEvent.Type.BOLUS_WIZARD.text
eventType = TherapyEvent.Type.BOLUS_WIZARD
insulin = insulinAfterConstraints
carbs = this@BolusWizard.carbs.toDouble()
context = ctx
@ -414,7 +414,7 @@ class BolusWizard @Inject constructor(
boluscalc = nsJSON()
source = Source.USER
notes = this@BolusWizard.notes
uel.log(Action.BOLUS, notes, XXXValueWithUnit.TherapyEvent(eventType), XXXValueWithUnit.Insulin(insulinAfterConstraints), XXXValueWithUnit.Gram(this@BolusWizard.carbs).takeIf { this@BolusWizard.carbs != 0 }, XXXValueWithUnit.Minute(carbTime).takeIf { carbTime != 0 })
uel.log(Action.BOLUS, notes, XXXValueWithUnit.TherapyEventType(eventType), XXXValueWithUnit.Insulin(insulinAfterConstraints), XXXValueWithUnit.Gram(this@BolusWizard.carbs).takeIf { this@BolusWizard.carbs != 0 }, XXXValueWithUnit.Minute(carbTime).takeIf { carbTime != 0 })
if (insulin > 0 || pump.pumpDescription.storesCarbInfo) {
commandQueue.bolus(this, object : Callback() {
override fun run() {

View file

@ -1158,7 +1158,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
dbi.pumpId = dbi.date;
dbi.source = Source.PUMP;
dbi.insulin = pumpBolus.amount;
dbi.eventType = TherapyEvent.Type.CORRECTION_BOLUS.getText();
dbi.eventType = TherapyEvent.Type.CORRECTION_BOLUS;
if (treatmentsPlugin.addToHistoryTreatment(dbi, true)) {
updated = true;
}

View file

@ -16,7 +16,7 @@ import info.nightscout.androidaps.db.Source;
public class DetailedBolusInfo {
public long date = System.currentTimeMillis();
public long lastKnownBolusTime;
public String eventType = TherapyEvent.Type.MEAL_BOLUS.getText();
public TherapyEvent.Type eventType = TherapyEvent.Type.MEAL_BOLUS;
public double insulin = 0;
public double carbs = 0;
public int source = Source.NONE;

View file

@ -248,7 +248,7 @@ public class NSUpload {
public void uploadTreatmentRecord(DetailedBolusInfo detailedBolusInfo) {
JSONObject data = new JSONObject();
try {
data.put("eventType", detailedBolusInfo.eventType);
data.put("eventType", detailedBolusInfo.eventType.getText());
if (detailedBolusInfo.insulin != 0d) data.put("insulin", detailedBolusInfo.insulin);
if (detailedBolusInfo.carbs != 0d) data.put("carbs", (int) detailedBolusInfo.carbs);
data.put("created_at", DateUtil.toISOString(detailedBolusInfo.date));

View file

@ -14,39 +14,7 @@ class Translator @Inject internal constructor(
) {
@Deprecated("use type instead of string")
fun translate(text: String): String =
when (text) {
TherapyEvent.Type.FINGER_STICK_BG_VALUE.text -> resourceHelper.gs(R.string.careportal_bgcheck)
TherapyEvent.Type.SNACK_BOLUS.text -> resourceHelper.gs(R.string.careportal_snackbolus)
TherapyEvent.Type.MEAL_BOLUS.text -> resourceHelper.gs(R.string.careportal_mealbolus)
TherapyEvent.Type.CORRECTION_BOLUS.text -> resourceHelper.gs(R.string.careportal_correctionbolus)
TherapyEvent.Type.CARBS_CORRECTION.text -> resourceHelper.gs(R.string.careportal_carbscorrection)
TherapyEvent.Type.BOLUS_WIZARD.text -> resourceHelper.gs(R.string.boluswizard)
TherapyEvent.Type.COMBO_BOLUS.text -> resourceHelper.gs(R.string.careportal_combobolus)
TherapyEvent.Type.ANNOUNCEMENT.text -> resourceHelper.gs(R.string.careportal_announcement)
TherapyEvent.Type.NOTE.text -> resourceHelper.gs(R.string.careportal_note)
TherapyEvent.Type.QUESTION.text -> resourceHelper.gs(R.string.careportal_question)
TherapyEvent.Type.EXERCISE.text -> resourceHelper.gs(R.string.careportal_exercise)
TherapyEvent.Type.CANNULA_CHANGE.text -> resourceHelper.gs(R.string.careportal_pumpsitechange)
TherapyEvent.Type.PUMP_BATTERY_CHANGE.text -> resourceHelper.gs(R.string.careportal_pumpbatterychange)
TherapyEvent.Type.SENSOR_STARTED.text -> resourceHelper.gs(R.string.careportal_cgmsensorstart)
TherapyEvent.Type.SENSOR_STOPPED.text -> resourceHelper.gs(R.string.careportal_cgm_sensor_stop)
TherapyEvent.Type.SENSOR_CHANGE.text -> resourceHelper.gs(R.string.careportal_cgmsensorinsert)
TherapyEvent.Type.INSULIN_CHANGE.text -> resourceHelper.gs(R.string.careportal_insulincartridgechange)
TherapyEvent.Type.DAD_ALERT.text -> resourceHelper.gs(R.string.careportal_dad_alert)
TherapyEvent.Type.TEMPORARY_BASAL_START.text -> resourceHelper.gs(R.string.careportal_tempbasalstart)
TherapyEvent.Type.TEMPORARY_BASAL_END.text -> resourceHelper.gs(R.string.careportal_tempbasalend)
TherapyEvent.Type.PROFILE_SWITCH.text -> resourceHelper.gs(R.string.careportal_profileswitch)
TherapyEvent.Type.TEMPORARY_TARGET.text -> resourceHelper.gs(R.string.careportal_temporarytarget)
TherapyEvent.Type.TEMPORARY_TARGET_CANCEL.text -> resourceHelper.gs(R.string.careportal_temporarytargetcancel)
TherapyEvent.Type.APS_OFFLINE.text -> resourceHelper.gs(R.string.careportal_openapsoffline)
TherapyEvent.Type.NS_MBG.text -> resourceHelper.gs(R.string.careportal_mbg)
TherapyEvent.MeterType.FINGER.text -> resourceHelper.gs(R.string.glucosetype_finger)
TherapyEvent.MeterType.SENSOR.text -> resourceHelper.gs(R.string.glucosetype_sensor)
TherapyEvent.MeterType.MANUAL.text -> resourceHelper.gs(R.string.manual)
else -> resourceHelper.gs(R.string.unknown)
}
fun translate(text: String): String = ""
fun translate(action: Action): String = when(action) {
Action.BOLUS -> resourceHelper.gs(R.string.uel_bolus)

View file

@ -28,17 +28,13 @@ sealed class XXXValueWithUnit {
class Percent(val value: Int) : XXXValueWithUnit()
class TherapyEvent(val value: String) : XXXValueWithUnit()
class TherapyEventType(val value: TherapyEvent.Type) : XXXValueWithUnit()
class TherapyEventType(val value: info.nightscout.androidaps.database.entities.TherapyEvent.Type) : XXXValueWithUnit()
class TherapyEventMeterType(val value: info.nightscout.androidaps.database.entities.TherapyEvent.MeterType) : XXXValueWithUnit()
class TherapyEventMeterType(val value: TherapyEvent.MeterType) : XXXValueWithUnit()
class TherapyEventTTReason(val value: TemporaryTarget.Reason) : XXXValueWithUnit()
class StringResource(@StringRes val value: Int, val params : List<XXXValueWithUnit> = listOf()) : XXXValueWithUnit()
class StringResource(@StringRes val value: Int, val params: List<XXXValueWithUnit> = listOf()) : XXXValueWithUnit()
companion object {
@ -50,10 +46,93 @@ sealed class XXXValueWithUnit {
}
}
fun List<XXXValueWithUnit>.toPresentationString(translator: Translator) = concat
// TODO Move to destination module, then uncomment
fun XXXValueWithUnit.toPresentationString(translator: Translator) : String = when(this){
is XXXValueWithUnit.Gram -> "$value ${translator.translate(UserEntry.Units.G)}"
is XXXValueWithUnit.Hour -> "$value ${translator.translate(UserEntry.Units.H)}"
is XXXValueWithUnit.Minute -> "$value ${translator.translate(UserEntry.Units.G)}"
is XXXValueWithUnit.Percent -> "$value ${translator.translate(UserEntry.Units.Percent)}"
is XXXValueWithUnit.Insulin -> "" // DecimalFormatter.to2Decimal(value) + translator.translate(UserEntry.Units.U)
is XXXValueWithUnit.UnitPerHour -> "" // DecimalFormatter.to2Decimal(value) + translator.translate(UserEntry.Units.U_H)
is XXXValueWithUnit.SimpleInt -> value.toString()
is XXXValueWithUnit.SimpleString -> value
is XXXValueWithUnit.StringResource -> "" //resourceHelper.gs(value, params.map { it.toPresentationString(translator) }) // recursively resolve params
is XXXValueWithUnit.TherapyEventMeterType -> translator.translate(value)
is XXXValueWithUnit.TherapyEventTTReason -> translator.translate(value)
is XXXValueWithUnit.TherapyEventType -> translator.translate(value)
is XXXValueWithUnit.Timestamp -> "" // TODO dateUtil.dateAndTimeAndSecondsString(value)
is XXXValueWithUnit.Mgdl -> {
// if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(value) + translator.translate(UserEntry.Units.Mg_Dl)
// else DecimalFormatter.to1Decimal(value/Constants.MMOLL_TO_MGDL) + translator.translate(UserEntry.Units.Mmol_L)
""
}
is XXXValueWithUnit.Mmoll -> {
// if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(value) + translator.translate(UserEntry.Units.Mmol_L)
// else DecimalFormatter.to1Decimal(value * Constants.MMOLL_TO_MGDL) + translator.translate(UserEntry.Units.Mg_Dl)
""
}
XXXValueWithUnit.UNKNOWN -> ""
}
/***
* Idea: Leverage sealed classes for units
* Advantage: it is clear what type of data a Unit contains. Still we are exhaustive on when
*
* The condition "condition" that is used to check if an item should be logged can be replaced by .takeIf { condition }.
* The value then would not have to be handled but the logging could simply discard null value.
*
* [x] new sealed classes
* [x] use entry type directly, not String
* [ ] database
* [ ] generate presentation string
* [ ] update fragment
* [ ] generate csv
*
*/
// just do develop here
interface Translator {
fun translate(action: UserEntry.Action): String
fun translate(units: UserEntry.Units): String
fun translate(meterType: TherapyEvent.MeterType): String
fun translate(type: TherapyEvent.Type): String
fun translate(reason: TemporaryTarget.Reason): String
}
/*
var valuesWithUnitString = ""
var rStringParam = 0
val separator = " "
for(v in current.values) {
if (rStringParam >0)
rStringParam--
else
when (v.unit) {
UserEntry.Units.Timestamp -> valuesWithUnitString += dateUtil.dateAndTimeAndSecondsString(v.lValue) + separator
UserEntry.Units.TherapyEvent -> valuesWithUnitString += translator.translate(v.sValue) + separator
UserEntry.Units.R_String -> {
rStringParam = v.lValue.toInt()
when (rStringParam) { //
0 -> valuesWithUnitString += resourceHelper.gs(v.iValue) + separator
1 -> valuesWithUnitString += resourceHelper.gs(v.iValue, current.values[current.values.indexOf(v)+1].value()) + separator
2 -> valuesWithUnitString += resourceHelper.gs(v.iValue, current.values[current.values.indexOf(v)+1].value(), current.values[current.values.indexOf(v)+2].value()) + separator
3 -> valuesWithUnitString += resourceHelper.gs(v.iValue, current.values[current.values.indexOf(v)+1].value(), current.values[current.values.indexOf(v)+2].value(), current.values[current.values.indexOf(v)+3].value()) + separator
4 -> rStringParam = 0
}
}
UserEntry.Units.Mg_Dl -> valuesWithUnitString += if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(v.dValue) + translator.translate(UserEntry.Units.Mg_Dl) + separator else DecimalFormatter.to1Decimal(v.dValue/Constants.MMOLL_TO_MGDL) + translator.translate(UserEntry.Units.Mmol_L) + separator
UserEntry.Units.Mmol_L -> valuesWithUnitString += if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(v.dValue*Constants.MMOLL_TO_MGDL) + translator.translate(UserEntry.Units.Mg_Dl) + separator else DecimalFormatter.to1Decimal(v.dValue) + translator.translate(UserEntry.Units.Mmol_L) + separator
UserEntry.Units.U_H, UserEntry.Units.U
-> valuesWithUnitString += DecimalFormatter.to2Decimal(v.dValue) + translator.translate(v.unit) + separator
UserEntry.Units.G, UserEntry.Units.M, UserEntry.Units.H, UserEntry.Units.Percent
-> valuesWithUnitString += v.iValue.toString() + translator.translate(v.unit) + separator
else -> valuesWithUnitString += if (v.iValue != 0 || v.sValue != "") { v.value().toString() + separator } else ""
}
}*/

View file

@ -5,6 +5,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.database.entities.TherapyEvent;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
@ -16,7 +17,7 @@ import info.nightscout.androidaps.logging.LTag;
public class ActiveBolus {
private long date;
private long lastKnownBolusTime;
private String eventType;
private TherapyEvent.Type eventType;
private double insulin;
private double carbs;
private int source;