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 ->
|
||||
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)
|
||||
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
|
||||
profileFunction.createProfileSwitch(profileStore,
|
||||
|
|
|
@ -163,7 +163,8 @@ class ProfileFunctionImplementation @Inject constructor(
|
|||
config,
|
||||
resourceHelper,
|
||||
rxBus,
|
||||
hardLimits
|
||||
hardLimits,
|
||||
false
|
||||
)
|
||||
var returnValue = true
|
||||
if (validity.isValid) {
|
||||
|
|
|
@ -203,8 +203,6 @@ class LocalProfilePlugin @Inject constructor(
|
|||
aapsLogger.error("Exception", e)
|
||||
}
|
||||
}
|
||||
// create at least one profile if doesn't exist
|
||||
if (profiles.size < 1) profiles.add(defaultProfile())
|
||||
isEdited = false
|
||||
numOfProfiles = profiles.size
|
||||
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 {
|
||||
var verifiedName = newName
|
||||
if (rawProfile?.getSpecificProfile(newName) != null) {
|
||||
|
|
|
@ -257,7 +257,7 @@ class SWDefinition @Inject constructor(
|
|||
.add(SWFragment(injector, this)
|
||||
.add(LocalProfileFragment()))
|
||||
.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
|
||||
}
|
||||
.visibility { localProfilePlugin.isEnabled() }
|
||||
|
|
|
@ -95,8 +95,7 @@ sealed class ProfileSealed(
|
|||
value.timeZone.rawOffset.toLong()
|
||||
)
|
||||
|
||||
override fun isValid(from: String, pump: Pump, config: Config, resourceHelper: ResourceHelper, rxBus: RxBus, hardLimits: HardLimits): Profile.ValidityCheck {
|
||||
val notify = true
|
||||
override fun isValid(from: String, pump: Pump, config: Config, resourceHelper: ResourceHelper, rxBus: RxBus, hardLimits: HardLimits, sendNotifications: Boolean): Profile.ValidityCheck {
|
||||
val validityCheck = Profile.ValidityCheck()
|
||||
val description = pump.pumpDescription
|
||||
for (basal in basalBlocks) {
|
||||
|
@ -105,7 +104,7 @@ sealed class ProfileSealed(
|
|||
// Check for hours alignment
|
||||
val duration: Long = basal.duration
|
||||
if (duration % 3600000 != 0L) {
|
||||
if (notify && config.APS) {
|
||||
if (sendNotifications && config.APS) {
|
||||
val notification = Notification(
|
||||
Notification.BASAL_PROFILE_NOT_ALIGNED_TO_HOURS,
|
||||
resourceHelper.gs(R.string.basalprofilenotaligned, from),
|
||||
|
@ -126,13 +125,13 @@ sealed class ProfileSealed(
|
|||
// Check for minimal basal value
|
||||
if (basalAmount < description.basalMinimumRate) {
|
||||
basal.amount = description.basalMinimumRate
|
||||
if (notify) sendBelowMinimumNotification(from, rxBus, resourceHelper)
|
||||
if (sendNotifications) sendBelowMinimumNotification(from, rxBus, resourceHelper)
|
||||
validityCheck.isValid = false
|
||||
validityCheck.reasons.add(resourceHelper.gs(R.string.minimalbasalvaluereplaced, from))
|
||||
break
|
||||
} else if (basalAmount > description.basalMaximumRate) {
|
||||
basal.amount = description.basalMaximumRate
|
||||
if (notify) sendAboveMaximumNotification(from, rxBus, resourceHelper)
|
||||
if (sendNotifications) sendAboveMaximumNotification(from, rxBus, resourceHelper)
|
||||
validityCheck.isValid = false
|
||||
validityCheck.reasons.add(resourceHelper.gs(R.string.maximumbasalvaluereplaced, from))
|
||||
break
|
||||
|
|
|
@ -152,7 +152,7 @@ class ProfileViewerDialog : DaggerDialogFragment() {
|
|||
}
|
||||
|
||||
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.visibility = validity.isValid.not().toVisibility()
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ class ProfileViewerDialog : DaggerDialogFragment() {
|
|||
binding.basalGraph.show(it)
|
||||
|
||||
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.visibility = validity.isValid.not().toVisibility()
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ interface Profile {
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue