fix TriggerProfilePercent and ProfileDialog

This commit is contained in:
Milos Kozak 2021-10-25 18:09:53 +02:00
parent 4c4122c6a6
commit 8efa66f23d
3 changed files with 64 additions and 64 deletions

View file

@ -29,6 +29,7 @@ import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.HardLimits import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
@ -78,8 +79,10 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
savedInstanceState.putDouble("timeshift", binding.timeshift.value) savedInstanceState.putDouble("timeshift", binding.timeshift.value)
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(
savedInstanceState: Bundle?): View { inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
onCreateViewGeneral() onCreateViewGeneral()
arguments?.let { bundle -> arguments?.let { bundle ->
profileIndex = bundle.getInt("profileIndex", 0) profileIndex = bundle.getInt("profileIndex", 0)
@ -91,14 +94,20 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding.duration.setParams(savedInstanceState?.getDouble("duration") binding.duration.setParams(
savedInstanceState?.getDouble("duration")
?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, binding.okcancel.ok, ?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, binding.okcancel.ok,
textWatcher) textWatcher
binding.percentage.setParams(savedInstanceState?.getDouble("percentage") )
binding.percentage.setParams(
savedInstanceState?.getDouble("percentage")
?: 100.0, Constants.CPP_MIN_PERCENTAGE.toDouble(), Constants.CPP_MAX_PERCENTAGE.toDouble(), 5.0, ?: 100.0, Constants.CPP_MIN_PERCENTAGE.toDouble(), Constants.CPP_MAX_PERCENTAGE.toDouble(), 5.0,
DecimalFormat("0"), false, binding.okcancel.ok, textWatcher) DecimalFormat("0"), false, binding.okcancel.ok, textWatcher
binding.timeshift.setParams(savedInstanceState?.getDouble("timeshift") )
?: 0.0, Constants.CPP_MIN_TIMESHIFT.toDouble(), Constants.CPP_MAX_TIMESHIFT.toDouble(), 1.0, DecimalFormat("0"), false, binding.okcancel.ok) binding.timeshift.setParams(
savedInstanceState?.getDouble("timeshift")
?: 0.0, Constants.CPP_MIN_TIMESHIFT.toDouble(), Constants.CPP_MAX_TIMESHIFT.toDouble(), 1.0, DecimalFormat("0"), false, binding.okcancel.ok
)
// profile // profile
context?.let { context -> context?.let { context ->
@ -117,12 +126,13 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
} ?: return } ?: return
profileFunction.getProfile()?.let { profile -> profileFunction.getProfile()?.let { profile ->
if (profile.percentage != 100 || profile.timeshift != 0) { if (profile is ProfileSealed.EPS)
if (profile.value.originalPercentage != 100 || profile.value.originalTimeshift != 0L) {
binding.reuselayout.visibility = View.VISIBLE binding.reuselayout.visibility = View.VISIBLE
binding.reusebutton.text = resourceHelper.gs(R.string.reuse_profile_pct_hours, profile.percentage, profile.timeshift) binding.reusebutton.text = resourceHelper.gs(R.string.reuse_profile_pct_hours, profile.value.originalPercentage, T.msecs(profile.value.originalTimeshift).hours().toInt())
binding.reusebutton.setOnClickListener { binding.reusebutton.setOnClickListener {
binding.percentage.value = profile.percentage.toDouble() binding.percentage.value = profile.value.originalPercentage.toDouble()
binding.timeshift.value = profile.timeshift.toDouble() binding.timeshift.value = profile.value.originalTimeshift.toDouble()
} }
} else { } else {
binding.reuselayout.visibility = View.GONE binding.reuselayout.visibility = View.GONE
@ -171,12 +181,14 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
val validity = ProfileSealed.PS(ps).isValid(resourceHelper.gs(R.string.careportal_profileswitch), activePlugin.activePump, config, resourceHelper, rxBus, hardLimits, false) val validity = ProfileSealed.PS(ps).isValid(resourceHelper.gs(R.string.careportal_profileswitch), activePlugin.activePump, config, resourceHelper, rxBus, hardLimits, false)
if (validity.isValid) if (validity.isValid)
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
profileFunction.createProfileSwitch(profileStore, profileFunction.createProfileSwitch(
profileStore,
profileName = profileName, profileName = profileName,
durationInMinutes = duration, durationInMinutes = duration,
percentage = percent, percentage = percent,
timeShiftInHours = timeShift, timeShiftInHours = timeShift,
timestamp = eventTime) timestamp = eventTime
)
uel.log(Action.PROFILE_SWITCH, uel.log(Action.PROFILE_SWITCH,
Sources.ProfileSwitchDialog, Sources.ProfileSwitchDialog,
notes, notes,
@ -201,8 +213,11 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
}, { }, {
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it) aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
}) })
uel.log(Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason( uel.log(
TemporaryTarget.Reason.ACTIVITY), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration)) Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason(
TemporaryTarget.Reason.ACTIVITY
), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration)
)
} }
}) })
else { else {

View file

@ -75,37 +75,19 @@
android:id="@+id/reuselayout" android:id="@+id/reuselayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" android:orientation="horizontal"
android:visibility="gone"> android:visibility="visible">
<TextView <info.nightscout.androidaps.utils.ui.SingleClickButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="120dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text=""
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="bold" />
<Button
android:id="@+id/reusebutton" android:id="@+id/reusebutton"
style="?android:attr/buttonStyle"
android:drawablePadding="10dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_clone"
android:text="@string/reuse_profile_pct_hours" /> android:text="@string/reuse_profile_pct_hours" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="start"
android:minWidth="45dp"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:text=" "
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

View file

@ -4,6 +4,7 @@ import android.widget.LinearLayout
import com.google.common.base.Optional import com.google.common.base.Optional
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.automation.R
import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.general.automation.elements.Comparator import info.nightscout.androidaps.plugins.general.automation.elements.Comparator
import info.nightscout.androidaps.plugins.general.automation.elements.InputPercent import info.nightscout.androidaps.plugins.general.automation.elements.InputPercent
@ -48,10 +49,12 @@ class TriggerProfilePercent(injector: HasAndroidInjector) : Trigger(injector) {
aapsLogger.debug(LTag.AUTOMATION, "NOT ready for execution: " + friendlyDescription()) aapsLogger.debug(LTag.AUTOMATION, "NOT ready for execution: " + friendlyDescription())
return false return false
} }
if (comparator.value.check(profile.percentage.toDouble(), pct.value)) { if (profile is ProfileSealed.EPS) {
if (comparator.value.check(profile.value.originalPercentage.toDouble(), pct.value)) {
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription()) aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
return true return true
} }
}
aapsLogger.debug(LTag.AUTOMATION, "NOT ready for execution: " + friendlyDescription()) aapsLogger.debug(LTag.AUTOMATION, "NOT ready for execution: " + friendlyDescription())
return false return false
} }