diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index afbc185878..35dee1accb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -235,11 +235,6 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList super.onPause() disposable.clear() loopHandler.removeCallbacksAndMessages(null) -/* overview_apsmode_llayout?.let { unregisterForContextMenu(it) } - overview_activeprofile?.let { unregisterForContextMenu(it) } - overview_temptarget?.let { unregisterForContextMenu(it) } - - */ } override fun onResume() { @@ -311,22 +306,9 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } loopHandler.postDelayed(refreshLoop, 60 * 1000L) -/* overview_apsmode_llayout?.let { registerForContextMenu(overview_apsmode) } - overview_activeprofile?.let { registerForContextMenu(it) } - overview_temptarget?.let { registerForContextMenu(it) } - - */ updateGUI("onResume") } - override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenuInfo?) { - super.onCreateContextMenu(menu, v, menuInfo) - overviewMenus.createContextMenu(menu, v) - } - - override fun onContextItemSelected(item: MenuItem): Boolean { - return if (overviewMenus.onContextItemSelected(item, childFragmentManager)) true else super.onContextItemSelected(item) - } override fun onClick(v: View) { // try to fix https://fabric.io/nightscout3/android/apps/info.nightscout.androidaps/issues/5aca7a1536c7b23527eb4be7?time=last-seven-days diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewMenus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewMenus.kt index 8347e9141f..f0313cc6fd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewMenus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewMenus.kt @@ -5,7 +5,6 @@ import android.content.Intent import android.os.Bundle import android.text.SpannableString import android.text.style.ForegroundColorSpan -import android.view.ContextMenu import android.view.Menu import android.view.MenuItem import android.view.View @@ -248,17 +247,17 @@ class OverviewMenus @Inject constructor( when (it.title) { resourceHelper.gs(R.string.careportal_profileswitch), resourceHelper.gs(R.string.viewprofile), - resourceHelper.gs(R.string.custom) -> onContextItemSelected(it, manager) + resourceHelper.gs(R.string.custom) -> onItemSelected(it, manager) else -> { OKDialog.showConfirmation(context, resourceHelper.gs(R.string.confirm), it.title.toString(), Runnable { - onContextItemSelected(it, manager) + onItemSelected(it, manager) }) } } } else { - onContextItemSelected(it, manager) + onItemSelected(it, manager) } } return@setOnMenuItemClickListener true @@ -268,65 +267,7 @@ class OverviewMenus @Inject constructor( } } - fun createContextMenu(menu: ContextMenu, v: View) { - when (v.id) { - R.id.overview_apsmode -> { - val pumpDescription: PumpDescription = activePlugin.activePump.pumpDescription - if (!profileFunction.isProfileValid("ContextMenuCreation")) return - menu.setHeaderTitle(resourceHelper.gs(R.string.loop)) - if (loopPlugin.isEnabled(PluginType.LOOP)) { - menu.add(resourceHelper.gs(R.string.disableloop)) - if (!loopPlugin.isSuspended) { - menu.add(resourceHelper.gs(R.string.suspendloopfor1h)) - menu.add(resourceHelper.gs(R.string.suspendloopfor2h)) - menu.add(resourceHelper.gs(R.string.suspendloopfor3h)) - menu.add(resourceHelper.gs(R.string.suspendloopfor10h)) - } else { - if (!loopPlugin.isDisconnected) { - menu.add(resourceHelper.gs(R.string.resume)) - } - } - } - if (!loopPlugin.isEnabled(PluginType.LOOP)) { - menu.add(resourceHelper.gs(R.string.enableloop)) - } - if (!loopPlugin.isDisconnected) { - showSuspendPump(menu, pumpDescription) - } else { - menu.add(resourceHelper.gs(R.string.reconnect)) - } - } - - R.id.overview_activeprofile -> { - menu.setHeaderTitle(resourceHelper.gs(R.string.profile)) - menu.add(resourceHelper.gs(R.string.viewprofile)) - if (activePlugin.activeProfileInterface.profile != null) { - menu.add(resourceHelper.gs(R.string.careportal_profileswitch)) - } - } - - R.id.overview_temptarget -> { - menu.setHeaderTitle(resourceHelper.gs(R.string.careportal_temporarytarget)) - menu.add(resourceHelper.gs(R.string.custom)) - menu.add(resourceHelper.gs(R.string.eatingsoon)) - menu.add(resourceHelper.gs(R.string.activity)) - menu.add(resourceHelper.gs(R.string.hypo)) - if (activePlugin.activeTreatments.tempTargetFromHistory != null) { - menu.add(resourceHelper.gs(R.string.cancel)) - } - } - } - } - - private fun showSuspendPump(menu: ContextMenu, pumpDescription: PumpDescription) { - if (pumpDescription.tempDurationStep15mAllowed) menu.add(resourceHelper.gs(R.string.disconnectpumpfor15m)) - if (pumpDescription.tempDurationStep30mAllowed) menu.add(resourceHelper.gs(R.string.disconnectpumpfor30m)) - menu.add(resourceHelper.gs(R.string.disconnectpumpfor1h)) - menu.add(resourceHelper.gs(R.string.disconnectpumpfor2h)) - menu.add(resourceHelper.gs(R.string.disconnectpumpfor3h)) - } - - fun onContextItemSelected(item: MenuItem, manager: FragmentManager): Boolean { + fun onItemSelected(item: MenuItem, manager: FragmentManager): Boolean { val profile = profileFunction.getProfile() ?: return true when (item.title) { resourceHelper.gs(R.string.disableloop) -> {