diff --git a/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt index 36fa1d7656..7ada27152f 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt @@ -10,7 +10,7 @@ import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag 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.utils.* import info.nightscout.androidaps.utils.resources.ResourceHelper import kotlinx.android.synthetic.main.survey_activity.* @@ -21,6 +21,7 @@ class SurveyActivity : NoSplashAppCompatActivity() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin @Inject lateinit var tddCalculator: TddCalculator + @Inject lateinit var profileFunction: ProfileFunction override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -52,7 +53,7 @@ class SurveyActivity : NoSplashAppCompatActivity() { ToastUtils.showToastInUiThread(this, R.string.invalidweight) return@setOnClickListener } - val profile = DefaultProfile().profile(age, tdd, weight, ProfileFunctions.getSystemUnits()) + val profile = DefaultProfile().profile(age, tdd, weight, profileFunction.getUnits()) val args = Bundle() args.putLong("time", DateUtil.now()) args.putInt("mode", ProfileViewerDialog.Mode.CUSTOM_PROFILE.ordinal) @@ -90,7 +91,7 @@ class SurveyActivity : NoSplashAppCompatActivity() { .addOnCompleteListener(this) { task -> if (task.isSuccessful) { aapsLogger.debug(LTag.CORE, "signInAnonymously:success") - val user = auth.currentUser // TODO: do we need this, seems unused? + //val user = auth.currentUser // TODO: do we need this, seems unused? val database = FirebaseDatabase.getInstance().reference database.child("survey").child(r.id).setValue(r) diff --git a/app/src/main/java/info/nightscout/androidaps/data/QuickWizard.kt b/app/src/main/java/info/nightscout/androidaps/data/QuickWizard.kt index f8bca8c450..039bdd3d2d 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/QuickWizard.kt +++ b/app/src/main/java/info/nightscout/androidaps/data/QuickWizard.kt @@ -1,14 +1,19 @@ package info.nightscout.androidaps.data -import info.nightscout.androidaps.utils.SP +import info.nightscout.androidaps.utils.sharedPreferences.SP import org.json.JSONArray import org.json.JSONObject +import javax.inject.Inject +import javax.inject.Singleton -object QuickWizard { +@Singleton +class QuickWizard @Inject constructor( + private val sp: SP +){ private var storage = JSONArray() init { - setData(JSONArray(SP.getString("QuickWizard", "[]"))) + setData(JSONArray(sp.getString("QuickWizard", "[]"))) } fun getActive(): QuickWizardEntry? { @@ -24,7 +29,7 @@ object QuickWizard { } fun save() { - SP.putString("QuickWizard", storage.toString()) + sp.putString("QuickWizard", storage.toString()) } fun size(): Int = storage.length() diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt index 837d58faa4..8bbc300d6f 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt @@ -17,7 +17,7 @@ import info.nightscout.androidaps.db.Source import info.nightscout.androidaps.db.TempTarget import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.treatments.CarbsGenerator import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin @@ -36,6 +36,7 @@ class CarbsDialog : DialogFragmentWithDate() { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var constraintChecker: ConstraintChecker @Inject lateinit var treatmentsPlugin: TreatmentsPlugin + @Inject lateinit var profileFunction: ProfileFunction companion object { private const val FAV1_DEFAULT = 5 @@ -141,7 +142,7 @@ class CarbsDialog : DialogFragmentWithDate() { override fun submit(): Boolean { val carbs = overview_carbs_carbs.value.toInt() val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(Constraint(carbs)).value() - val units = ProfileFunctions.getSystemUnits() + val units = profileFunction.getUnits() val activityTTDuration = DefaultValueHelper.determineActivityTTDuration() val activityTT = DefaultValueHelper.determineActivityTT() val eatingSoonTTDuration = DefaultValueHelper.determineEatingSoonTTDuration() @@ -187,8 +188,8 @@ class CarbsDialog : DialogFragmentWithDate() { .duration(activityTTDuration) .reason(resourceHelper.gs(R.string.activity)) .source(Source.USER) - .low(Profile.toMgdl(activityTT, ProfileFunctions.getSystemUnits())) - .high(Profile.toMgdl(activityTT, ProfileFunctions.getSystemUnits())) + .low(Profile.toMgdl(activityTT, profileFunction.getUnits())) + .high(Profile.toMgdl(activityTT, profileFunction.getUnits())) treatmentsPlugin.addToHistoryTempTarget(tempTarget) } @@ -198,8 +199,8 @@ class CarbsDialog : DialogFragmentWithDate() { .duration(eatingSoonTTDuration) .reason(resourceHelper.gs(R.string.eatingsoon)) .source(Source.USER) - .low(Profile.toMgdl(eatingSoonTT, ProfileFunctions.getSystemUnits())) - .high(Profile.toMgdl(eatingSoonTT, ProfileFunctions.getSystemUnits())) + .low(Profile.toMgdl(eatingSoonTT, profileFunction.getUnits())) + .high(Profile.toMgdl(eatingSoonTT, profileFunction.getUnits())) treatmentsPlugin.addToHistoryTempTarget(tempTarget) } @@ -209,8 +210,8 @@ class CarbsDialog : DialogFragmentWithDate() { .duration(hypoTTDuration) .reason(resourceHelper.gs(R.string.hypo)) .source(Source.USER) - .low(Profile.toMgdl(hypoTT, ProfileFunctions.getSystemUnits())) - .high(Profile.toMgdl(hypoTT, ProfileFunctions.getSystemUnits())) + .low(Profile.toMgdl(hypoTT, profileFunction.getUnits())) + .high(Profile.toMgdl(hypoTT, profileFunction.getUnits())) treatmentsPlugin.addToHistoryTempTarget(tempTarget) } } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt index f744a2c9b5..1dc801b358 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt @@ -13,7 +13,7 @@ import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.db.CareportalEvent -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.utils.DateUtil @@ -32,6 +32,7 @@ import javax.inject.Inject class CareDialog : DialogFragmentWithDate() { @Inject lateinit var mainApp: MainApp @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var profileFunction: ProfileFunction enum class EventType { BGCHECK, @@ -86,7 +87,7 @@ class CareDialog : DialogFragmentWithDate() { } val bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData()?.glucose - ?: 0.0, ProfileFunctions.getSystemUnits()) + ?: 0.0, profileFunction.getUnits()) val bgTextWatcher: TextWatcher = object : TextWatcher { override fun afterTextChanged(s: Editable) {} override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} @@ -95,7 +96,7 @@ class CareDialog : DialogFragmentWithDate() { } } - if (ProfileFunctions.getSystemUnits() == Constants.MMOL) { + if (profileFunction.getUnits() == Constants.MMOL) { actions_care_bgunits.text = resourceHelper.gs(R.string.mmol) actions_care_bg.setParams(savedInstanceState?.getDouble("actions_care_bg") ?: bg, 2.0, 30.0, 0.1, DecimalFormat("0.0"), false, ok, bgTextWatcher) @@ -108,7 +109,7 @@ class CareDialog : DialogFragmentWithDate() { override fun submit(): Boolean { val enteredBy = sp.getString("careportal_enteredby", "") - val unitResId = if (ProfileFunctions.getSystemUnits() == Constants.MGDL) R.string.mgdl else R.string.mmol + val unitResId = if (profileFunction.getUnits() == Constants.MGDL) R.string.mgdl else R.string.mmol val json = JSONObject() val actions: LinkedList = LinkedList() @@ -138,7 +139,7 @@ class CareDialog : DialogFragmentWithDate() { EventType.SENSOR_INSERT -> CareportalEvent.SENSORCHANGE EventType.BATTERY_CHANGE -> CareportalEvent.PUMPBATTERYCHANGE }) - json.put("units", ProfileFunctions.getSystemUnits()) + json.put("units", profileFunction.getUnits()) if (enteredBy.isNotEmpty()) json.put("enteredBy", enteredBy) 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 22f80c7e73..aeabf6ee50 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt @@ -23,15 +23,10 @@ import java.util.* import javax.inject.Inject class ProfileSwitchDialog : DialogFragmentWithDate() { - - @Inject - lateinit var resourceHelper: ResourceHelper - - @Inject - lateinit var profileFunction: ProfileFunction - - @Inject - lateinit var treatmentsPlugin: TreatmentsPlugin + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var profileFunction: ProfileFunction + @Inject lateinit var treatmentsPlugin: TreatmentsPlugin + @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin override fun onSaveInstanceState(savedInstanceState: Bundle) { super.onSaveInstanceState(savedInstanceState) @@ -58,7 +53,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() { // profile context?.let { context -> - val profileStore = ConfigBuilderPlugin.getPlugin().activeProfileInterface?.profile + val profileStore = configBuilderPlugin.activeProfileInterface.profile ?: return val profileList = profileStore.getProfileList() val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList) @@ -69,7 +64,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() { overview_profileswitch_profile.setSelection(p) } ?: return - TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(DateUtil.now())?.let { ps -> + treatmentsPlugin.getProfileSwitchFromHistory(DateUtil.now())?.let { ps -> if (ps.isCPP) { overview_profileswitch_reuselayout.visibility = View.VISIBLE overview_profileswitch_reusebutton.text = resourceHelper.gs(R.string.reuse) + " " + ps.percentage + "% " + ps.timeshift + "h" @@ -84,7 +79,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() { } override fun submit(): Boolean { - val profileStore = ConfigBuilderPlugin.getPlugin().activeProfileInterface?.profile + val profileStore = configBuilderPlugin.activeProfileInterface.profile ?: return false val actions: LinkedList = LinkedList() diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt index a295e3dafa..b731ad540d 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt @@ -19,9 +19,8 @@ import org.json.JSONObject import javax.inject.Inject class ProfileViewerDialog : DaggerDialogFragment() { - - @Inject - lateinit var resourceHelper: ResourceHelper + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var treatmentsPlugin: TreatmentsPlugin private var time: Long = 0 @@ -64,9 +63,9 @@ class ProfileViewerDialog : DaggerDialogFragment() { val date: String? when (mode) { Mode.RUNNING_PROFILE -> { - profile = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time)?.profileObject - profileName = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time)?.customizedName - date = DateUtil.dateAndTimeString(TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time)?.date + profile = treatmentsPlugin.getProfileSwitchFromHistory(time)?.profileObject + profileName = treatmentsPlugin.getProfileSwitchFromHistory(time)?.customizedName + date = DateUtil.dateAndTimeString(treatmentsPlugin.getProfileSwitchFromHistory(time)?.date ?: 0) profileview_datelayout.visibility = View.VISIBLE } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt index 32f54a3083..9370bf795d 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt @@ -14,6 +14,7 @@ import info.nightscout.androidaps.interfaces.PumpDescription import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.OKDialog @@ -27,18 +28,11 @@ import javax.inject.Inject import kotlin.math.abs class TempBasalDialog : DialogFragmentWithDate() { - - @Inject - lateinit var constraintChecker: ConstraintChecker - - @Inject - lateinit var mainApp: MainApp - - @Inject - lateinit var resourceHelper: ResourceHelper - - @Inject - lateinit var profileFunction: ProfileFunction + @Inject lateinit var constraintChecker: ConstraintChecker + @Inject lateinit var mainApp: MainApp + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var profileFunction: ProfileFunction + @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin private var isPercentPump = true @@ -58,7 +52,7 @@ class TempBasalDialog : DialogFragmentWithDate() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription ?: return + val pumpDescription = configBuilderPlugin.activePump?.pumpDescription ?: return val profile = profileFunction.getProfile() ?: return val maxTempPercent = pumpDescription.maxTempPercent.toDouble() @@ -106,7 +100,7 @@ class TempBasalDialog : DialogFragmentWithDate() { actions.add("" + resourceHelper.gs(R.string.constraintapllied) + "") } activity?.let { activity -> - OKDialog.showConfirmation(activity, MainApp.gs(R.string.pump_tempbasal_label), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), Runnable { + OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.pump_tempbasal_label), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), Runnable { val callback: Callback = object : Callback() { override fun run() { if (!result.success) { @@ -120,9 +114,9 @@ class TempBasalDialog : DialogFragmentWithDate() { } } if (isPercentPump) { - ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalPercent(percent, durationInMinutes, true, profile, callback) + configBuilderPlugin.commandQueue.tempBasalPercent(percent, durationInMinutes, true, profile, callback) } else { - ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalAbsolute(absolute, durationInMinutes, true, profile, callback) + configBuilderPlugin.commandQueue.tempBasalAbsolute(absolute, durationInMinutes, true, profile, callback) } }) } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt index 15006a1371..7f2c20224a 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt @@ -33,15 +33,11 @@ import javax.inject.Inject import kotlin.math.abs class TreatmentDialog : DialogFragmentWithDate() { - - @Inject - lateinit var constraintChecker: ConstraintChecker - - @Inject - lateinit var mainApp: MainApp - - @Inject - lateinit var resourceHelper: ResourceHelper + @Inject lateinit var constraintChecker: ConstraintChecker + @Inject lateinit var mainApp: MainApp + @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin + @Inject lateinit var treatmentsPlugin: TreatmentsPlugin private val textWatcher: TextWatcher = object : TextWatcher { override fun afterTextChanged(s: Editable) {} @@ -81,7 +77,7 @@ class TreatmentDialog : DialogFragmentWithDate() { val maxCarbs = constraintChecker.getMaxCarbsAllowed().value().toDouble() val maxInsulin = constraintChecker.getMaxBolusAllowed().value() - val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription ?: return + val pumpDescription = configBuilderPlugin.activePump?.pumpDescription ?: return overview_treatment_carbs.setParams(savedInstanceState?.getDouble("overview_treatment_carbs") ?: 0.0, 0.0, maxCarbs, 1.0, DecimalFormat("0"), false, ok, textWatcher) overview_treatment_insulin.setParams(savedInstanceState?.getDouble("overview_treatment_insulin") @@ -89,7 +85,7 @@ class TreatmentDialog : DialogFragmentWithDate() { } override fun submit(): Boolean { - val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription + val pumpDescription = configBuilderPlugin.activePump?.pumpDescription ?: return false val insulin = SafeParse.stringToDouble(overview_treatment_insulin.text) val carbs = SafeParse.stringToInt(overview_treatment_carbs.text) @@ -121,7 +117,7 @@ class TreatmentDialog : DialogFragmentWithDate() { detailedBolusInfo.context = context detailedBolusInfo.source = Source.USER if (!(recordOnlyChecked && (detailedBolusInfo.insulin > 0 || pumpDescription.storesCarbInfo))) { - ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() { + configBuilderPlugin.commandQueue.bolus(detailedBolusInfo, object : Callback() { override fun run() { if (!result.success) { val i = Intent(mainApp, ErrorHelperActivity::class.java) @@ -134,7 +130,7 @@ class TreatmentDialog : DialogFragmentWithDate() { } }) } else - TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false) + treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, false) }) } } else diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt index 4ae0396524..f911dc1123 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt @@ -6,7 +6,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import dagger.android.support.DaggerFragment -import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -17,6 +16,7 @@ import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.JSONFormatter import info.nightscout.androidaps.utils.plusAssign +import info.nightscout.androidaps.utils.resources.ResourceHelper import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import kotlinx.android.synthetic.main.openapsama_fragment.* @@ -30,6 +30,7 @@ class OpenAPSAMAFragment : DaggerFragment() { @Inject lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var resourceHelper: ResourceHelper override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -86,7 +87,7 @@ class OpenAPSAMAFragment : DaggerFragment() { openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterAMAJS.currentTempParam) try { val iobArray = JSONArray(determineBasalAdapterAMAJS.iobDataParam) - openapsma_iobdata.text = TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0))) + openapsma_iobdata.text = TextUtils.concat(resourceHelper.gs(R.string.array_of_elements, iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0))) } catch (e: JSONException) { aapsLogger.error(LTag.APS, "Unhandled exception", e) @Suppress("SetTextI18n") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt index 491dba1037..e4dd042289 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt @@ -7,7 +7,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import dagger.android.support.DaggerFragment -import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -18,6 +17,7 @@ import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.JSONFormatter import info.nightscout.androidaps.utils.plusAssign +import info.nightscout.androidaps.utils.resources.ResourceHelper import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import kotlinx.android.synthetic.main.openapsama_fragment.* @@ -31,6 +31,7 @@ class OpenAPSSMBFragment : DaggerFragment() { @Inject lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var resourceHelper: ResourceHelper override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -86,7 +87,7 @@ class OpenAPSSMBFragment : DaggerFragment() { openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterSMBJS.currentTempParam) try { val iobArray = JSONArray(determineBasalAdapterSMBJS.iobDataParam) - openapsma_iobdata.text = TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0))) + openapsma_iobdata.text = TextUtils.concat(resourceHelper.gs(R.string.array_of_elements, iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0))) } catch (e: JSONException) { aapsLogger.error(LTag.APS, "Unhandled exception", e) @SuppressLint("SetTextI18n") 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 037934db6f..5c8a6db7e9 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 @@ -15,6 +15,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.PasswordProtection import info.nightscout.androidaps.utils.plusAssign +import info.nightscout.androidaps.utils.resources.ResourceHelper import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import kotlinx.android.synthetic.main.configbuilder_fragment.* @@ -23,7 +24,8 @@ import javax.inject.Inject class ConfigBuilderFragment : DaggerFragment() { @Inject lateinit var rxBus: RxBusWrapper - + @Inject lateinit var resourceHelper: ResourceHelper + private var disposable: CompositeDisposable = CompositeDisposable() private val pluginViewHolders = ArrayList() @@ -86,8 +88,8 @@ class ConfigBuilderFragment : DaggerFragment() { private fun createViewsForPlugins(@StringRes title: Int, @StringRes description: Int, pluginType: PluginType, plugins: List) { if (plugins.size == 0) return val parent = layoutInflater.inflate(R.layout.configbuilder_single_category, null) as LinearLayout - (parent.findViewById(R.id.category_title) as TextView).text = MainApp.gs(title) - (parent.findViewById(R.id.category_description) as TextView).text = MainApp.gs(description) + (parent.findViewById(R.id.category_title) as TextView).text = resourceHelper.gs(title) + (parent.findViewById(R.id.category_description) as TextView).text = resourceHelper.gs(description) val pluginContainer = parent.findViewById(R.id.category_plugins) for (plugin in plugins) { val pluginViewHolder = PluginViewHolder(this, pluginType, plugin) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java index c70cbedfc7..7d59dafa77 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java @@ -142,6 +142,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList @Inject XdripPlugin xdripPlugin; @Inject NotificationStore notificationStore; @Inject ActionStringHandler actionStringHandler; + @Inject QuickWizard quickWizard; private CompositeDisposable disposable = new CompositeDisposable(); @@ -937,7 +938,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList final String profileName = profileFunction.getProfileName(); final PumpInterface pump = configBuilderPlugin.getActivePump(); - final QuickWizardEntry quickWizardEntry = QuickWizard.INSTANCE.getActive(); + final QuickWizardEntry quickWizardEntry = quickWizard.getActive(); if (quickWizardEntry != null && actualBg != null && profile != null && pump != null) { quickWizardButton.setVisibility(View.VISIBLE); final BolusWizard wizard = quickWizardEntry.doCalc(profile, profileName, actualBg, true); @@ -1229,7 +1230,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList } // QuickWizard button - QuickWizardEntry quickWizardEntry = QuickWizard.INSTANCE.getActive(); + QuickWizardEntry quickWizardEntry = quickWizard.getActive(); if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) { quickWizardButton.setVisibility(View.VISIBLE); String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.kt index a8b5ccf1c0..243fb53b6f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.kt @@ -27,6 +27,7 @@ import javax.inject.Inject class QuickWizardListActivity : NoSplashAppCompatActivity() { @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var quickWizard: QuickWizard private var disposable: CompositeDisposable = CompositeDisposable() @@ -37,13 +38,13 @@ class QuickWizardListActivity : NoSplashAppCompatActivity() { } override fun onBindViewHolder(holder: QuickWizardEntryViewHolder, position: Int) { - holder.from.text = DateUtil.timeString(QuickWizard[position].validFromDate()) - holder.to.text = DateUtil.timeString(QuickWizard[position].validToDate()) - holder.buttonText.text = QuickWizard[position].buttonText() - holder.carbs.text = resourceHelper.gs(R.string.format_carbs, QuickWizard[position].carbs()) + holder.from.text = DateUtil.timeString(quickWizard[position].validFromDate()) + holder.to.text = DateUtil.timeString(quickWizard[position].validToDate()) + holder.buttonText.text = quickWizard[position].buttonText() + holder.carbs.text = resourceHelper.gs(R.string.format_carbs, quickWizard[position].carbs()) } - override fun getItemCount(): Int = QuickWizard.size() + override fun getItemCount(): Int = quickWizard.size() private inner class QuickWizardEntryViewHolder internal constructor(itemView: View, internal var fragmentManager: FragmentManager) : RecyclerView.ViewHolder(itemView) { val buttonText: TextView = itemView.findViewById(R.id.overview_quickwizard_item_buttonText) @@ -57,11 +58,13 @@ class QuickWizardListActivity : NoSplashAppCompatActivity() { editButton.setOnClickListener { val manager = fragmentManager val editQuickWizardDialog = EditQuickWizardDialog() - editQuickWizardDialog.entry = QuickWizard[adapterPosition] + val bundle = Bundle() + bundle.putInt("position", adapterPosition) + editQuickWizardDialog.arguments = bundle editQuickWizardDialog.show(manager, "EditQuickWizardDialog") } removeButton.setOnClickListener { - QuickWizard.remove(adapterPosition) + quickWizard.remove(adapterPosition) rxBus.send(EventQuickWizardChange()) } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/EditQuickWizardDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/EditQuickWizardDialog.kt index 393de5a445..3aa997572e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/EditQuickWizardDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/EditQuickWizardDialog.kt @@ -26,8 +26,9 @@ import javax.inject.Inject class EditQuickWizardDialog : DaggerDialogFragment() { @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var quickWizard: QuickWizard - internal var entry = QuickWizard.newEmptyItem() + var position = -1 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -39,6 +40,10 @@ class EditQuickWizardDialog : DaggerDialogFragment() { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + (arguments ?: savedInstanceState)?.let { bundle -> + position = bundle.getInt("position", -1) + } + val entry = if (position ==-1) quickWizard.newEmptyItem() else quickWizard[position] ok.setOnClickListener { if (overview_editquickwizard_from_spinner.selectedItem == null) return@setOnClickListener if (overview_editquickwizard_to_spinner.selectedItem == null) return@setOnClickListener @@ -60,7 +65,7 @@ class EditQuickWizardDialog : DaggerDialogFragment() { aapsLogger.error("Unhandled exception", e) } - QuickWizard.addOrUpdate(entry) + quickWizard.addOrUpdate(entry) rxBus.send(EventQuickWizardChange()) dismiss() } @@ -109,6 +114,11 @@ class EditQuickWizardDialog : DaggerDialogFragment() { dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) } + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + outState.putInt("position", position) + } + private fun processCob() { if (overview_editquickwizard_usecob_spinner.selectedItemPosition == QuickWizardEntry.YES) { overview_editquickwizard_usebolusiob_spinner.isEnabled = false