Constructor for formated Strings with param, add notes, convert to AAPS units in fragment

This commit is contained in:
Philoul 2021-03-02 22:43:18 +01:00
parent f226a03c83
commit efa9e18f83
12 changed files with 91 additions and 55 deletions

View file

@ -250,10 +250,10 @@ class CarbsDialog : DialogFragmentWithDate() {
}
if (carbsAfterConstraints > 0) {
if (duration == 0) {
uel.log(Action.CARBS, ValueWithUnit(carbsAfterConstraints.toDouble(), Units.G), ValueWithUnit(timeOffset, Units.M))
uel.log(Action.CARBS, notes, ValueWithUnit(carbsAfterConstraints.toDouble(), Units.G), ValueWithUnit(timeOffset, Units.M))
carbsGenerator.createCarb(carbsAfterConstraints, time, CareportalEvent.CARBCORRECTION, notes)
} else {
uel.log(Action.CARBS, ValueWithUnit(carbsAfterConstraints.toDouble(), Units.G), ValueWithUnit(timeOffset,Units.M), ValueWithUnit(duration, Units.H))
uel.log(Action.CARBS, notes, ValueWithUnit(carbsAfterConstraints.toDouble(), Units.G), ValueWithUnit(timeOffset,Units.M), ValueWithUnit(duration, Units.H))
carbsGenerator.generateCarbs(carbsAfterConstraints, time, duration, notes)
nsUpload.uploadEvent(CareportalEvent.NOTE, DateUtil.now() - 2000, resourceHelper.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset))
}

View file

@ -223,7 +223,7 @@ class CareDialog : DialogFragmentWithDate() {
EventType.ANNOUNCEMENT -> CareportalEvent.ANNOUNCEMENT
}
careportalEvent.json = json.toString()
uel.log(Action.CAREPORTAL, ValueWithUnit(careportalEvent.eventType, Units.CPEvent))
uel.log(Action.CAREPORTAL, notes, ValueWithUnit(careportalEvent.eventType, Units.CPEvent))
MainApp.getDbHelper().createOrUpdate(careportalEvent)
nsUpload.uploadCareportalEntryToNS(json)
}, null)

View file

@ -128,16 +128,16 @@ class FillDialog : DialogFragmentWithDate() {
activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.primefill), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
if (insulinAfterConstraints > 0) {
uel.log(Action.PRIME_BOLUS, ValueWithUnit(insulinAfterConstraints, Units.U))
uel.log(Action.PRIME_BOLUS, notes, ValueWithUnit(insulinAfterConstraints, Units.U))
requestPrimeBolus(insulinAfterConstraints, notes)
}
if (siteChange) {
uel.log(Action.SITE_CHANGE)
uel.log(Action.SITE_CHANGE, notes)
nsUpload.generateCareportalEvent(CareportalEvent.SITECHANGE, eventTime, notes)
}
if (insulinChange) {
// add a second for case of both checked
uel.log(Action.INSULIN_CHANGE)
uel.log(Action.INSULIN_CHANGE, notes)
nsUpload.generateCareportalEvent(CareportalEvent.INSULINCHANGE, eventTime + 1000, notes)
}
}, null)

View file

@ -179,7 +179,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_EATING_SOON, ValueWithUnit(eatingSoonTT, units), ValueWithUnit(eatingSoonTTDuration, Units.M))
uel.log(Action.TT_EATING_SOON, notes, ValueWithUnit(eatingSoonTT, units), ValueWithUnit(eatingSoonTTDuration, Units.M))
val tempTarget = TempTarget()
.date(System.currentTimeMillis())
.duration(eatingSoonTTDuration)
@ -197,11 +197,11 @@ class InsulinDialog : DialogFragmentWithDate() {
detailedBolusInfo.source = Source.USER
detailedBolusInfo.notes = notes
if (recordOnlyChecked) {
uel.log(Action.BOLUS_RECORD, ValueWithUnit(insulinAfterConstraints, Units.U), ValueWithUnit(timeOffset, Units.M))
uel.log(Action.BOLUS_RECORD, notes, ValueWithUnit(insulinAfterConstraints, Units.U), ValueWithUnit(timeOffset, Units.M))
detailedBolusInfo.date = time
activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, false)
} else {
uel.log(Action.BOLUS, ValueWithUnit(insulinAfterConstraints, Units.U))
uel.log(Action.BOLUS, notes, ValueWithUnit(insulinAfterConstraints, Units.U))
detailedBolusInfo.date = DateUtil.now()
commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() {

View file

@ -125,7 +125,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
activity?.let { activity ->
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
uel.log(Action.PROFILE_SWITCH, ValueWithUnit(percent, Units.Percent), ValueWithUnit(timeShift, Units.H), ValueWithUnit(duration, Units.M))
uel.log(Action.PROFILE_SWITCH, notes, ValueWithUnit(percent, Units.Percent), ValueWithUnit(timeShift, Units.H), ValueWithUnit(duration, Units.M))
treatmentsPlugin.doProfileSwitch(profileStore, profile, duration, percent, timeShift, eventTime)
})
}

View file

@ -648,9 +648,9 @@ class SmsCommunicatorPlugin @Inject constructor(
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
if (result.isPercent)
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalset_percent, Units.R_String), ValueWithUnit(result.percent, Units.Percent), ValueWithUnit(result.duration, Units.M))
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalset_percent, 2), ValueWithUnit(result.percent, Units.Percent), ValueWithUnit(result.duration, Units.M))
else
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalset, Units.R_String), ValueWithUnit(result.absolute, Units.U_H), ValueWithUnit(result.duration, Units.M))
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalset, 2), ValueWithUnit(result.absolute, Units.U_H), ValueWithUnit(result.duration, Units.M))
} else {
var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
@ -686,9 +686,9 @@ class SmsCommunicatorPlugin @Inject constructor(
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
if (result.isPercent)
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalset_percent, Units.R_String), ValueWithUnit(result.percent, Units.Percent), ValueWithUnit(result.duration, Units.M))
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalset_percent, 2), ValueWithUnit(result.percent, Units.Percent), ValueWithUnit(result.duration, Units.M))
else
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalset, Units.R_String), ValueWithUnit(result.absolute, Units.U_H), ValueWithUnit(result.duration, Units.M))
uel.log(Action.SMS_BASAL, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_tempbasalset, 2), ValueWithUnit(result.absolute, Units.U_H), ValueWithUnit(result.duration, Units.M))
} else {
var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
@ -747,9 +747,9 @@ class SmsCommunicatorPlugin @Inject constructor(
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
if (config.APS)
uel.log(Action.SMS_EXTENDED_BOLUS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_extendedset, Units.R_String), ValueWithUnit(aDouble, Units.U), ValueWithUnit(duration, Units.M), ValueWithUnit(R.string.loopsuspended, Units.R_String))
uel.log(Action.SMS_EXTENDED_BOLUS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_extendedset, 2), ValueWithUnit(aDouble, Units.U), ValueWithUnit(duration, Units.M), ValueWithUnit(R.string.loopsuspended, Units.R_String))
else
uel.log(Action.SMS_EXTENDED_BOLUS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_extendedset, Units.R_String), ValueWithUnit(aDouble, Units.U), ValueWithUnit(duration, Units.M))
uel.log(Action.SMS_EXTENDED_BOLUS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_extendedset, 2), ValueWithUnit(aDouble, Units.U), ValueWithUnit(duration, Units.M))
} else {
var replyText = resourceHelper.gs(R.string.smscommunicator_extendedfailed)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
@ -868,12 +868,12 @@ class SmsCommunicatorPlugin @Inject constructor(
var replyText = String.format(resourceHelper.gs(R.string.smscommunicator_carbsset), anInteger)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_CARBS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_carbsset, Units.R_String), ValueWithUnit(anInteger,Units.G))
uel.log(Action.SMS_CARBS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_carbsset, 1), ValueWithUnit(anInteger,Units.G))
} else {
var replyText = resourceHelper.gs(R.string.smscommunicator_carbsfailed, anInteger)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_CARBS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_carbsfailed, Units.R_String), ValueWithUnit(anInteger,Units.G))
uel.log(Action.SMS_CARBS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_carbsfailed, 1), ValueWithUnit(anInteger,Units.G))
}
}
})
@ -882,7 +882,7 @@ class SmsCommunicatorPlugin @Inject constructor(
var replyText = String.format(resourceHelper.gs(R.string.smscommunicator_carbsset), anInteger)
replyText += "\n" + activePlugin.activePump.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_CARBS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_carbsset, Units.R_String), ValueWithUnit(anInteger,Units.G))
uel.log(Action.SMS_CARBS, activePlugin.activePump.shortStatus(true), ValueWithUnit(R.string.smscommunicator_carbsset, 1), ValueWithUnit(anInteger,Units.G))
}
}
})
@ -947,7 +947,8 @@ class SmsCommunicatorPlugin @Inject constructor(
val ttString = if (units == Constants.MMOL) DecimalFormatter.to1Decimal(tt) else DecimalFormatter.to0Decimal(tt)
val replyText = String.format(resourceHelper.gs(R.string.smscommunicator_tt_set), ttString, ttDuration)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
uel.log(Action.SMS_TT, ValueWithUnit(R.string.smscommunicator_tt_set, Units.R_String), ValueWithUnit(tt, units), ValueWithUnit(ttDuration, Units.M))
//uel.log(Action.SMS_TT, ValueWithUnit(R.string.smscommunicator_tt_set, 2), ValueWithUnit(tt, units), ValueWithUnit(ttDuration, Units.M))
uel.log(Action.SMS_TT, ValueWithUnit(tt, units), ValueWithUnit(ttDuration, Units.M))
}
})
} else if (isStop) {

View file

@ -7,16 +7,20 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R
import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.UserEntry
import info.nightscout.androidaps.database.entities.UserEntry.*
import info.nightscout.androidaps.databinding.TreatmentsUserEntryFragmentBinding
import info.nightscout.androidaps.databinding.TreatmentsUserEntryItemBinding
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.Translator
import info.nightscout.androidaps.utils.extensions.stringId
import info.nightscout.androidaps.utils.extensions.*
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
@ -29,6 +33,9 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var translator: Translator
private val disposable = CompositeDisposable()
@ -74,16 +81,30 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
if (current.s != "") holder.binding.s.text = current.s else holder.binding.s.visibility = View.GONE
//holder.binding.s.text = current.toString() //for debug
var valuesWithUnitString = ""
var rStringParam = 0
for(v in current.values) {
when (v.unit) {
Units.Timestamp -> valuesWithUnitString += dateUtil.dateAndTimeAndSecondsString(v.lValue) + " "
Units.CPEvent -> valuesWithUnitString += translator.translate(v.sValue) + " "
Units.R_String -> valuesWithUnitString += resourceHelper.gs(v.iValue) + " "
Units.Mg_Dl -> valuesWithUnitString += DecimalFormatter.to0Decimal(v.dValue) + resourceHelper.gs(Units.Mg_Dl.stringId()) + " "
Units.Mmol_L -> valuesWithUnitString += DecimalFormatter.to1Decimal(v.dValue) + resourceHelper.gs(Units.Mmol_L.stringId()) + " "
Units.G -> valuesWithUnitString += DecimalFormatter.to0Decimal(v.dValue) + resourceHelper.gs(Units.G.stringId()) + " "
else -> valuesWithUnitString += if (!v.value().equals(0) && !v.value().equals("")) { v.value().toString() + if (!v.unit.stringId().equals(0)) resourceHelper.gs(v.unit.stringId()) + " " else " " } else ""
}
if (rStringParam >0)
rStringParam--
else
when (v.unit) {
Units.Timestamp -> valuesWithUnitString += dateUtil.dateAndTimeAndSecondsString(v.lValue) + " "
Units.CPEvent -> valuesWithUnitString += translator.translate(v.sValue) + " "
Units.R_String -> {
rStringParam = v.lValue.toInt()
when (rStringParam) { //
0 -> valuesWithUnitString += resourceHelper.gs(v.iValue) + " "
1 -> valuesWithUnitString += resourceHelper.gs(v.iValue, current.values[current.values.indexOf(v)+1].value()) + " "
2 -> valuesWithUnitString += resourceHelper.gs(v.iValue, current.values[current.values.indexOf(v)+1].value(), current.values[current.values.indexOf(v)+2].value()) + " "
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()) + " "
4 -> rStringParam = 0
}
}
Units.Mg_Dl -> valuesWithUnitString += if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(v.dValue) + resourceHelper.gs(Units.Mg_Dl.stringId()) + " " else DecimalFormatter.to1Decimal(v.dValue/Constants.MMOLL_TO_MGDL) + resourceHelper.gs(Units.Mmol_L.stringId()) + " "
Units.Mmol_L -> valuesWithUnitString += if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(v.dValue*Constants.MMOLL_TO_MGDL) + resourceHelper.gs(Units.Mg_Dl.stringId()) + " " else DecimalFormatter.to1Decimal(v.dValue) + resourceHelper.gs(Units.Mmol_L.stringId()) + " "
Units.G -> valuesWithUnitString += DecimalFormatter.to0Decimal(v.dValue) + resourceHelper.gs(Units.G.stringId()) + " "
Units.U_H -> valuesWithUnitString += DecimalFormatter.to2Decimal(v.dValue) + resourceHelper.gs(Units.U_H.stringId()) + " "
else -> valuesWithUnitString += if (!v.value().equals(0) && !v.value().equals("")) { v.value().toString() + if (!v.unit.stringId().equals(0)) resourceHelper.gs(v.unit.stringId()) + " " else " " } else ""
}
}
if (current.values.size > 0)
holder.binding.values.visibility = View.VISIBLE

View file

@ -46,7 +46,7 @@
<TextView
android:id="@+id/values"
android:layout_width="wrap_content"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
@ -57,10 +57,10 @@
<TextView
android:id="@+id/s"
android:layout_width="wrap_content"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="10dp"
android:layout_weight="0.5"
android:paddingStart="20dp"
android:textAppearance="?android:attr/textAppearanceSmall"
tools:ignore="HardcodedText,RtlSymmetry" />

View file

@ -1,19 +0,0 @@
package info.nightscout.androidaps.utils.extensions
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.database.entities.UserEntry
fun UserEntry.Units.stringId(): Int {
return when {
this == UserEntry.Units.Mg_Dl -> R.string.mgdl
this == UserEntry.Units.Mmol_L -> R.string.mmol
this == UserEntry.Units.U -> R.string.insulin_unit_shortname
this == UserEntry.Units.U_H -> R.string.profile_ins_units_per_hour
this == UserEntry.Units.G -> R.string.shortgram
this == UserEntry.Units.M -> R.string.shortminute
this == UserEntry.Units.H -> R.string.shorthour
this == UserEntry.Units.Percent -> R.string.shortpercent
else -> 0
}
}

View file

@ -100,4 +100,34 @@ fun UserEntry.Action.stringId(): Int {
this == UserEntry.Action.SMS_TT -> R.string.uel_sms_tt
else -> R.string.uel_unknown
}
}
fun UserEntry.Units.stringId(): Int {
return when {
this == UserEntry.Units.Mg_Dl -> R.string.mgdl
this == UserEntry.Units.Mmol_L -> R.string.mmol
this == UserEntry.Units.U -> R.string.insulin_unit_shortname
this == UserEntry.Units.U_H -> R.string.profile_ins_units_per_hour
this == UserEntry.Units.G -> R.string.shortgram
this == UserEntry.Units.M -> R.string.shortminute
this == UserEntry.Units.H -> R.string.shorthour
this == UserEntry.Units.Percent -> R.string.shortpercent
this == UserEntry.Units.R_String -> R.string.formated_string
else -> 0
}
}
fun UserEntry.ValueWithUnit.toStringWithUnit(): String {
/* need injection to maje convertion
return when (this.unit) {
UserEntry.Units.Timestamp -> dateUtil.dateAndTimeAndSecondsString(this.lValue)
UserEntry.Units.CPEvent -> translator.translate(this.sValue)
UserEntry.Units.R_String -> resourceHelper.gs(this.iValue)
UserEntry.Units.Mg_Dl -> DecimalFormatter.to0Decimal(this.dValue) + resourceHelper.gs(UserEntry.Units.Mg_Dl.stringId())
UserEntry.Units.Mmol_L -> DecimalFormatter.to1Decimal(this.dValue) + resourceHelper.gs(UserEntry.Units.Mmol_L.stringId())
UserEntry.Units.G -> DecimalFormatter.to0Decimal(this.dValue) + resourceHelper.gs(UserEntry.Units.G.stringId())
else -> if (!this.value().equals(0) && !this.value().equals("")) { v.value().toString() + if (!this.unit.stringId().equals(0)) resourceHelper.gs(this.unit.stringId()) else "" } else ""
} */
return ""
}

View file

@ -482,6 +482,7 @@
<string name="uel_sms_sms">SMS SMS</string>
<string name="uel_sms_tt">SMS TT</string>
<string name="uel_unknown">UNKNOWN</string>
<string name="formated_string">Formated string</string>
<plurals name="days">
<item quantity="one">%1$d day</item>

View file

@ -125,11 +125,13 @@ data class UserEntry(
constructor(lvalue:Long?, unit:Units) : this(0.0,0, lvalue ?:0, "", unit)
constructor(svalue:String?, unit:Units) : this(0.0,0, 0, svalue ?:"", unit)
constructor(dvalue:Double?, unit:String) : this(dvalue ?:0.0,0, 0, "", Units.fromText(unit))
constructor(rStringRef:Int, nbParam: Long) : this(0.0, rStringRef, nbParam, "", Units.R_String) // additionnal constructors for formated strings with additional values as parameters (define number of parameters as long
fun value() : Any {
if (sValue != "") return sValue
if (!dValue.equals(0.0)) return dValue
if (!iValue.equals(0)) return iValue
if (!lValue.equals(0)) return lValue
return sValue
return lValue
}
}
enum class Units(val text: String) {