Safe Delete old ValueWithUnit Class in UserEntry
This commit is contained in:
parent
195c810606
commit
206bac6da8
|
@ -18,7 +18,6 @@ import info.nightscout.androidaps.activities.ErrorHelperActivity
|
||||||
import info.nightscout.androidaps.activities.TDDStatsActivity
|
import info.nightscout.androidaps.activities.TDDStatsActivity
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
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.entities.UserEntry.ValueWithUnit
|
|
||||||
import info.nightscout.androidaps.dialogs.*
|
import info.nightscout.androidaps.dialogs.*
|
||||||
import info.nightscout.androidaps.events.*
|
import info.nightscout.androidaps.events.*
|
||||||
import info.nightscout.androidaps.historyBrowser.HistoryBrowseActivity
|
import info.nightscout.androidaps.historyBrowser.HistoryBrowseActivity
|
||||||
|
|
|
@ -18,7 +18,6 @@ import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.database.entities.Food
|
import info.nightscout.androidaps.database.entities.Food
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
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.entities.UserEntry.ValueWithUnit
|
|
||||||
import info.nightscout.androidaps.database.transactions.InvalidateFoodTransaction
|
import info.nightscout.androidaps.database.transactions.InvalidateFoodTransaction
|
||||||
import info.nightscout.androidaps.databinding.FoodFragmentBinding
|
import info.nightscout.androidaps.databinding.FoodFragmentBinding
|
||||||
import info.nightscout.androidaps.databinding.FoodItemBinding
|
import info.nightscout.androidaps.databinding.FoodItemBinding
|
||||||
|
|
|
@ -16,8 +16,6 @@ import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
|
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
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.entities.UserEntry.Units
|
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit
|
|
||||||
import info.nightscout.androidaps.databinding.ActivitySmscommunicatorOtpBinding
|
import info.nightscout.androidaps.databinding.ActivitySmscommunicatorOtpBinding
|
||||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
|
|
@ -18,8 +18,6 @@ import info.nightscout.androidaps.database.ValueWrapper
|
||||||
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
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.entities.UserEntry.Units
|
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit
|
|
||||||
import info.nightscout.androidaps.database.entities.XXXValueWithUnit
|
import info.nightscout.androidaps.database.entities.XXXValueWithUnit
|
||||||
import info.nightscout.androidaps.database.interfaces.end
|
import info.nightscout.androidaps.database.interfaces.end
|
||||||
import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction
|
import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction
|
||||||
|
|
|
@ -201,7 +201,7 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
||||||
XXXValueWithUnit.TherapyEventTTReason(tempTarget.reason),
|
XXXValueWithUnit.TherapyEventTTReason(tempTarget.reason),
|
||||||
XXXValueWithUnit.Mgdl(tempTarget.lowTarget),
|
XXXValueWithUnit.Mgdl(tempTarget.lowTarget),
|
||||||
XXXValueWithUnit.Mgdl(tempTarget.highTarget).takeIf { tempTarget.lowTarget != tempTarget.highTarget },
|
XXXValueWithUnit.Mgdl(tempTarget.highTarget).takeIf { tempTarget.lowTarget != tempTarget.highTarget },
|
||||||
XXXValueWithUnit.Minute(tempTarget.duration.toInt()))
|
XXXValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tempTarget.duration).toInt()))
|
||||||
disposable += repository.runTransactionForResult(InvalidateTemporaryTargetTransaction(tempTarget.id))
|
disposable += repository.runTransactionForResult(InvalidateTemporaryTargetTransaction(tempTarget.id))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
{ aapsLogger.debug(LTag.DATABASE, "Removed temp target $tempTarget") },
|
{ aapsLogger.debug(LTag.DATABASE, "Removed temp target $tempTarget") },
|
||||||
|
|
|
@ -4,7 +4,6 @@ import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.database.entities.XXXValueWithUnit
|
import info.nightscout.androidaps.database.entities.XXXValueWithUnit
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
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.entities.UserEntry.ValueWithUnit
|
|
||||||
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 io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
package info.nightscout.androidaps.database
|
package info.nightscout.androidaps.database
|
||||||
|
|
||||||
import androidx.room.TypeConverter
|
import androidx.room.TypeConverter
|
||||||
import com.google.gson.JsonArray
|
|
||||||
import info.nightscout.androidaps.database.data.Block
|
import info.nightscout.androidaps.database.data.Block
|
||||||
import info.nightscout.androidaps.database.data.TargetBlock
|
import info.nightscout.androidaps.database.data.TargetBlock
|
||||||
import info.nightscout.androidaps.database.embedments.InterfaceIDs
|
import info.nightscout.androidaps.database.embedments.InterfaceIDs
|
||||||
import info.nightscout.androidaps.database.entities.*
|
import info.nightscout.androidaps.database.entities.*
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
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.entities.UserEntry.Units
|
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.ValueWithUnit
|
|
||||||
import info.nightscout.androidaps.database.serialisation.SealedClassHelper
|
import info.nightscout.androidaps.database.serialisation.SealedClassHelper
|
||||||
import info.nightscout.androidaps.database.serialisation.fromJson
|
import info.nightscout.androidaps.database.serialisation.fromJson
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
|
@ -39,30 +36,6 @@ class Converters {
|
||||||
|
|
||||||
private class ValueWithUnitWrapper(val wrapped: XXXValueWithUnit)
|
private class ValueWithUnitWrapper(val wrapped: XXXValueWithUnit)
|
||||||
|
|
||||||
@TypeConverter
|
|
||||||
fun fromMutableListOfValueWithUnit(values: MutableList<ValueWithUnit>): String {
|
|
||||||
val jsonArray = JSONArray()
|
|
||||||
values.forEach {
|
|
||||||
if (it.condition) {
|
|
||||||
val jsonObject = JSONObject()
|
|
||||||
jsonObject.put("dValue", it.dValue).put("iValue", it.iValue).put("lValue", it.lValue).put("sValue", it.sValue).put("unit", it.unit.name)
|
|
||||||
jsonArray.put(jsonObject)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return jsonArray.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
@TypeConverter
|
|
||||||
fun toMutableListOfValueWithUnit(jsonString: String): MutableList<ValueWithUnit> {
|
|
||||||
val jsonArray = JSONArray(jsonString)
|
|
||||||
val list = mutableListOf<ValueWithUnit>()
|
|
||||||
for (i in 0 until jsonArray.length()) {
|
|
||||||
val jsonObject = jsonArray.getJSONObject(i)
|
|
||||||
list.add(ValueWithUnit(jsonObject.getDouble("dValue"), jsonObject.getInt("iValue"), jsonObject.getLong("lValue"), jsonObject.getString("sValue"), Units.fromString(jsonObject.getString("unit"))))
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun fromBolusType(bolusType: Bolus.Type?) = bolusType?.name
|
fun fromBolusType(bolusType: Bolus.Type?) = bolusType?.name
|
||||||
|
|
||||||
|
|
|
@ -96,22 +96,7 @@ data class UserEntry(
|
||||||
fun fromString(source: String?) = values().firstOrNull { it.name == source } ?: UNKNOWN
|
fun fromString(source: String?) = values().firstOrNull { it.name == source } ?: UNKNOWN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data class ValueWithUnit (val dValue: Double=0.0, val iValue: Int=0, val lValue: Long=0, val sValue: String="", val unit: Units=Units.None, val condition:Boolean=true){
|
|
||||||
constructor(dvalue: Double, unit: Units, condition:Boolean = true) : this(dvalue, 0, 0, "", unit, condition)
|
|
||||||
constructor(ivalue: Int, unit: Units, condition:Boolean = true) : this(0.0, ivalue, 0, "", unit, condition)
|
|
||||||
constructor(lvalue: Long, unit: Units, condition:Boolean = true) : this(0.0,0, lvalue, "", unit, condition)
|
|
||||||
constructor(svalue: String, unit:Units) : this(0.0,0, 0, svalue, unit, svalue != "")
|
|
||||||
constructor(source: Sources) : this(0.0,0, 0, source.name, Units.Source, true)
|
|
||||||
constructor(dvalue: Double, unit:String, condition:Boolean = true) : this(dvalue,0, 0, "", Units.fromText(unit), condition)
|
|
||||||
constructor(rStringRef: Int, nbParam: Long) : this(0.0, rStringRef, nbParam, "", Units.R_String, !rStringRef.equals(0)) // 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
|
|
||||||
return lValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
enum class Units(val text: String) {
|
enum class Units(val text: String) {
|
||||||
None (""), //Int or String
|
None (""), //Int or String
|
||||||
Mg_Dl ("mg/dl"), //Double
|
Mg_Dl ("mg/dl"), //Double
|
||||||
|
|
Loading…
Reference in a new issue