Merge pull request #1235 from Andries-Smit/fix/carbs-event-time
Fix carbs event time
This commit is contained in:
commit
65eb96a580
|
@ -105,6 +105,12 @@ class CarbsDialog : DialogFragmentWithDate() {
|
|||
): View {
|
||||
onCreateViewGeneral()
|
||||
_binding = DialogCarbsBinding.inflate(inflater, container, false)
|
||||
binding.time.setOnValueChangedListener { timeOffset: Double ->
|
||||
run {
|
||||
val newTime = eventTimeOriginal + timeOffset.toLong() * 1000 * 60
|
||||
updateDateTime(newTime)
|
||||
}
|
||||
}
|
||||
return binding.root
|
||||
}
|
||||
|
||||
|
@ -159,6 +165,13 @@ class CarbsDialog : DialogFragmentWithDate() {
|
|||
validateInputs()
|
||||
}
|
||||
|
||||
setOnValueChangedListener { eventTime: Long ->
|
||||
run {
|
||||
val timeOffset = ((eventTime - eventTimeOriginal) / (1000 * 60)).toDouble()
|
||||
binding.time.value = timeOffset
|
||||
}
|
||||
}
|
||||
|
||||
iobCobCalculator.ads.actualBg()?.let { bgReading ->
|
||||
if (bgReading.value < 72)
|
||||
binding.hypoTt.isChecked = true
|
||||
|
@ -229,10 +242,6 @@ class CarbsDialog : DialogFragmentWithDate() {
|
|||
)
|
||||
|
||||
val timeOffset = binding.time.value.toInt()
|
||||
eventTime -= eventTime % 1000
|
||||
val time = eventTime + timeOffset * 1000 * 60
|
||||
if (timeOffset != 0)
|
||||
actions.add(rh.gs(R.string.time) + ": " + dateUtil.dateAndTimeString(time))
|
||||
if (useAlarm && carbs > 0 && timeOffset > 0)
|
||||
actions.add(rh.gs(R.string.alarminxmin, timeOffset).formatColor(rh, R.color.info))
|
||||
val duration = binding.duration.value.toInt()
|
||||
|
@ -330,7 +339,7 @@ class CarbsDialog : DialogFragmentWithDate() {
|
|||
detailedBolusInfo.context = context
|
||||
detailedBolusInfo.notes = notes
|
||||
detailedBolusInfo.carbsDuration = T.hours(duration.toLong()).msecs()
|
||||
detailedBolusInfo.carbsTimestamp = time
|
||||
detailedBolusInfo.carbsTimestamp = eventTime
|
||||
uel.log(if (duration == 0) Action.CARBS else Action.EXTENDED_CARBS, Sources.CarbDialog,
|
||||
notes,
|
||||
ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged },
|
||||
|
|
|
@ -81,11 +81,11 @@
|
|||
android:layout_gravity="center_horizontal"
|
||||
android:width="120dp"
|
||||
android:padding="10dp"
|
||||
android:text="@string/time"
|
||||
android:text="@string/time_offset"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<info.nightscout.androidaps.utils.ui.NumberPicker
|
||||
<info.nightscout.androidaps.utils.ui.MinutesNumberPicker
|
||||
android:id="@+id/time"
|
||||
android:layout_width="130dp"
|
||||
android:layout_height="40dp" />
|
||||
|
|
|
@ -27,8 +27,18 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() {
|
|||
@Inject lateinit var sp: SP
|
||||
@Inject lateinit var dateUtil: DateUtil
|
||||
|
||||
fun interface OnValueChangedListener {
|
||||
fun onValueChanged(value: Long)
|
||||
}
|
||||
|
||||
var eventTime: Long = 0
|
||||
var eventTimeChanged = false
|
||||
var eventTimeOriginal: Long = 0
|
||||
val eventTimeChanged: Boolean
|
||||
get() = eventTime != eventTimeOriginal
|
||||
|
||||
var eventDateView: TextView? = null
|
||||
var eventTimeView: TextView? = null
|
||||
private var mOnValueChangedListener: OnValueChangedListener? = null
|
||||
|
||||
//one shot guards
|
||||
private var okClicked: Boolean = false
|
||||
|
@ -50,7 +60,7 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() {
|
|||
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
||||
super.onSaveInstanceState(savedInstanceState)
|
||||
savedInstanceState.putLong("eventTime", eventTime)
|
||||
savedInstanceState.putBoolean("eventTimeChanged", eventTimeChanged)
|
||||
savedInstanceState.putLong("eventTimeOriginal", eventTimeOriginal)
|
||||
}
|
||||
|
||||
fun onCreateViewGeneral() {
|
||||
|
@ -60,12 +70,18 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() {
|
|||
dialog?.setCanceledOnTouchOutside(false)
|
||||
}
|
||||
|
||||
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?
|
||||
fun updateDateTime(timeMs: Long) {
|
||||
eventTime = timeMs
|
||||
eventDateView?.text = dateUtil.dateString(eventTime)
|
||||
eventTimeView?.text = dateUtil.timeString(eventTime)
|
||||
}
|
||||
|
||||
eventTime = savedInstanceState?.getLong("eventTime") ?: dateUtil.nowWithoutMilliseconds()
|
||||
eventTimeChanged = savedInstanceState?.getBoolean("eventTimeChanged") ?: false
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
eventDateView = view.findViewById(R.id.eventdate) as TextView?
|
||||
eventTimeView = view.findViewById(R.id.eventtime) as TextView?
|
||||
|
||||
eventTimeOriginal = savedInstanceState?.getLong("eventTimeOriginal") ?: dateUtil.nowWithoutMilliseconds()
|
||||
eventTime = savedInstanceState?.getLong("eventTime") ?: eventTimeOriginal
|
||||
|
||||
eventDateView?.text = dateUtil.dateString(eventTime)
|
||||
eventTimeView?.text = dateUtil.timeString(eventTime)
|
||||
|
@ -79,8 +95,8 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() {
|
|||
cal.set(Calendar.MONTH, monthOfYear)
|
||||
cal.set(Calendar.DAY_OF_MONTH, dayOfMonth)
|
||||
eventTime = cal.timeInMillis
|
||||
eventTimeChanged = true
|
||||
eventDateView?.text = dateUtil.dateString(eventTime)
|
||||
callValueChangedListener()
|
||||
}
|
||||
|
||||
eventDateView?.setOnClickListener {
|
||||
|
@ -107,8 +123,8 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() {
|
|||
seconds++
|
||||
) // randomize seconds to prevent creating record of the same time, if user choose time manually
|
||||
eventTime = cal.timeInMillis
|
||||
eventTimeChanged = true
|
||||
eventTimeView?.text = dateUtil.timeString(eventTime)
|
||||
callValueChangedListener()
|
||||
}
|
||||
|
||||
eventTimeView?.setOnClickListener {
|
||||
|
@ -150,6 +166,14 @@ abstract class DialogFragmentWithDate : DaggerDialogFragment() {
|
|||
|
||||
}
|
||||
|
||||
private fun callValueChangedListener() {
|
||||
mOnValueChangedListener?.onValueChanged(eventTime)
|
||||
}
|
||||
|
||||
fun setOnValueChangedListener(onValueChangedListener: OnValueChangedListener?) {
|
||||
mOnValueChangedListener = onValueChangedListener
|
||||
}
|
||||
|
||||
override fun show(manager: FragmentManager, tag: String?) {
|
||||
try {
|
||||
manager.beginTransaction().let {
|
||||
|
|
Loading…
Reference in a new issue