transfer overview configuration to NSClient
This commit is contained in:
parent
5f1492976b
commit
30624053e3
|
@ -173,8 +173,8 @@ class MainActivity : NoSplashAppCompatActivity() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
protectionCheck.queryProtection(this, ProtectionCheck.Protection.APPLICATION, null,
|
||||
UIRunnable(Runnable { OKDialog.show(this, "", resourceHelper.gs(R.string.authorizationfailed), Runnable { finish() }) }),
|
||||
UIRunnable(Runnable { OKDialog.show(this, "", resourceHelper.gs(R.string.authorizationfailed), Runnable { finish() }) })
|
||||
UIRunnable { OKDialog.show(this, "", resourceHelper.gs(R.string.authorizationfailed)) { finish() } },
|
||||
UIRunnable { OKDialog.show(this, "", resourceHelper.gs(R.string.authorizationfailed)) { finish() } }
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -193,14 +193,14 @@ class MainActivity : NoSplashAppCompatActivity() {
|
|||
val pageAdapter = TabPageAdapter(this)
|
||||
main_navigation_view.setNavigationItemSelectedListener { true }
|
||||
val menu = main_navigation_view.menu.also { it.clear() }
|
||||
for (p in activePlugin.pluginsList) {
|
||||
for (p in activePlugin.getPluginsList()) {
|
||||
pageAdapter.registerNewFragment(p)
|
||||
if (p.isEnabled() && p.hasFragment() && !p.isFragmentVisible() && !p.pluginDescription.neverVisible) {
|
||||
val menuItem = menu.add(p.name)
|
||||
menuItem.isCheckable = true
|
||||
menuItem.setOnMenuItemClickListener {
|
||||
val intent = Intent(this, SingleFragmentActivity::class.java)
|
||||
intent.putExtra("plugin", activePlugin.pluginsList.indexOf(p))
|
||||
intent.putExtra("plugin", activePlugin.getPluginsList().indexOf(p))
|
||||
startActivity(intent)
|
||||
main_drawer_layout.closeDrawers()
|
||||
true
|
||||
|
@ -274,7 +274,7 @@ class MainActivity : NoSplashAppCompatActivity() {
|
|||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.nav_preferences -> {
|
||||
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
|
||||
val i = Intent(this, PreferencesActivity::class.java)
|
||||
i.putExtra("id", -1)
|
||||
startActivity(i)
|
||||
|
@ -323,7 +323,7 @@ class MainActivity : NoSplashAppCompatActivity() {
|
|||
|
||||
R.id.nav_plugin_preferences -> {
|
||||
val plugin = (main_pager.adapter as TabPageAdapter).getPluginAt(main_pager.currentItem)
|
||||
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
||||
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
|
||||
val i = Intent(this, PreferencesActivity::class.java)
|
||||
i.putExtra("id", plugin.preferencesId)
|
||||
startActivity(i)
|
||||
|
|
|
@ -46,17 +46,17 @@ class ConfigBuilderPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
private fun setAlwaysEnabledPluginsEnabled() {
|
||||
for (plugin in activePlugin.pluginsList) {
|
||||
for (plugin in activePlugin.getPluginsList()) {
|
||||
if (plugin.pluginDescription.alwaysEnabled) plugin.setPluginEnabled(plugin.getType(), true)
|
||||
}
|
||||
storeSettings("setAlwaysEnabledPluginsEnabled")
|
||||
}
|
||||
|
||||
override fun storeSettings(from: String) {
|
||||
activePlugin.pluginsList
|
||||
activePlugin.getPluginsList()
|
||||
aapsLogger.debug(LTag.CONFIGBUILDER, "Storing settings from: $from")
|
||||
activePlugin.verifySelectionInCategories()
|
||||
for (p in activePlugin.pluginsList) {
|
||||
for (p in activePlugin.getPluginsList()) {
|
||||
val type = p.getType()
|
||||
if (p.pluginDescription.alwaysEnabled && p.pluginDescription.alwaysVisible) continue
|
||||
if (p.pluginDescription.alwaysEnabled && p.pluginDescription.neverVisible) continue
|
||||
|
@ -82,7 +82,7 @@ class ConfigBuilderPlugin @Inject constructor(
|
|||
|
||||
private fun loadSettings() {
|
||||
aapsLogger.debug(LTag.CONFIGBUILDER, "Loading stored settings")
|
||||
for (p in activePlugin.pluginsList) {
|
||||
for (p in activePlugin.getPluginsList()) {
|
||||
val type = p.getType()
|
||||
loadPref(p, type, true)
|
||||
if (p.getType() == PluginType.PUMP) {
|
||||
|
@ -110,7 +110,7 @@ class ConfigBuilderPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
fun logPluginStatus() {
|
||||
for (p in activePlugin.pluginsList) {
|
||||
for (p in activePlugin.getPluginsList()) {
|
||||
aapsLogger.debug(LTag.CONFIGBUILDER, p.name + ":" +
|
||||
(if (p.isEnabled(PluginType.GENERAL)) " GENERAL" else "") +
|
||||
(if (p.isEnabled(PluginType.TREATMENT)) " TREATMENT" else "") +
|
||||
|
|
|
@ -15,13 +15,13 @@ class PluginStore @Inject constructor(
|
|||
|
||||
lateinit var plugins: List<@JvmSuppressWildcards PluginBase>
|
||||
|
||||
private var activeBgSource: BgSourceInterface? = null
|
||||
private var activePump: PumpInterface? = null
|
||||
private var activeBgSourceStore: BgSourceInterface? = null
|
||||
private var activePumpStore: PumpInterface? = null
|
||||
private var activeProfile: ProfileInterface? = null
|
||||
private var activeAPS: APSInterface? = null
|
||||
private var activeInsulin: InsulinInterface? = null
|
||||
private var activeSensitivity: SensitivityInterface? = null
|
||||
private var activeTreatments: TreatmentsInterface? = null
|
||||
private var activeAPSStore: APSInterface? = null
|
||||
private var activeInsulinStore: InsulinInterface? = null
|
||||
private var activeSensitivityStore: SensitivityInterface? = null
|
||||
private var activeTreatmentsStore: TreatmentsInterface? = null
|
||||
|
||||
fun loadDefaults() {
|
||||
verifySelectionInCategories()
|
||||
|
@ -71,34 +71,34 @@ class PluginStore @Inject constructor(
|
|||
// PluginType.APS
|
||||
if (!config.NSCLIENT && !config.PUMPCONTROL) {
|
||||
pluginsInCategory = getSpecificPluginsList(PluginType.APS)
|
||||
activeAPS = getTheOneEnabledInArray(pluginsInCategory, PluginType.APS) as APSInterface?
|
||||
if (activeAPS == null) {
|
||||
activeAPS = getDefaultPlugin(PluginType.APS) as APSInterface
|
||||
(activeAPS as PluginBase).setPluginEnabled(PluginType.APS, true)
|
||||
activeAPSStore = getTheOneEnabledInArray(pluginsInCategory, PluginType.APS) as APSInterface?
|
||||
if (activeAPSStore == null) {
|
||||
activeAPSStore = getDefaultPlugin(PluginType.APS) as APSInterface
|
||||
(activeAPSStore as PluginBase).setPluginEnabled(PluginType.APS, true)
|
||||
aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting APSInterface")
|
||||
}
|
||||
setFragmentVisiblities((activeAPS as PluginBase).name, pluginsInCategory, PluginType.APS)
|
||||
setFragmentVisiblities((activeAPSStore as PluginBase).name, pluginsInCategory, PluginType.APS)
|
||||
}
|
||||
|
||||
// PluginType.INSULIN
|
||||
pluginsInCategory = getSpecificPluginsList(PluginType.INSULIN)
|
||||
activeInsulin = getTheOneEnabledInArray(pluginsInCategory, PluginType.INSULIN) as InsulinInterface?
|
||||
if (activeInsulin == null) {
|
||||
activeInsulin = getDefaultPlugin(PluginType.INSULIN) as InsulinInterface
|
||||
(activeInsulin as PluginBase).setPluginEnabled(PluginType.INSULIN, true)
|
||||
activeInsulinStore = getTheOneEnabledInArray(pluginsInCategory, PluginType.INSULIN) as InsulinInterface?
|
||||
if (activeInsulinStore == null) {
|
||||
activeInsulinStore = getDefaultPlugin(PluginType.INSULIN) as InsulinInterface
|
||||
(activeInsulinStore as PluginBase).setPluginEnabled(PluginType.INSULIN, true)
|
||||
aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting InsulinInterface")
|
||||
}
|
||||
setFragmentVisiblities((activeInsulin as PluginBase).name, pluginsInCategory, PluginType.INSULIN)
|
||||
setFragmentVisiblities((activeInsulinStore as PluginBase).name, pluginsInCategory, PluginType.INSULIN)
|
||||
|
||||
// PluginType.SENSITIVITY
|
||||
pluginsInCategory = getSpecificPluginsList(PluginType.SENSITIVITY)
|
||||
activeSensitivity = getTheOneEnabledInArray(pluginsInCategory, PluginType.SENSITIVITY) as SensitivityInterface?
|
||||
if (activeSensitivity == null) {
|
||||
activeSensitivity = getDefaultPlugin(PluginType.SENSITIVITY) as SensitivityInterface
|
||||
(activeSensitivity as PluginBase).setPluginEnabled(PluginType.SENSITIVITY, true)
|
||||
activeSensitivityStore = getTheOneEnabledInArray(pluginsInCategory, PluginType.SENSITIVITY) as SensitivityInterface?
|
||||
if (activeSensitivityStore == null) {
|
||||
activeSensitivityStore = getDefaultPlugin(PluginType.SENSITIVITY) as SensitivityInterface
|
||||
(activeSensitivityStore as PluginBase).setPluginEnabled(PluginType.SENSITIVITY, true)
|
||||
aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting SensitivityInterface")
|
||||
}
|
||||
setFragmentVisiblities((activeSensitivity as PluginBase).name, pluginsInCategory, PluginType.SENSITIVITY)
|
||||
setFragmentVisiblities((activeSensitivityStore as PluginBase).name, pluginsInCategory, PluginType.SENSITIVITY)
|
||||
|
||||
// PluginType.PROFILE
|
||||
pluginsInCategory = getSpecificPluginsList(PluginType.PROFILE)
|
||||
|
@ -112,33 +112,33 @@ class PluginStore @Inject constructor(
|
|||
|
||||
// PluginType.BGSOURCE
|
||||
pluginsInCategory = getSpecificPluginsList(PluginType.BGSOURCE)
|
||||
activeBgSource = getTheOneEnabledInArray(pluginsInCategory, PluginType.BGSOURCE) as BgSourceInterface?
|
||||
if (activeBgSource == null) {
|
||||
activeBgSource = getDefaultPlugin(PluginType.BGSOURCE) as BgSourceInterface
|
||||
(activeBgSource as PluginBase).setPluginEnabled(PluginType.BGSOURCE, true)
|
||||
activeBgSourceStore = getTheOneEnabledInArray(pluginsInCategory, PluginType.BGSOURCE) as BgSourceInterface?
|
||||
if (activeBgSourceStore == null) {
|
||||
activeBgSourceStore = getDefaultPlugin(PluginType.BGSOURCE) as BgSourceInterface
|
||||
(activeBgSourceStore as PluginBase).setPluginEnabled(PluginType.BGSOURCE, true)
|
||||
aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting BgInterface")
|
||||
}
|
||||
setFragmentVisiblities((activeBgSource as PluginBase).name, pluginsInCategory, PluginType.PUMP)
|
||||
setFragmentVisiblities((activeBgSourceStore as PluginBase).name, pluginsInCategory, PluginType.PUMP)
|
||||
|
||||
// PluginType.PUMP
|
||||
pluginsInCategory = getSpecificPluginsList(PluginType.PUMP)
|
||||
activePump = getTheOneEnabledInArray(pluginsInCategory, PluginType.PUMP) as PumpInterface?
|
||||
if (activePump == null) {
|
||||
activePump = getDefaultPlugin(PluginType.PUMP) as PumpInterface
|
||||
(activePump as PluginBase).setPluginEnabled(PluginType.PUMP, true)
|
||||
activePumpStore = getTheOneEnabledInArray(pluginsInCategory, PluginType.PUMP) as PumpInterface?
|
||||
if (activePumpStore == null) {
|
||||
activePumpStore = getDefaultPlugin(PluginType.PUMP) as PumpInterface
|
||||
(activePumpStore as PluginBase).setPluginEnabled(PluginType.PUMP, true)
|
||||
aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting PumpInterface")
|
||||
}
|
||||
setFragmentVisiblities((activePump as PluginBase).name, pluginsInCategory, PluginType.PUMP)
|
||||
setFragmentVisiblities((activePumpStore as PluginBase).name, pluginsInCategory, PluginType.PUMP)
|
||||
|
||||
// PluginType.TREATMENT
|
||||
pluginsInCategory = getSpecificPluginsList(PluginType.TREATMENT)
|
||||
activeTreatments = getTheOneEnabledInArray(pluginsInCategory, PluginType.TREATMENT) as TreatmentsInterface?
|
||||
if (activeTreatments == null) {
|
||||
activeTreatments = getDefaultPlugin(PluginType.TREATMENT) as TreatmentsInterface
|
||||
(activeTreatments as PluginBase).setPluginEnabled(PluginType.TREATMENT, true)
|
||||
activeTreatmentsStore = getTheOneEnabledInArray(pluginsInCategory, PluginType.TREATMENT) as TreatmentsInterface?
|
||||
if (activeTreatmentsStore == null) {
|
||||
activeTreatmentsStore = getDefaultPlugin(PluginType.TREATMENT) as TreatmentsInterface
|
||||
(activeTreatmentsStore as PluginBase).setPluginEnabled(PluginType.TREATMENT, true)
|
||||
aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting PumpInterface")
|
||||
}
|
||||
setFragmentVisiblities((activeTreatments as PluginBase).name, pluginsInCategory, PluginType.TREATMENT)
|
||||
setFragmentVisiblities((activeTreatmentsStore as PluginBase).name, pluginsInCategory, PluginType.TREATMENT)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,27 +203,31 @@ class PluginStore @Inject constructor(
|
|||
|
||||
// ***** Interface *****
|
||||
|
||||
override fun getActiveBgSource(): BgSourceInterface {
|
||||
return activeBgSource ?: checkNotNull(activeBgSource) { "No bg source selected" }
|
||||
}
|
||||
override val activeBgSource: BgSourceInterface
|
||||
get() = activeBgSourceStore ?: checkNotNull(activeBgSourceStore) { "No bg source selected" }
|
||||
|
||||
override fun getActiveProfileInterface(): ProfileInterface =
|
||||
activeProfile ?: checkNotNull(activeProfile) { "No profile selected" }
|
||||
override val activeProfileInterface: ProfileInterface
|
||||
get() = activeProfile ?: checkNotNull(activeProfile) { "No profile selected" }
|
||||
|
||||
override fun getActiveInsulin(): InsulinInterface =
|
||||
activeInsulin ?: checkNotNull(activeInsulin) { "No insulin selected" }
|
||||
override val activeInsulin: InsulinInterface
|
||||
get() = activeInsulinStore ?: checkNotNull(activeInsulinStore) { "No insulin selected" }
|
||||
|
||||
override fun getActiveAPS(): APSInterface =
|
||||
activeAPS ?: checkNotNull(activeAPS) { "No APS selected" }
|
||||
override val activeAPS: APSInterface
|
||||
get() = activeAPSStore ?: checkNotNull(activeAPSStore) { "No APS selected" }
|
||||
|
||||
override fun getActivePump(): PumpInterface =
|
||||
activePump ?: checkNotNull(activePump) { "No pump selected" }
|
||||
override val activePump: PumpInterface
|
||||
get() = activePumpStore ?: checkNotNull(activePumpStore) { "No pump selected" }
|
||||
|
||||
override fun getActiveSensitivity(): SensitivityInterface =
|
||||
activeSensitivity ?: checkNotNull(activeSensitivity) { "No sensitivity selected" }
|
||||
override val activeSensitivity: SensitivityInterface
|
||||
get() = activeSensitivityStore
|
||||
?: checkNotNull(activeSensitivityStore) { "No sensitivity selected" }
|
||||
|
||||
override fun getActiveTreatments(): TreatmentsInterface =
|
||||
activeTreatments ?: checkNotNull(activeTreatments) { "No treatments selected" }
|
||||
override val activeTreatments: TreatmentsInterface
|
||||
get() = activeTreatmentsStore
|
||||
?: checkNotNull(activeTreatmentsStore) { "No treatments selected" }
|
||||
|
||||
override val activeOverview: OverviewInterface
|
||||
get() = getSpecificPluginsListByInterface(OverviewInterface::class.java).first() as OverviewInterface
|
||||
|
||||
override fun getPluginsList(): ArrayList<PluginBase> = ArrayList(plugins)
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import dagger.android.HasAndroidInjector
|
|||
import info.nightscout.androidaps.Config
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.events.EventRefreshOverview
|
||||
import info.nightscout.androidaps.interfaces.OverviewInterface
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
|
@ -16,9 +17,12 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotifi
|
|||
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.extensions.plusAssign
|
||||
import info.nightscout.androidaps.utils.extensions.*
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import org.json.JSONObject
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
@ -28,6 +32,7 @@ class OverviewPlugin @Inject constructor(
|
|||
private val notificationStore: NotificationStore,
|
||||
private val fabricPrivacy: FabricPrivacy,
|
||||
private val rxBus: RxBusWrapper,
|
||||
private val sp: SP,
|
||||
aapsLogger: AAPSLogger,
|
||||
resourceHelper: ResourceHelper,
|
||||
private val config: Config
|
||||
|
@ -41,7 +46,7 @@ class OverviewPlugin @Inject constructor(
|
|||
.preferencesId(R.xml.pref_overview)
|
||||
.description(R.string.description_overview),
|
||||
aapsLogger, resourceHelper, injector
|
||||
) {
|
||||
), OverviewInterface {
|
||||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
|
@ -82,4 +87,57 @@ class OverviewPlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun configuration(): JSONObject =
|
||||
JSONObject()
|
||||
.putString(R.string.key_quickwizard, sp, resourceHelper)
|
||||
.putInt(R.string.key_eatingsoon_duration, sp, resourceHelper)
|
||||
.putDouble(R.string.key_eatingsoon_target, sp, resourceHelper)
|
||||
.putInt(R.string.key_activity_duration, sp, resourceHelper)
|
||||
.putDouble(R.string.key_activity_target, sp, resourceHelper)
|
||||
.putInt(R.string.key_hypo_duration, sp, resourceHelper)
|
||||
.putDouble(R.string.key_hypo_target, sp, resourceHelper)
|
||||
.putDouble(R.string.key_low_mark, sp, resourceHelper)
|
||||
.putDouble(R.string.key_high_mark, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_cage_warning, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_cage_critical, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_iage_warning, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_iage_critical, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_sage_warning, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_sage_critical, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_sbat_warning, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_sbat_critical, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_bage_warning, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_bage_critical, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_res_warning, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_res_critical, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_bat_warning, sp, resourceHelper)
|
||||
.putDouble(R.string.key_statuslights_bat_critical, sp, resourceHelper)
|
||||
|
||||
override fun applyConfiguration(configuration: JSONObject) {
|
||||
configuration
|
||||
.storeString(R.string.key_quickwizard, sp, resourceHelper)
|
||||
.storeInt(R.string.key_eatingsoon_duration, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_eatingsoon_target, sp, resourceHelper)
|
||||
.storeInt(R.string.key_activity_duration, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_activity_target, sp, resourceHelper)
|
||||
.storeInt(R.string.key_hypo_duration, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_hypo_target, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_low_mark, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_high_mark, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_cage_warning, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_cage_critical, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_iage_warning, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_iage_critical, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_sage_warning, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_sage_critical, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_sbat_warning, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_sbat_critical, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_bage_warning, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_bage_critical, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_res_warning, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_res_critical, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_bat_warning, sp, resourceHelper)
|
||||
.storeDouble(R.string.key_statuslights_bat_critical, sp, resourceHelper)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ class InsulinFragment : DaggerFragment() {
|
|||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
insulin_name?.setText(activePlugin.getActiveInsulin().friendlyName)
|
||||
insulin_comment?.setText(activePlugin.getActiveInsulin().comment)
|
||||
insulin_dia?.text = resourceHelper.gs(R.string.dia) + ": " + activePlugin.getActiveInsulin().dia + "h"
|
||||
insulin_graph?.show(activePlugin.getActiveInsulin())
|
||||
insulin_name?.setText(activePlugin.activeInsulin.friendlyName)
|
||||
insulin_comment?.setText(activePlugin.activeInsulin.comment)
|
||||
insulin_dia?.text = resourceHelper.gs(R.string.dia) + ": " + activePlugin.activeInsulin.dia + "h"
|
||||
insulin_graph?.show(activePlugin.activeInsulin)
|
||||
}
|
||||
}
|
|
@ -6,6 +6,8 @@ import info.nightscout.androidaps.interfaces.InsulinInterface
|
|||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.utils.extensions.storeInt
|
||||
import info.nightscout.androidaps.utils.extensions.putInt
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import org.json.JSONObject
|
||||
|
@ -28,10 +30,9 @@ class InsulinOrefFreePeakPlugin @Inject constructor(
|
|||
|
||||
override val friendlyName get(): String = resourceHelper.gs(R.string.free_peak_oref)
|
||||
|
||||
override fun configuration(): JSONObject = JSONObject().put(resourceHelper.gs(R.string.key_insulin_oref_peak), peak)
|
||||
override fun configuration(): JSONObject = JSONObject().putInt(R.string.key_insulin_oref_peak, sp, resourceHelper)
|
||||
override fun applyConfiguration(configuration: JSONObject) {
|
||||
if (configuration.has(resourceHelper.gs(R.string.key_insulin_oref_peak)))
|
||||
sp.putInt(R.string.key_insulin_oref_peak, configuration.getInt(resourceHelper.gs(R.string.key_insulin_oref_peak)))
|
||||
configuration.storeInt(R.string.key_insulin_oref_peak, sp, resourceHelper)
|
||||
}
|
||||
|
||||
override fun commentStandardText(): String {
|
||||
|
|
|
@ -68,7 +68,7 @@ class TddCalculator @Inject constructor(
|
|||
val absoluteRate = tbr?.tempBasalConvertedToAbsolute(t, profile) ?: profile.getBasal(t)
|
||||
tdd.basal += absoluteRate / 60.0 * 5.0
|
||||
|
||||
if (!activePlugin.getActivePump().isFakingTempsByExtendedBoluses()) {
|
||||
if (!activePlugin.activePump.isFakingTempsByExtendedBoluses()) {
|
||||
// they are not included in TBRs
|
||||
val eb = getExtendedBolusFromHistory(t)
|
||||
val absoluteEbRate = eb?.absoluteRate() ?: 0.0
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.androidaps.utils.wizard
|
||||
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
@ -16,7 +17,7 @@ class QuickWizard @Inject constructor(
|
|||
private var storage = JSONArray()
|
||||
|
||||
init {
|
||||
setData(JSONArray(sp.getString("QuickWizard", "[]")))
|
||||
setData(JSONArray(sp.getString(R.string.key_quickwizard, "[]")))
|
||||
}
|
||||
|
||||
fun getActive(): QuickWizardEntry? {
|
||||
|
@ -32,7 +33,7 @@ class QuickWizard @Inject constructor(
|
|||
}
|
||||
|
||||
fun save() {
|
||||
sp.putString("QuickWizard", storage.toString())
|
||||
sp.putString(R.string.key_quickwizard, storage.toString())
|
||||
}
|
||||
|
||||
fun size(): Int = storage.length()
|
||||
|
|
|
@ -40,7 +40,7 @@ class ProfileTest : TestBaseWithProfile() {
|
|||
|
||||
@Before
|
||||
fun prepare() {
|
||||
`when`(activePluginProvider.getActivePump()).thenReturn(virtualPumpPlugin)
|
||||
`when`(activePluginProvider.activePump).thenReturn(virtualPumpPlugin)
|
||||
`when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription)
|
||||
`when`(resourceHelper.gs(R.string.profile_per_unit)).thenReturn("/U")
|
||||
`when`(resourceHelper.gs(R.string.profile_carbs_per_unit)).thenReturn("g/U")
|
||||
|
|
|
@ -61,7 +61,7 @@ class LoopPluginTest : TestBase() {
|
|||
hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context, nsUpload)
|
||||
|
||||
loopPlugin = LoopPlugin(injector, aapsLogger, rxBus, sp, constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, treatmentsPlugin, virtualPumpPlugin, actionStringHandler, iobCobCalculatorPlugin, receiverStatusStore, fabricPrivacy, nsUpload, hardLimits)
|
||||
`when`(activePlugin.getActivePump()).thenReturn(virtualPumpPlugin)
|
||||
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
package info.nightscout.androidaps.interfaces;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface ActivePluginProvider {
|
||||
|
||||
@NotNull BgSourceInterface getActiveBgSource(); // Forced to Dexcom
|
||||
|
||||
@NotNull ProfileInterface getActiveProfileInterface(); // Forced to LocalProfile if not changed
|
||||
|
||||
@NotNull InsulinInterface getActiveInsulin(); // Forced to RapidActing if not changed
|
||||
|
||||
@NotNull APSInterface getActiveAPS(); // Forced to SMB
|
||||
|
||||
@NotNull PumpInterface getActivePump(); // Use in places not reachable without active pump. Otherwise IllegalStateException is thrown
|
||||
|
||||
@NotNull SensitivityInterface getActiveSensitivity(); // Forced to oref1 if not changed
|
||||
|
||||
@NotNull TreatmentsInterface getActiveTreatments(); // Forced to treatments
|
||||
|
||||
@NotNull ArrayList<PluginBase> getPluginsList();
|
||||
|
||||
@NotNull ArrayList<PluginBase> getSpecificPluginsVisibleInListByInterface(Class interfaceClass, PluginType type);
|
||||
|
||||
@NotNull ArrayList<PluginBase> getSpecificPluginsVisibleInList(PluginType type);
|
||||
|
||||
@NotNull ArrayList<PluginBase> getSpecificPluginsListByInterface(Class interfaceClass);
|
||||
|
||||
// @NotNull ArrayList<PluginBase> getSpecificPluginsVisibleInList(Class interfaceClass);
|
||||
|
||||
void verifySelectionInCategories();
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package info.nightscout.androidaps.interfaces
|
||||
|
||||
import java.util.*
|
||||
|
||||
interface ActivePluginProvider {
|
||||
|
||||
val activeBgSource: BgSourceInterface // Forced to Dexcom
|
||||
val activeProfileInterface: ProfileInterface // Forced to LocalProfile if not changed
|
||||
val activeInsulin: InsulinInterface // Forced to RapidActing if not changed
|
||||
val activeAPS: APSInterface // Forced to SMB
|
||||
val activePump: PumpInterface // Use in places not reachable without active pump. Otherwise IllegalStateException is thrown
|
||||
val activeSensitivity: SensitivityInterface // Forced to oref1 if not changed
|
||||
val activeTreatments: TreatmentsInterface // Forced to treatments
|
||||
val activeOverview: OverviewInterface // Forced to overview
|
||||
|
||||
fun getPluginsList(): ArrayList<PluginBase>
|
||||
|
||||
fun getSpecificPluginsVisibleInListByInterface(interfaceClass: Class<*>, type: PluginType): ArrayList<PluginBase>
|
||||
fun getSpecificPluginsVisibleInList(type: PluginType): ArrayList<PluginBase>
|
||||
fun getSpecificPluginsListByInterface(interfaceClass: Class<*>): ArrayList<PluginBase>
|
||||
fun verifySelectionInCategories()
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package info.nightscout.androidaps.interfaces
|
||||
|
||||
import org.json.JSONObject
|
||||
|
||||
interface ConfigExportImportInterface {
|
||||
|
||||
fun configuration(): JSONObject
|
||||
fun applyConfiguration(configuration: JSONObject)
|
||||
}
|
|
@ -4,7 +4,7 @@ import info.nightscout.androidaps.data.Iob
|
|||
import info.nightscout.androidaps.db.Treatment
|
||||
import org.json.JSONObject
|
||||
|
||||
interface InsulinInterface {
|
||||
interface InsulinInterface : ConfigExportImportInterface{
|
||||
|
||||
enum class InsulinType(val value: Int) {
|
||||
UNKNOWN(-1),
|
||||
|
@ -27,7 +27,4 @@ interface InsulinInterface {
|
|||
val dia: Double
|
||||
|
||||
fun iobCalcForTreatment(treatment: Treatment, time: Long, dia: Double): Iob
|
||||
|
||||
fun configuration(): JSONObject
|
||||
fun applyConfiguration(configuration: JSONObject)
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package info.nightscout.androidaps.interfaces
|
||||
|
||||
interface OverviewInterface : ConfigExportImportInterface
|
|
@ -3,7 +3,7 @@ package info.nightscout.androidaps.interfaces
|
|||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult
|
||||
import org.json.JSONObject
|
||||
|
||||
interface SensitivityInterface {
|
||||
interface SensitivityInterface : ConfigExportImportInterface {
|
||||
|
||||
enum class SensitivityType(val value: Int) {
|
||||
UNKNOWN(-1),
|
||||
|
@ -20,9 +20,6 @@ interface SensitivityInterface {
|
|||
val id: SensitivityType
|
||||
fun detectSensitivity(plugin: IobCobCalculatorInterface, fromTime: Long, toTime: Long): AutosensResult
|
||||
|
||||
fun configuration(): JSONObject
|
||||
fun applyConfiguration(configuration: JSONObject)
|
||||
|
||||
companion object {
|
||||
const val MIN_HOURS = 1.0
|
||||
const val MIN_HOURS_FULL_AUTOSENS = 4.0
|
||||
|
|
|
@ -24,18 +24,24 @@ class RunningConfiguration @Inject constructor(
|
|||
private val aapsLogger: AAPSLogger
|
||||
) {
|
||||
|
||||
private var counter = 0
|
||||
private val every = 20 // Send only every 20 devicestatus to save traffic
|
||||
|
||||
// called in AAPS mode only
|
||||
fun configuration(): JSONObject {
|
||||
val json = JSONObject()
|
||||
if (counter++ % every == 0)
|
||||
try {
|
||||
val insulinInterface = activePlugin.activeInsulin
|
||||
val sensitivityInterface = activePlugin.activeSensitivity
|
||||
val pumpInterface = activePlugin.activePump
|
||||
val overviewInterface = activePlugin.activeOverview
|
||||
|
||||
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("pump", pumpInterface.model().description)
|
||||
} catch (e: JSONException) {
|
||||
aapsLogger.error("Unhandled exception", e)
|
||||
|
@ -68,8 +74,12 @@ class RunningConfiguration @Inject constructor(
|
|||
sensitivityPlugin.applyConfiguration(configuration.getJSONObject("sensitivityConfiguration"))
|
||||
}
|
||||
}
|
||||
|
||||
val pumpType = JsonHelper.safeGetString(configuration, "pump", PumpType.GenericAAPS.description)
|
||||
sp.putString(R.string.key_virtualpump_type, pumpType)
|
||||
activePlugin.activePump.pumpDescription.setPumpDescription(PumpType.getByDescription(pumpType))
|
||||
|
||||
if (configuration.has("overviewConfiguration"))
|
||||
activePlugin.activeOverview.applyConfiguration(configuration.getJSONObject("overviewConfiguration"))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package info.nightscout.androidaps.utils.extensions
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import org.json.JSONObject
|
||||
|
||||
fun JSONObject.putInt(@StringRes key: Int, sp: SP, resourceHelper: ResourceHelper): JSONObject =
|
||||
if (sp.contains(key)) put(resourceHelper.gs(key), sp.getInt(key, 0)) else this
|
||||
|
||||
fun JSONObject.putLong(@StringRes key: Int, sp: SP, resourceHelper: ResourceHelper): JSONObject =
|
||||
if (sp.contains(key)) put(resourceHelper.gs(key), sp.getLong(key, 0)) else this
|
||||
|
||||
fun JSONObject.putDouble(@StringRes key: Int, sp: SP, resourceHelper: ResourceHelper): JSONObject =
|
||||
if (sp.contains(key)) put(resourceHelper.gs(key), sp.getDouble(key, 0.0)) else this
|
||||
|
||||
fun JSONObject.putString(@StringRes key: Int, sp: SP, resourceHelper: ResourceHelper): JSONObject =
|
||||
if (sp.contains(key)) put(resourceHelper.gs(key), sp.getString(key, "")) else this
|
||||
|
||||
fun JSONObject.putBoolean(@StringRes key: Int, sp: SP, resourceHelper: ResourceHelper): JSONObject =
|
||||
if (sp.contains(key)) put(resourceHelper.gs(key), sp.getBoolean(key, false)) else this
|
||||
|
||||
fun JSONObject.storeInt(@StringRes key: Int, sp: SP, resourceHelper: ResourceHelper): JSONObject {
|
||||
if (has(resourceHelper.gs(key))) sp.putInt(key, getInt(resourceHelper.gs(key)))
|
||||
return this
|
||||
}
|
||||
|
||||
fun JSONObject.storeLong(@StringRes key: Int, sp: SP, resourceHelper: ResourceHelper): JSONObject {
|
||||
if (has(resourceHelper.gs(key))) sp.putLong(key, getLong(resourceHelper.gs(key)))
|
||||
return this
|
||||
}
|
||||
|
||||
fun JSONObject.storeDouble(@StringRes key: Int, sp: SP, resourceHelper: ResourceHelper): JSONObject {
|
||||
if (has(resourceHelper.gs(key))) sp.putDouble(key, getDouble(resourceHelper.gs(key)))
|
||||
return this
|
||||
}
|
||||
|
||||
fun JSONObject.storeString(@StringRes key: Int, sp: SP, resourceHelper: ResourceHelper): JSONObject {
|
||||
if (has(resourceHelper.gs(key))) sp.putString(key, getString(resourceHelper.gs(key)))
|
||||
return this
|
||||
}
|
||||
|
||||
fun JSONObject.storeBoolean(@StringRes key: Int, sp: SP, resourceHelper: ResourceHelper): JSONObject {
|
||||
if (has(resourceHelper.gs(key))) sp.putBoolean(key, getBoolean(resourceHelper.gs(key)))
|
||||
return this
|
||||
}
|
||||
|
||||
|
|
@ -28,6 +28,7 @@
|
|||
<string name="key_gradually_increase_notification_volume" translatable="false">gradually_increase_notification_volume</string>
|
||||
<string name="key_ns_sync_use_absolute" translatable="false">ns_sync_use_absolute</string>
|
||||
<string name="key_virtualpump_type" translatable="false">virtualpump_type</string>
|
||||
<string name="key_quickwizard" translatable="false">QuickWizard</string>
|
||||
|
||||
<!-- General-->
|
||||
<string name="error">Error</string>
|
||||
|
|
Loading…
Reference in a new issue