From 416735e9163c259e5014789764338ad7b586b67d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 31 Dec 2019 13:25:28 +0100 Subject: [PATCH] WizardDialogInfo, ProfileFunction --- .../dependencyInjection/FragmentsModule.kt | 14 +-- .../androidaps/dialogs/WizardDialog.kt | 26 +++--- .../androidaps/dialogs/WizardInfoDialog.kt | 88 +++++++++++++++++++ .../configBuilder/ConfigBuilderFragment.kt | 84 +++++++++++++++++- .../plugins/configBuilder/PluginViewHolder.kt | 69 --------------- .../plugins/general/wear/WearPlugin.kt | 28 +++--- .../plugins/insulin/InsulinOrefBasePlugin.kt | 10 +-- .../insulin/InsulinOrefFreePeakPlugin.kt | 6 +- .../insulin/InsulinOrefRapidActingPlugin.kt | 6 +- .../InsulinOrefUltraRapidActingPlugin.kt | 10 ++- .../profile/local/LocalProfilePlugin.kt | 8 +- .../plugins/profile/ns/NSProfileFragment.kt | 5 +- .../danaR/activities/DanaRHistoryActivity.kt | 5 +- .../pump/medtronic/MedtronicFragment.kt | 2 +- .../treatments/dialogs/WizardInfoDialog.kt | 76 ---------------- .../fragments/TreatmentsBolusFragment.kt | 2 +- .../androidaps/utils/StringUtils.java | 8 -- ...dinfo_dialog.xml => dialog_wizardinfo.xml} | 55 ++++++++---- 18 files changed, 276 insertions(+), 226 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/dialogs/WizardInfoDialog.kt delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt rename app/src/main/res/layout/{treatments_wizardinfo_dialog.xml => dialog_wizardinfo.xml} (92%) diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt index b3d5ae59c9..27ea80b881 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt @@ -30,6 +30,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpFragment import info.nightscout.androidaps.plugins.source.BGSourceFragment import info.nightscout.androidaps.plugins.treatments.TreatmentsFragment +import info.nightscout.androidaps.dialogs.WizardInfoDialog import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsBolusFragment import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsCareportalFragment import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsProfileSwitchFragment @@ -45,12 +46,6 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesBGSourceFragment(): BGSourceFragment @ContributesAndroidInjector abstract fun contributesConfigBuilderFragment(): ConfigBuilderFragment @ContributesAndroidInjector abstract fun contributesDanaRFragment(): DanaRFragment - @ContributesAndroidInjector abstract fun contributesEditActionDialog(): EditActionDialog - @ContributesAndroidInjector abstract fun contributesEditEventDialog(): EditEventDialog - @ContributesAndroidInjector abstract fun contributesEditTriggerDialog(): EditTriggerDialog - @ContributesAndroidInjector abstract fun contributesEditQuickWizardDialog(): EditQuickWizardDialog - @ContributesAndroidInjector abstract fun contributesChooseActionDialog(): ChooseActionDialog - @ContributesAndroidInjector abstract fun contributesChooseTriggerDialog(): ChooseTriggerDialog @ContributesAndroidInjector abstract fun contributesLocalProfileFragment(): LocalProfileFragment @ContributesAndroidInjector abstract fun contributesObjectivesFragment(): ObjectivesFragment @ContributesAndroidInjector abstract fun contributesOpenAPSAMAFragment(): OpenAPSAMAFragment @@ -72,9 +67,15 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesCalibrationDialog(): CalibrationDialog @ContributesAndroidInjector abstract fun contributesCarbsDialog(): CarbsDialog @ContributesAndroidInjector abstract fun contributesCareDialog(): CareDialog + @ContributesAndroidInjector abstract fun contributesEditActionDialog(): EditActionDialog + @ContributesAndroidInjector abstract fun contributesEditEventDialog(): EditEventDialog + @ContributesAndroidInjector abstract fun contributesEditTriggerDialog(): EditTriggerDialog + @ContributesAndroidInjector abstract fun contributesEditQuickWizardDialog(): EditQuickWizardDialog @ContributesAndroidInjector abstract fun contributesErrorDialog(): ErrorDialog @ContributesAndroidInjector abstract fun contributesExtendedBolusDialog(): ExtendedBolusDialog @ContributesAndroidInjector abstract fun contributesFillDialog(): FillDialog + @ContributesAndroidInjector abstract fun contributesChooseActionDialog(): ChooseActionDialog + @ContributesAndroidInjector abstract fun contributesChooseTriggerDialog(): ChooseTriggerDialog @ContributesAndroidInjector abstract fun contributesInsulinDialog(): InsulinDialog @ContributesAndroidInjector abstract fun contributesNtpProgressDialog(): NtpProgressDialog @ContributesAndroidInjector abstract fun contributesObjectivesExamDialog(): ObjectivesExamDialog @@ -84,4 +85,5 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesTempTargetDialog(): TempTargetDialog @ContributesAndroidInjector abstract fun contributesTreatmentDialog(): TreatmentDialog @ContributesAndroidInjector abstract fun contributesWizardDialog(): WizardDialog + @ContributesAndroidInjector abstract fun contributesWizardInfoDialog(): WizardInfoDialog } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt index 9c8326ad96..5a77843bba 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt @@ -29,9 +29,13 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin -import info.nightscout.androidaps.utils.* +import info.nightscout.androidaps.utils.DecimalFormatter +import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.SafeParse +import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP +import info.nightscout.androidaps.utils.toVisibility import info.nightscout.androidaps.utils.wizard.BolusWizard import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable @@ -250,8 +254,8 @@ class WizardDialog : DaggerDialogFragment() { treatmentsPlugin.updateTotalIOBTempBasals() val basalIob = treatmentsPlugin.lastCalculationTempBasals.round() - treatments_wizard_bolusiobinsulin.text = StringUtils.formatInsulin(-bolusIob.iob) - treatments_wizard_basaliobinsulin.text = StringUtils.formatInsulin(-basalIob.basaliob) + treatments_wizard_bolusiobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, -bolusIob.iob) + treatments_wizard_basaliobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, -basalIob.basaliob) calculateInsulin() @@ -308,19 +312,19 @@ class WizardDialog : DaggerDialogFragment() { wizard?.let { wizard -> treatments_wizard_bg.text = String.format(resourceHelper.gs(R.string.format_bg_isf), BgReading().value(Profile.toMgdl(bg, profileFunction.getUnits())).valueToUnitsToString(profileFunction.getUnits()), wizard.sens) - treatments_wizard_bginsulin.text = StringUtils.formatInsulin(wizard.insulinFromBG) + treatments_wizard_bginsulin.text = resourceHelper.gs(R.string.formatinsulinunits, wizard.insulinFromBG) treatments_wizard_carbs.text = String.format(resourceHelper.gs(R.string.format_carbs_ic), carbs.toDouble(), wizard.ic) - treatments_wizard_carbsinsulin.text = StringUtils.formatInsulin(wizard.insulinFromCarbs) + treatments_wizard_carbsinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, wizard.insulinFromCarbs) - treatments_wizard_bolusiobinsulin.text = StringUtils.formatInsulin(wizard.insulinFromBolusIOB) - treatments_wizard_basaliobinsulin.text = StringUtils.formatInsulin(wizard.insulinFromBasalsIOB) + treatments_wizard_bolusiobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, wizard.insulinFromBolusIOB) + treatments_wizard_basaliobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, wizard.insulinFromBasalsIOB) - treatments_wizard_correctioninsulin.text = StringUtils.formatInsulin(wizard.insulinFromCorrection) + treatments_wizard_correctioninsulin.text = resourceHelper.gs(R.string.formatinsulinunits, wizard.insulinFromCorrection) // Superbolus treatments_wizard_sb.text = if (treatments_wizard_sbcheckbox.isChecked) resourceHelper.gs(R.string.twohours) else "" - treatments_wizard_sbinsulin.text = StringUtils.formatInsulin(wizard.insulinFromSuperBolus) + treatments_wizard_sbinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, wizard.insulinFromSuperBolus) // Trend if (treatments_wizard_bgtrendcheckbox.isChecked && wizard.glucoseStatus != null) { @@ -330,12 +334,12 @@ class WizardDialog : DaggerDialogFragment() { } else { treatments_wizard_bgtrend.text = "" } - treatments_wizard_bgtrendinsulin.text = StringUtils.formatInsulin(wizard.insulinFromTrend) + treatments_wizard_bgtrendinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, wizard.insulinFromTrend) // COB if (treatments_wizard_cobcheckbox.isChecked) { treatments_wizard_cob.text = String.format(resourceHelper.gs(R.string.format_cob_ic), cob, wizard.ic) - treatments_wizard_cobinsulin.text = StringUtils.formatInsulin(wizard.insulinFromCOB) + treatments_wizard_cobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, wizard.insulinFromCOB) } else { treatments_wizard_cob.text = "" treatments_wizard_cobinsulin.text = "" diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardInfoDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardInfoDialog.kt new file mode 100644 index 0000000000..2c25836f8d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardInfoDialog.kt @@ -0,0 +1,88 @@ +package info.nightscout.androidaps.dialogs + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.Window +import android.view.WindowManager +import dagger.android.support.DaggerDialogFragment +import info.nightscout.androidaps.Constants +import info.nightscout.androidaps.R +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction +import info.nightscout.androidaps.utils.DecimalFormatter +import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.androidaps.utils.resources.ResourceHelper +import kotlinx.android.synthetic.main.dialog_wizardinfo.* +import org.json.JSONObject +import javax.inject.Inject + +class WizardInfoDialog : DaggerDialogFragment() { + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var profileFunction: ProfileFunction + + private var json: JSONObject? = null + + fun setData(json: JSONObject) { + this.json = json + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE) + dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) + isCancelable = true + dialog?.setCanceledOnTouchOutside(false) + return inflater.inflate(R.layout.dialog_wizardinfo, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + close.setOnClickListener { dismiss() } + val units = profileFunction.getUnits() + val bgString = + if (units == Constants.MGDL) DecimalFormatter.to0Decimal(JsonHelper.safeGetDouble(json, "bg")) + else DecimalFormatter.to1Decimal(JsonHelper.safeGetDouble(json, "bg")) + // BG + treatments_wizard_bg.text = resourceHelper.gs(R.string.format_bg_isf, bgString, JsonHelper.safeGetDouble(json, "isf")) + treatments_wizard_bginsulin.text = resourceHelper.gs(R.string.formatinsulinunits, JsonHelper.safeGetDouble(json, "insulinbg")) + treatments_wizard_bgcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "insulinbgused") + treatments_wizard_ttcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "ttused") + // Trend + treatments_wizard_bgtrend.text = JsonHelper.safeGetString(json, "trend") + treatments_wizard_bgtrendinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, JsonHelper.safeGetDouble(json, "insulintrend")) + treatments_wizard_bgtrendcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "trendused") + // COB + treatments_wizard_cob.text = resourceHelper.gs(R.string.format_cob_ic, JsonHelper.safeGetDouble(json, "cob"), JsonHelper.safeGetDouble(json, "ic")) + treatments_wizard_cobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, JsonHelper.safeGetDouble(json, "insulincob")) + treatments_wizard_cobcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "cobused") + // Bolus IOB + treatments_wizard_bolusiobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, JsonHelper.safeGetDouble(json, "bolusiob")) + treatments_wizard_bolusiobcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "bolusiobused") + // Basal IOB + treatments_wizard_basaliobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, JsonHelper.safeGetDouble(json, "basaliob")) + treatments_wizard_basaliobcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "basaliobused") + // Superbolus + treatments_wizard_sbinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, JsonHelper.safeGetDouble(json, "insulinsuperbolus")) + treatments_wizard_sbcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "superbolusused") + // Carbs + treatments_wizard_carbs.text = resourceHelper.gs(R.string.format_carbs_ic, JsonHelper.safeGetDouble(json, "carbs"), JsonHelper.safeGetDouble(json, "ic")) + treatments_wizard_carbsinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, JsonHelper.safeGetDouble(json, "insulincarbs")) + // Correction + treatments_wizard_correctioninsulin.text = resourceHelper.gs(R.string.formatinsulinunits, JsonHelper.safeGetDouble(json, "othercorrection")) + // Profile + treatments_wizard_profile.text = JsonHelper.safeGetString(json, "profile") + // Notes + treatments_wizard_notes.text = JsonHelper.safeGetString(json, "notes") + // Percentage + treatments_wizard_percent_used.text = DecimalFormatter.to0Decimal(JsonHelper.safeGetDouble(json, "percentageCorrection", 100.0)) + "%" + // Total + treatments_wizard_totalinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, JsonHelper.safeGetDouble(json, "insulin")) + } + + override fun onStart() { + super.onStart() + dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.kt index f0ed9ec9af..a7aefc263f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.kt @@ -1,21 +1,28 @@ package info.nightscout.androidaps.plugins.configBuilder +import android.content.Intent import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.CheckBox +import android.widget.ImageButton import android.widget.LinearLayout +import android.widget.RadioButton import android.widget.TextView import androidx.annotation.StringRes import dagger.android.support.DaggerFragment import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.activities.PreferencesActivity +import info.nightscout.androidaps.events.EventRebuildTabs import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.PasswordProtection import info.nightscout.androidaps.utils.extensions.plusAssign import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.toVisibility import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import kotlinx.android.synthetic.main.configbuilder_fragment.* @@ -25,7 +32,8 @@ import javax.inject.Inject class ConfigBuilderFragment : DaggerFragment() { @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var resourceHelper: ResourceHelper - + @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin + private var disposable: CompositeDisposable = CompositeDisposable() private val pluginViewHolders = ArrayList() @@ -86,7 +94,8 @@ class ConfigBuilderFragment : DaggerFragment() { } private fun createViewsForPlugins(@StringRes title: Int, @StringRes description: Int, pluginType: PluginType, plugins: List) { - if (plugins.size == 0) return + if (plugins.isEmpty()) return + @Suppress("InflateParams") val parent = layoutInflater.inflate(R.layout.configbuilder_single_category, null) as LinearLayout (parent.findViewById(R.id.category_title) as TextView).text = resourceHelper.gs(title) (parent.findViewById(R.id.category_description) as TextView).text = resourceHelper.gs(description) @@ -99,4 +108,75 @@ class ConfigBuilderFragment : DaggerFragment() { configbuilder_categories.addView(parent) } + inner class PluginViewHolder internal constructor(private val fragment: ConfigBuilderFragment, + private val pluginType: PluginType, + private val plugin: PluginBase) { + + @Suppress("InflateParams") + val baseView: LinearLayout = fragment.layoutInflater.inflate(R.layout.configbuilder_single_plugin, null) as LinearLayout + private val enabledExclusive: RadioButton + private val enabledInclusive: CheckBox + private val pluginName: TextView + private val pluginDescription: TextView + private val pluginPreferences: ImageButton + private val pluginVisibility: CheckBox + + init { + enabledExclusive = baseView.findViewById(R.id.plugin_enabled_exclusive) + enabledInclusive = baseView.findViewById(R.id.plugin_enabled_inclusive) + pluginName = baseView.findViewById(R.id.plugin_name) + pluginDescription = baseView.findViewById(R.id.plugin_description) + pluginPreferences = baseView.findViewById(R.id.plugin_preferences) + pluginVisibility = baseView.findViewById(R.id.plugin_visibility) + + pluginVisibility.setOnClickListener { + plugin.setFragmentVisible(pluginType, pluginVisibility.isChecked) + configBuilderPlugin.storeSettings("CheckedCheckboxVisible") + rxBus.send(EventRebuildTabs()) + configBuilderPlugin.logPluginStatus() + } + + enabledExclusive.setOnClickListener { + plugin.switchAllowed(if (enabledExclusive.visibility == View.VISIBLE) enabledExclusive.isChecked else enabledInclusive.isChecked, fragment.activity, pluginType) + } + enabledInclusive.setOnClickListener { + plugin.switchAllowed(if (enabledExclusive.visibility == View.VISIBLE) enabledExclusive.isChecked else enabledInclusive.isChecked, fragment.activity, pluginType) + } + + pluginPreferences.setOnClickListener { + PasswordProtection.QueryPassword(fragment.context, R.string.settings_password, "settings_password", { + val i = Intent(fragment.context, PreferencesActivity::class.java) + i.putExtra("id", plugin.preferencesId) + fragment.startActivity(i) + }, null) + } + update() + } + + fun update() { + enabledExclusive.visibility = areMultipleSelectionsAllowed(pluginType).not().toVisibility() + enabledInclusive.visibility = areMultipleSelectionsAllowed(pluginType).toVisibility() + enabledExclusive.isChecked = plugin.isEnabled(pluginType) + enabledInclusive.isChecked = plugin.isEnabled(pluginType) + enabledInclusive.isEnabled = !plugin.pluginDescription.alwaysEnabled + enabledExclusive.isEnabled = !plugin.pluginDescription.alwaysEnabled + pluginName.text = plugin.name + if (plugin.description == null) + pluginDescription.visibility = View.GONE + else { + pluginDescription.visibility = View.VISIBLE + pluginDescription.text = plugin.description + } + pluginPreferences.visibility = if (plugin.preferencesId == -1 || !plugin.isEnabled(pluginType)) View.INVISIBLE else View.VISIBLE + pluginVisibility.visibility = plugin.hasFragment().toVisibility() + pluginVisibility.isEnabled = !(plugin.pluginDescription.neverVisible || plugin.pluginDescription.alwaysVisible) && plugin.isEnabled(pluginType) + pluginVisibility.isChecked = plugin.isFragmentVisible() + } + + private fun areMultipleSelectionsAllowed(type: PluginType): Boolean { + return type == PluginType.GENERAL || type == PluginType.CONSTRAINTS || type == PluginType.LOOP + } + + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginViewHolder.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginViewHolder.kt index f14d0d87dd..f69c52b46e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginViewHolder.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginViewHolder.kt @@ -16,72 +16,3 @@ import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.PasswordProtection import info.nightscout.androidaps.utils.toVisibility -class PluginViewHolder internal constructor(private val fragment: ConfigBuilderFragment, - private val pluginType: PluginType, - private val plugin: PluginBase) { - - val baseView: LinearLayout = fragment.layoutInflater.inflate(R.layout.configbuilder_single_plugin, null) as LinearLayout - private val enabledExclusive: RadioButton - private val enabledInclusive: CheckBox - private val pluginName: TextView - private val pluginDescription: TextView - private val pluginPreferences: ImageButton - private val pluginVisibility: CheckBox - - init { - enabledExclusive = baseView.findViewById(R.id.plugin_enabled_exclusive) - enabledInclusive = baseView.findViewById(R.id.plugin_enabled_inclusive) - pluginName = baseView.findViewById(R.id.plugin_name) - pluginDescription = baseView.findViewById(R.id.plugin_description) - pluginPreferences = baseView.findViewById(R.id.plugin_preferences) - pluginVisibility = baseView.findViewById(R.id.plugin_visibility) - - pluginVisibility.setOnClickListener { - plugin.setFragmentVisible(pluginType, pluginVisibility.isChecked) - ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxVisible") - RxBus.INSTANCE.send(EventRebuildTabs()) - ConfigBuilderPlugin.getPlugin().logPluginStatus() - } - - enabledExclusive.setOnClickListener { - plugin.switchAllowed(if (enabledExclusive.visibility == View.VISIBLE) enabledExclusive.isChecked else enabledInclusive.isChecked, fragment.activity, pluginType) - } - enabledInclusive.setOnClickListener { - plugin.switchAllowed(if (enabledExclusive.visibility == View.VISIBLE) enabledExclusive.isChecked else enabledInclusive.isChecked, fragment.activity, pluginType) - } - - pluginPreferences.setOnClickListener { - PasswordProtection.QueryPassword(fragment.context, R.string.settings_password, "settings_password", { - val i = Intent(fragment.context, PreferencesActivity::class.java) - i.putExtra("id", plugin.preferencesId) - fragment.startActivity(i) - }, null) - } - update() - } - - fun update() { - enabledExclusive.visibility = areMultipleSelectionsAllowed(pluginType).not().toVisibility() - enabledInclusive.visibility = areMultipleSelectionsAllowed(pluginType).toVisibility() - enabledExclusive.isChecked = plugin.isEnabled(pluginType) - enabledInclusive.isChecked = plugin.isEnabled(pluginType) - enabledInclusive.isEnabled = !plugin.pluginDescription.alwaysEnabled - enabledExclusive.isEnabled = !plugin.pluginDescription.alwaysEnabled - pluginName.text = plugin.name - if (plugin.description == null) - pluginDescription.visibility = View.GONE - else { - pluginDescription.visibility = View.VISIBLE - pluginDescription.text = plugin.description - } - pluginPreferences.visibility = if (plugin.preferencesId == -1 || !plugin.isEnabled(pluginType)) View.INVISIBLE else View.VISIBLE - pluginVisibility.visibility = plugin.hasFragment().toVisibility() - pluginVisibility.isEnabled = !(plugin.pluginDescription.neverVisible || plugin.pluginDescription.alwaysVisible) && plugin.isEnabled(pluginType) - pluginVisibility.isChecked = plugin.isFragmentVisible() - } - - private fun areMultipleSelectionsAllowed(type: PluginType): Boolean { - return type == PluginType.GENERAL || type == PluginType.CONSTRAINTS || type == PluginType.LOOP - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt index 342b023343..74bdd47aaa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt @@ -24,7 +24,7 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -class WearPlugin internal @Inject constructor( +class WearPlugin @Inject constructor( private val rxBus: RxBusWrapper, private val resourceHelper: ResourceHelper, private val sp: SP, @@ -45,40 +45,42 @@ class WearPlugin internal @Inject constructor( disposable.add(rxBus .toObservable(EventOpenAPSUpdateGui::class.java) .observeOn(Schedulers.io()) - .subscribe({ sendDataToWatch(true, true, false) }) { FabricPrivacy.logException(it) }) + .subscribe({ sendDataToWatch(status = true, basals = true, bgValue = false) }) { FabricPrivacy.logException(it) }) disposable.add(rxBus .toObservable(EventExtendedBolusChange::class.java) .observeOn(Schedulers.io()) - .subscribe({ sendDataToWatch(true, true, false) }) { FabricPrivacy.logException(it) }) + .subscribe({ sendDataToWatch(status = true, basals = true, bgValue = false) }) { FabricPrivacy.logException(it) }) disposable.add(rxBus .toObservable(EventTempBasalChange::class.java) .observeOn(Schedulers.io()) - .subscribe({ event: EventTempBasalChange? -> sendDataToWatch(true, true, false) }) { FabricPrivacy.logException(it) }) + .subscribe({ sendDataToWatch(status = true, basals = true, bgValue = false) }) { FabricPrivacy.logException(it) }) disposable.add(rxBus .toObservable(EventTreatmentChange::class.java) .observeOn(Schedulers.io()) - .subscribe({ sendDataToWatch(true, true, false) }) { FabricPrivacy.logException(it) }) + .subscribe({ sendDataToWatch(status = true, basals = true, bgValue = false) }) { FabricPrivacy.logException(it) }) disposable.add(rxBus .toObservable(EventNewBasalProfile::class.java) .observeOn(Schedulers.io()) - .subscribe({ event: EventNewBasalProfile? -> sendDataToWatch(false, true, false) }) { FabricPrivacy.logException(it) }) + .subscribe({ sendDataToWatch(status = false, basals = true, bgValue = false) }) { FabricPrivacy.logException(it) }) disposable.add(rxBus .toObservable(EventAutosensCalculationFinished::class.java) .observeOn(Schedulers.io()) - .subscribe({ event: EventAutosensCalculationFinished? -> sendDataToWatch(true, true, true) }) { FabricPrivacy.logException(it) }) + .subscribe({ sendDataToWatch(status = true, basals = true, bgValue = true) }) { FabricPrivacy.logException(it) }) disposable.add(rxBus .toObservable(EventPreferenceChange::class.java) .observeOn(Schedulers.io()) - .subscribe({ event: EventPreferenceChange? -> + .subscribe({ // possibly new high or low mark resendDataToWatch() - // status may be formated differently - sendDataToWatch(true, false, false) + // status may be formatted differently + sendDataToWatch(status = true, basals = false, bgValue = false) }) { FabricPrivacy.logException(it) }) disposable.add(rxBus .toObservable(EventRefreshOverview::class.java) .observeOn(Schedulers.io()) - .subscribe({ event: EventRefreshOverview? -> if (WatchUpdaterService.shouldReportLoopStatus(loopPlugin.get().isEnabled(PluginType.LOOP))) sendDataToWatch(true, false, false) }) { FabricPrivacy.logException(it) }) + .subscribe({ + if (WatchUpdaterService.shouldReportLoopStatus(loopPlugin.get().isEnabled(PluginType.LOOP))) + sendDataToWatch(status = true, basals = false, bgValue = false) }) { FabricPrivacy.logException(it) }) disposable.add(rxBus .toObservable(EventBolusRequested::class.java) .observeOn(Schedulers.io()) @@ -148,10 +150,10 @@ class WearPlugin internal @Inject constructor( mainApp.startService(Intent(mainApp, WatchUpdaterService::class.java).setAction(WatchUpdaterService.ACTION_OPEN_SETTINGS)) } - fun requestNotificationCancel(actionstring: String?) { //Log.d(TAG, "WR: WearPlugin:requestNotificationCancel"); + fun requestNotificationCancel(actionString: String?) { //Log.d(TAG, "WR: WearPlugin:requestNotificationCancel"); val intent = Intent(mainApp, WatchUpdaterService::class.java) .setAction(WatchUpdaterService.ACTION_CANCEL_NOTIFICATION) - intent.putExtra("actionstring", actionstring) + intent.putExtra("actionstring", actionString) mainApp.startService(intent) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.kt index 7a19dda90c..4e210e15a8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.kt @@ -7,12 +7,11 @@ import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.plugins.treatments.Treatment import info.nightscout.androidaps.utils.resources.ResourceHelper -import javax.inject.Inject /** * Created by adrian on 13.08.2017. @@ -20,9 +19,10 @@ import javax.inject.Inject * parameters are injected from child class * */ -abstract class InsulinOrefBasePlugin ( +abstract class InsulinOrefBasePlugin( val rxBus: RxBusWrapper, - val resourceHelper: ResourceHelper + val resourceHelper: ResourceHelper, + val profileFunction: ProfileFunction ) : PluginBase(PluginDescription() .mainType(PluginType.INSULIN) .fragmentClass(InsulinFragment::class.java.name) @@ -54,7 +54,7 @@ abstract class InsulinOrefBasePlugin ( open val userDefinedDia: Double get() { - val profile = ProfileFunctions.getInstance().getProfile() + val profile = profileFunction.getProfile() return profile?.dia ?: MIN_DIA } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPlugin.kt index 2e22e18af4..c8bc87ff40 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPlugin.kt @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.insulin import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.InsulinInterface import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import javax.inject.Inject @@ -15,8 +16,9 @@ import javax.inject.Singleton class InsulinOrefFreePeakPlugin @Inject constructor( private val sp: SP, resourceHelper: ResourceHelper, - rxBus: RxBusWrapper -) : InsulinOrefBasePlugin(rxBus, resourceHelper) { + rxBus: RxBusWrapper, + profileFunction: ProfileFunction +) : InsulinOrefBasePlugin(rxBus, resourceHelper, profileFunction) { override fun getId(): Int { return InsulinInterface.OREF_FREE_PEAK diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPlugin.kt index 67ec420b17..b9fc161743 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPlugin.kt @@ -4,6 +4,7 @@ import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.InsulinInterface import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import javax.inject.Inject @@ -13,8 +14,9 @@ import javax.inject.Inject */ class InsulinOrefRapidActingPlugin @Inject constructor( resourceHelper: ResourceHelper, - rxBus: RxBusWrapper -) : InsulinOrefBasePlugin(rxBus, resourceHelper) { + rxBus: RxBusWrapper, + profileFunction: ProfileFunction +) : InsulinOrefBasePlugin(rxBus, resourceHelper, profileFunction) { override fun getId(): Int { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPlugin.kt index 4e7be23e2a..d09492053e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPlugin.kt @@ -4,6 +4,7 @@ import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.InsulinInterface import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import javax.inject.Inject @@ -14,8 +15,9 @@ import javax.inject.Inject class InsulinOrefUltraRapidActingPlugin @Inject constructor( private val sp: SP, resourceHelper: ResourceHelper, - rxBus: RxBusWrapper -) : InsulinOrefBasePlugin(rxBus, resourceHelper) { + rxBus: RxBusWrapper, + profileFunction: ProfileFunction +) : InsulinOrefBasePlugin(rxBus, resourceHelper, profileFunction) { override fun getId(): Int { @@ -23,11 +25,11 @@ class InsulinOrefUltraRapidActingPlugin @Inject constructor( } override fun getFriendlyName(): String { - return MainApp.gs(R.string.ultrarapid_oref) + return resourceHelper.gs(R.string.ultrarapid_oref) } override fun commentStandardText(): String { - return MainApp.gs(R.string.ultrafastactinginsulincomment) + return resourceHelper.gs(R.string.ultrafastactinginsulincomment) } override val peak = 55 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 5d27fe007b..1016a12c1f 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 @@ -13,6 +13,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.utils.DateUtil @@ -33,7 +34,8 @@ class LocalProfilePlugin @Inject constructor( private val aapsLogger: AAPSLogger, private val rxBus: RxBusWrapper, private val resourceHelper: ResourceHelper, - private val sp: SP + private val sp: SP, + private val profileFunction: ProfileFunction ) : PluginBase(PluginDescription() .mainType(PluginType.PROFILE) .fragmentClass(LocalProfileFragment::class.java.name) @@ -232,7 +234,7 @@ class LocalProfilePlugin @Inject constructor( aapsLogger.debug(LTag.PROFILE, "Loading stored settings") val p = SingleProfile() - p.mgdl = sp.getBoolean(LOCAL_PROFILE + "mgdl", ProfileFunctions.getSystemUnits() == Constants.MGDL) + p.mgdl = sp.getBoolean(LOCAL_PROFILE + "mgdl", profileFunction.getUnits() == Constants.MGDL) p.dia = sp.getDouble(LOCAL_PROFILE + "dia", Constants.defaultDIA) try { p.ic = JSONArray(sp.getString(LOCAL_PROFILE + "ic", defaultArray)) @@ -351,7 +353,7 @@ class LocalProfilePlugin @Inject constructor( } val p = SingleProfile() p.name = LOCAL_PROFILE + free - p.mgdl = ProfileFunctions.getSystemUnits() == Constants.MGDL + p.mgdl = profileFunction.getUnits() == Constants.MGDL p.dia = Constants.defaultDIA p.ic = JSONArray(defaultArray) p.isf = JSONArray(defaultArray) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.kt index 6c9227263a..a88c2719d4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.kt @@ -9,7 +9,7 @@ import android.widget.ArrayAdapter import dagger.android.support.DaggerFragment import info.nightscout.androidaps.R import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.profile.ns.events.EventNSProfileUpdateGUI import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DateUtil @@ -30,6 +30,7 @@ class NSProfileFragment : DaggerFragment() { @Inject lateinit var treatmentsPlugin: TreatmentsPlugin @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var profileFunction: ProfileFunction private var disposable: CompositeDisposable = CompositeDisposable() @@ -128,7 +129,7 @@ class NSProfileFragment : DaggerFragment() { nsprofile_spinner.adapter = adapter // set selected to actual profile for (p in profileList.indices) { - if (profileList[p] == ProfileFunctions.getInstance().getProfileName()) + if (profileList[p] == profileFunction.getProfileName()) nsprofile_spinner.setSelection(p) } profileview_noprofile.visibility = View.GONE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt index f1c2c3d807..ef1d7cf1fd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.kt @@ -21,7 +21,7 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin @@ -42,6 +42,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() { @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var danaRKoreanPlugin: DanaRKoreanPlugin @Inject lateinit var danaRSPlugin: DanaRSPlugin @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin @@ -189,7 +190,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() { } RecordTypes.RECORD_TYPE_GLUCOSE -> { - holder.value.text = Profile.toUnitsString(record.recordValue, record.recordValue * Constants.MGDL_TO_MMOLL, ProfileFunctions.getSystemUnits()) + holder.value.text = Profile.toUnitsString(record.recordValue, record.recordValue * Constants.MGDL_TO_MMOLL, profileFunction.getUnits()) holder.time.visibility = View.VISIBLE holder.value.visibility = View.VISIBLE holder.stringValue.visibility = View.GONE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt index fbc04823e3..aba141abac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt @@ -319,7 +319,7 @@ class MedtronicFragment : DaggerFragment() { SetWarnColor.setColorInverse(medtronic_pumpstate_battery, pumpStatus.batteryRemaining.toDouble(), 25.0, 10.0) // reservoir - medtronic_reservoir.text = MainApp.gs(R.string.reservoirvalue, pumpStatus.reservoirRemainingUnits, pumpStatus.reservoirFullUnits) + medtronic_reservoir.text = resourceHelper.gs(R.string.reservoirvalue, pumpStatus.reservoirRemainingUnits, pumpStatus.reservoirFullUnits) SetWarnColor.setColorInverse(medtronic_reservoir, pumpStatus.reservoirRemainingUnits, 50.0, 20.0) medtronic_errors.text = pumpStatus.errorInfo diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt deleted file mode 100644 index 63f3b57f65..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt +++ /dev/null @@ -1,76 +0,0 @@ -package info.nightscout.androidaps.plugins.treatments.dialogs - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.view.WindowManager -import androidx.fragment.app.DialogFragment -import info.nightscout.androidaps.MainApp -import info.nightscout.androidaps.R -import info.nightscout.androidaps.Constants -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions -import info.nightscout.androidaps.utils.DecimalFormatter -import info.nightscout.androidaps.utils.JsonHelper -import info.nightscout.androidaps.utils.StringUtils -import kotlinx.android.synthetic.main.treatments_wizardinfo_dialog.* -import org.json.JSONObject - -class WizardInfoDialog : DialogFragment() { - private var json: JSONObject? = null - - fun setData(json: JSONObject) { - this.json = json - } - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { - dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) - isCancelable = true - return inflater.inflate(R.layout.treatments_wizardinfo_dialog, container, false) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - close.setOnClickListener { dismiss() } - val units = ProfileFunctions.getSystemUnits() - val bg_string: String - if (units.equals(Constants.MGDL)) { bg_string = DecimalFormatter.to0Decimal(JsonHelper.safeGetDouble(json, "bg"))} else { bg_string = DecimalFormatter.to1Decimal(JsonHelper.safeGetDouble(json, "bg"))} - // BG - treatments_wizard_bg.text = MainApp.gs(R.string.format_bg_isf, bg_string , JsonHelper.safeGetDouble(json, "isf")) - treatments_wizard_bginsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulinbg")) - treatments_wizard_bgcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "insulinbgused") - treatments_wizard_ttcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "ttused") - // Trend - treatments_wizard_bgtrend.text = JsonHelper.safeGetString(json, "trend") - treatments_wizard_bgtrendinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulintrend")) - treatments_wizard_bgtrendcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "trendused") - // COB - treatments_wizard_cob.text = MainApp.gs(R.string.format_cob_ic, JsonHelper.safeGetDouble(json, "cob"), JsonHelper.safeGetDouble(json, "ic")) - treatments_wizard_cobinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulincob")) - treatments_wizard_cobcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "cobused") - // Bolus IOB - treatments_wizard_bolusiobinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "bolusiob")) - treatments_wizard_bolusiobcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "bolusiobused") - // Basal IOB - treatments_wizard_basaliobinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "basaliob")) - treatments_wizard_basaliobcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "basaliobused") - // Superbolus - treatments_wizard_sbinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulinsuperbolus")) - treatments_wizard_sbcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "superbolusused") - // Carbs - treatments_wizard_carbs.text = MainApp.gs(R.string.format_carbs_ic, JsonHelper.safeGetDouble(json, "carbs"), JsonHelper.safeGetDouble(json, "ic")) - treatments_wizard_carbsinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulincarbs")) - // Correction - treatments_wizard_correctioninsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "othercorrection")) - // Profile - treatments_wizard_profile.text = JsonHelper.safeGetString(json, "profile") - // Notes - treatments_wizard_notes.text = JsonHelper.safeGetString(json, "notes") - // Percentage - treatments_wizard_percent_used.text = DecimalFormatter.to0Decimal(JsonHelper.safeGetDouble(json, "percentageCorrection", 100.0)) + "%" - // Total - treatments_wizard_totalinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulin")) - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt index f9eda70da0..b1ab383931 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusFragment.kt @@ -21,7 +21,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientR import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished import info.nightscout.androidaps.plugins.treatments.Treatment import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin -import info.nightscout.androidaps.plugins.treatments.dialogs.WizardInfoDialog +import info.nightscout.androidaps.dialogs.WizardInfoDialog import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsBolusFragment.RecyclerViewAdapter.TreatmentsViewHolder import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy diff --git a/app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java b/app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java index 74e8da7c9d..ebd31dea17 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/StringUtils.java @@ -8,10 +8,6 @@ import info.nightscout.androidaps.R; */ public class StringUtils { - private StringUtils() { - // this constructor is private, since this class should not get instantiated - } - public static String removeSurroundingQuotes(String string) { if (string.length() >= 2 && string.charAt(0) == '"' && string.charAt(string.length() - 1) == '"') { @@ -24,8 +20,4 @@ public class StringUtils { public static boolean emptyString(final String str) { return str == null || str.length() == 0; } - - public static String formatInsulin(double insulin) { - return String.format(MainApp.gs(R.string.formatinsulinunits), insulin); - } } diff --git a/app/src/main/res/layout/treatments_wizardinfo_dialog.xml b/app/src/main/res/layout/dialog_wizardinfo.xml similarity index 92% rename from app/src/main/res/layout/treatments_wizardinfo_dialog.xml rename to app/src/main/res/layout/dialog_wizardinfo.xml index d6ba1bfc58..3ce946ab0d 100644 --- a/app/src/main/res/layout/treatments_wizardinfo_dialog.xml +++ b/app/src/main/res/layout/dialog_wizardinfo.xml @@ -1,34 +1,51 @@ - + tools:context=".dialogs.WizardInfoDialog"> - - - + android:layout_gravity="center" + android:background="@color/dialog_title_background" + android:orientation="horizontal" + android:padding="5dp"> + + + + + + + + @@ -474,11 +491,11 @@ android:id="@+id/close" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginRight="16dp" android:layout_marginEnd="16dp" style="@style/mdtp_ActionButton.Text" android:text="@string/mdtp_ok" /> + \ No newline at end of file