do not create default profile at app start
This commit is contained in:
parent
8631ab12de
commit
2e0c7e48ba
7 changed files with 11 additions and 29 deletions
|
@ -168,7 +168,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
val ps = profileFunction.buildProfileSwitch(profileStore, profileName, duration, percent, timeShift, eventTime)
|
val ps = profileFunction.buildProfileSwitch(profileStore, profileName, duration, percent, timeShift, eventTime)
|
||||||
val validity = ProfileSealed.PS(ps).isValid(resourceHelper.gs(R.string.careportal_profileswitch), activePlugin.activePump, config, resourceHelper, rxBus, hardLimits)
|
val validity = ProfileSealed.PS(ps).isValid(resourceHelper.gs(R.string.careportal_profileswitch), activePlugin.activePump, config, resourceHelper, rxBus, hardLimits, false)
|
||||||
if (validity.isValid)
|
if (validity.isValid)
|
||||||
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
|
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
|
||||||
profileFunction.createProfileSwitch(profileStore,
|
profileFunction.createProfileSwitch(profileStore,
|
||||||
|
|
|
@ -163,7 +163,8 @@ class ProfileFunctionImplementation @Inject constructor(
|
||||||
config,
|
config,
|
||||||
resourceHelper,
|
resourceHelper,
|
||||||
rxBus,
|
rxBus,
|
||||||
hardLimits
|
hardLimits,
|
||||||
|
false
|
||||||
)
|
)
|
||||||
var returnValue = true
|
var returnValue = true
|
||||||
if (validity.isValid) {
|
if (validity.isValid) {
|
||||||
|
|
|
@ -203,8 +203,6 @@ class LocalProfilePlugin @Inject constructor(
|
||||||
aapsLogger.error("Exception", e)
|
aapsLogger.error("Exception", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create at least one profile if doesn't exist
|
|
||||||
if (profiles.size < 1) profiles.add(defaultProfile())
|
|
||||||
isEdited = false
|
isEdited = false
|
||||||
numOfProfiles = profiles.size
|
numOfProfiles = profiles.size
|
||||||
createAndStoreConvertedProfile()
|
createAndStoreConvertedProfile()
|
||||||
|
@ -236,22 +234,6 @@ class LocalProfilePlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun defaultProfile(): SingleProfile =
|
|
||||||
SingleProfile().also { p ->
|
|
||||||
p.name = Constants.LOCAL_PROFILE
|
|
||||||
p.mgdl = profileFunction.getUnits() == GlucoseUnit.MGDL
|
|
||||||
p.dia = Constants.defaultDIA
|
|
||||||
try {
|
|
||||||
p.ic = JSONArray(defaultArray)
|
|
||||||
p.isf = JSONArray(defaultArray)
|
|
||||||
p.basal = JSONArray(defaultArray)
|
|
||||||
p.targetLow = JSONArray(defaultArray)
|
|
||||||
p.targetHigh = JSONArray(defaultArray)
|
|
||||||
} catch (e: JSONException) {
|
|
||||||
aapsLogger.error("Exception", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun copyFrom(pureProfile: PureProfile, newName: String): SingleProfile {
|
fun copyFrom(pureProfile: PureProfile, newName: String): SingleProfile {
|
||||||
var verifiedName = newName
|
var verifiedName = newName
|
||||||
if (rawProfile?.getSpecificProfile(newName) != null) {
|
if (rawProfile?.getSpecificProfile(newName) != null) {
|
||||||
|
|
|
@ -257,7 +257,7 @@ class SWDefinition @Inject constructor(
|
||||||
.add(SWFragment(injector, this)
|
.add(SWFragment(injector, this)
|
||||||
.add(LocalProfileFragment()))
|
.add(LocalProfileFragment()))
|
||||||
.validator {
|
.validator {
|
||||||
localProfilePlugin.profile?.getDefaultProfile()?.let { ProfileSealed.Pure(it).isValid("StartupWizard", activePlugin.activePump, config, resourceHelper, rxBus, hardLimits).isValid }
|
localProfilePlugin.profile?.getDefaultProfile()?.let { ProfileSealed.Pure(it).isValid("StartupWizard", activePlugin.activePump, config, resourceHelper, rxBus, hardLimits, false).isValid }
|
||||||
?: false
|
?: false
|
||||||
}
|
}
|
||||||
.visibility { localProfilePlugin.isEnabled() }
|
.visibility { localProfilePlugin.isEnabled() }
|
||||||
|
|
|
@ -95,8 +95,7 @@ sealed class ProfileSealed(
|
||||||
value.timeZone.rawOffset.toLong()
|
value.timeZone.rawOffset.toLong()
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun isValid(from: String, pump: Pump, config: Config, resourceHelper: ResourceHelper, rxBus: RxBus, hardLimits: HardLimits): Profile.ValidityCheck {
|
override fun isValid(from: String, pump: Pump, config: Config, resourceHelper: ResourceHelper, rxBus: RxBus, hardLimits: HardLimits, sendNotifications: Boolean): Profile.ValidityCheck {
|
||||||
val notify = true
|
|
||||||
val validityCheck = Profile.ValidityCheck()
|
val validityCheck = Profile.ValidityCheck()
|
||||||
val description = pump.pumpDescription
|
val description = pump.pumpDescription
|
||||||
for (basal in basalBlocks) {
|
for (basal in basalBlocks) {
|
||||||
|
@ -105,7 +104,7 @@ sealed class ProfileSealed(
|
||||||
// Check for hours alignment
|
// Check for hours alignment
|
||||||
val duration: Long = basal.duration
|
val duration: Long = basal.duration
|
||||||
if (duration % 3600000 != 0L) {
|
if (duration % 3600000 != 0L) {
|
||||||
if (notify && config.APS) {
|
if (sendNotifications && config.APS) {
|
||||||
val notification = Notification(
|
val notification = Notification(
|
||||||
Notification.BASAL_PROFILE_NOT_ALIGNED_TO_HOURS,
|
Notification.BASAL_PROFILE_NOT_ALIGNED_TO_HOURS,
|
||||||
resourceHelper.gs(R.string.basalprofilenotaligned, from),
|
resourceHelper.gs(R.string.basalprofilenotaligned, from),
|
||||||
|
@ -126,13 +125,13 @@ sealed class ProfileSealed(
|
||||||
// Check for minimal basal value
|
// Check for minimal basal value
|
||||||
if (basalAmount < description.basalMinimumRate) {
|
if (basalAmount < description.basalMinimumRate) {
|
||||||
basal.amount = description.basalMinimumRate
|
basal.amount = description.basalMinimumRate
|
||||||
if (notify) sendBelowMinimumNotification(from, rxBus, resourceHelper)
|
if (sendNotifications) sendBelowMinimumNotification(from, rxBus, resourceHelper)
|
||||||
validityCheck.isValid = false
|
validityCheck.isValid = false
|
||||||
validityCheck.reasons.add(resourceHelper.gs(R.string.minimalbasalvaluereplaced, from))
|
validityCheck.reasons.add(resourceHelper.gs(R.string.minimalbasalvaluereplaced, from))
|
||||||
break
|
break
|
||||||
} else if (basalAmount > description.basalMaximumRate) {
|
} else if (basalAmount > description.basalMaximumRate) {
|
||||||
basal.amount = description.basalMaximumRate
|
basal.amount = description.basalMaximumRate
|
||||||
if (notify) sendAboveMaximumNotification(from, rxBus, resourceHelper)
|
if (sendNotifications) sendAboveMaximumNotification(from, rxBus, resourceHelper)
|
||||||
validityCheck.isValid = false
|
validityCheck.isValid = false
|
||||||
validityCheck.reasons.add(resourceHelper.gs(R.string.maximumbasalvaluereplaced, from))
|
validityCheck.reasons.add(resourceHelper.gs(R.string.maximumbasalvaluereplaced, from))
|
||||||
break
|
break
|
||||||
|
|
|
@ -152,7 +152,7 @@ class ProfileViewerDialog : DaggerDialogFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.noprofile.visibility = View.GONE
|
binding.noprofile.visibility = View.GONE
|
||||||
val validity = profile1.isValid("ProfileViewDialog", activePlugin.activePump, config, resourceHelper, rxBus, hardLimits)
|
val validity = profile1.isValid("ProfileViewDialog", activePlugin.activePump, config, resourceHelper, rxBus, hardLimits, false)
|
||||||
binding.invalidprofile.text = resourceHelper.gs(R.string.invalidprofile) + "\n" + validity.reasons.joinToString(separator = "\n")
|
binding.invalidprofile.text = resourceHelper.gs(R.string.invalidprofile) + "\n" + validity.reasons.joinToString(separator = "\n")
|
||||||
binding.invalidprofile.visibility = validity.isValid.not().toVisibility()
|
binding.invalidprofile.visibility = validity.isValid.not().toVisibility()
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ class ProfileViewerDialog : DaggerDialogFragment() {
|
||||||
binding.basalGraph.show(it)
|
binding.basalGraph.show(it)
|
||||||
|
|
||||||
binding.noprofile.visibility = View.GONE
|
binding.noprofile.visibility = View.GONE
|
||||||
val validity = it.isValid("ProfileViewDialog", activePlugin.activePump, config, resourceHelper, rxBus, hardLimits)
|
val validity = it.isValid("ProfileViewDialog", activePlugin.activePump, config, resourceHelper, rxBus, hardLimits, false)
|
||||||
binding.invalidprofile.text = resourceHelper.gs(R.string.invalidprofile) + "\n" + validity.reasons.joinToString(separator = "\n")
|
binding.invalidprofile.text = resourceHelper.gs(R.string.invalidprofile) + "\n" + validity.reasons.joinToString(separator = "\n")
|
||||||
binding.invalidprofile.visibility = validity.isValid.not().toVisibility()
|
binding.invalidprofile.visibility = validity.isValid.not().toVisibility()
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ interface Profile {
|
||||||
|
|
||||||
class ValidityCheck(var isValid: Boolean = true, val reasons: ArrayList<String> = arrayListOf())
|
class ValidityCheck(var isValid: Boolean = true, val reasons: ArrayList<String> = arrayListOf())
|
||||||
|
|
||||||
fun isValid(from: String, pump: Pump, config: Config, resourceHelper: ResourceHelper, rxBus: RxBus, hardLimits: HardLimits): ValidityCheck
|
fun isValid(from: String, pump: Pump, config: Config, resourceHelper: ResourceHelper, rxBus: RxBus, hardLimits: HardLimits, sendNotifications: Boolean): ValidityCheck
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Units used for ISF & target
|
* Units used for ISF & target
|
||||||
|
|
Loading…
Reference in a new issue