From 4ad9f1d42885a29771f04ca8dfe6339c9a8a49f4 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 27 May 2022 08:40:41 +0200 Subject: [PATCH] Fragments menu improvements --- .../fragments/TreatmentsBolusCarbsFragment.kt | 5 +- .../fragments/TreatmentsCareportalFragment.kt | 2 +- .../TreatmentsExtendedBolusesFragment.kt | 8 +- .../TreatmentsProfileSwitchFragment.kt | 2 +- .../fragments/TreatmentsTempTargetFragment.kt | 8 +- .../TreatmentsTemporaryBasalsFragment.kt | 4 +- .../plugins/aps/loop/LoopFragment.kt | 13 ++-- .../aps/openAPSAMA/OpenAPSAMAFragment.kt | 21 +++-- .../aps/openAPSSMB/OpenAPSSMBFragment.kt | 18 +++-- .../general/nsclient/NSClientFragment.kt | 76 ++++++++++++++----- .../activities/QuickWizardListActivity.kt | 2 +- .../plugins/source/BGSourceFragment.kt | 14 ++-- .../main/res/layout/ns_client_fragment.xml | 52 +------------ .../general/automation/AutomationFragment.kt | 2 +- .../androidaps/utils/ActionModeHelper.kt | 11 ++- 15 files changed, 113 insertions(+), 125 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsBolusCarbsFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsBolusCarbsFragment.kt index bac313ee14..1f7b9686e6 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsBolusCarbsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsBolusCarbsFragment.kt @@ -14,7 +14,6 @@ import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.Bolus import info.nightscout.androidaps.database.entities.BolusCalculatorResult import info.nightscout.androidaps.database.entities.Carbs -import info.nightscout.androidaps.database.entities.UserEntry import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.database.entities.ValueWithUnit @@ -30,6 +29,7 @@ import info.nightscout.androidaps.extensions.iobCalc import info.nightscout.androidaps.extensions.toVisibility import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart @@ -41,7 +41,6 @@ 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.interfaces.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.LTag @@ -91,7 +90,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() { @SuppressLint("NotifyDataSetChanged") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - actionHelper = ActionModeHelper(rh, activity) + actionHelper = ActionModeHelper(rh, activity, this) actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() } actionHelper.setOnRemoveHandler { removeSelected(it) } setHasOptionsMenu(true) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsCareportalFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsCareportalFragment.kt index 14f2554dcc..a1de658977 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsCareportalFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsCareportalFragment.kt @@ -67,7 +67,7 @@ class TreatmentsCareportalFragment : DaggerFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - actionHelper = ActionModeHelper(rh, activity) + actionHelper = ActionModeHelper(rh, activity, this) actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() } actionHelper.setOnRemoveHandler { removeSelected(it) } setHasOptionsMenu(true) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsExtendedBolusesFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsExtendedBolusesFragment.kt index a6aa6de45b..ce91e33a51 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsExtendedBolusesFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsExtendedBolusesFragment.kt @@ -25,6 +25,7 @@ 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.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.ActionModeHelper @@ -33,7 +34,6 @@ 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.interfaces.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.LTag @@ -73,7 +73,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() { @SuppressLint("NotifyDataSetChanged") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - actionHelper = ActionModeHelper(rh, activity) + actionHelper = ActionModeHelper(rh, activity, this) actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() } actionHelper.setOnRemoveHandler { removeSelected(it) } setHasOptionsMenu(true) @@ -140,7 +140,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() { holder.binding.date.text = if (newDay) dateUtil.dateStringRelative(extendedBolus.timestamp, rh) else "" if (extendedBolus.isInProgress(dateUtil)) { holder.binding.time.text = dateUtil.timeString(extendedBolus.timestamp) - holder.binding.time.setTextColor(rh.gac(context , R.attr.activeColor)) + holder.binding.time.setTextColor(rh.gac(context, R.attr.activeColor)) } else { holder.binding.time.text = dateUtil.timeRangeString(extendedBolus.timestamp, extendedBolus.end) holder.binding.time.setTextColor(holder.binding.insulin.currentTextColor) @@ -151,7 +151,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() { val iob = extendedBolus.iobCalc(System.currentTimeMillis(), profile, activePlugin.activeInsulin) 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.gac(context , R.attr.activeColor)) else holder.binding.iob.setTextColor(holder.binding.insulin.currentTextColor) + if (iob.iob != 0.0) holder.binding.iob.setTextColor(rh.gac(context, R.attr.activeColor)) else holder.binding.iob.setTextColor(holder.binding.insulin.currentTextColor) holder.binding.cbRemove.visibility = (extendedBolus.isValid && actionHelper.isRemoving).toVisibility() if (actionHelper.isRemoving) { holder.binding.cbRemove.setOnCheckedChangeListener { _, value -> diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsProfileSwitchFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsProfileSwitchFragment.kt index 183b94942f..08e91af77a 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsProfileSwitchFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsProfileSwitchFragment.kt @@ -78,7 +78,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() { @SuppressLint("NotifyDataSetChanged") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - actionHelper = ActionModeHelper(rh, activity) + actionHelper = ActionModeHelper(rh, activity, this) actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() } actionHelper.setOnRemoveHandler { removeSelected(it) } setHasOptionsMenu(true) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTempTargetFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTempTargetFragment.kt index 3bed1259c8..09e138bcee 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTempTargetFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTempTargetFragment.kt @@ -28,6 +28,7 @@ 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.interfaces.ResourceHelper import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart @@ -35,7 +36,6 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHi import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.buildHelper.BuildHelper -import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.LTag @@ -78,7 +78,7 @@ class TreatmentsTempTargetFragment : DaggerFragment() { @SuppressLint("NotifyDataSetChanged") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding.recyclerview.setHasFixedSize(true) - actionHelper = ActionModeHelper(rh, activity) + actionHelper = ActionModeHelper(rh, activity, this) actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() } actionHelper.setOnRemoveHandler { removeSelected(it) } setHasOptionsMenu(true) @@ -187,8 +187,8 @@ class TreatmentsTempTargetFragment : DaggerFragment() { holder.binding.reason.text = translator.translate(tempTarget.reason) holder.binding.time.setTextColor( when { - tempTarget.id == currentlyActiveTarget?.id -> rh.gac(context , R.attr.activeColor) - tempTarget.timestamp > dateUtil.now() -> rh.gac(context , R.attr.scheduledColor) + tempTarget.id == currentlyActiveTarget?.id -> rh.gac(context, R.attr.activeColor) + tempTarget.timestamp > dateUtil.now() -> rh.gac(context, R.attr.scheduledColor) else -> holder.binding.reasonColon.currentTextColor } ) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTemporaryBasalsFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTemporaryBasalsFragment.kt index 7e62e28f1e..b55a0723a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTemporaryBasalsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/fragments/TreatmentsTemporaryBasalsFragment.kt @@ -30,6 +30,7 @@ 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.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.ActionModeHelper @@ -38,7 +39,6 @@ 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.interfaces.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.LTag @@ -78,7 +78,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() { @SuppressLint("NotifyDataSetChanged") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - actionHelper = ActionModeHelper(rh, activity) + actionHelper = ActionModeHelper(rh, activity, this) actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() } actionHelper.setOnRemoveHandler { removeSelected(it) } setHasOptionsMenu(true) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt index 7d97f489d5..1970d7c179 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt @@ -42,14 +42,11 @@ class LoopFragment : DaggerFragment() { // onDestroyView. private val binding get() = _binding!! - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - setHasOptionsMenu(true) - _binding = LoopFragmentBinding.inflate(inflater, container, false) - return binding.root - } + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = + LoopFragmentBinding.inflate(inflater, container, false).also { + _binding = it + setHasOptionsMenu(true) + }.root override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt index 320ce0f2c8..d3fa56acf1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAFragment.kt @@ -43,14 +43,11 @@ class OpenAPSAMAFragment : DaggerFragment() { // onDestroyView. private val binding get() = _binding!! - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - setHasOptionsMenu(true) - _binding = OpenapsamaFragmentBinding.inflate(inflater, container, false) - return binding.root - } + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = + OpenapsamaFragmentBinding.inflate(inflater, container, false).also { + _binding = it + setHasOptionsMenu(true) + }.root override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -67,9 +64,11 @@ class OpenAPSAMAFragment : DaggerFragment() { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { super.onCreateOptionsMenu(menu, inflater) - menu.removeItem(ID_MENU_RUN) - menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER) - menu.setGroupDividerEnabled(true) + if (isResumed) { + menu.removeItem(ID_MENU_RUN) + menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER) + menu.setGroupDividerEnabled(true) + } } override fun onOptionsItemSelected(item: MenuItem): Boolean = diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt index 23a61db108..db729031a0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBFragment.kt @@ -46,11 +46,11 @@ class OpenAPSSMBFragment : DaggerFragment() { // onDestroyView. private val binding get() = _binding!! - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { - setHasOptionsMenu(true) - _binding = OpenapsamaFragmentBinding.inflate(inflater, container, false) - return binding.root - } + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = + OpenapsamaFragmentBinding.inflate(inflater, container, false).also { + _binding = it + setHasOptionsMenu(true) + }.root override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -66,9 +66,11 @@ class OpenAPSSMBFragment : DaggerFragment() { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { super.onCreateOptionsMenu(menu, inflater) - menu.removeItem(ID_MENU_RUN) - menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER) - menu.setGroupDividerEnabled(true) + if (isResumed) { + menu.removeItem(ID_MENU_RUN) + menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER) + menu.setGroupDividerEnabled(true) + } } override fun onOptionsItemSelected(item: MenuItem): Boolean = diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.kt index 4aa2b84a85..2b6efed560 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientFragment.kt @@ -1,10 +1,7 @@ package info.nightscout.androidaps.plugins.general.nsclient -import android.graphics.Paint import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup +import android.view.* import android.widget.ScrollView import dagger.android.support.DaggerFragment import info.nightscout.androidaps.R @@ -12,13 +9,13 @@ import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.databinding.NsClientFragmentBinding import info.nightscout.androidaps.interfaces.DataSyncSelector +import info.nightscout.androidaps.interfaces.ResourceHelper 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.general.nsclient.events.EventNSClientUpdateGUI import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.alertDialogs.OKDialog -import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.shared.sharedPreferences.SP import io.reactivex.rxjava3.disposables.CompositeDisposable @@ -36,6 +33,14 @@ class NSClientFragment : DaggerFragment() { @Inject lateinit var dataSyncSelector: DataSyncSelector @Inject lateinit var uel: UserEntryLogger + companion object { + + const val ID_MENU_CLEAR_LOG = 6 + const val ID_MENU_RESTART = 7 + const val ID_MENU_SEND_NOW = 8 + const val ID_MENU_FULL_SYNC = 8 + } + private val disposable = CompositeDisposable() private var _binding: NsClientFragmentBinding? = null @@ -45,7 +50,10 @@ class NSClientFragment : DaggerFragment() { private val binding get() = _binding!! override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = - NsClientFragmentBinding.inflate(inflater, container, false).also { _binding = it }.root + NsClientFragmentBinding.inflate(inflater, container, false).also { + _binding = it + setHasOptionsMenu(true) + }.root override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -63,23 +71,49 @@ class NSClientFragment : DaggerFragment() { nsClientPlugin.pause(isChecked) updateGui() } - binding.clearLog.setOnClickListener { nsClientPlugin.clearLog() } - binding.clearLog.paintFlags = binding.clearLog.paintFlags or Paint.UNDERLINE_TEXT_FLAG - binding.restart.setOnClickListener { rxBus.send(EventNSClientRestart()) } - binding.restart.paintFlags = binding.restart.paintFlags or Paint.UNDERLINE_TEXT_FLAG - binding.deliverNow.setOnClickListener { nsClientPlugin.resend("GUI") } - binding.deliverNow.paintFlags = binding.deliverNow.paintFlags or Paint.UNDERLINE_TEXT_FLAG - binding.fullSync.setOnClickListener { - context?.let { context -> - OKDialog.showConfirmation(context, rh.gs(R.string.nsclientinternal), - rh.gs(R.string.full_sync_comment), Runnable { - dataSyncSelector.resetToNextFullSync() - }) - } - } - binding.fullSync.paintFlags = binding.fullSync.paintFlags or Paint.UNDERLINE_TEXT_FLAG } + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + super.onCreateOptionsMenu(menu, inflater) + if (isResumed) { + menu.add(Menu.FIRST, ID_MENU_CLEAR_LOG, 0, rh.gs(R.string.clearlog)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER) + menu.add(Menu.FIRST, ID_MENU_RESTART, 0, rh.gs(R.string.restart)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER) + menu.add(Menu.FIRST, ID_MENU_SEND_NOW, 0, rh.gs(R.string.deliver_now)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER) + menu.add(Menu.FIRST, ID_MENU_FULL_SYNC, 0, rh.gs(R.string.full_sync)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER) + menu.setGroupDividerEnabled(true) + } + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean = + when (item.itemId) { + ID_MENU_CLEAR_LOG -> { + nsClientPlugin.clearLog() + true + } + + ID_MENU_RESTART -> { + rxBus.send(EventNSClientRestart()) + true + } + + ID_MENU_SEND_NOW -> { + nsClientPlugin.resend("GUI") + true + } + + ID_MENU_FULL_SYNC -> { + context?.let { context -> + OKDialog.showConfirmation( + context, rh.gs(R.string.nsclientinternal), rh.gs(R.string.full_sync_comment), + Runnable { dataSyncSelector.resetToNextFullSync() } + ) + } + true + } + + else -> false + } + @Synchronized override fun onResume() { super.onResume() disposable += rxBus diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.kt index 5960f22b15..7522148982 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.kt @@ -125,7 +125,7 @@ class QuickWizardListActivity : DaggerAppCompatActivityWithResult(), OnStartDrag binding = OverviewQuickwizardlistActivityBinding.inflate(layoutInflater) setContentView(binding.root) - actionHelper = ActionModeHelper(rh, this) + actionHelper = ActionModeHelper(rh, this, null) actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() } actionHelper.setOnRemoveHandler { removeSelected(it) } actionHelper.enableSort = true diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt index b04b104a01..a3fd240570 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt @@ -23,6 +23,7 @@ import info.nightscout.androidaps.extensions.valueToUnitsString import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.ActionModeHelper @@ -30,7 +31,6 @@ import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.alertDialogs.OKDialog -import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.LTag @@ -61,14 +61,16 @@ class BGSourceFragment : DaggerFragment() { private val binding get() = _binding!! override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = - BgsourceFragmentBinding.inflate(inflater, container, false).also { _binding = it }.root + BgsourceFragmentBinding.inflate(inflater, container, false).also { + _binding = it + actionHelper = ActionModeHelper(rh, activity, this) + actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() } + actionHelper.setOnRemoveHandler { handler -> removeSelected(handler) } + setHasOptionsMenu(true) + }.root 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(actionHelper.inMenu) binding.recyclerview.setHasFixedSize(true) binding.recyclerview.layoutManager = LinearLayoutManager(view.context) diff --git a/app/src/main/res/layout/ns_client_fragment.xml b/app/src/main/res/layout/ns_client_fragment.xml index a79fb66dc8..199f4075d8 100644 --- a/app/src/main/res/layout/ns_client_fragment.xml +++ b/app/src/main/res/layout/ns_client_fragment.xml @@ -58,6 +58,7 @@ @@ -95,57 +96,6 @@ - - - - - - - - - - - - (val rh: ResourceHelper, val activity: FragmentActivity?) { +class ActionModeHelper(val rh: ResourceHelper, val activity: FragmentActivity?, val fragment: Fragment?) { var enableSort = false private var selectedItems: SparseArray = SparseArray() @@ -20,7 +21,7 @@ class ActionModeHelper(val rh: ResourceHelper, val activity: FragmentActivity private var onRemove: ((selectedItems: SparseArray) -> Unit)? = null private var onUpdate: (() -> Unit)? = null - val inMenu: Boolean + private val inSingleFragment: Boolean get() { val parentClass = this.activity?.let { it::class.simpleName } return parentClass == "SingleFragmentActivity" @@ -67,8 +68,12 @@ class ActionModeHelper(val rh: ResourceHelper, val activity: FragmentActivity } fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - if (inMenu) { + if (inSingleFragment) { inflater.inflate(R.menu.menu_actions, menu) + } else if (fragment?.isResumed == true) { + menu.add(Menu.FIRST, R.id.nav_remove_items, 0, rh.gs(R.string.remove_items)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER) + menu.add(Menu.FIRST, R.id.nav_sort_items, 0, rh.gs(R.string.sort_items)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER) + menu.setGroupDividerEnabled(true) } }