chore: treatments menu code cleanup
This commit is contained in:
parent
67e5fb8dc7
commit
967d8bb9d3
8 changed files with 61 additions and 70 deletions
|
@ -86,7 +86,6 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
private var showInvalidated = false
|
||||
private var removeActionMode: ActionMode? = null
|
||||
|
||||
// val TAG = "TreatmentMenu"
|
||||
private var toolbar: Toolbar? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
|
@ -128,7 +127,8 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
fun swapAdapter() {
|
||||
val now = System.currentTimeMillis()
|
||||
|
||||
disposable += if (showInvalidated)
|
||||
disposable +=
|
||||
if (showInvalidated)
|
||||
carbsMealLinksWithInvalid(now)
|
||||
.zipWith(bolusMealLinksWithInvalid(now)) { first, second -> first + second }
|
||||
.zipWith(calcResultMealLinksWithInvalid(now)) { first, second -> first + second }
|
||||
|
@ -262,10 +262,10 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
}
|
||||
removeActionMode?.title = rh.gs(R.string.count_selected, selectedItems.size)
|
||||
}
|
||||
holder.binding.cbBolusRemove.visibility = ((ml.bolus?.isValid == true) && (removeActionMode != null)).toVisibility()
|
||||
holder.binding.cbBolusRemove.visibility = ((ml.bolus?.isValid == true) && removeActionMode != null).toVisibility()
|
||||
holder.binding.cbBolusRemove.setOnCheckedChangeListener(onChange)
|
||||
|
||||
holder.binding.cbCarbsRemove.visibility = (ml.carbs?.isValid == true && (removeActionMode != null)).toVisibility()
|
||||
holder.binding.cbCarbsRemove.visibility = (ml.carbs?.isValid == true && removeActionMode != null).toVisibility()
|
||||
holder.binding.cbCarbsRemove.setOnCheckedChangeListener(onChange)
|
||||
|
||||
holder.binding.calculation.tag = ml
|
||||
|
@ -310,8 +310,8 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> {
|
||||
removeActionMode = toolbar?.startActionMode(RemoveActionModeCallback())
|
||||
true
|
||||
|
@ -335,15 +335,14 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
R.id.nav_refresh_ns -> {
|
||||
refreshFromNightScout()
|
||||
refreshFromNightscout()
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshFromNightScout() {
|
||||
private fun refreshFromNightscout() {
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.refresheventsfromnightscout) + "?") {
|
||||
uel.log(Action.TREATMENTS_NS_REFRESH, Sources.Treatments)
|
||||
|
@ -457,13 +456,11 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
val mealLink = selectedItems.first()
|
||||
val bolus = mealLink.bolus
|
||||
if (bolus != null)
|
||||
return rh.gs(R.string.configbuilder_insulin) + ": " +
|
||||
rh.gs(R.string.formatinsulinunits, bolus.amount) + "\n" +
|
||||
return rh.gs(R.string.configbuilder_insulin) + ": " + rh.gs(R.string.formatinsulinunits, bolus.amount) + "\n" +
|
||||
rh.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(bolus.timestamp)
|
||||
val carbs = mealLink.carbs
|
||||
if (carbs != null)
|
||||
return rh.gs(R.string.carbs) + ": " +
|
||||
rh.gs(R.string.carbs) + ": " + rh.gs(R.string.format_carbs, carbs.amount.toInt()) + "\n" +
|
||||
return rh.gs(R.string.carbs) + ": " + rh.gs(R.string.format_carbs, carbs.amount.toInt()) + "\n" +
|
||||
rh.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(carbs.timestamp)
|
||||
}
|
||||
return rh.gs(R.string.confirm_remove_multiple_items, selectedItems.size)
|
||||
|
@ -499,9 +496,6 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
)
|
||||
}
|
||||
}
|
||||
selectedItems = mutableListOf()
|
||||
}, Runnable {
|
||||
selectedItems = mutableListOf()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
holder.binding.duration.text = if (therapyEvent.duration == 0L) "" else dateUtil.niceTimeScalar(therapyEvent.duration, rh)
|
||||
holder.binding.note.text = therapyEvent.note
|
||||
holder.binding.type.text = translator.translate(therapyEvent.type)
|
||||
holder.binding.cbRemove.visibility = (therapyEvent.isValid && (removeActionMode != null)).toVisibility()
|
||||
holder.binding.cbRemove.visibility = (therapyEvent.isValid && removeActionMode != null).toVisibility()
|
||||
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
||||
if (value) {
|
||||
selectedItems.add(therapyEvent)
|
||||
|
@ -193,7 +193,6 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
|
||||
}
|
||||
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.menu_treatments_careportal, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
|
@ -208,8 +207,8 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> {
|
||||
removeActionMode = toolbar?.startActionMode(RemoveActionModeCallback())
|
||||
true
|
||||
|
@ -239,7 +238,6 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemoveActionModeCallback : ActionMode.Callback {
|
||||
|
||||
|
|
|
@ -67,7 +67,6 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
|
|||
private var showInvalidated = false
|
||||
private var removeActionMode: ActionMode? = null
|
||||
private var toolbar: Toolbar? = null
|
||||
// val TAG = "TreatmentMenu"
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
TreatmentsExtendedbolusFragmentBinding.inflate(inflater, container, false).also { _binding = it }.root
|
||||
|
@ -149,7 +148,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
|
|||
holder.binding.iob.text = rh.gs(R.string.formatinsulinunits, iob.iob)
|
||||
holder.binding.ratio.text = rh.gs(R.string.pump_basebasalrate, extendedBolus.rate)
|
||||
if (iob.iob != 0.0) holder.binding.iob.setTextColor(rh.gc(R.color.colorActive)) else holder.binding.iob.setTextColor(holder.binding.insulin.currentTextColor)
|
||||
holder.binding.cbRemove.visibility = (extendedBolus.isValid && (removeActionMode != null)).toVisibility()
|
||||
holder.binding.cbRemove.visibility = (extendedBolus.isValid && removeActionMode != null).toVisibility()
|
||||
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
||||
if (value) {
|
||||
selectedItems.add(extendedBolus)
|
||||
|
|
|
@ -188,7 +188,8 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
holder.binding.date.text = dateUtil.dateString(profileSwitch.timestamp)
|
||||
holder.binding.time.text = dateUtil.timeString(profileSwitch.timestamp)
|
||||
holder.binding.duration.text = rh.gs(R.string.format_mins, T.msecs(profileSwitch.duration ?: 0L).mins())
|
||||
holder.binding.name.text = if (profileSwitch is ProfileSealed.PS) profileSwitch.value.getCustomizedName() else if (profileSwitch is ProfileSealed.EPS) profileSwitch.value.originalCustomizedName else ""
|
||||
holder.binding.name.text = if (profileSwitch is ProfileSealed.PS) profileSwitch.value.getCustomizedName()
|
||||
else if (profileSwitch is ProfileSealed.EPS) profileSwitch.value.originalCustomizedName else ""
|
||||
if (profileSwitch.isInProgress(dateUtil)) holder.binding.date.setTextColor(rh.gc(R.color.colorActive))
|
||||
else holder.binding.date.setTextColor(holder.binding.duration.currentTextColor)
|
||||
holder.binding.clone.tag = profileSwitch
|
||||
|
@ -282,8 +283,8 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> {
|
||||
removeActionMode = toolbar?.startActionMode(RemoveActionModeCallback())
|
||||
true
|
||||
|
@ -308,7 +309,6 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemoveActionModeCallback : ActionMode.Callback {
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
val tempTarget = tempTargetList[position]
|
||||
holder.binding.ns.visibility = (tempTarget.interfaceIDs.nightscoutId != null).toVisibility()
|
||||
holder.binding.invalid.visibility = tempTarget.isValid.not().toVisibility()
|
||||
holder.binding.cbRemove.visibility = (tempTarget.isValid && (removeActionMode != null)).toVisibility()
|
||||
holder.binding.cbRemove.visibility = (tempTarget.isValid && removeActionMode != null).toVisibility()
|
||||
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
||||
if (value) {
|
||||
selectedItems.add(tempTarget)
|
||||
|
@ -211,7 +211,6 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
private fun removeSelected() {
|
||||
// TODO check if item should not be delete val profile = profileFunction.getProfile(dateUtil.now()) == null
|
||||
if (selectedItems.size > 0)
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(), Runnable {
|
||||
|
@ -247,8 +246,8 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> {
|
||||
removeActionMode = toolbar?.startActionMode(RemoveActionModeCallback())
|
||||
true
|
||||
|
@ -273,7 +272,6 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemoveActionModeCallback : ActionMode.Callback {
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
holder.binding.emulatedSuspendFlag.visibility = (tempBasal.type == TemporaryBasal.Type.EMULATED_PUMP_SUSPEND).toVisibility()
|
||||
holder.binding.superBolusFlag.visibility = (tempBasal.type == TemporaryBasal.Type.SUPERBOLUS).toVisibility()
|
||||
if (abs(iob.basaliob) > 0.01) holder.binding.iob.setTextColor(rh.gc(R.color.colorActive)) else holder.binding.iob.setTextColor(holder.binding.duration.currentTextColor)
|
||||
holder.binding.cbRemove.visibility = (tempBasal.isValid && (removeActionMode != null)).toVisibility()
|
||||
holder.binding.cbRemove.visibility = (tempBasal.isValid && removeActionMode != null).toVisibility()
|
||||
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
||||
if (value) {
|
||||
selectedItems.add(tempBasal)
|
||||
|
@ -226,8 +226,8 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> {
|
||||
removeActionMode = toolbar?.startActionMode(RemoveActionModeCallback())
|
||||
true
|
||||
|
@ -247,7 +247,6 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemoveActionModeCallback : ActionMode.Callback {
|
||||
|
||||
|
|
|
@ -53,8 +53,7 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
|||
private var showLoop = false
|
||||
private var _binding: TreatmentsUserEntryFragmentBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
// This property is only valid between onCreateView and onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
|
@ -164,8 +163,8 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
|||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_show_loop -> {
|
||||
showLoop = true
|
||||
rxBus.send(EventTreatmentUpdateGui())
|
||||
|
@ -186,4 +185,3 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
|||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#FFFFFF"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z" />
|
||||
</vector>
|
||||
|
|
Loading…
Reference in a new issue