fix TriggerProfilePercent and ProfileDialog
This commit is contained in:
parent
4c4122c6a6
commit
8efa66f23d
3 changed files with 64 additions and 64 deletions
|
@ -29,6 +29,7 @@ import info.nightscout.androidaps.plugins.bus.RxBus
|
|||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||
import info.nightscout.androidaps.utils.HardLimits
|
||||
import info.nightscout.androidaps.utils.HtmlHelper
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
|
@ -78,8 +79,10 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
|
|||
savedInstanceState.putDouble("timeshift", binding.timeshift.value)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View {
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
onCreateViewGeneral()
|
||||
arguments?.let { bundle ->
|
||||
profileIndex = bundle.getInt("profileIndex", 0)
|
||||
|
@ -91,14 +94,20 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
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,
|
||||
textWatcher)
|
||||
binding.percentage.setParams(savedInstanceState?.getDouble("percentage")
|
||||
textWatcher
|
||||
)
|
||||
binding.percentage.setParams(
|
||||
savedInstanceState?.getDouble("percentage")
|
||||
?: 100.0, Constants.CPP_MIN_PERCENTAGE.toDouble(), Constants.CPP_MAX_PERCENTAGE.toDouble(), 5.0,
|
||||
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)
|
||||
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
|
||||
)
|
||||
|
||||
// profile
|
||||
context?.let { context ->
|
||||
|
@ -117,12 +126,13 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
|
|||
} ?: return
|
||||
|
||||
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.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.percentage.value = profile.percentage.toDouble()
|
||||
binding.timeshift.value = profile.timeshift.toDouble()
|
||||
binding.percentage.value = profile.value.originalPercentage.toDouble()
|
||||
binding.timeshift.value = profile.value.originalTimeshift.toDouble()
|
||||
}
|
||||
} else {
|
||||
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)
|
||||
if (validity.isValid)
|
||||
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
|
||||
profileFunction.createProfileSwitch(profileStore,
|
||||
profileFunction.createProfileSwitch(
|
||||
profileStore,
|
||||
profileName = profileName,
|
||||
durationInMinutes = duration,
|
||||
percentage = percent,
|
||||
timeShiftInHours = timeShift,
|
||||
timestamp = eventTime)
|
||||
timestamp = eventTime
|
||||
)
|
||||
uel.log(Action.PROFILE_SWITCH,
|
||||
Sources.ProfileSwitchDialog,
|
||||
notes,
|
||||
|
@ -201,8 +213,11 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
|
|||
}, {
|
||||
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
|
||||
})
|
||||
uel.log(Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason(
|
||||
TemporaryTarget.Reason.ACTIVITY), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration))
|
||||
uel.log(
|
||||
Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason(
|
||||
TemporaryTarget.Reason.ACTIVITY
|
||||
), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration)
|
||||
)
|
||||
}
|
||||
})
|
||||
else {
|
||||
|
|
|
@ -75,37 +75,19 @@
|
|||
android:id="@+id/reuselayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone">
|
||||
android:visibility="visible">
|
||||
|
||||
<TextView
|
||||
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
|
||||
<info.nightscout.androidaps.utils.ui.SingleClickButton
|
||||
android:id="@+id/reusebutton"
|
||||
style="?android:attr/buttonStyle"
|
||||
android:drawablePadding="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableStart="@drawable/ic_clone"
|
||||
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
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.widget.LinearLayout
|
|||
import com.google.common.base.Optional
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.automation.R
|
||||
import info.nightscout.androidaps.data.ProfileSealed
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.Comparator
|
||||
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())
|
||||
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())
|
||||
return true
|
||||
}
|
||||
}
|
||||
aapsLogger.debug(LTag.AUTOMATION, "NOT ready for execution: " + friendlyDescription())
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue