diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginStore.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginStore.kt index 42281c32c3..548625c396 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginStore.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginStore.kt @@ -166,6 +166,9 @@ class PluginStore @Inject constructor( override val activeOverview: Overview get() = getSpecificPluginsListByInterface(Overview::class.java).first() as Overview + override val activeSafety: Safety + get() = getSpecificPluginsListByInterface(Safety::class.java).first() as Safety + override fun getPluginsList(): ArrayList = ArrayList(plugins) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt index 32fa6abf91..6c8523b482 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.constraints.safety import dagger.android.HasAndroidInjector import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.R +import info.nightscout.androidaps.extensions.* import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger @@ -20,6 +21,7 @@ import info.nightscout.androidaps.utils.Round import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP +import org.json.JSONObject import javax.inject.Inject import javax.inject.Singleton import kotlin.math.floor @@ -49,7 +51,7 @@ class SafetyPlugin @Inject constructor( .pluginName(R.string.safety) .preferencesId(R.xml.pref_safety), aapsLogger, resourceHelper, injector -), Constraints { +), Constraints, Safety { /** * Constraints interface @@ -193,4 +195,16 @@ class SafetyPlugin @Inject constructor( if (apsMode == "lgs") maxIob.setIfSmaller(aapsLogger, HardLimits.MAX_IOB_LGS, String.format(resourceHelper.gs(R.string.limitingiob), HardLimits.MAX_IOB_LGS, resourceHelper.gs(R.string.lowglucosesuspend)), this) return maxIob } + + override fun configuration(): JSONObject = + JSONObject() + .putString(R.string.key_age, sp, resourceHelper) + .putDouble(R.string.key_treatmentssafety_maxbolus, sp, resourceHelper) + .putDouble(R.string.key_treatmentssafety_maxcarbs, sp, resourceHelper) + + override fun applyConfiguration(configuration: JSONObject) { + configuration.storeString(R.string.key_age, sp, resourceHelper) + configuration.storeDouble(R.string.key_treatmentssafety_maxbolus, sp, resourceHelper) + configuration.storeDouble(R.string.key_treatmentssafety_maxcarbs, sp, resourceHelper) + } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt index 24433dfadc..3a56f7bcee 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt @@ -176,6 +176,7 @@ class OverviewPlugin @Inject constructor( override fun configuration(): JSONObject = JSONObject() + .putInt(R.string.key_units, sp, resourceHelper) .putString(R.string.key_quickwizard, sp, resourceHelper) .putInt(R.string.key_eatingsoon_duration, sp, resourceHelper) .putDouble(R.string.key_eatingsoon_target, sp, resourceHelper) @@ -202,6 +203,7 @@ class OverviewPlugin @Inject constructor( override fun applyConfiguration(configuration: JSONObject) { configuration + .storeInt(R.string.key_units, sp, resourceHelper) .storeString(R.string.key_quickwizard, sp, resourceHelper) .storeInt(R.string.key_eatingsoon_duration, sp, resourceHelper) .storeDouble(R.string.key_eatingsoon_target, sp, resourceHelper) diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/ActivePlugin.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/ActivePlugin.kt index 3f8545afb5..da514c7dd9 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/ActivePlugin.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/ActivePlugin.kt @@ -46,6 +46,12 @@ interface ActivePlugin { */ val activeOverview: Overview + /** + * Currently selected Safety plugin + * Always SafetyPlugin + */ + val activeSafety: Safety + /** * List of all registered plugins */ diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/Safety.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/Safety.kt new file mode 100644 index 0000000000..d3bc26ae30 --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/Safety.kt @@ -0,0 +1,3 @@ +package info.nightscout.androidaps.interfaces + +interface Safety : ConfigExportImport \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/RunningConfiguration.kt b/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/RunningConfiguration.kt index 7b5cb9c382..709ed1b71e 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/RunningConfiguration.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/RunningConfiguration.kt @@ -36,12 +36,14 @@ class RunningConfiguration @Inject constructor( val sensitivityInterface = activePlugin.activeSensitivity val pumpInterface = activePlugin.activePump val overviewInterface = activePlugin.activeOverview + val safetyInterface = activePlugin.activeSafety json.put("insulin", insulinInterface.id.value) json.put("insulinConfiguration", insulinInterface.configuration()) json.put("sensitivity", sensitivityInterface.id.value) json.put("sensitivityConfiguration", sensitivityInterface.configuration()) json.put("overviewConfiguration", overviewInterface.configuration()) + json.put("safetyConfiguration", safetyInterface.configuration()) json.put("pump", pumpInterface.model().description) } catch (e: JSONException) { aapsLogger.error("Unhandled exception", e) @@ -88,5 +90,8 @@ class RunningConfiguration @Inject constructor( if (configuration.has("overviewConfiguration")) activePlugin.activeOverview.applyConfiguration(configuration.getJSONObject("overviewConfiguration")) + + if (configuration.has("safetyConfiguration")) + activePlugin.activeSafety.applyConfiguration(configuration.getJSONObject("safetyConfiguration")) } } \ No newline at end of file