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