chore: treatment use shared actionModeHelper
This commit is contained in:
parent
47f835469d
commit
f4a65097e7
27 changed files with 482 additions and 579 deletions
|
@ -5,9 +5,6 @@ import android.graphics.Paint
|
|||
import android.os.Bundle
|
||||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import android.widget.CompoundButton
|
||||
import android.view.ActionMode
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.util.forEach
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
@ -38,9 +35,11 @@ import info.nightscout.androidaps.logging.UserEntryLogger
|
|||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData
|
||||
import info.nightscout.androidaps.utils.ActionModeHelper
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.ToastUtils
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
|
@ -71,8 +70,10 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
@Inject lateinit var activePlugin: ActivePlugin
|
||||
|
||||
private var _binding: TreatmentsBolusCarbsFragmentBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
private var menu: Menu? = null
|
||||
|
||||
class MealLink(
|
||||
val bolus: Bolus? = null,
|
||||
|
@ -81,21 +82,22 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
)
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
private lateinit var actionHelper: ActionModeHelper<MealLink>
|
||||
private val millsToThePast = T.days(30).msecs()
|
||||
|
||||
private var selectedItems: SparseArray<MealLink> = SparseArray()
|
||||
// private var selectedItems: SparseArray<MealLink> = SparseArray()
|
||||
private var showInvalidated = false
|
||||
private var removeActionMode: ActionMode? = null
|
||||
private var toolbar: Toolbar? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
TreatmentsBolusCarbsFragmentBinding.inflate(inflater, container, false).also { _binding = it }.root
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
actionHelper = ActionModeHelper(rh, activity)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
setHasOptionsMenu(true)
|
||||
toolbar = activity?.findViewById(R.id.toolbar)
|
||||
binding.recyclerview.setHasFixedSize(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||
}
|
||||
|
@ -183,13 +185,13 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
@Synchronized
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
actionHelper.finish()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
removeActionMode?.finish()
|
||||
binding.recyclerview.adapter = null // avoid leaks
|
||||
_binding = null
|
||||
}
|
||||
|
@ -242,6 +244,17 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
Bolus.Type.NORMAL -> rh.gs(R.string.mealbolus)
|
||||
Bolus.Type.PRIMING -> rh.gs(R.string.prime)
|
||||
}
|
||||
holder.binding.cbBolusRemove.visibility = (ml.bolus.isValid && actionHelper.isRemoving).toVisibility()
|
||||
if (actionHelper.isRemoving) {
|
||||
holder.binding.cbBolusRemove.setOnCheckedChangeListener { _, value ->
|
||||
actionHelper.updateSelection(position, ml, value)
|
||||
}
|
||||
holder.binding.root.setOnClickListener {
|
||||
holder.binding.cbBolusRemove.toggle()
|
||||
actionHelper.updateSelection(position, ml, holder.binding.cbBolusRemove.isChecked)
|
||||
}
|
||||
holder.binding.cbBolusRemove.isChecked = actionHelper.isSelected(position)
|
||||
}
|
||||
}
|
||||
// Carbs
|
||||
holder.binding.carbsLayout.visibility = (ml.carbs != null && (ml.carbs.isValid || showInvalidated)).toVisibility()
|
||||
|
@ -252,23 +265,19 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
holder.binding.carbsNs.visibility = (carbs.interfaceIDs.nightscoutId != null).toVisibility()
|
||||
holder.binding.carbsPump.visibility = (carbs.interfaceIDs.pumpId != null).toVisibility()
|
||||
holder.binding.carbsInvalid.visibility = carbs.isValid.not().toVisibility()
|
||||
}
|
||||
holder.binding.cbBolusRemove.visibility = (ml.bolus?.isValid == true && removeActionMode != null).toVisibility()
|
||||
holder.binding.cbCarbsRemove.visibility = (ml.carbs?.isValid == true && removeActionMode != null).toVisibility()
|
||||
if (removeActionMode != null) {
|
||||
val onChange = CompoundButton.OnCheckedChangeListener { _, value ->
|
||||
if (value) {
|
||||
selectedItems.put(position, ml)
|
||||
} else {
|
||||
selectedItems.remove(position)
|
||||
holder.binding.cbCarbsRemove.visibility = (ml.carbs.isValid && actionHelper.isRemoving).toVisibility()
|
||||
if (actionHelper.isRemoving) {
|
||||
holder.binding.cbCarbsRemove.setOnCheckedChangeListener { _, value ->
|
||||
actionHelper.updateSelection(position, ml, value)
|
||||
}
|
||||
removeActionMode?.title = rh.gs(R.string.count_selected, selectedItems.size())
|
||||
holder.binding.root.setOnClickListener {
|
||||
holder.binding.cbBolusRemove.toggle()
|
||||
actionHelper.updateSelection(position, ml, holder.binding.cbBolusRemove.isChecked)
|
||||
}
|
||||
holder.binding.cbCarbsRemove.isChecked = actionHelper.isSelected(position)
|
||||
}
|
||||
holder.binding.cbBolusRemove.setOnCheckedChangeListener(onChange)
|
||||
holder.binding.cbBolusRemove.isChecked = selectedItems.get(position) != null
|
||||
holder.binding.cbCarbsRemove.setOnCheckedChangeListener(onChange)
|
||||
holder.binding.cbCarbsRemove.isChecked = selectedItems.get(position) != null
|
||||
}
|
||||
|
||||
holder.binding.calculation.tag = ml
|
||||
val nextTimestamp = if (mealLinks.size != position + 1) timestamp(mealLinks[position + 1]) else 0L
|
||||
holder.binding.delimiter.visibility = dateUtil.isSameDayGroup(timestamp(ml), nextTimestamp).toVisibility()
|
||||
|
@ -296,13 +305,18 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
this.menu = menu
|
||||
inflater.inflate(R.menu.menu_treatments_carbs_bolus, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
private fun updateMenuVisibility() {
|
||||
menu?.findItem(R.id.nav_hide_invalidated)?.isVisible = showInvalidated
|
||||
menu?.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
menu.findItem(R.id.nav_hide_invalidated)?.isVisible = showInvalidated
|
||||
menu.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
updateMenuVisibility()
|
||||
val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_insulin, false) || !sp.getBoolean(R.string.key_ns_receive_carbs, false) || !buildHelper.isEngineeringMode()
|
||||
menu.findItem(R.id.nav_refresh_ns)?.isVisible = !nsUploadOnly
|
||||
val hasItems = (binding.recyclerview.adapter?.itemCount ?: 0) > 0
|
||||
|
@ -313,19 +327,20 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> {
|
||||
removeActionMode = toolbar?.startActionMode(RemoveActionModeCallback())
|
||||
true
|
||||
}
|
||||
R.id.nav_remove_items -> actionHelper.startRemove()
|
||||
|
||||
R.id.nav_show_invalidated -> {
|
||||
showInvalidated = true
|
||||
updateMenuVisibility()
|
||||
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records))
|
||||
rxBus.send(EventTreatmentUpdateGui())
|
||||
true
|
||||
}
|
||||
|
||||
R.id.nav_hide_invalidated -> {
|
||||
showInvalidated = false
|
||||
updateMenuVisibility()
|
||||
ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records))
|
||||
rxBus.send(EventTreatmentUpdateGui())
|
||||
true
|
||||
}
|
||||
|
@ -422,36 +437,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
inner class RemoveActionModeCallback : ActionMode.Callback {
|
||||
|
||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu?): Boolean {
|
||||
mode.menuInflater.inflate(R.menu.menu_delete_selection, menu)
|
||||
selectedItems.clear()
|
||||
mode.title = rh.gs(R.string.count_selected, selectedItems.size())
|
||||
binding.recyclerview.adapter?.notifyDataSetChanged()
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?) = false
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.remove_selected -> {
|
||||
removeSelected()
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyActionMode(mode: ActionMode?) {
|
||||
removeActionMode = null
|
||||
binding.recyclerview.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getConfirmationText(): String {
|
||||
private fun getConfirmationText(selectedItems: SparseArray<MealLink>): String {
|
||||
if (selectedItems.size() == 1) {
|
||||
val mealLink = selectedItems.valueAt(0)
|
||||
val bolus = mealLink.bolus
|
||||
|
@ -466,40 +452,38 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
return rh.gs(R.string.confirm_remove_multiple_items, selectedItems.size())
|
||||
}
|
||||
|
||||
fun removeSelected() {
|
||||
if (selectedItems.size() > 0)
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(), Runnable {
|
||||
selectedItems.forEach { _, ml ->
|
||||
ml.bolus?.let { bolus ->
|
||||
uel.log(
|
||||
Action.BOLUS_REMOVED, Sources.Treatments,
|
||||
ValueWithUnit.Timestamp(bolus.timestamp),
|
||||
ValueWithUnit.Insulin(bolus.amount)
|
||||
private fun removeSelected(selectedItems: SparseArray<MealLink>) {
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(selectedItems), Runnable {
|
||||
selectedItems.forEach { _, ml ->
|
||||
ml.bolus?.let { bolus ->
|
||||
uel.log(
|
||||
Action.BOLUS_REMOVED, Sources.Treatments,
|
||||
ValueWithUnit.Timestamp(bolus.timestamp),
|
||||
ValueWithUnit.Insulin(bolus.amount)
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateBolusTransaction(bolus.id))
|
||||
.subscribe(
|
||||
{ result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated bolus $it") } },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating bolus", it) }
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateBolusTransaction(bolus.id))
|
||||
.subscribe(
|
||||
{ result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated bolus $it") } },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating bolus", it) }
|
||||
)
|
||||
}
|
||||
ml.carbs?.let { carb ->
|
||||
uel.log(
|
||||
Action.CARBS_REMOVED, Sources.Treatments,
|
||||
ValueWithUnit.Timestamp(carb.timestamp),
|
||||
ValueWithUnit.Gram(carb.amount.toInt())
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateCarbsTransaction(carb.id))
|
||||
.subscribe(
|
||||
{ result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated carbs $it") } },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating carbs", it) }
|
||||
)
|
||||
}
|
||||
}
|
||||
removeActionMode?.finish()
|
||||
})
|
||||
}
|
||||
else
|
||||
removeActionMode?.finish()
|
||||
ml.carbs?.let { carb ->
|
||||
uel.log(
|
||||
Action.CARBS_REMOVED, Sources.Treatments,
|
||||
ValueWithUnit.Timestamp(carb.timestamp),
|
||||
ValueWithUnit.Gram(carb.amount.toInt())
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateCarbsTransaction(carb.id))
|
||||
.subscribe(
|
||||
{ result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated carbs $it") } },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating carbs", it) }
|
||||
)
|
||||
}
|
||||
}
|
||||
actionHelper.finish()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,39 +3,34 @@ package info.nightscout.androidaps.activities.fragments
|
|||
import android.os.Bundle
|
||||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import android.view.ActionMode
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.util.forEach
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsCareportalFragment.RecyclerViewAdapter.TherapyEventsViewHolder
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
||||
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
||||
import info.nightscout.androidaps.database.transactions.InvalidateAAPSStartedTherapyEventTransaction
|
||||
import info.nightscout.androidaps.database.transactions.InvalidateTherapyEventTransaction
|
||||
import info.nightscout.androidaps.databinding.TreatmentsCareportalFragmentBinding
|
||||
import info.nightscout.androidaps.databinding.TreatmentsCareportalItemBinding
|
||||
import info.nightscout.androidaps.events.EventTherapyEventChange
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import info.nightscout.androidaps.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||
import info.nightscout.androidaps.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsCareportalFragment.RecyclerViewAdapter.TherapyEventsViewHolder
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.Translator
|
||||
import info.nightscout.androidaps.utils.*
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import io.reactivex.rxjava3.core.Completable
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
|
@ -59,23 +54,23 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
@Inject lateinit var uel: UserEntryLogger
|
||||
|
||||
private var _binding: TreatmentsCareportalFragmentBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private var menu: Menu? = null
|
||||
private val disposable = CompositeDisposable()
|
||||
private val millsToThePast = T.days(30).msecs()
|
||||
private var selectedItems: SparseArray<TherapyEvent> = SparseArray()
|
||||
private lateinit var actionHelper: ActionModeHelper<TherapyEvent>
|
||||
private var showInvalidated = false
|
||||
private var toolbar: Toolbar? = null
|
||||
private var removeActionMode: ActionMode? = null
|
||||
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
TreatmentsCareportalFragmentBinding.inflate(inflater, container, false).also { _binding = it }.root
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
toolbar = activity?.findViewById(R.id.toolbar)
|
||||
actionHelper = ActionModeHelper(rh, activity)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
setHasOptionsMenu(true)
|
||||
binding.recyclerview.setHasFixedSize(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||
|
@ -143,13 +138,13 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
@Synchronized
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
actionHelper.finish()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
removeActionMode?.finish()
|
||||
binding.recyclerview.adapter = null // avoid leaks
|
||||
_binding = null
|
||||
}
|
||||
|
@ -172,18 +167,15 @@ 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()
|
||||
if (removeActionMode != null) {
|
||||
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
||||
if (value) {
|
||||
selectedItems.put(position, therapyEvent)
|
||||
} else {
|
||||
selectedItems.remove(position)
|
||||
}
|
||||
removeActionMode?.title = rh.gs(R.string.count_selected, selectedItems.size())
|
||||
}
|
||||
holder.binding.cbRemove.isChecked = selectedItems.get(position) != null
|
||||
holder.binding.cbRemove.visibility = (therapyEvent.isValid && actionHelper.isRemoving).toVisibility()
|
||||
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
||||
actionHelper.updateSelection(position, therapyEvent, value)
|
||||
}
|
||||
holder.binding.root.setOnClickListener {
|
||||
holder.binding.cbRemove.toggle()
|
||||
actionHelper.updateSelection(position, therapyEvent, holder.binding.cbRemove.isChecked)
|
||||
}
|
||||
holder.binding.cbRemove.isChecked = actionHelper.isSelected(position)
|
||||
val nextTimestamp = if (therapyList.size != position + 1) therapyList[position + 1].timestamp else 0L
|
||||
holder.binding.delimiter.visibility = dateUtil.isSameDayGroup(therapyEvent.timestamp, nextTimestamp).toVisibility()
|
||||
}
|
||||
|
@ -198,34 +190,40 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
this.menu = menu
|
||||
inflater.inflate(R.menu.menu_treatments_careportal, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
menu.findItem(R.id.nav_hide_invalidated)?.isVisible = showInvalidated
|
||||
menu.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
updateMenuVisibility()
|
||||
val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_therapy_events, false) || !buildHelper.isEngineeringMode()
|
||||
menu.findItem(R.id.nav_refresh_ns)?.isVisible = !nsUploadOnly
|
||||
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
private fun updateMenuVisibility() {
|
||||
menu?.findItem(R.id.nav_hide_invalidated)?.isVisible = showInvalidated
|
||||
menu?.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> {
|
||||
removeActionMode = toolbar?.startActionMode(RemoveActionModeCallback())
|
||||
true
|
||||
}
|
||||
R.id.nav_remove_items -> actionHelper.startRemove()
|
||||
|
||||
R.id.nav_show_invalidated -> {
|
||||
showInvalidated = true
|
||||
updateMenuVisibility()
|
||||
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records))
|
||||
rxBus.send(EventTreatmentUpdateGui())
|
||||
true
|
||||
}
|
||||
|
||||
R.id.nav_hide_invalidated -> {
|
||||
showInvalidated = false
|
||||
updateMenuVisibility()
|
||||
ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records))
|
||||
rxBus.send(EventTreatmentUpdateGui())
|
||||
true
|
||||
}
|
||||
|
@ -243,36 +241,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
else -> false
|
||||
}
|
||||
|
||||
inner class RemoveActionModeCallback : ActionMode.Callback {
|
||||
|
||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu?): Boolean {
|
||||
mode.menuInflater.inflate(R.menu.menu_delete_selection, menu)
|
||||
selectedItems.clear()
|
||||
mode.title = rh.gs(R.string.count_selected, selectedItems.size())
|
||||
binding.recyclerview.adapter?.notifyDataSetChanged()
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?) = false
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.remove_selected -> {
|
||||
removeSelected()
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyActionMode(mode: ActionMode?) {
|
||||
removeActionMode = null
|
||||
binding.recyclerview.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getConfirmationText(): String {
|
||||
private fun getConfirmationText(selectedItems: SparseArray<TherapyEvent>): String {
|
||||
if (selectedItems.size() == 1) {
|
||||
val therapyEvent = selectedItems.valueAt(0)
|
||||
return rh.gs(R.string.eventtype) + ": " + translator.translate(therapyEvent.type) + "\n" +
|
||||
|
@ -282,27 +251,24 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
return rh.gs(R.string.confirm_remove_multiple_items, selectedItems.size())
|
||||
}
|
||||
|
||||
private fun removeSelected() {
|
||||
if (selectedItems.size() > 0)
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(), Runnable {
|
||||
selectedItems.forEach { _, therapyEvent ->
|
||||
uel.log(
|
||||
Action.CAREPORTAL_REMOVED, Sources.Treatments, therapyEvent.note,
|
||||
ValueWithUnit.Timestamp(therapyEvent.timestamp),
|
||||
ValueWithUnit.TherapyEventType(therapyEvent.type)
|
||||
private fun removeSelected(selectedItems: SparseArray<TherapyEvent>) {
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(selectedItems), Runnable {
|
||||
selectedItems.forEach { _, therapyEvent ->
|
||||
uel.log(
|
||||
Action.CAREPORTAL_REMOVED, Sources.Treatments, therapyEvent.note,
|
||||
ValueWithUnit.Timestamp(therapyEvent.timestamp),
|
||||
ValueWithUnit.TherapyEventType(therapyEvent.type)
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateTherapyEventTransaction(therapyEvent.id))
|
||||
.subscribe(
|
||||
{ result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated therapy event $it") } },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating therapy event", it) }
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateTherapyEventTransaction(therapyEvent.id))
|
||||
.subscribe(
|
||||
{ result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated therapy event $it") } },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating therapy event", it) }
|
||||
)
|
||||
}
|
||||
removeActionMode?.finish()
|
||||
})
|
||||
}
|
||||
else
|
||||
removeActionMode?.finish()
|
||||
}
|
||||
actionHelper.finish()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package info.nightscout.androidaps.activities.fragments
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import android.view.ActionMode
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.util.forEach
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsExtendedBolusesFragment.RecyclerViewAdapter.ExtendedBolusesViewHolder
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.entities.ExtendedBolus
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||
|
@ -20,25 +20,26 @@ import info.nightscout.androidaps.database.transactions.InvalidateExtendedBolusT
|
|||
import info.nightscout.androidaps.databinding.TreatmentsExtendedbolusFragmentBinding
|
||||
import info.nightscout.androidaps.databinding.TreatmentsExtendedbolusItemBinding
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange
|
||||
import info.nightscout.androidaps.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.extensions.iobCalc
|
||||
import info.nightscout.androidaps.extensions.isInProgress
|
||||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsExtendedBolusesFragment.RecyclerViewAdapter.ExtendedBolusesViewHolder
|
||||
import info.nightscout.androidaps.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.utils.ActionModeHelper
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.ToastUtils
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -60,20 +61,23 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
|
|||
@Inject lateinit var repository: AppRepository
|
||||
|
||||
private var _binding: TreatmentsExtendedbolusFragmentBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private var selectedItems: SparseArray<ExtendedBolus> = SparseArray()
|
||||
private var menu: Menu? = null
|
||||
private lateinit var actionHelper: ActionModeHelper<ExtendedBolus>
|
||||
private var showInvalidated = false
|
||||
private var removeActionMode: ActionMode? = null
|
||||
private var toolbar: Toolbar? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
TreatmentsExtendedbolusFragmentBinding.inflate(inflater, container, false).also { _binding = it }.root
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
actionHelper = ActionModeHelper(rh, activity)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
setHasOptionsMenu(true)
|
||||
toolbar = activity?.findViewById(R.id.toolbar)
|
||||
binding.recyclerview.setHasFixedSize(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||
}
|
||||
|
@ -96,24 +100,28 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
swapAdapter()
|
||||
|
||||
disposable += rxBus
|
||||
.toObservable(EventExtendedBolusChange::class.java)
|
||||
.observeOn(aapsSchedulers.io)
|
||||
.debounce(1L, TimeUnit.SECONDS)
|
||||
.subscribe({ swapAdapter() }, fabricPrivacy::logException)
|
||||
disposable += rxBus
|
||||
.toObservable(EventTreatmentUpdateGui::class.java) // TODO join with above
|
||||
.observeOn(aapsSchedulers.io)
|
||||
.debounce(1L, TimeUnit.SECONDS)
|
||||
.subscribe({ swapAdapter() }, fabricPrivacy::logException)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
actionHelper.finish()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
removeActionMode?.finish()
|
||||
binding.recyclerview.adapter = null // avoid leaks
|
||||
_binding = null
|
||||
}
|
||||
|
@ -147,17 +155,16 @@ 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()
|
||||
if (removeActionMode != null) {
|
||||
holder.binding.cbRemove.visibility = (extendedBolus.isValid && actionHelper.isRemoving).toVisibility()
|
||||
if (actionHelper.isRemoving) {
|
||||
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
||||
if (value) {
|
||||
selectedItems.put(position, extendedBolus)
|
||||
} else {
|
||||
selectedItems.remove(position)
|
||||
}
|
||||
removeActionMode?.title = rh.gs(R.string.count_selected, selectedItems.size())
|
||||
actionHelper.updateSelection(position, extendedBolus, value)
|
||||
}
|
||||
holder.binding.cbRemove.isChecked = selectedItems.get(position) != null
|
||||
holder.binding.root.setOnClickListener {
|
||||
holder.binding.cbRemove.toggle()
|
||||
actionHelper.updateSelection(position, extendedBolus, holder.binding.cbRemove.isChecked)
|
||||
}
|
||||
holder.binding.cbRemove.isChecked = actionHelper.isSelected(position)
|
||||
}
|
||||
val nextTimestamp = if (extendedBolusList.size != position + 1) extendedBolusList[position + 1].timestamp else 0L
|
||||
holder.binding.delimiter.visibility = dateUtil.isSameDayGroup(extendedBolus.timestamp, nextTimestamp).toVisibility()
|
||||
|
@ -173,32 +180,37 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
this.menu = menu
|
||||
inflater.inflate(R.menu.menu_treatments_extended_bolus, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
menu.findItem(R.id.nav_hide_invalidated)?.isVisible = showInvalidated
|
||||
menu.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
private fun updateMenuVisibility() {
|
||||
menu?.findItem(R.id.nav_hide_invalidated)?.isVisible = showInvalidated
|
||||
menu?.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
updateMenuVisibility()
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.nav_remove_items -> {
|
||||
removeActionMode = toolbar?.startActionMode(RemoveActionModeCallback())
|
||||
true
|
||||
}
|
||||
R.id.nav_remove_items -> actionHelper.startRemove()
|
||||
|
||||
R.id.nav_show_invalidated -> {
|
||||
showInvalidated = true
|
||||
updateMenuVisibility()
|
||||
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records))
|
||||
rxBus.send(EventTreatmentUpdateGui())
|
||||
true
|
||||
}
|
||||
|
||||
R.id.nav_hide_invalidated -> {
|
||||
showInvalidated = false
|
||||
updateMenuVisibility()
|
||||
ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records))
|
||||
rxBus.send(EventTreatmentUpdateGui())
|
||||
true
|
||||
}
|
||||
|
@ -207,36 +219,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
inner class RemoveActionModeCallback : ActionMode.Callback {
|
||||
|
||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu?): Boolean {
|
||||
mode.menuInflater.inflate(R.menu.menu_delete_selection, menu)
|
||||
selectedItems.clear()
|
||||
mode.title = rh.gs(R.string.count_selected, selectedItems.size())
|
||||
binding.recyclerview.adapter?.notifyDataSetChanged()
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?) = false
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.remove_selected -> {
|
||||
removeSelected()
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyActionMode(mode: ActionMode?) {
|
||||
removeActionMode = null
|
||||
binding.recyclerview.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getConfirmationText(): String {
|
||||
private fun getConfirmationText(selectedItems: SparseArray<ExtendedBolus>): String {
|
||||
if (selectedItems.size() == 1) {
|
||||
val bolus = selectedItems.valueAt(0)
|
||||
return rh.gs(R.string.extended_bolus) + "\n" +
|
||||
|
@ -245,27 +228,25 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
|
|||
return rh.gs(R.string.confirm_remove_multiple_items, selectedItems.size())
|
||||
}
|
||||
|
||||
private fun removeSelected() {
|
||||
if (selectedItems.size() > 0)
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(), Runnable {
|
||||
selectedItems.forEach { _, extendedBolus ->
|
||||
uel.log(
|
||||
Action.EXTENDED_BOLUS_REMOVED, Sources.Treatments,
|
||||
ValueWithUnit.Timestamp(extendedBolus.timestamp),
|
||||
ValueWithUnit.Insulin(extendedBolus.amount),
|
||||
ValueWithUnit.UnitPerHour(extendedBolus.rate),
|
||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(extendedBolus.duration).toInt())
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateExtendedBolusTransaction(extendedBolus.id))
|
||||
.subscribe(
|
||||
{ aapsLogger.debug(LTag.DATABASE, "Removed extended bolus $extendedBolus") },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating extended bolus", it) })
|
||||
}
|
||||
removeActionMode?.finish()
|
||||
})
|
||||
}
|
||||
else
|
||||
removeActionMode?.finish()
|
||||
private fun removeSelected(selectedItems: SparseArray<ExtendedBolus>) {
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(selectedItems), Runnable {
|
||||
selectedItems.forEach { _, extendedBolus ->
|
||||
uel.log(
|
||||
Action.EXTENDED_BOLUS_REMOVED, Sources.Treatments,
|
||||
ValueWithUnit.Timestamp(extendedBolus.timestamp),
|
||||
ValueWithUnit.Insulin(extendedBolus.amount),
|
||||
ValueWithUnit.UnitPerHour(extendedBolus.rate),
|
||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(extendedBolus.duration).toInt())
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateExtendedBolusTransaction(extendedBolus.id))
|
||||
.subscribe(
|
||||
{ aapsLogger.debug(LTag.DATABASE, "Removed extended bolus $extendedBolus") },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating extended bolus", it) })
|
||||
}
|
||||
actionHelper.finish()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package info.nightscout.androidaps.activities.fragments
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Paint
|
||||
import android.os.Bundle
|
||||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import android.view.ActionMode
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.util.forEach
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
@ -32,9 +31,11 @@ import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientR
|
|||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData
|
||||
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin
|
||||
import info.nightscout.androidaps.plugins.profile.local.events.EventLocalProfileChanged
|
||||
import info.nightscout.androidaps.utils.ActionModeHelper
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.ToastUtils
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
|
@ -46,6 +47,7 @@ import io.reactivex.rxjava3.core.Completable
|
|||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import io.reactivex.rxjava3.kotlin.subscribeBy
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
||||
|
@ -63,24 +65,25 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
@Inject lateinit var uel: UserEntryLogger
|
||||
|
||||
private var _binding: TreatmentsProfileswitchFragmentBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private var menu: Menu? = null
|
||||
private lateinit var actionHelper: ActionModeHelper<ProfileSealed>
|
||||
private val disposable = CompositeDisposable()
|
||||
private val millsToThePast = T.days(30).msecs()
|
||||
private var selectedItems: SparseArray<ProfileSealed> = SparseArray()
|
||||
private var showInvalidated = false
|
||||
private var removeActionMode: ActionMode? = null
|
||||
private var toolbar: Toolbar? = null
|
||||
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
TreatmentsProfileswitchFragmentBinding.inflate(inflater, container, false).also { _binding = it }.root
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
actionHelper = ActionModeHelper(rh, activity)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
setHasOptionsMenu(true)
|
||||
toolbar = activity?.findViewById(R.id.toolbar)
|
||||
binding.recyclerview.setHasFixedSize(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||
}
|
||||
|
@ -159,18 +162,23 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
.toObservable(EventEffectiveProfileSwitchChanged::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe({ swapAdapter() }, fabricPrivacy::logException)
|
||||
disposable += rxBus
|
||||
.toObservable(EventTreatmentUpdateGui::class.java) // TODO join with above
|
||||
.observeOn(aapsSchedulers.io)
|
||||
.debounce(1L, TimeUnit.SECONDS)
|
||||
.subscribe({ swapAdapter() }, fabricPrivacy::logException)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
actionHelper.finish()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
removeActionMode?.finish()
|
||||
binding.recyclerview.adapter = null // avoid leaks
|
||||
_binding = null
|
||||
}
|
||||
|
@ -198,17 +206,16 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
holder.binding.date.tag = profileSwitch
|
||||
holder.binding.invalid.visibility = profileSwitch.isValid.not().toVisibility()
|
||||
holder.binding.duration.visibility = (profileSwitch.duration != 0L && profileSwitch.duration != null).toVisibility()
|
||||
holder.binding.cbRemove.visibility = (removeActionMode != null && profileSwitch is ProfileSealed.PS).toVisibility()
|
||||
if (removeActionMode != null) {
|
||||
holder.binding.cbRemove.visibility = (actionHelper.isRemoving && profileSwitch is ProfileSealed.PS).toVisibility()
|
||||
if (actionHelper.isRemoving) {
|
||||
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
||||
if (value) {
|
||||
selectedItems.put(position, profileSwitch)
|
||||
} else {
|
||||
selectedItems.remove(position)
|
||||
}
|
||||
removeActionMode?.title = rh.gs(R.string.count_selected, selectedItems.size())
|
||||
actionHelper.updateSelection(position, profileSwitch, value)
|
||||
}
|
||||
holder.binding.cbRemove.isChecked = selectedItems.get(position) != null
|
||||
holder.binding.root.setOnClickListener {
|
||||
holder.binding.cbRemove.toggle()
|
||||
actionHelper.updateSelection(position, profileSwitch, holder.binding.cbRemove.isChecked)
|
||||
}
|
||||
holder.binding.cbRemove.isChecked = actionHelper.isSelected(position)
|
||||
}
|
||||
holder.binding.clone.visibility = (profileSwitch is ProfileSealed.PS).toVisibility()
|
||||
holder.binding.spacer.visibility = (profileSwitch is ProfileSealed.PS).toVisibility()
|
||||
|
@ -273,13 +280,18 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
this.menu = menu
|
||||
inflater.inflate(R.menu.menu_treatments_profile_switch, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
private fun updateMenuVisibility() {
|
||||
menu?.findItem(R.id.nav_hide_invalidated)?.isVisible = showInvalidated
|
||||
menu?.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
menu.findItem(R.id.nav_hide_invalidated)?.isVisible = showInvalidated
|
||||
menu.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
updateMenuVisibility()
|
||||
val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_profile_switch, false) || !buildHelper.isEngineeringMode()
|
||||
menu.findItem(R.id.nav_refresh_ns)?.isVisible = !nsUploadOnly
|
||||
|
||||
|
@ -288,19 +300,20 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> {
|
||||
removeActionMode = toolbar?.startActionMode(RemoveActionModeCallback())
|
||||
true
|
||||
}
|
||||
R.id.nav_remove_items -> actionHelper.startRemove()
|
||||
|
||||
R.id.nav_show_invalidated -> {
|
||||
showInvalidated = true
|
||||
updateMenuVisibility()
|
||||
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records))
|
||||
rxBus.send(EventTreatmentUpdateGui())
|
||||
true
|
||||
}
|
||||
|
||||
R.id.nav_hide_invalidated -> {
|
||||
showInvalidated = false
|
||||
updateMenuVisibility()
|
||||
ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records))
|
||||
rxBus.send(EventTreatmentUpdateGui())
|
||||
true
|
||||
}
|
||||
|
@ -313,36 +326,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
else -> false
|
||||
}
|
||||
|
||||
inner class RemoveActionModeCallback : ActionMode.Callback {
|
||||
|
||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu?): Boolean {
|
||||
mode.menuInflater.inflate(R.menu.menu_delete_selection, menu)
|
||||
selectedItems.clear()
|
||||
mode.title = rh.gs(R.string.count_selected, selectedItems.size())
|
||||
binding.recyclerview.adapter?.notifyDataSetChanged()
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?) = false
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.remove_selected -> {
|
||||
removeSelected()
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyActionMode(mode: ActionMode?) {
|
||||
removeActionMode = null
|
||||
binding.recyclerview.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getConfirmationText(): String {
|
||||
private fun getConfirmationText(selectedItems: SparseArray<ProfileSealed>): String {
|
||||
if (selectedItems.size() == 1) {
|
||||
val profileSwitch = selectedItems.valueAt(0)
|
||||
return rh.gs(R.string.careportal_profileswitch) + ": " + profileSwitch.profileName + "\n" + rh.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(profileSwitch.timestamp)
|
||||
|
@ -350,25 +334,22 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
return rh.gs(R.string.confirm_remove_multiple_items, selectedItems.size())
|
||||
}
|
||||
|
||||
private fun removeSelected() {
|
||||
if (selectedItems.size() > 0)
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(), Runnable {
|
||||
selectedItems.forEach { _, profileSwitch ->
|
||||
uel.log(
|
||||
Action.PROFILE_SWITCH_REMOVED, Sources.Treatments, profileSwitch.profileName,
|
||||
ValueWithUnit.Timestamp(profileSwitch.timestamp)
|
||||
private fun removeSelected(selectedItems: SparseArray<ProfileSealed>) {
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(selectedItems), Runnable {
|
||||
selectedItems.forEach { _, profileSwitch ->
|
||||
uel.log(
|
||||
Action.PROFILE_SWITCH_REMOVED, Sources.Treatments, profileSwitch.profileName,
|
||||
ValueWithUnit.Timestamp(profileSwitch.timestamp)
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateProfileSwitchTransaction(profileSwitch.id))
|
||||
.subscribe(
|
||||
{ result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated ProfileSwitch $it") } },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating ProfileSwitch", it) }
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateProfileSwitchTransaction(profileSwitch.id))
|
||||
.subscribe(
|
||||
{ result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated ProfileSwitch $it") } },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating ProfileSwitch", it) }
|
||||
)
|
||||
}
|
||||
removeActionMode?.finish()
|
||||
})
|
||||
}
|
||||
else
|
||||
removeActionMode?.finish()
|
||||
}
|
||||
actionHelper.finish()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,46 +4,42 @@ import android.annotation.SuppressLint
|
|||
import android.os.Bundle
|
||||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.util.forEach
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsTempTargetFragment.RecyclerViewAdapter.TempTargetsViewHolder
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.ValueWrapper
|
||||
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
||||
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
||||
import info.nightscout.androidaps.database.interfaces.end
|
||||
import info.nightscout.androidaps.database.transactions.InvalidateTemporaryTargetTransaction
|
||||
import info.nightscout.androidaps.databinding.TreatmentsTemptargetFragmentBinding
|
||||
import info.nightscout.androidaps.databinding.TreatmentsTemptargetItemBinding
|
||||
import info.nightscout.androidaps.events.EventTempTargetChange
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||
import info.nightscout.androidaps.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsTempTargetFragment.RecyclerViewAdapter.TempTargetsViewHolder
|
||||
import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged
|
||||
import info.nightscout.androidaps.events.EventProfileSwitchChanged
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.Translator
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||
import info.nightscout.androidaps.events.EventTempTargetChange
|
||||
import info.nightscout.androidaps.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.extensions.friendlyDescription
|
||||
import info.nightscout.androidaps.extensions.highValueToUnitsToString
|
||||
import info.nightscout.androidaps.extensions.lowValueToUnitsToString
|
||||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData
|
||||
import info.nightscout.androidaps.utils.*
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import io.reactivex.rxjava3.core.Completable
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
|
@ -68,22 +64,24 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
@Inject lateinit var repository: AppRepository
|
||||
|
||||
private var _binding: TreatmentsTemptargetFragmentBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private var menu: Menu? = null
|
||||
private lateinit var actionHelper: ActionModeHelper<TemporaryTarget>
|
||||
private val disposable = CompositeDisposable()
|
||||
private val millsToThePast = T.days(30).msecs()
|
||||
private var selectedItems: SparseArray<TemporaryTarget> = SparseArray()
|
||||
private var showInvalidated = false
|
||||
private var toolbar: Toolbar? = null
|
||||
private var removeActionMode: ActionMode? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
TreatmentsTemptargetFragmentBinding.inflate(inflater, container, false).also { _binding = it }.root
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
binding.recyclerview.setHasFixedSize(true)
|
||||
toolbar = activity?.findViewById(R.id.toolbar)
|
||||
actionHelper = ActionModeHelper(rh, activity)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
setHasOptionsMenu(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||
}
|
||||
|
@ -131,13 +129,11 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
swapAdapter()
|
||||
|
||||
disposable += rxBus
|
||||
.toObservable(EventTempTargetChange::class.java)
|
||||
.observeOn(aapsSchedulers.io)
|
||||
.debounce(1L, TimeUnit.SECONDS)
|
||||
.subscribe({ swapAdapter() }, fabricPrivacy::logException)
|
||||
|
||||
disposable += rxBus
|
||||
.toObservable(EventTreatmentUpdateGui::class.java) // TODO join with above
|
||||
.observeOn(aapsSchedulers.io)
|
||||
|
@ -148,13 +144,13 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
@Synchronized
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
actionHelper.finish()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
removeActionMode?.finish()
|
||||
binding.recyclerview.adapter = null // avoid leaks
|
||||
_binding = null
|
||||
}
|
||||
|
@ -173,17 +169,16 @@ 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()
|
||||
if (removeActionMode != null) {
|
||||
holder.binding.cbRemove.visibility = (tempTarget.isValid && actionHelper.isRemoving).toVisibility()
|
||||
if (actionHelper.isRemoving) {
|
||||
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
||||
if (value) {
|
||||
selectedItems.put(position, tempTarget)
|
||||
} else {
|
||||
selectedItems.remove(position)
|
||||
}
|
||||
removeActionMode?.title = rh.gs(R.string.count_selected, selectedItems.size())
|
||||
actionHelper.updateSelection(position, tempTarget, value)
|
||||
}
|
||||
holder.binding.cbRemove.isChecked = selectedItems.get(position) != null
|
||||
holder.binding.root.setOnClickListener {
|
||||
holder.binding.cbRemove.toggle()
|
||||
actionHelper.updateSelection(position, tempTarget, holder.binding.cbRemove.isChecked)
|
||||
}
|
||||
holder.binding.cbRemove.isChecked = actionHelper.isSelected(position)
|
||||
}
|
||||
val newDay = position == 0 || !dateUtil.isSameDayGroup(tempTarget.timestamp, tempTargetList[position - 1].timestamp)
|
||||
holder.binding.date.visibility = newDay.toVisibility()
|
||||
|
@ -213,39 +208,19 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun removeSelected() {
|
||||
if (selectedItems.size() > 0)
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(), Runnable {
|
||||
selectedItems.forEach { _, tempTarget ->
|
||||
uel.log(
|
||||
Action.TT_REMOVED, Sources.Treatments,
|
||||
ValueWithUnit.Timestamp(tempTarget.timestamp),
|
||||
ValueWithUnit.TherapyEventTTReason(tempTarget.reason),
|
||||
ValueWithUnit.Mgdl(tempTarget.lowTarget),
|
||||
ValueWithUnit.Mgdl(tempTarget.highTarget).takeIf { tempTarget.lowTarget != tempTarget.highTarget },
|
||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tempTarget.duration).toInt())
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateTemporaryTargetTransaction(tempTarget.id))
|
||||
.subscribe(
|
||||
{ aapsLogger.debug(LTag.DATABASE, "Removed temp target $tempTarget") },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating temporary target", it) })
|
||||
}
|
||||
removeActionMode?.finish()
|
||||
})
|
||||
}
|
||||
else
|
||||
removeActionMode?.finish()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
this.menu = menu
|
||||
inflater.inflate(R.menu.menu_treatments_temp_target, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
private fun updateMenuVisibility() {
|
||||
menu?.findItem(R.id.nav_hide_invalidated)?.isVisible = showInvalidated
|
||||
menu?.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
menu.findItem(R.id.nav_hide_invalidated)?.isVisible = showInvalidated
|
||||
menu.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
updateMenuVisibility()
|
||||
val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_temp_target, false) || !buildHelper.isEngineeringMode()
|
||||
menu.findItem(R.id.nav_refresh_ns)?.isVisible = !nsUploadOnly
|
||||
|
||||
|
@ -254,19 +229,20 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> {
|
||||
removeActionMode = toolbar?.startActionMode(RemoveActionModeCallback())
|
||||
true
|
||||
}
|
||||
R.id.nav_remove_items -> actionHelper.startRemove()
|
||||
|
||||
R.id.nav_show_invalidated -> {
|
||||
showInvalidated = true
|
||||
updateMenuVisibility()
|
||||
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records))
|
||||
rxBus.send(EventTreatmentUpdateGui())
|
||||
true
|
||||
}
|
||||
|
||||
R.id.nav_hide_invalidated -> {
|
||||
showInvalidated = false
|
||||
updateMenuVisibility()
|
||||
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records))
|
||||
rxBus.send(EventTreatmentUpdateGui())
|
||||
true
|
||||
}
|
||||
|
@ -279,36 +255,7 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
else -> false
|
||||
}
|
||||
|
||||
inner class RemoveActionModeCallback : ActionMode.Callback {
|
||||
|
||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu?): Boolean {
|
||||
mode.menuInflater.inflate(R.menu.menu_delete_selection, menu)
|
||||
selectedItems.clear()
|
||||
mode.title = rh.gs(R.string.count_selected, selectedItems.size())
|
||||
binding.recyclerview.adapter?.notifyDataSetChanged()
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?) = false
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.remove_selected -> {
|
||||
removeSelected()
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyActionMode(mode: ActionMode?) {
|
||||
removeActionMode = null
|
||||
binding.recyclerview.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getConfirmationText(): String {
|
||||
private fun getConfirmationText(selectedItems: SparseArray<TemporaryTarget>): String {
|
||||
if (selectedItems.size() == 1) {
|
||||
val tempTarget = selectedItems.valueAt(0)
|
||||
return "${rh.gs(R.string.careportal_temporarytarget)}: ${tempTarget.friendlyDescription(profileFunction.getUnits(), rh)}\n" +
|
||||
|
@ -317,4 +264,26 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
return rh.gs(R.string.confirm_remove_multiple_items, selectedItems.size())
|
||||
}
|
||||
|
||||
private fun removeSelected(selectedItems: SparseArray<TemporaryTarget>) {
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(selectedItems), Runnable {
|
||||
selectedItems.forEach { _, tempTarget ->
|
||||
uel.log(
|
||||
Action.TT_REMOVED, Sources.Treatments,
|
||||
ValueWithUnit.Timestamp(tempTarget.timestamp),
|
||||
ValueWithUnit.TherapyEventTTReason(tempTarget.reason),
|
||||
ValueWithUnit.Mgdl(tempTarget.lowTarget),
|
||||
ValueWithUnit.Mgdl(tempTarget.highTarget).takeIf { tempTarget.lowTarget != tempTarget.highTarget },
|
||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tempTarget.duration).toInt())
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateTemporaryTargetTransaction(tempTarget.id))
|
||||
.subscribe(
|
||||
{ aapsLogger.debug(LTag.DATABASE, "Removed temp target $tempTarget") },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating temporary target", it) })
|
||||
}
|
||||
actionHelper.finish()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package info.nightscout.androidaps.activities.fragments
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.util.forEach
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsTemporaryBasalsFragment.RecyclerViewAdapter.TempBasalsViewHolder
|
||||
import info.nightscout.androidaps.data.IobTotal
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.ValueWrapper
|
||||
|
@ -24,24 +25,25 @@ import info.nightscout.androidaps.databinding.TreatmentsTempbasalsFragmentBindin
|
|||
import info.nightscout.androidaps.databinding.TreatmentsTempbasalsItemBinding
|
||||
import info.nightscout.androidaps.events.EventAutosensCalculationFinished
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange
|
||||
import info.nightscout.androidaps.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.extensions.iobCalc
|
||||
import info.nightscout.androidaps.extensions.toStringFull
|
||||
import info.nightscout.androidaps.extensions.toTemporaryBasal
|
||||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsTemporaryBasalsFragment.RecyclerViewAdapter.TempBasalsViewHolder
|
||||
import info.nightscout.androidaps.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.utils.ActionModeHelper
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.ToastUtils
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
@ -64,21 +66,23 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
@Inject lateinit var repository: AppRepository
|
||||
|
||||
private var _binding: TreatmentsTempbasalsFragmentBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private var menu: Menu? = null
|
||||
private lateinit var actionHelper: ActionModeHelper<TemporaryBasal>
|
||||
private val millsToThePast = T.days(30).msecs()
|
||||
private var selectedItems: SparseArray<TemporaryBasal> = SparseArray()
|
||||
private var showInvalidated = false
|
||||
private var toolbar: Toolbar? = null
|
||||
private var removeActionMode: ActionMode? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
TreatmentsTempbasalsFragmentBinding.inflate(inflater, container, false).also { _binding = it }.root
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
toolbar = activity?.findViewById(R.id.toolbar)
|
||||
actionHelper = ActionModeHelper(rh, activity)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
setHasOptionsMenu(true)
|
||||
binding.recyclerview.setHasFixedSize(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||
|
@ -133,28 +137,31 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
swapAdapter()
|
||||
|
||||
disposable += rxBus
|
||||
.toObservable(EventTempBasalChange::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe({ swapAdapter() }, fabricPrivacy::logException)
|
||||
|
||||
disposable += rxBus
|
||||
.toObservable(EventAutosensCalculationFinished::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe({ swapAdapter() }, fabricPrivacy::logException)
|
||||
disposable += rxBus
|
||||
.toObservable(EventTreatmentUpdateGui::class.java) // TODO join with above
|
||||
.observeOn(aapsSchedulers.io)
|
||||
.debounce(1L, TimeUnit.SECONDS)
|
||||
.subscribe({ swapAdapter() }, fabricPrivacy::logException)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
actionHelper.finish()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
removeActionMode?.finish()
|
||||
binding.recyclerview.adapter = null // avoid leaks
|
||||
_binding = null
|
||||
}
|
||||
|
@ -194,17 +201,16 @@ 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()
|
||||
if (removeActionMode != null) {
|
||||
holder.binding.cbRemove.visibility = (tempBasal.isValid && actionHelper.isRemoving).toVisibility()
|
||||
if (actionHelper.isRemoving) {
|
||||
holder.binding.cbRemove.setOnCheckedChangeListener { _, value ->
|
||||
if (value) {
|
||||
selectedItems.put(position, tempBasal)
|
||||
} else {
|
||||
selectedItems.remove(position)
|
||||
}
|
||||
removeActionMode?.title = rh.gs(R.string.count_selected, selectedItems.size())
|
||||
actionHelper.updateSelection(position, tempBasal, value)
|
||||
}
|
||||
holder.binding.cbRemove.isChecked = selectedItems.get(position) != null
|
||||
holder.binding.root.setOnClickListener {
|
||||
holder.binding.cbRemove.toggle()
|
||||
actionHelper.updateSelection(position, tempBasal, holder.binding.cbRemove.isChecked)
|
||||
}
|
||||
holder.binding.cbRemove.isChecked = actionHelper.isSelected(position)
|
||||
}
|
||||
val nextTimestamp = if (tempBasalList.size != position + 1) tempBasalList[position + 1].timestamp else 0L
|
||||
holder.binding.delimiter.visibility = dateUtil.isSameDayGroup(tempBasal.timestamp, nextTimestamp).toVisibility()
|
||||
|
@ -221,32 +227,38 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
this.menu = menu
|
||||
inflater.inflate(R.menu.menu_treatments_temp_basal, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
private fun updateMenuVisibility() {
|
||||
menu?.findItem(R.id.nav_hide_invalidated)?.isVisible = showInvalidated
|
||||
menu?.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
menu.findItem(R.id.nav_hide_invalidated)?.isVisible = showInvalidated
|
||||
menu.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
updateMenuVisibility()
|
||||
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> {
|
||||
removeActionMode = toolbar?.startActionMode(RemoveActionModeCallback())
|
||||
true
|
||||
}
|
||||
R.id.nav_remove_items -> actionHelper.startRemove()
|
||||
|
||||
R.id.nav_show_invalidated -> {
|
||||
showInvalidated = true
|
||||
updateMenuVisibility()
|
||||
ToastUtils.showToastInUiThread(context, rh.gs(R.string.show_invalidated_records))
|
||||
rxBus.send(EventTreatmentUpdateGui())
|
||||
true
|
||||
}
|
||||
|
||||
R.id.nav_hide_invalidated -> {
|
||||
showInvalidated = false
|
||||
updateMenuVisibility()
|
||||
ToastUtils.showToastInUiThread(context, rh.gs(R.string.hide_invalidated_records))
|
||||
rxBus.send(EventTreatmentUpdateGui())
|
||||
true
|
||||
}
|
||||
|
@ -254,36 +266,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
else -> false
|
||||
}
|
||||
|
||||
inner class RemoveActionModeCallback : ActionMode.Callback {
|
||||
|
||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu?): Boolean {
|
||||
mode.menuInflater.inflate(R.menu.menu_delete_selection, menu)
|
||||
selectedItems.clear()
|
||||
mode.title = rh.gs(R.string.count_selected, selectedItems.size())
|
||||
binding.recyclerview.adapter?.notifyDataSetChanged()
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?) = false
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.remove_selected -> {
|
||||
removeSelected()
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyActionMode(mode: ActionMode?) {
|
||||
removeActionMode = null
|
||||
binding.recyclerview.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getConfirmationText(): String {
|
||||
private fun getConfirmationText(selectedItems: SparseArray<TemporaryBasal>): String {
|
||||
if (selectedItems.size() == 1) {
|
||||
val tempBasal = selectedItems.valueAt(0)
|
||||
val isFakeExtended = tempBasal.type == TemporaryBasal.Type.FAKE_EXTENDED
|
||||
|
@ -295,46 +278,44 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
return rh.gs(R.string.confirm_remove_multiple_items, selectedItems.size())
|
||||
}
|
||||
|
||||
private fun removeSelected() {
|
||||
private fun removeSelected(selectedItems: SparseArray<TemporaryBasal>) {
|
||||
if (selectedItems.size() > 0)
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(), Runnable {
|
||||
selectedItems.forEach {_, tempBasal ->
|
||||
var extendedBolus: ExtendedBolus? = null
|
||||
val isFakeExtended = tempBasal.type == TemporaryBasal.Type.FAKE_EXTENDED
|
||||
if (isFakeExtended) {
|
||||
val eb = repository.getExtendedBolusActiveAt(tempBasal.timestamp).blockingGet()
|
||||
extendedBolus = if (eb is ValueWrapper.Existing) eb.value else null
|
||||
}
|
||||
if (isFakeExtended && extendedBolus != null) {
|
||||
uel.log(
|
||||
Action.EXTENDED_BOLUS_REMOVED, Sources.Treatments,
|
||||
ValueWithUnit.Timestamp(extendedBolus.timestamp),
|
||||
ValueWithUnit.Insulin(extendedBolus.amount),
|
||||
ValueWithUnit.UnitPerHour(extendedBolus.rate),
|
||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(extendedBolus.duration).toInt())
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateExtendedBolusTransaction(extendedBolus.id))
|
||||
.subscribe(
|
||||
{ aapsLogger.debug(LTag.DATABASE, "Removed extended bolus $extendedBolus") },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating extended bolus", it) })
|
||||
} else if (!isFakeExtended) {
|
||||
uel.log(
|
||||
Action.TEMP_BASAL_REMOVED, Sources.Treatments,
|
||||
ValueWithUnit.Timestamp(tempBasal.timestamp),
|
||||
if (tempBasal.isAbsolute) ValueWithUnit.UnitPerHour(tempBasal.rate) else ValueWithUnit.Percent(tempBasal.rate.toInt()),
|
||||
ValueWithUnit.Minute(T.msecs(tempBasal.duration).mins().toInt())
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateTemporaryBasalTransaction(tempBasal.id))
|
||||
.subscribe(
|
||||
{ aapsLogger.debug(LTag.DATABASE, "Removed temporary basal $tempBasal") },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating temporary basal", it) })
|
||||
}
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(selectedItems), Runnable {
|
||||
selectedItems.forEach {_, tempBasal ->
|
||||
var extendedBolus: ExtendedBolus? = null
|
||||
val isFakeExtended = tempBasal.type == TemporaryBasal.Type.FAKE_EXTENDED
|
||||
if (isFakeExtended) {
|
||||
val eb = repository.getExtendedBolusActiveAt(tempBasal.timestamp).blockingGet()
|
||||
extendedBolus = if (eb is ValueWrapper.Existing) eb.value else null
|
||||
}
|
||||
removeActionMode?.finish()
|
||||
})
|
||||
}
|
||||
else
|
||||
removeActionMode?.finish()
|
||||
if (isFakeExtended && extendedBolus != null) {
|
||||
uel.log(
|
||||
Action.EXTENDED_BOLUS_REMOVED, Sources.Treatments,
|
||||
ValueWithUnit.Timestamp(extendedBolus.timestamp),
|
||||
ValueWithUnit.Insulin(extendedBolus.amount),
|
||||
ValueWithUnit.UnitPerHour(extendedBolus.rate),
|
||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(extendedBolus.duration).toInt())
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateExtendedBolusTransaction(extendedBolus.id))
|
||||
.subscribe(
|
||||
{ aapsLogger.debug(LTag.DATABASE, "Removed extended bolus $extendedBolus") },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating extended bolus", it) })
|
||||
} else if (!isFakeExtended) {
|
||||
uel.log(
|
||||
Action.TEMP_BASAL_REMOVED, Sources.Treatments,
|
||||
ValueWithUnit.Timestamp(tempBasal.timestamp),
|
||||
if (tempBasal.isAbsolute) ValueWithUnit.UnitPerHour(tempBasal.rate) else ValueWithUnit.Percent(tempBasal.rate.toInt()),
|
||||
ValueWithUnit.Minute(T.msecs(tempBasal.duration).mins().toInt())
|
||||
)
|
||||
disposable += repository.runTransactionForResult(InvalidateTemporaryBasalTransaction(tempBasal.id))
|
||||
.subscribe(
|
||||
{ aapsLogger.debug(LTag.DATABASE, "Removed temporary basal $tempBasal") },
|
||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating temporary basal", it) })
|
||||
}
|
||||
}
|
||||
actionHelper.finish()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
|||
@Inject lateinit var userEntryPresentationHelper: UserEntryPresentationHelper
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
|
||||
private val millsToThePastFiltered = T.days(30).msecs()
|
||||
private val millsToThePastUnFiltered = T.days(3).msecs()
|
||||
private var showLoop = false
|
||||
|
@ -94,7 +93,6 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
swapAdapter()
|
||||
|
||||
disposable += rxBus
|
||||
.toObservable(EventPreferenceChange::class.java)
|
||||
.observeOn(aapsSchedulers.io)
|
||||
|
|
|
@ -20,7 +20,7 @@ import info.nightscout.androidaps.utils.dragHelpers.OnStartDragListener
|
|||
import info.nightscout.androidaps.utils.dragHelpers.SimpleItemTouchHelperCallback
|
||||
import info.nightscout.androidaps.plugins.general.overview.dialogs.EditQuickWizardDialog
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWizardChange
|
||||
import info.nightscout.androidaps.utils.ActionHelper
|
||||
import info.nightscout.androidaps.utils.ActionModeHelper
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
|
@ -42,7 +42,7 @@ class QuickWizardListActivity : DaggerAppCompatActivityWithResult(), OnStartDrag
|
|||
@Inject lateinit var sp: SP
|
||||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
private lateinit var actionHelper: ActionHelper<QuickWizardEntry>
|
||||
private lateinit var actionHelper: ActionModeHelper<QuickWizardEntry>
|
||||
private val itemTouchHelper = ItemTouchHelper(SimpleItemTouchHelperCallback())
|
||||
private lateinit var binding: OverviewQuickwizardlistActivityBinding
|
||||
|
||||
|
@ -121,7 +121,7 @@ class QuickWizardListActivity : DaggerAppCompatActivityWithResult(), OnStartDrag
|
|||
binding = OverviewQuickwizardlistActivityBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
actionHelper = ActionHelper(rh, this)
|
||||
actionHelper = ActionModeHelper(rh, this)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
actionHelper.enableSort = true
|
||||
|
|
|
@ -25,7 +25,7 @@ import info.nightscout.androidaps.interfaces.PluginBase
|
|||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.utils.ActionHelper
|
||||
import info.nightscout.androidaps.utils.ActionModeHelper
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
|
@ -54,7 +54,7 @@ class BGSourceFragment : DaggerFragment() {
|
|||
|
||||
private val disposable = CompositeDisposable()
|
||||
private val millsToThePast = T.hours(36).msecs()
|
||||
private lateinit var actionHelper: ActionHelper<GlucoseValue>
|
||||
private lateinit var actionHelper: ActionModeHelper<GlucoseValue>
|
||||
private var _binding: BgsourceFragmentBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and onDestroyView.
|
||||
|
@ -65,7 +65,7 @@ class BGSourceFragment : DaggerFragment() {
|
|||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
actionHelper = ActionHelper(rh, activity)
|
||||
actionHelper = ActionModeHelper(rh, activity)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
setHasOptionsMenu(actionHelper.inMenu)
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M12,4.531c-4.971,0 -9.209,3.1 -10.912,7.469C2.791,16.368 7.029,19.469 12,19.469s9.209,-3.1 10.912,-7.469C21.209,7.632 16.971,4.531 12,4.531zM12,17.063c-2.796,0 -5.063,-2.267 -5.063,-5.063S9.204,6.938 12,6.938S17.063,9.204 17.063,12S14.796,17.063 12,17.063z"
|
||||
android:fillColor="#FFFFFF"/>
|
||||
android:fillColor="?attr/colorControlNormal"/>
|
||||
<path
|
||||
android:pathData="M12,12m-2.938,0a2.938,2.938 0,1 1,5.876 0a2.938,2.938 0,1 1,-5.876 0"
|
||||
android:fillColor="#FFFFFF"/>
|
||||
android:fillColor="?attr/colorControlNormal"/>
|
||||
</vector>
|
||||
|
|
9
app/src/main/res/drawable/ic_visibility_off.xml
Normal file
9
app/src/main/res/drawable/ic_visibility_off.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="?attr/colorControlNormal"
|
||||
android:pathData="M12,7c2.76,0 5,2.24 5,5 0,0.65 -0.13,1.26 -0.36,1.83l2.92,2.92c1.51,-1.26 2.7,-2.89 3.43,-4.75 -1.73,-4.39 -6,-7.5 -11,-7.5 -1.4,0 -2.74,0.25 -3.98,0.7l2.16,2.16C10.74,7.13 11.35,7 12,7zM2,4.27l2.28,2.28 0.46,0.46C3.08,8.3 1.78,10.02 1,12c1.73,4.39 6,7.5 11,7.5 1.55,0 3.03,-0.3 4.38,-0.84l0.42,0.42L19.73,22 21,20.73 3.27,3 2,4.27zM7.53,9.8l1.55,1.55c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.66 1.34,3 3,3 0.22,0 0.44,-0.03 0.65,-0.08l1.55,1.55c-0.67,0.33 -1.41,0.53 -2.2,0.53 -2.76,0 -5,-2.24 -5,-5 0,-0.79 0.2,-1.53 0.53,-2.2zM11.84,9.02l3.15,3.15 0.02,-0.16c0,-1.66 -1.34,-3 -3,-3l-0.17,0.01z" />
|
||||
</vector>
|
|
@ -164,8 +164,9 @@
|
|||
<CheckBox
|
||||
android:id="@+id/cb_bolus_remove"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="19dp"
|
||||
android:contentDescription="@string/select_for_removal"
|
||||
android:minWidth="0dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
|
@ -253,22 +254,13 @@
|
|||
android:text="@string/invalid"
|
||||
android:textColor="@android:color/holo_red_light" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/carbs_remove"
|
||||
android:visibility="gone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
|
||||
android:text="@string/remove_button"
|
||||
android:textAlignment="viewEnd"
|
||||
android:textColor="@android:color/holo_orange_light" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cb_carbs_remove"
|
||||
android:visibility="gone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:id="@+id/cb_carbs_remove"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="19dp"
|
||||
android:contentDescription="@string/select_for_removal"
|
||||
android:minWidth="0dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -115,8 +115,9 @@
|
|||
<CheckBox
|
||||
android:id="@+id/cb_remove"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="19dp"
|
||||
android:contentDescription="@string/select_for_removal"
|
||||
android:minWidth="0dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -156,8 +156,9 @@
|
|||
<CheckBox
|
||||
android:id="@+id/cb_remove"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="19dp"
|
||||
android:contentDescription="@string/select_for_removal"
|
||||
android:minWidth="0dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
|
|
|
@ -127,8 +127,9 @@
|
|||
<CheckBox
|
||||
android:id="@+id/cb_remove"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="19dp"
|
||||
android:contentDescription="@string/select_for_removal"
|
||||
android:minWidth="0dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -175,8 +175,9 @@
|
|||
<CheckBox
|
||||
android:id="@+id/cb_remove"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="19dp"
|
||||
android:contentDescription="@string/select_for_removal"
|
||||
android:minWidth="0dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
|
|
|
@ -150,8 +150,9 @@
|
|||
<CheckBox
|
||||
android:id="@+id/cb_remove"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="19dp"
|
||||
android:contentDescription="@string/select_for_removal"
|
||||
android:minWidth="0dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -3,20 +3,27 @@
|
|||
|
||||
<item
|
||||
android:id="@+id/nav_remove_items"
|
||||
android:icon="@drawable/ic_trash"
|
||||
android:title="@string/remove_items"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_show_invalidated"
|
||||
android:icon="@drawable/ic_visibility"
|
||||
android:title="@string/show_invalidated"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_hide_invalidated"
|
||||
android:icon="@drawable/ic_visibility_off"
|
||||
android:title="@string/hide_invalidated"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_delete_future"
|
||||
android:title="@string/delete_future_treatments"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_refresh_ns"
|
||||
android:title="@string/refresh_from_nightscout"
|
||||
|
|
|
@ -3,20 +3,27 @@
|
|||
|
||||
<item
|
||||
android:id="@+id/nav_remove_items"
|
||||
android:icon="@drawable/ic_trash"
|
||||
android:title="@string/remove_items"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_show_invalidated"
|
||||
android:icon="@drawable/ic_visibility"
|
||||
android:title="@string/show_invalidated"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_hide_invalidated"
|
||||
android:icon="@drawable/ic_visibility_off"
|
||||
android:title="@string/hide_invalidated"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_refresh_ns"
|
||||
android:title="@string/refresh_from_nightscout"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_remove_started_events"
|
||||
android:title="@string/careportal_removestartedevents"
|
||||
|
|
|
@ -3,15 +3,20 @@
|
|||
|
||||
<item
|
||||
android:id="@+id/nav_remove_items"
|
||||
android:icon="@drawable/ic_trash"
|
||||
android:title="@string/remove_items"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_show_invalidated"
|
||||
android:icon="@drawable/ic_visibility"
|
||||
android:title="@string/show_invalidated"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_hide_invalidated"
|
||||
android:icon="@drawable/ic_visibility_off"
|
||||
android:title="@string/hide_invalidated"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
</menu>
|
||||
|
|
|
@ -3,15 +3,20 @@
|
|||
|
||||
<item
|
||||
android:id="@+id/nav_remove_items"
|
||||
android:icon="@drawable/ic_trash"
|
||||
android:title="@string/remove_items"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_show_invalidated"
|
||||
android:icon="@drawable/ic_visibility"
|
||||
android:title="@string/show_invalidated"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_hide_invalidated"
|
||||
android:icon="@drawable/ic_visibility_off"
|
||||
android:title="@string/hide_invalidated"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
</menu>
|
||||
|
|
|
@ -3,15 +3,20 @@
|
|||
|
||||
<item
|
||||
android:id="@+id/nav_remove_items"
|
||||
android:icon="@drawable/ic_trash"
|
||||
android:title="@string/remove_items"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_show_invalidated"
|
||||
android:icon="@drawable/ic_visibility"
|
||||
android:title="@string/show_invalidated"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_hide_invalidated"
|
||||
android:icon="@drawable/ic_visibility_off"
|
||||
android:title="@string/hide_invalidated"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
</menu>
|
||||
|
|
|
@ -3,16 +3,22 @@
|
|||
|
||||
<item
|
||||
android:id="@+id/nav_remove_items"
|
||||
android:icon="@drawable/ic_trash"
|
||||
android:title="@string/remove_items"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_show_invalidated"
|
||||
android:icon="@drawable/ic_visibility"
|
||||
android:title="@string/show_invalidated"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_hide_invalidated"
|
||||
android:title="@string/hide_invalidated"
|
||||
app:showAsAction="never" />
|
||||
android:icon="@drawable/ic_visibility_off"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_refresh_ns"
|
||||
android:title="@string/refresh_from_nightscout"
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
android:id="@+id/nav_show_loop"
|
||||
android:title="@string/show_loop"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_hide_loop"
|
||||
android:title="@string/hide_loop"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_export"
|
||||
android:title="@string/ue_export_to_csv"
|
||||
|
|
|
@ -1188,6 +1188,8 @@
|
|||
<string name="wear_unknown_action_string">Unknown action command:</string>
|
||||
<string name="overview_editquickwizard_percentage">Percentage</string>
|
||||
<string name="app_default">Application default</string>
|
||||
<string name="show_invalidated_records">Show invalidated / removed records</string>
|
||||
<string name="hide_invalidated_records">Hide invalidated / removed records</string>
|
||||
<string name="select_profile">Select profile to edit</string>
|
||||
<string name="refresh_from_nightscout">Refresh from Nightscout</string>
|
||||
<string name="remove_selected_items">Remove selected items</string>
|
||||
|
|
|
@ -3,8 +3,6 @@ package info.nightscout.androidaps.plugins.general.automation
|
|||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.text.method.ScrollingMovementMethod
|
||||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
|
@ -29,7 +27,7 @@ import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDi
|
|||
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged
|
||||
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui
|
||||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector
|
||||
import info.nightscout.androidaps.utils.ActionHelper
|
||||
import info.nightscout.androidaps.utils.ActionModeHelper
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.HtmlHelper
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
|
@ -54,7 +52,7 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
|
|||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
private lateinit var eventListAdapter: EventListAdapter
|
||||
private lateinit var actionHelper: ActionHelper<AutomationEvent>
|
||||
private lateinit var actionHelper: ActionModeHelper<AutomationEvent>
|
||||
private val itemTouchHelper = ItemTouchHelper(SimpleItemTouchHelperCallback())
|
||||
private var _binding: AutomationFragmentBinding? = null
|
||||
|
||||
|
@ -63,7 +61,7 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
|
|||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
_binding = AutomationFragmentBinding.inflate(inflater, container, false)
|
||||
actionHelper = ActionHelper(rh, activity)
|
||||
actionHelper = ActionModeHelper(rh, activity)
|
||||
actionHelper.setUpdateListHandler { binding.eventListView.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
actionHelper.enableSort = true
|
||||
|
|
|
@ -10,7 +10,7 @@ import info.nightscout.androidaps.core.R
|
|||
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
|
||||
class ActionHelper<T>(val rh: ResourceHelper, val activity: FragmentActivity?) {
|
||||
class ActionModeHelper<T>(val rh: ResourceHelper, val activity: FragmentActivity?) {
|
||||
|
||||
var enableSort = false
|
||||
private var selectedItems: SparseArray<T> = SparseArray()
|
Loading…
Reference in a new issue