WizardDialog spinner replacement
This commit is contained in:
parent
6d27f5fad0
commit
a3ffd23e29
2 changed files with 63 additions and 62 deletions
|
@ -1,12 +1,16 @@
|
|||
package info.nightscout.androidaps.dialogs
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import android.view.WindowManager
|
||||
import android.widget.AdapterView
|
||||
import android.widget.AdapterView.OnItemSelectedListener
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.CompoundButton
|
||||
import androidx.fragment.app.FragmentManager
|
||||
|
@ -20,23 +24,23 @@ import info.nightscout.androidaps.database.ValueWrapper
|
|||
import info.nightscout.androidaps.databinding.DialogWizardBinding
|
||||
import info.nightscout.androidaps.events.EventAutosensCalculationFinished
|
||||
import info.nightscout.androidaps.extensions.formatColor
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||
import info.nightscout.shared.SafeParse
|
||||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.extensions.valueToUnits
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||
import info.nightscout.androidaps.utils.*
|
||||
import info.nightscout.androidaps.utils.protection.ProtectionCheck
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import info.nightscout.androidaps.utils.wizard.BolusWizard
|
||||
import info.nightscout.shared.SafeParse
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import java.text.DecimalFormat
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.abs
|
||||
|
||||
|
@ -108,8 +112,7 @@ class WizardDialog : DaggerDialogFragment() {
|
|||
savedInstanceState.putDouble("carb_time_input", binding.carbTimeInput.value)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View {
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
this.arguments?.let { bundle ->
|
||||
carbsPassedIntoWizard = bundle.getInt("carbs_input").toDouble()
|
||||
notesPassedIntoWizard = bundle.getString("notes_input").toString()
|
||||
|
@ -139,14 +142,18 @@ class WizardDialog : DaggerDialogFragment() {
|
|||
if (profileFunction.getUnits() == GlucoseUnit.MGDL) {
|
||||
binding.bgInput.setParams(
|
||||
savedInstanceState?.getDouble("bg_input")
|
||||
?: 0.0, 0.0, 500.0, 1.0, DecimalFormat("0"), false, binding.okcancel.ok, timeTextWatcher)
|
||||
?: 0.0, 0.0, 500.0, 1.0, DecimalFormat("0"), false, binding.okcancel.ok, timeTextWatcher
|
||||
)
|
||||
} else {
|
||||
binding.bgInput.setParams(
|
||||
savedInstanceState?.getDouble("bg_input")
|
||||
?: 0.0, 0.0, 30.0, 0.1, DecimalFormat("0.0"), false, binding.okcancel.ok, textWatcher)
|
||||
?: 0.0, 0.0, 30.0, 0.1, DecimalFormat("0.0"), false, binding.okcancel.ok, textWatcher
|
||||
)
|
||||
}
|
||||
binding.carbsInput.setParams(savedInstanceState?.getDouble("carbs_input")
|
||||
?: 0.0, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), false, binding.okcancel.ok, textWatcher)
|
||||
binding.carbsInput.setParams(
|
||||
savedInstanceState?.getDouble("carbs_input")
|
||||
?: 0.0, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), false, binding.okcancel.ok, textWatcher
|
||||
)
|
||||
|
||||
if (correctionPercent) {
|
||||
calculatedPercentage = sp.getInt(R.string.key_boluswizard_percentage, 100).toDouble()
|
||||
|
@ -156,11 +163,14 @@ class WizardDialog : DaggerDialogFragment() {
|
|||
} else {
|
||||
binding.correctionInput.setParams(
|
||||
savedInstanceState?.getDouble("correction_input")
|
||||
?: 0.0, -maxCorrection, maxCorrection, bolusStep, DecimalFormatter.pumpSupportedBolusFormat(activePlugin.activePump), false, binding.okcancel.ok, textWatcher)
|
||||
?: 0.0, -maxCorrection, maxCorrection, bolusStep, DecimalFormatter.pumpSupportedBolusFormat(activePlugin.activePump), false, binding.okcancel.ok, textWatcher
|
||||
)
|
||||
binding.correctionUnit.text = rh.gs(R.string.insulin_unit_shortname)
|
||||
}
|
||||
binding.carbTimeInput.setParams(savedInstanceState?.getDouble("carb_time_input")
|
||||
?: 0.0, -60.0, 60.0, 5.0, DecimalFormat("0"), false, binding.okcancel.ok, timeTextWatcher)
|
||||
binding.carbTimeInput.setParams(
|
||||
savedInstanceState?.getDouble("carb_time_input")
|
||||
?: 0.0, -60.0, 60.0, 5.0, DecimalFormat("0"), false, binding.okcancel.ok, timeTextWatcher
|
||||
)
|
||||
initDialog()
|
||||
calculatedPercentage = sp.getInt(R.string.key_boluswizard_percentage, 100).toDouble()
|
||||
binding.percentUsed.text = rh.gs(R.string.format_percent, sp.getInt(R.string.key_boluswizard_percentage, 100))
|
||||
|
@ -230,27 +240,13 @@ class WizardDialog : DaggerDialogFragment() {
|
|||
binding.correctionInput.value = if (correctionPercent) calculatedPercentage else Round.roundTo(calculatedCorrection, bolusStep)
|
||||
}
|
||||
}
|
||||
// profile spinner
|
||||
binding.profile.onItemSelectedListener = object : OnItemSelectedListener {
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
ToastUtils.showToastInUiThread(ctx, rh.gs(R.string.noprofileset))
|
||||
binding.okcancel.ok.visibility = View.GONE
|
||||
}
|
||||
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
calculateInsulin()
|
||||
binding.okcancel.ok.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
// profile
|
||||
binding.profileList.onItemClickListener = AdapterView.OnItemClickListener { _, _, _, _ -> calculateInsulin() }
|
||||
// bus
|
||||
disposable.add(rxBus
|
||||
disposable += rxBus
|
||||
.toObservable(EventAutosensCalculationFinished::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe({
|
||||
activity?.runOnUiThread { calculateInsulin() }
|
||||
}, fabricPrivacy::logException)
|
||||
)
|
||||
|
||||
.subscribe({ calculateInsulin() }, fabricPrivacy::logException)
|
||||
setA11yLabels()
|
||||
}
|
||||
|
||||
|
@ -347,9 +343,9 @@ class WizardDialog : DaggerDialogFragment() {
|
|||
val profileList: ArrayList<CharSequence> = profileStore.getProfileList()
|
||||
profileList.add(0, rh.gs(R.string.active))
|
||||
context?.let { context ->
|
||||
val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList)
|
||||
binding.profile.adapter = adapter
|
||||
} ?: return
|
||||
binding.profileList.setAdapter(ArrayAdapter(context, R.layout.spinner_centered, profileList))
|
||||
binding.profileList.setText(profileList[0], false)
|
||||
}
|
||||
|
||||
val units = profileFunction.getUnits()
|
||||
binding.bgUnits.text = units.asText
|
||||
|
@ -372,11 +368,10 @@ class WizardDialog : DaggerDialogFragment() {
|
|||
binding.percentUsed.visibility = (sp.getInt(R.string.key_boluswizard_percentage, 100) != 100 || correctionPercent).toVisibility()
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private fun calculateInsulin() {
|
||||
val profileStore = activePlugin.activeProfileSource.profile
|
||||
if (binding.profile.selectedItem == null || profileStore == null)
|
||||
return // not initialized yet
|
||||
var profileName = binding.profile.selectedItem.toString()
|
||||
val profileStore = activePlugin.activeProfileSource.profile ?: return // not initialized yet
|
||||
var profileName = binding.profileList.text.toString()
|
||||
val specificProfile: Profile?
|
||||
if (profileName == rh.gs(R.string.active)) {
|
||||
specificProfile = profileFunction.getProfile()
|
||||
|
@ -424,7 +419,8 @@ class WizardDialog : DaggerDialogFragment() {
|
|||
|
||||
val carbTime = SafeParse.stringToInt(binding.carbTimeInput.text)
|
||||
|
||||
wizard = BolusWizard(injector).doCalc(specificProfile, profileName, tempTarget, carbsAfterConstraint, cob, bg, correction, sp.getInt(R.string.key_boluswizard_percentage, 100),
|
||||
wizard = BolusWizard(injector).doCalc(
|
||||
specificProfile, profileName, tempTarget, carbsAfterConstraint, cob, bg, correction, sp.getInt(R.string.key_boluswizard_percentage, 100),
|
||||
binding.bgCheckbox.isChecked,
|
||||
binding.cobCheckbox.isChecked,
|
||||
binding.iobCheckbox.isChecked,
|
||||
|
|
|
@ -403,21 +403,26 @@
|
|||
android:layout_gravity="center_horizontal"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:labelFor="@id/profile"
|
||||
android:padding="10dp"
|
||||
android:text="@string/profile_label"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/profile"
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
android:layout_weight="0.5" />
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:hint="@string/profile"
|
||||
android:paddingStart="7dp"
|
||||
android:layout_weight="0.5"
|
||||
app:boxStrokeColor="@color/list_delimiter">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
|
||||
android:id="@+id/profileList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:enabled="false"
|
||||
tools:ignore="KeyboardInaccessibleWidget" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/sb_checkbox"
|
||||
|
|
Loading…
Reference in a new issue