Replace Context menu by long click menu
This commit is contained in:
parent
2c43bc75c0
commit
28fa373d83
2 changed files with 109 additions and 2 deletions
|
@ -214,6 +214,9 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
overviewMenus.setupChartMenu(overview_chartMenuButton)
|
overviewMenus.setupChartMenu(overview_chartMenuButton)
|
||||||
prepareGraphs()
|
prepareGraphs()
|
||||||
|
|
||||||
|
overviewMenus.setupPopupMenu(overview_apsmode, requireContext(), childFragmentManager)
|
||||||
|
overviewMenus.setupPopupMenu(overview_activeprofile, requireContext(), childFragmentManager)
|
||||||
|
overviewMenus.setupPopupMenu(overview_temptarget, requireContext(), childFragmentManager)
|
||||||
overview_accepttempbutton?.setOnClickListener(this)
|
overview_accepttempbutton?.setOnClickListener(this)
|
||||||
overview_treatmentbutton?.setOnClickListener(this)
|
overview_treatmentbutton?.setOnClickListener(this)
|
||||||
overview_wizardbutton?.setOnClickListener(this)
|
overview_wizardbutton?.setOnClickListener(this)
|
||||||
|
@ -223,15 +226,20 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
overview_carbsbutton?.setOnClickListener(this)
|
overview_carbsbutton?.setOnClickListener(this)
|
||||||
overview_quickwizardbutton?.setOnClickListener(this)
|
overview_quickwizardbutton?.setOnClickListener(this)
|
||||||
overview_quickwizardbutton?.setOnLongClickListener(this)
|
overview_quickwizardbutton?.setOnLongClickListener(this)
|
||||||
|
overview_apsmode?.setOnLongClickListener(this)
|
||||||
|
overview_activeprofile?.setOnLongClickListener(this)
|
||||||
|
overview_temptarget?.setOnLongClickListener(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
disposable.clear()
|
disposable.clear()
|
||||||
loopHandler.removeCallbacksAndMessages(null)
|
loopHandler.removeCallbacksAndMessages(null)
|
||||||
overview_apsmode_llayout?.let { unregisterForContextMenu(it) }
|
/* overview_apsmode_llayout?.let { unregisterForContextMenu(it) }
|
||||||
overview_activeprofile?.let { unregisterForContextMenu(it) }
|
overview_activeprofile?.let { unregisterForContextMenu(it) }
|
||||||
overview_temptarget?.let { unregisterForContextMenu(it) }
|
overview_temptarget?.let { unregisterForContextMenu(it) }
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
@ -303,9 +311,11 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
}
|
}
|
||||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L)
|
loopHandler.postDelayed(refreshLoop, 60 * 1000L)
|
||||||
|
|
||||||
overview_apsmode_llayout?.let { registerForContextMenu(overview_apsmode) }
|
/* overview_apsmode_llayout?.let { registerForContextMenu(overview_apsmode) }
|
||||||
overview_activeprofile?.let { registerForContextMenu(it) }
|
overview_activeprofile?.let { registerForContextMenu(it) }
|
||||||
overview_temptarget?.let { registerForContextMenu(it) }
|
overview_temptarget?.let { registerForContextMenu(it) }
|
||||||
|
|
||||||
|
*/
|
||||||
updateGUI("onResume")
|
updateGUI("onResume")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,6 +407,10 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
||||||
startActivity(Intent(v.context, QuickWizardListActivity::class.java))
|
startActivity(Intent(v.context, QuickWizardListActivity::class.java))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
R.id.overview_apsmode, R.id.overview_activeprofile, R.id.overview_temptarget -> {
|
||||||
|
OverviewMenus.showOKCancel = false
|
||||||
|
v.performClick()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import info.nightscout.androidaps.queue.Callback
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||||
import info.nightscout.androidaps.utils.ToastUtils
|
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.buildHelper.BuildHelper
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
@ -75,6 +76,7 @@ class OverviewMenus @Inject constructor(
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val MAX_GRAPHS = 5 // including main
|
const val MAX_GRAPHS = 5 // including main
|
||||||
|
var showOKCancel = true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun enabledTypes(graph: Int): String {
|
fun enabledTypes(graph: Int): String {
|
||||||
|
@ -175,6 +177,97 @@ class OverviewMenus @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setupPopupMenu(v: View, context: Context, manager: FragmentManager) {
|
||||||
|
v.setOnClickListener {
|
||||||
|
val popup = PopupMenu(v.context, v)
|
||||||
|
when (v.id) {
|
||||||
|
R.id.overview_apsmode -> {
|
||||||
|
val pumpDescription: PumpDescription = activePlugin.activePump.pumpDescription
|
||||||
|
if (profileFunction.isProfileValid("ContextMenuCreation")) {
|
||||||
|
val item = popup.menu.add(Menu.NONE,1,Menu.NONE,resourceHelper.gs(R.string.loop)) // title
|
||||||
|
val title = item.title
|
||||||
|
val s = SpannableString(title)
|
||||||
|
s.setSpan( ForegroundColorSpan(resourceHelper.gc(R.color.colorAccent)), 0, s.length, 0)
|
||||||
|
item.setTitle(s)
|
||||||
|
if (loopPlugin.isEnabled(PluginType.LOOP)) {
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.disableloop))
|
||||||
|
if (!loopPlugin.isSuspended) {
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.suspendloopfor1h))
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.suspendloopfor2h))
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.suspendloopfor3h))
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.suspendloopfor10h))
|
||||||
|
} else {
|
||||||
|
if (!loopPlugin.isDisconnected) {
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.resume))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!loopPlugin.isEnabled(PluginType.LOOP)) {
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.enableloop))
|
||||||
|
}
|
||||||
|
if (!loopPlugin.isDisconnected) {
|
||||||
|
if (pumpDescription.tempDurationStep15mAllowed) popup.menu.add(resourceHelper.gs(R.string.disconnectpumpfor15m))
|
||||||
|
if (pumpDescription.tempDurationStep30mAllowed) popup.menu.add(resourceHelper.gs(R.string.disconnectpumpfor30m))
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.disconnectpumpfor1h))
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.disconnectpumpfor2h))
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.disconnectpumpfor3h))
|
||||||
|
} else {
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.reconnect))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
R.id.overview_activeprofile -> {
|
||||||
|
val item = popup.menu.add(Menu.NONE,1,Menu.NONE,resourceHelper.gs(R.string.profile)) // title
|
||||||
|
val title = item.title
|
||||||
|
val s = SpannableString(title)
|
||||||
|
s.setSpan(ForegroundColorSpan(resourceHelper.gc(R.color.colorAccent)), 0, s.length, 0)
|
||||||
|
item.setTitle(s)
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.viewprofile))
|
||||||
|
if (activePlugin.activeProfileInterface.profile != null) {
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.careportal_profileswitch))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
R.id.overview_temptarget -> {
|
||||||
|
val item = popup.menu.add(Menu.NONE,1,Menu.NONE,resourceHelper.gs(R.string.careportal_temporarytarget)) // title
|
||||||
|
val title = item.title
|
||||||
|
val s = SpannableString(title)
|
||||||
|
s.setSpan(ForegroundColorSpan(resourceHelper.gc(R.color.colorAccent)), 0, s.length, 0)
|
||||||
|
item.setTitle(s)
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.custom))
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.eatingsoon))
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.activity))
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.hypo))
|
||||||
|
if (activePlugin.activeTreatments.tempTargetFromHistory != null) {
|
||||||
|
popup.menu.add(resourceHelper.gs(R.string.cancel))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
popup.setOnMenuItemClickListener {
|
||||||
|
if (it.itemId != 1) {
|
||||||
|
if (showOKCancel) {
|
||||||
|
when (it.title) {
|
||||||
|
resourceHelper.gs(R.string.careportal_profileswitch),
|
||||||
|
resourceHelper.gs(R.string.viewprofile),
|
||||||
|
resourceHelper.gs(R.string.custom) -> onContextItemSelected(it, manager)
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
OKDialog.showConfirmation(context, resourceHelper.gs(R.string.confirm), it.title.toString(),
|
||||||
|
Runnable {
|
||||||
|
onContextItemSelected(it, manager)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
onContextItemSelected(it, manager)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return@setOnMenuItemClickListener true
|
||||||
|
}
|
||||||
|
popup.setOnDismissListener { showOKCancel = true }
|
||||||
|
popup.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun createContextMenu(menu: ContextMenu, v: View) {
|
fun createContextMenu(menu: ContextMenu, v: View) {
|
||||||
when (v.id) {
|
when (v.id) {
|
||||||
R.id.overview_apsmode -> {
|
R.id.overview_apsmode -> {
|
||||||
|
|
Loading…
Reference in a new issue