ExtendedBolusDialog -> jetpack
This commit is contained in:
parent
d376ee2229
commit
f1f0703a88
4 changed files with 47 additions and 30 deletions
|
@ -8,6 +8,8 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import android.view.WindowManager
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import dagger.android.support.DaggerDialogFragment
|
||||
import info.nightscout.androidaps.R
|
||||
|
@ -16,9 +18,6 @@ import info.nightscout.androidaps.logging.LTag
|
|||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.extensions.toVisibility
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import kotlinx.android.synthetic.main.datetime.*
|
||||
import kotlinx.android.synthetic.main.notes.*
|
||||
import kotlinx.android.synthetic.main.okcancel.*
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -58,10 +57,14 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() {
|
|||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
val eventDateView = view.findViewById(R.id.eventdate) as TextView
|
||||
val eventTimeView = view.findViewById(R.id.eventtime) as TextView
|
||||
|
||||
eventTime = savedInstanceState?.getLong("eventTime") ?: DateUtil.now()
|
||||
eventTimeChanged = savedInstanceState?.getBoolean("eventTimeChanged") ?: false
|
||||
overview_eventdate?.text = DateUtil.dateString(eventTime)
|
||||
overview_eventtime?.text = dateUtil.timeString(eventTime)
|
||||
|
||||
eventDateView.text = DateUtil.dateString(eventTime)
|
||||
eventTimeView.text = dateUtil.timeString(eventTime)
|
||||
|
||||
// create an OnDateSetListener
|
||||
val dateSetListener = DatePickerDialog.OnDateSetListener { _, year, monthOfYear, dayOfMonth ->
|
||||
|
@ -72,10 +75,10 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() {
|
|||
cal.set(Calendar.DAY_OF_MONTH, dayOfMonth)
|
||||
eventTime = cal.timeInMillis
|
||||
eventTimeChanged = true
|
||||
overview_eventdate?.text = DateUtil.dateString(eventTime)
|
||||
eventDateView.text = DateUtil.dateString(eventTime)
|
||||
}
|
||||
|
||||
overview_eventdate?.setOnClickListener {
|
||||
eventDateView.setOnClickListener {
|
||||
context?.let {
|
||||
val cal = Calendar.getInstance()
|
||||
cal.timeInMillis = eventTime
|
||||
|
@ -96,10 +99,10 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() {
|
|||
cal.set(Calendar.SECOND, seconds++) // randomize seconds to prevent creating record of the same time, if user choose time manually
|
||||
eventTime = cal.timeInMillis
|
||||
eventTimeChanged = true
|
||||
overview_eventtime?.text = dateUtil.timeString(eventTime)
|
||||
eventTimeView.text = dateUtil.timeString(eventTime)
|
||||
}
|
||||
|
||||
overview_eventtime?.setOnClickListener {
|
||||
eventTimeView.setOnClickListener {
|
||||
context?.let {
|
||||
val cal = Calendar.getInstance()
|
||||
cal.timeInMillis = eventTime
|
||||
|
@ -111,9 +114,9 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
notes_layout?.visibility = sp.getBoolean(R.string.key_show_notes_entry_dialogs, false).toVisibility()
|
||||
(view.findViewById(R.id.notes_layout) as View).visibility = sp.getBoolean(R.string.key_show_notes_entry_dialogs, false).toVisibility()
|
||||
|
||||
ok.setOnClickListener {
|
||||
(view.findViewById(R.id.ok) as Button).setOnClickListener {
|
||||
synchronized(okClicked) {
|
||||
if (okClicked) {
|
||||
aapsLogger.warn(LTag.UI, "guarding: ok already clicked")
|
||||
|
@ -124,7 +127,7 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() {
|
|||
}
|
||||
}
|
||||
}
|
||||
cancel.setOnClickListener { dismiss() }
|
||||
(view.findViewById(R.id.cancel) as Button).setOnClickListener { dismiss() }
|
||||
}
|
||||
|
||||
override fun show(manager: FragmentManager, tag: String?) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.view.ViewGroup
|
|||
import com.google.common.base.Joiner
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.activities.ErrorHelperActivity
|
||||
import info.nightscout.androidaps.databinding.DialogExtendedbolusBinding
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
||||
import info.nightscout.androidaps.interfaces.Constraint
|
||||
|
@ -19,8 +20,6 @@ import info.nightscout.androidaps.utils.SafeParse
|
|||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.extensions.formatColor
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import kotlinx.android.synthetic.main.dialog_extendedbolus.*
|
||||
import kotlinx.android.synthetic.main.okcancel.*
|
||||
import java.text.DecimalFormat
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
@ -34,16 +33,23 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
|
|||
@Inject lateinit var commandQueue: CommandQueueProvider
|
||||
@Inject lateinit var activePlugin: ActivePluginProvider
|
||||
|
||||
private var _binding: DialogExtendedbolusBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
||||
super.onSaveInstanceState(savedInstanceState)
|
||||
savedInstanceState.putDouble("actions_extendedbolus_insulin", actions_extendedbolus_insulin.value)
|
||||
savedInstanceState.putDouble("actions_extendedbolus_duration", actions_extendedbolus_duration.value)
|
||||
savedInstanceState.putDouble("insulin", binding.insulin.value)
|
||||
savedInstanceState.putDouble("duration", binding.duration.value)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
savedInstanceState: Bundle?): View {
|
||||
onCreateViewGeneral()
|
||||
return inflater.inflate(R.layout.dialog_extendedbolus, container, false)
|
||||
_binding = DialogExtendedbolusBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
@ -53,18 +59,24 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
|
|||
|
||||
val maxInsulin = constraintChecker.getMaxExtendedBolusAllowed().value()
|
||||
val extendedStep = pumpDescription.extendedBolusStep
|
||||
actions_extendedbolus_insulin.setParams(savedInstanceState?.getDouble("actions_extendedbolus_insulin")
|
||||
?: extendedStep, extendedStep, maxInsulin, extendedStep, DecimalFormat("0.00"), false, ok)
|
||||
binding.insulin.setParams(savedInstanceState?.getDouble("insulin")
|
||||
?: extendedStep, extendedStep, maxInsulin, extendedStep, DecimalFormat("0.00"), false, binding.okcancel.ok)
|
||||
|
||||
val extendedDurationStep = pumpDescription.extendedBolusDurationStep
|
||||
val extendedMaxDuration = pumpDescription.extendedBolusMaxDuration
|
||||
actions_extendedbolus_duration.setParams(savedInstanceState?.getDouble("actions_extendedbolus_duration")
|
||||
?: extendedDurationStep, extendedDurationStep, extendedMaxDuration, extendedDurationStep, DecimalFormat("0"), false, ok)
|
||||
binding.duration.setParams(savedInstanceState?.getDouble("duration")
|
||||
?: extendedDurationStep, extendedDurationStep, extendedMaxDuration, extendedDurationStep, DecimalFormat("0"), false, binding.okcancel.ok)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
override fun submit(): Boolean {
|
||||
val insulin = SafeParse.stringToDouble(actions_extendedbolus_insulin?.text ?: return false)
|
||||
val durationInMinutes = actions_extendedbolus_duration.value.toInt()
|
||||
if (_binding == null) return false
|
||||
val insulin = SafeParse.stringToDouble(binding.insulin.text ?: return false)
|
||||
val durationInMinutes = binding.duration.value.toInt()
|
||||
val actions: LinkedList<String> = LinkedList()
|
||||
val insulinAfterConstraint = constraintChecker.applyExtendedBolusConstraints(Constraint(insulin)).value()
|
||||
actions.add(resourceHelper.gs(R.string.formatinsulinunits, insulinAfterConstraint))
|
||||
|
@ -73,7 +85,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
|
|||
actions.add(resourceHelper.gs(R.string.constraintapllied).formatColor(resourceHelper, R.color.warning))
|
||||
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.extended_bolus), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
||||
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.extended_bolus), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
|
||||
aapsLogger.debug("USER ENTRY: EXTENDED BOLUS $insulinAfterConstraint duration: $durationInMinutes")
|
||||
commandQueue.extendedBolus(insulinAfterConstraint, durationInMinutes, object : Callback() {
|
||||
override fun run() {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/overview_eventdate"
|
||||
android:id="@+id/eventdate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
|
@ -25,7 +25,7 @@
|
|||
android:text="2017/05/05" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/overview_eventtime"
|
||||
android:id="@+id/eventtime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
android:textStyle="bold" />
|
||||
|
||||
<info.nightscout.androidaps.utils.ui.NumberPicker
|
||||
android:id="@+id/actions_extendedbolus_insulin"
|
||||
android:id="@+id/insulin"
|
||||
android:layout_width="130dp"
|
||||
android:layout_height="40dp" />
|
||||
|
||||
|
@ -96,7 +96,7 @@
|
|||
android:textStyle="bold" />
|
||||
|
||||
<info.nightscout.androidaps.utils.ui.MinutesNumberPicker
|
||||
android:id="@+id/actions_extendedbolus_duration"
|
||||
android:id="@+id/duration"
|
||||
android:layout_width="130dp"
|
||||
android:layout_height="40dp" />
|
||||
|
||||
|
@ -114,7 +114,9 @@
|
|||
</LinearLayout>
|
||||
|
||||
|
||||
<include layout="@layout/okcancel" />
|
||||
<include
|
||||
android:id="@+id/okcancel"
|
||||
layout="@layout/okcancel" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
Loading…
Reference in a new issue