diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt index 77a2418cca..f4c5c9d362 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt @@ -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("
").join(actions)), { profileFunction.createProfileSwitch(profileStore, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImplementation.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImplementation.kt index 55509c7fc3..cd1e73b647 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImplementation.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImplementation.kt @@ -163,7 +163,8 @@ class ProfileFunctionImplementation @Inject constructor( config, resourceHelper, rxBus, - hardLimits + hardLimits, + false ) var returnValue = true if (validity.isValid) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt index 5830375b5f..32253598c4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt @@ -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) { diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt index 83c1055352..7212f13967 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -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() } diff --git a/core/src/main/java/info/nightscout/androidaps/data/ProfileSealed.kt b/core/src/main/java/info/nightscout/androidaps/data/ProfileSealed.kt index c78fbc7174..93286b5a3d 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/ProfileSealed.kt +++ b/core/src/main/java/info/nightscout/androidaps/data/ProfileSealed.kt @@ -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 diff --git a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt index 4066b7df4e..c0263cec07 100644 --- a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt +++ b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt @@ -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() } diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/Profile.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/Profile.kt index affbafef04..9947426be4 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/Profile.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/Profile.kt @@ -16,7 +16,7 @@ interface Profile { class ValidityCheck(var isValid: Boolean = true, val reasons: ArrayList = 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