fix empty mgdl local profile
This commit is contained in:
parent
1bbca2787b
commit
4bacfad0db
5 changed files with 68 additions and 150 deletions
|
@ -136,7 +136,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
|
|||
else defaultProfileDPV.profile(age, tdd, pct / 100.0, profileFunction.getUnits())
|
||||
profile?.let {
|
||||
OKDialog.showConfirmation(this, resourceHelper.gs(R.string.careportal_profileswitch), resourceHelper.gs(R.string.copytolocalprofile), Runnable {
|
||||
localProfilePlugin.addProfile(LocalProfilePlugin.SingleProfile().copyFrom(localProfilePlugin.rawProfile, it, "DefaultProfile" + dateUtil.dateAndTimeAndSecondsString(dateUtil._now())))
|
||||
localProfilePlugin.addProfile(localProfilePlugin.copyFrom(it, "DefaultProfile" + dateUtil.dateAndTimeAndSecondsString(dateUtil._now())))
|
||||
rxBus.send(EventLocalProfileChanged())
|
||||
})
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
|
|||
|
||||
tabSelected = tab
|
||||
typeSelected[tabSelected] = newContent
|
||||
profilehelper_profiletype_title.setDefaultHintTextColor(ColorStateList.valueOf(resourceHelper.gc(if (tab == 0) R.color.tabBgColorSelected else R.color.examinedProfile)))
|
||||
profilehelper_profiletype_title.defaultHintTextColor = ColorStateList.valueOf(resourceHelper.gc(if (tab == 0) R.color.tabBgColorSelected else R.color.examinedProfile))
|
||||
|
||||
// show new content
|
||||
profilehelper_profiletype.setText(
|
||||
|
|
|
@ -52,8 +52,8 @@ class LocalProfileFragment : DaggerFragment() {
|
|||
override fun afterTextChanged(s: Editable) {}
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
localProfilePlugin.currentProfile().dia = SafeParse.stringToDouble(localprofile_dia.text.toString())
|
||||
localProfilePlugin.currentProfile().name = localprofile_name.text.toString()
|
||||
localProfilePlugin.currentProfile()?.dia = SafeParse.stringToDouble(localprofile_dia.text.toString())
|
||||
localProfilePlugin.currentProfile()?.name = localprofile_name.text.toString()
|
||||
doEdit()
|
||||
}
|
||||
}
|
||||
|
@ -99,21 +99,23 @@ class LocalProfileFragment : DaggerFragment() {
|
|||
|
||||
fun build() {
|
||||
val pumpDescription = activePlugin.activePump.pumpDescription
|
||||
val units = if (localProfilePlugin.currentProfile().mgdl) Constants.MGDL else Constants.MMOL
|
||||
if (localProfilePlugin.numOfProfiles == 0) localProfilePlugin.addNewProfile()
|
||||
val currentProfile = localProfilePlugin.currentProfile() ?: return
|
||||
val units = if (currentProfile.mgdl) Constants.MGDL else Constants.MMOL
|
||||
|
||||
localprofile_name.removeTextChangedListener(textWatch)
|
||||
localprofile_name.setText(localProfilePlugin.currentProfile().name)
|
||||
localprofile_name.setText(currentProfile.name)
|
||||
localprofile_name.addTextChangedListener(textWatch)
|
||||
localprofile_dia.setParams(localProfilePlugin.currentProfile().dia, hardLimits.MINDIA, hardLimits.MAXDIA, 0.1, DecimalFormat("0.0"), false, localprofile_save, textWatch)
|
||||
localprofile_dia.setParams(currentProfile.dia, hardLimits.MINDIA, hardLimits.MAXDIA, 0.1, DecimalFormat("0.0"), false, localprofile_save, textWatch)
|
||||
localprofile_dia.tag = "LP_DIA"
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_ic, "IC", resourceHelper.gs(R.string.ic_label), localProfilePlugin.currentProfile().ic, null, hardLimits.MINIC, hardLimits.MAXIC, 0.1, DecimalFormat("0.0"), save)
|
||||
basalView = TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_basal, "BASAL", resourceHelper.gs(R.string.basal_label) + ": " + sumLabel(), localProfilePlugin.currentProfile().basal, null, pumpDescription.basalMinimumRate, 10.0, 0.01, DecimalFormat("0.00"), save)
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_ic, "IC", resourceHelper.gs(R.string.ic_label), currentProfile.ic, null, hardLimits.MINIC, hardLimits.MAXIC, 0.1, DecimalFormat("0.0"), save)
|
||||
basalView = TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_basal, "BASAL", resourceHelper.gs(R.string.basal_label) + ": " + sumLabel(), currentProfile.basal, null, pumpDescription.basalMinimumRate, 10.0, 0.01, DecimalFormat("0.00"), save)
|
||||
if (units == Constants.MGDL) {
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_isf, "ISF", resourceHelper.gs(R.string.isf_label), localProfilePlugin.currentProfile().isf, null, hardLimits.MINISF, hardLimits.MAXISF, 1.0, DecimalFormat("0"), save)
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_target, "TARGET", resourceHelper.gs(R.string.target_label), localProfilePlugin.currentProfile().targetLow, localProfilePlugin.currentProfile().targetHigh, hardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), hardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), 1.0, DecimalFormat("0"), save)
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_isf, "ISF", resourceHelper.gs(R.string.isf_label), currentProfile.isf, null, hardLimits.MINISF, hardLimits.MAXISF, 1.0, DecimalFormat("0"), save)
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_target, "TARGET", resourceHelper.gs(R.string.target_label), currentProfile.targetLow, currentProfile.targetHigh, hardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), hardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), 1.0, DecimalFormat("0"), save)
|
||||
} else {
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_isf, "ISF", resourceHelper.gs(R.string.isf_label), localProfilePlugin.currentProfile().isf, null, Profile.fromMgdlToUnits(hardLimits.MINISF, Constants.MMOL), Profile.fromMgdlToUnits(hardLimits.MAXISF, Constants.MMOL), 0.1, DecimalFormat("0.0"), save)
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_target, "TARGET", resourceHelper.gs(R.string.target_label), localProfilePlugin.currentProfile().targetLow, localProfilePlugin.currentProfile().targetHigh, Profile.fromMgdlToUnits(hardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), Constants.MMOL), Profile.fromMgdlToUnits(hardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), Constants.MMOL), 0.1, DecimalFormat("0.0"), save)
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_isf, "ISF", resourceHelper.gs(R.string.isf_label), currentProfile.isf, null, Profile.fromMgdlToUnits(hardLimits.MINISF, Constants.MMOL), Profile.fromMgdlToUnits(hardLimits.MAXISF, Constants.MMOL), 0.1, DecimalFormat("0.0"), save)
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_target, "TARGET", resourceHelper.gs(R.string.target_label), currentProfile.targetLow, currentProfile.targetHigh, Profile.fromMgdlToUnits(hardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), Constants.MMOL), Profile.fromMgdlToUnits(hardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), Constants.MMOL), 0.1, DecimalFormat("0.0"), save)
|
||||
}
|
||||
|
||||
// Spinner
|
||||
|
@ -177,24 +179,24 @@ class LocalProfileFragment : DaggerFragment() {
|
|||
// if (!pumpDescription.isTempBasalCapable) localprofile_basal.visibility = View.GONE
|
||||
|
||||
@Suppress("SetTextI18n")
|
||||
localprofile_units.text = resourceHelper.gs(R.string.units_colon) + " " + (if (localProfilePlugin.currentProfile().mgdl) resourceHelper.gs(R.string.mgdl) else resourceHelper.gs(R.string.mmol))
|
||||
localprofile_units.text = resourceHelper.gs(R.string.units_colon) + " " + (if (currentProfile.mgdl) resourceHelper.gs(R.string.mgdl) else resourceHelper.gs(R.string.mmol))
|
||||
|
||||
localprofile_profileswitch.setOnClickListener {
|
||||
ProfileSwitchDialog()
|
||||
.also { it.arguments = Bundle().also { bundle -> bundle.putInt("profileIndex", localProfilePlugin.currentProfileIndex) }}
|
||||
.also { it.arguments = Bundle().also { bundle -> bundle.putInt("profileIndex", localProfilePlugin.currentProfileIndex) } }
|
||||
.show(childFragmentManager, "NewNSTreatmentDialog")
|
||||
}
|
||||
|
||||
localprofile_reset.setOnClickListener {
|
||||
localProfilePlugin.loadSettings()
|
||||
@Suppress("SetTextI18n")
|
||||
localprofile_units.text = resourceHelper.gs(R.string.units_colon) + " " + (if (localProfilePlugin.currentProfile().mgdl) resourceHelper.gs(R.string.mgdl) else resourceHelper.gs(R.string.mmol))
|
||||
localprofile_dia.setParams(localProfilePlugin.currentProfile().dia, MIN_DIA, 12.0, 0.1, DecimalFormat("0.0"), false, localprofile_save, textWatch)
|
||||
localprofile_units.text = resourceHelper.gs(R.string.units_colon) + " " + (if (currentProfile.mgdl) resourceHelper.gs(R.string.mgdl) else resourceHelper.gs(R.string.mmol))
|
||||
localprofile_dia.setParams(currentProfile.dia, MIN_DIA, 12.0, 0.1, DecimalFormat("0.0"), false, localprofile_save, textWatch)
|
||||
localprofile_dia.tag = "LP_DIA"
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_ic, "IC", resourceHelper.gs(R.string.ic_label) + ":", localProfilePlugin.currentProfile().ic, null, 0.5, 50.0, 0.1, DecimalFormat("0.0"), save)
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_isf, "ISF", resourceHelper.gs(R.string.isf_label) + ":", localProfilePlugin.currentProfile().isf, null, 0.5, 500.0, 0.1, DecimalFormat("0.0"), save)
|
||||
basalView = TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_basal, "BASAL", resourceHelper.gs(R.string.basal_label) + ": " + sumLabel(), localProfilePlugin.currentProfile().basal, null, pumpDescription.basalMinimumRate, 10.0, 0.01, DecimalFormat("0.00"), save)
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_target, "TARGET", resourceHelper.gs(R.string.target_label) + ":", localProfilePlugin.currentProfile().targetLow, localProfilePlugin.currentProfile().targetHigh, 3.0, 200.0, 0.1, DecimalFormat("0.0"), save)
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_ic, "IC", resourceHelper.gs(R.string.ic_label) + ":", currentProfile.ic, null, 0.5, 50.0, 0.1, DecimalFormat("0.0"), save)
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_isf, "ISF", resourceHelper.gs(R.string.isf_label) + ":", currentProfile.isf, null, 0.5, 500.0, 0.1, DecimalFormat("0.0"), save)
|
||||
basalView = TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_basal, "BASAL", resourceHelper.gs(R.string.basal_label) + ": " + sumLabel(), currentProfile.basal, null, pumpDescription.basalMinimumRate, 10.0, 0.01, DecimalFormat("0.00"), save)
|
||||
TimeListEdit(context, aapsLogger, dateUtil, view, R.id.localprofile_target, "TARGET", resourceHelper.gs(R.string.target_label) + ":", currentProfile.targetLow, currentProfile.targetHigh, 3.0, 200.0, 0.1, DecimalFormat("0.0"), save)
|
||||
updateGUI()
|
||||
}
|
||||
|
||||
|
|
|
@ -5,16 +5,11 @@ import dagger.android.HasAndroidInjector
|
|||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.interfaces.ProfileStore
|
||||
import info.nightscout.androidaps.events.EventProfileStoreChanged
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||
|
@ -28,7 +23,6 @@ import java.util.*
|
|||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.math.max
|
||||
|
||||
@Singleton
|
||||
class LocalProfilePlugin @Inject constructor(
|
||||
|
@ -50,7 +44,7 @@ class LocalProfilePlugin @Inject constructor(
|
|||
aapsLogger, resourceHelper, injector
|
||||
), ProfileInterface {
|
||||
|
||||
var rawProfile: ProfileStore? = null
|
||||
private var rawProfile: ProfileStore? = null
|
||||
|
||||
private val defaultArray = "[{\"time\":\"00:00\",\"timeAsSeconds\":0,\"value\":0}]"
|
||||
|
||||
|
@ -82,22 +76,6 @@ class LocalProfilePlugin @Inject constructor(
|
|||
return sp
|
||||
}
|
||||
|
||||
fun copyFrom(rawProfile: ProfileStore?, profile: Profile, newName: String): SingleProfile {
|
||||
var verifiedName = newName
|
||||
if (rawProfile?.getSpecificProfile(newName) != null) {
|
||||
verifiedName += " " + DateUtil.now().toString()
|
||||
}
|
||||
val sp = SingleProfile()
|
||||
sp.name = verifiedName
|
||||
sp.mgdl = profile.units == Constants.MGDL
|
||||
sp.dia = profile.dia
|
||||
sp.ic = JSONArray(profile.data.getJSONArray("carbratio").toString())
|
||||
sp.isf = JSONArray(profile.data.getJSONArray("sens").toString())
|
||||
sp.basal = JSONArray(profile.data.getJSONArray("basal").toString())
|
||||
sp.targetLow = JSONArray(profile.data.getJSONArray("target_low").toString())
|
||||
sp.targetHigh = JSONArray(profile.data.getJSONArray("target_high").toString())
|
||||
return sp
|
||||
}
|
||||
}
|
||||
|
||||
var isEdited: Boolean = false
|
||||
|
@ -106,7 +84,7 @@ class LocalProfilePlugin @Inject constructor(
|
|||
var numOfProfiles = 0
|
||||
internal var currentProfileIndex = 0
|
||||
|
||||
fun currentProfile() = profiles[currentProfileIndex]
|
||||
fun currentProfile(): SingleProfile? = if (numOfProfiles > 0) profiles[currentProfileIndex] else null
|
||||
|
||||
@Synchronized
|
||||
fun isValidEditState(): Boolean {
|
||||
|
@ -118,15 +96,15 @@ class LocalProfilePlugin @Inject constructor(
|
|||
fun storeSettings(activity: Activity? = null) {
|
||||
for (i in 0 until numOfProfiles) {
|
||||
profiles[i].run {
|
||||
val LOCAL_PROFILE_NUMBERED = Constants.LOCAL_PROFILE + "_" + i + "_"
|
||||
sp.putString(LOCAL_PROFILE_NUMBERED + "name", name!!)
|
||||
sp.putBoolean(LOCAL_PROFILE_NUMBERED + "mgdl", mgdl)
|
||||
sp.putDouble(LOCAL_PROFILE_NUMBERED + "dia", dia)
|
||||
sp.putString(LOCAL_PROFILE_NUMBERED + "ic", ic.toString())
|
||||
sp.putString(LOCAL_PROFILE_NUMBERED + "isf", isf.toString())
|
||||
sp.putString(LOCAL_PROFILE_NUMBERED + "basal", basal.toString())
|
||||
sp.putString(LOCAL_PROFILE_NUMBERED + "targetlow", targetLow.toString())
|
||||
sp.putString(LOCAL_PROFILE_NUMBERED + "targethigh", targetHigh.toString())
|
||||
val localProfileNumbered = Constants.LOCAL_PROFILE + "_" + i + "_"
|
||||
sp.putString(localProfileNumbered + "name", name!!)
|
||||
sp.putBoolean(localProfileNumbered + "mgdl", mgdl)
|
||||
sp.putDouble(localProfileNumbered + "dia", dia)
|
||||
sp.putString(localProfileNumbered + "ic", ic.toString())
|
||||
sp.putString(localProfileNumbered + "isf", isf.toString())
|
||||
sp.putString(localProfileNumbered + "basal", basal.toString())
|
||||
sp.putString(localProfileNumbered + "targetlow", targetLow.toString())
|
||||
sp.putString(localProfileNumbered + "targethigh", targetHigh.toString())
|
||||
}
|
||||
}
|
||||
sp.putInt(Constants.LOCAL_PROFILE + "_profiles", numOfProfiles)
|
||||
|
@ -150,25 +128,20 @@ class LocalProfilePlugin @Inject constructor(
|
|||
|
||||
@Synchronized
|
||||
fun loadSettings() {
|
||||
if (sp.contains(Constants.LOCAL_PROFILE + "mgdl")) {
|
||||
doConversion()
|
||||
return
|
||||
}
|
||||
|
||||
numOfProfiles = sp.getInt(Constants.LOCAL_PROFILE + "_profiles", 0)
|
||||
profiles.clear()
|
||||
numOfProfiles = max(numOfProfiles, 1) // create at least one default profile if none exists
|
||||
// numOfProfiles = max(numOfProfiles, 1) // create at least one default profile if none exists
|
||||
|
||||
for (i in 0 until numOfProfiles) {
|
||||
val p = SingleProfile()
|
||||
val LOCAL_PROFILE_NUMBERED = Constants.LOCAL_PROFILE + "_" + i + "_"
|
||||
val localProfileNumbered = Constants.LOCAL_PROFILE + "_" + i + "_"
|
||||
|
||||
p.name = sp.getString(LOCAL_PROFILE_NUMBERED + "name", Constants.LOCAL_PROFILE + i)
|
||||
p.name = sp.getString(localProfileNumbered + "name", Constants.LOCAL_PROFILE + i)
|
||||
if (isExistingName(p.name)) continue
|
||||
p.mgdl = sp.getBoolean(LOCAL_PROFILE_NUMBERED + "mgdl", false)
|
||||
p.dia = sp.getDouble(LOCAL_PROFILE_NUMBERED + "dia", Constants.defaultDIA)
|
||||
p.mgdl = sp.getBoolean(localProfileNumbered + "mgdl", false)
|
||||
p.dia = sp.getDouble(localProfileNumbered + "dia", Constants.defaultDIA)
|
||||
try {
|
||||
p.ic = JSONArray(sp.getString(LOCAL_PROFILE_NUMBERED + "ic", defaultArray))
|
||||
p.ic = JSONArray(sp.getString(localProfileNumbered + "ic", defaultArray))
|
||||
} catch (e1: JSONException) {
|
||||
try {
|
||||
p.ic = JSONArray(defaultArray)
|
||||
|
@ -178,7 +151,7 @@ class LocalProfilePlugin @Inject constructor(
|
|||
}
|
||||
|
||||
try {
|
||||
p.isf = JSONArray(sp.getString(LOCAL_PROFILE_NUMBERED + "isf", defaultArray))
|
||||
p.isf = JSONArray(sp.getString(localProfileNumbered + "isf", defaultArray))
|
||||
} catch (e1: JSONException) {
|
||||
try {
|
||||
p.isf = JSONArray(defaultArray)
|
||||
|
@ -188,7 +161,7 @@ class LocalProfilePlugin @Inject constructor(
|
|||
}
|
||||
|
||||
try {
|
||||
p.basal = JSONArray(sp.getString(LOCAL_PROFILE_NUMBERED + "basal", defaultArray))
|
||||
p.basal = JSONArray(sp.getString(localProfileNumbered + "basal", defaultArray))
|
||||
} catch (e1: JSONException) {
|
||||
try {
|
||||
p.basal = JSONArray(defaultArray)
|
||||
|
@ -198,7 +171,7 @@ class LocalProfilePlugin @Inject constructor(
|
|||
}
|
||||
|
||||
try {
|
||||
p.targetLow = JSONArray(sp.getString(LOCAL_PROFILE_NUMBERED + "targetlow", defaultArray))
|
||||
p.targetLow = JSONArray(sp.getString(localProfileNumbered + "targetlow", defaultArray))
|
||||
} catch (e1: JSONException) {
|
||||
try {
|
||||
p.targetLow = JSONArray(defaultArray)
|
||||
|
@ -208,7 +181,7 @@ class LocalProfilePlugin @Inject constructor(
|
|||
}
|
||||
|
||||
try {
|
||||
p.targetHigh = JSONArray(sp.getString(LOCAL_PROFILE_NUMBERED + "targethigh", defaultArray))
|
||||
p.targetHigh = JSONArray(sp.getString(localProfileNumbered + "targethigh", defaultArray))
|
||||
} catch (e1: JSONException) {
|
||||
try {
|
||||
p.targetHigh = JSONArray(defaultArray)
|
||||
|
@ -224,6 +197,23 @@ class LocalProfilePlugin @Inject constructor(
|
|||
createAndStoreConvertedProfile()
|
||||
}
|
||||
|
||||
fun copyFrom(profile: Profile, newName: String): SingleProfile {
|
||||
var verifiedName = newName
|
||||
if (rawProfile?.getSpecificProfile(newName) != null) {
|
||||
verifiedName += " " + DateUtil.now().toString()
|
||||
}
|
||||
val sp = SingleProfile()
|
||||
sp.name = verifiedName
|
||||
sp.mgdl = profile.units == Constants.MGDL
|
||||
sp.dia = profile.dia
|
||||
sp.ic = JSONArray(profile.data.getJSONArray("carbratio").toString())
|
||||
sp.isf = JSONArray(profile.data.getJSONArray("sens").toString())
|
||||
sp.basal = JSONArray(profile.data.getJSONArray("basal").toString())
|
||||
sp.targetLow = JSONArray(profile.data.getJSONArray("target_low").toString())
|
||||
sp.targetHigh = JSONArray(profile.data.getJSONArray("target_high").toString())
|
||||
return sp
|
||||
}
|
||||
|
||||
private fun isExistingName(name: String?): Boolean {
|
||||
for (p in profiles) {
|
||||
if (p.name == name) return true
|
||||
|
@ -231,78 +221,6 @@ class LocalProfilePlugin @Inject constructor(
|
|||
return false
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun doConversion() { // conversion from 2.3 to 2.4 format
|
||||
aapsLogger.debug(LTag.PROFILE, "Loading stored settings")
|
||||
val p = SingleProfile()
|
||||
|
||||
p.mgdl = sp.getBoolean(Constants.LOCAL_PROFILE + "mgdl", profileFunction.getUnits() == Constants.MGDL)
|
||||
p.dia = sp.getDouble(Constants.LOCAL_PROFILE + "dia", Constants.defaultDIA)
|
||||
try {
|
||||
p.ic = JSONArray(sp.getString(Constants.LOCAL_PROFILE + "ic", defaultArray))
|
||||
} catch (e1: JSONException) {
|
||||
try {
|
||||
p.ic = JSONArray(defaultArray)
|
||||
} catch (ignored: JSONException) {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
p.isf = JSONArray(sp.getString(Constants.LOCAL_PROFILE + "isf", defaultArray))
|
||||
} catch (e1: JSONException) {
|
||||
try {
|
||||
p.isf = JSONArray(defaultArray)
|
||||
} catch (ignored: JSONException) {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
p.basal = JSONArray(sp.getString(Constants.LOCAL_PROFILE + "basal", defaultArray))
|
||||
} catch (e1: JSONException) {
|
||||
try {
|
||||
p.basal = JSONArray(defaultArray)
|
||||
} catch (ignored: JSONException) {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
p.targetLow = JSONArray(sp.getString(Constants.LOCAL_PROFILE + "targetlow", defaultArray))
|
||||
} catch (e1: JSONException) {
|
||||
try {
|
||||
p.targetLow = JSONArray(defaultArray)
|
||||
} catch (ignored: JSONException) {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
p.targetHigh = JSONArray(sp.getString(Constants.LOCAL_PROFILE + "targethigh", defaultArray))
|
||||
} catch (e1: JSONException) {
|
||||
try {
|
||||
p.targetHigh = JSONArray(defaultArray)
|
||||
} catch (ignored: JSONException) {
|
||||
}
|
||||
}
|
||||
p.name = Constants.LOCAL_PROFILE
|
||||
|
||||
sp.remove(Constants.LOCAL_PROFILE + "mgdl")
|
||||
sp.remove(Constants.LOCAL_PROFILE + "mmol")
|
||||
sp.remove(Constants.LOCAL_PROFILE + "dia")
|
||||
sp.remove(Constants.LOCAL_PROFILE + "ic")
|
||||
sp.remove(Constants.LOCAL_PROFILE + "isf")
|
||||
sp.remove(Constants.LOCAL_PROFILE + "basal")
|
||||
sp.remove(Constants.LOCAL_PROFILE + "targetlow")
|
||||
sp.remove(Constants.LOCAL_PROFILE + "targethigh")
|
||||
|
||||
currentProfileIndex = 0
|
||||
numOfProfiles = 1
|
||||
profiles.clear()
|
||||
profiles.add(p)
|
||||
storeSettings()
|
||||
|
||||
isEdited = false
|
||||
createAndStoreConvertedProfile()
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"_id": "576264a12771b7500d7ad184",
|
||||
|
@ -418,7 +336,7 @@ class LocalProfilePlugin @Inject constructor(
|
|||
store.put(name, profile)
|
||||
}
|
||||
}
|
||||
json.put("defaultProfile", currentProfile().name)
|
||||
if (numOfProfiles > 0) json.put("defaultProfile", currentProfile()?.name)
|
||||
json.put("startDate", DateUtil.toISOAsUTC(DateUtil.now()))
|
||||
json.put("store", store)
|
||||
} catch (e: JSONException) {
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.cardview.widget.CardView
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
|
@ -25,11 +24,11 @@ import info.nightscout.androidaps.plugins.profile.local.events.EventLocalProfile
|
|||
import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsProfileSwitchFragment.RecyclerProfileViewAdapter.ProfileSwitchViewHolder
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.extensions.toVisibility
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import info.nightscout.androidaps.utils.extensions.toVisibility
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import kotlinx.android.synthetic.main.treatments_profileswitch_fragment.*
|
||||
|
@ -118,7 +117,6 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
inner class ProfileSwitchViewHolder internal constructor(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener {
|
||||
var cv: CardView = itemView.findViewById<View>(R.id.profileswitch_cardview) as CardView
|
||||
var date: TextView = itemView.findViewById<View>(R.id.profileswitch_date) as TextView
|
||||
var duration: TextView = itemView.findViewById<View>(R.id.profileswitch_duration) as TextView
|
||||
var name: TextView = itemView.findViewById<View>(R.id.profileswitch_name) as TextView
|
||||
|
@ -147,7 +145,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), resourceHelper.gs(R.string.copytolocalprofile) + "\n" + profileSwitch.customizedName + "\n" + dateUtil.dateAndTimeString(profileSwitch.date), Runnable {
|
||||
profileSwitch.profileObject?.let {
|
||||
val nonCustomized = it.convertToNonCustomizedProfile()
|
||||
localProfilePlugin.addProfile(LocalProfilePlugin.SingleProfile().copyFrom(localProfilePlugin.rawProfile, nonCustomized, profileSwitch.customizedName + " " + dateUtil.dateAndTimeString(profileSwitch.date).replace(".", "_")))
|
||||
localProfilePlugin.addProfile(localProfilePlugin.copyFrom(nonCustomized, profileSwitch.customizedName + " " + dateUtil.dateAndTimeString(profileSwitch.date).replace(".", "_")))
|
||||
rxBus.send(EventLocalProfileChanged())
|
||||
}
|
||||
})
|
||||
|
|
|
@ -31,8 +31,8 @@ class ProfileStore(val injector: HasAndroidInjector, val data: JSONObject) {
|
|||
fun getDefaultProfile(): Profile? = getDefaultProfileName()?.let { getSpecificProfile(it) }
|
||||
|
||||
fun getDefaultProfileName(): String? {
|
||||
val defaultProfileName = data.getString("defaultProfile")
|
||||
return getStore()?.has(defaultProfileName)?.let { defaultProfileName }
|
||||
val defaultProfileName = data.optString("defaultProfile")
|
||||
return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null
|
||||
}
|
||||
|
||||
fun getProfileList(): ArrayList<CharSequence> {
|
||||
|
|
Loading…
Reference in a new issue