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.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(
|
||||||
?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, binding.okcancel.ok,
|
savedInstanceState?.getDouble("duration")
|
||||||
textWatcher)
|
?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, binding.okcancel.ok,
|
||||||
binding.percentage.setParams(savedInstanceState?.getDouble("percentage")
|
textWatcher
|
||||||
?: 100.0, Constants.CPP_MIN_PERCENTAGE.toDouble(), Constants.CPP_MAX_PERCENTAGE.toDouble(), 5.0,
|
)
|
||||||
DecimalFormat("0"), false, binding.okcancel.ok, textWatcher)
|
binding.percentage.setParams(
|
||||||
binding.timeshift.setParams(savedInstanceState?.getDouble("timeshift")
|
savedInstanceState?.getDouble("percentage")
|
||||||
?: 0.0, Constants.CPP_MIN_TIMESHIFT.toDouble(), Constants.CPP_MAX_TIMESHIFT.toDouble(), 1.0, DecimalFormat("0"), false, binding.okcancel.ok)
|
?: 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
|
||||||
|
)
|
||||||
|
|
||||||
// profile
|
// profile
|
||||||
context?.let { context ->
|
context?.let { context ->
|
||||||
|
@ -117,16 +126,17 @@ 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)
|
||||||
binding.reuselayout.visibility = View.VISIBLE
|
if (profile.value.originalPercentage != 100 || profile.value.originalTimeshift != 0L) {
|
||||||
binding.reusebutton.text = resourceHelper.gs(R.string.reuse_profile_pct_hours, profile.percentage, profile.timeshift)
|
binding.reuselayout.visibility = View.VISIBLE
|
||||||
binding.reusebutton.setOnClickListener {
|
binding.reusebutton.text = resourceHelper.gs(R.string.reuse_profile_pct_hours, profile.value.originalPercentage, T.msecs(profile.value.originalTimeshift).hours().toInt())
|
||||||
binding.percentage.value = profile.percentage.toDouble()
|
binding.reusebutton.setOnClickListener {
|
||||||
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
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
binding.reuselayout.visibility = View.GONE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
binding.ttLayout.visibility = View.GONE
|
binding.ttLayout.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
@ -171,38 +181,43 @@ 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,
|
||||||
ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged },
|
ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged },
|
||||||
ValueWithUnit.SimpleString(profileName),
|
ValueWithUnit.SimpleString(profileName),
|
||||||
ValueWithUnit.Percent(percent),
|
ValueWithUnit.Percent(percent),
|
||||||
ValueWithUnit.Hour(timeShift).takeIf { timeShift != 0 },
|
ValueWithUnit.Hour(timeShift).takeIf { timeShift != 0 },
|
||||||
ValueWithUnit.Minute(duration).takeIf { duration != 0 })
|
ValueWithUnit.Minute(duration).takeIf { duration != 0 })
|
||||||
if (percent == 90 && duration == 10) sp.putBoolean(R.string.key_objectiveuseprofileswitch, true)
|
if (percent == 90 && duration == 10) sp.putBoolean(R.string.key_objectiveuseprofileswitch, true)
|
||||||
if (isTT) {
|
if (isTT) {
|
||||||
disposable += repository.runTransactionForResult(
|
disposable += repository.runTransactionForResult(
|
||||||
InsertAndCancelCurrentTemporaryTargetTransaction(
|
InsertAndCancelCurrentTemporaryTargetTransaction(
|
||||||
timestamp = eventTime,
|
timestamp = eventTime,
|
||||||
duration = TimeUnit.MINUTES.toMillis(duration.toLong()),
|
duration = TimeUnit.MINUTES.toMillis(duration.toLong()),
|
||||||
reason = TemporaryTarget.Reason.ACTIVITY,
|
reason = TemporaryTarget.Reason.ACTIVITY,
|
||||||
lowTarget = Profile.toMgdl(target, profileFunction.getUnits()),
|
lowTarget = Profile.toMgdl(target, profileFunction.getUnits()),
|
||||||
highTarget = Profile.toMgdl(target, profileFunction.getUnits())
|
highTarget = Profile.toMgdl(target, profileFunction.getUnits())
|
||||||
)
|
)
|
||||||
).subscribe({ result ->
|
).subscribe({ result ->
|
||||||
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
|
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
|
||||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
|
||||||
}, {
|
}, {
|
||||||
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 {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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,9 +49,11 @@ 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) {
|
||||||
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
|
if (comparator.value.check(profile.value.originalPercentage.toDouble(), pct.value)) {
|
||||||
return true
|
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
aapsLogger.debug(LTag.AUTOMATION, "NOT ready for execution: " + friendlyDescription())
|
aapsLogger.debug(LTag.AUTOMATION, "NOT ready for execution: " + friendlyDescription())
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in a new issue