Merge pull request #117 from Philoul/ShortClick
Short Click menu added in overview
This commit is contained in:
commit
68a7c70e23
|
@ -85,23 +85,11 @@ class TempTargetDialog : DialogFragmentWithDate() {
|
|||
val adapterReason = ArrayAdapter(context, R.layout.spinner_centered, reasonList)
|
||||
overview_temptarget_reason.adapter = adapterReason
|
||||
|
||||
overview_temptarget_custom?.setOnClickListener {
|
||||
overview_temptarget_temptarget.value = savedInstanceState?.getDouble("overview_temptarget_temptarget") ?: if (profileFunction.getUnits() == Constants.MMOL) Constants.MIN_TT_MMOL else Constants.MIN_TT_MGDL
|
||||
overview_temptarget_duration.value = savedInstanceState?.getDouble("overview_temptarget_duration") ?: 0.0
|
||||
overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.manual)));
|
||||
}
|
||||
|
||||
overview_temptarget_cancel?.setOnClickListener { shortClick(it) }
|
||||
overview_temptarget_eating_soon?.setOnClickListener { shortClick(it) }
|
||||
overview_temptarget_activity?.setOnClickListener { shortClick(it) }
|
||||
overview_temptarget_hypo?.setOnClickListener { shortClick(it) }
|
||||
/*
|
||||
overview_temptarget_cancel?.setOnLongClickListener {
|
||||
longClick(it)
|
||||
return@setOnLongClickListener true
|
||||
}
|
||||
|
||||
*/
|
||||
overview_temptarget_eating_soon?.setOnLongClickListener {
|
||||
longClick(it)
|
||||
return@setOnLongClickListener true
|
||||
|
@ -124,11 +112,6 @@ class TempTargetDialog : DialogFragmentWithDate() {
|
|||
|
||||
private fun longClick(v:View) {
|
||||
when (v.id) {
|
||||
R.id.overview_temptarget_cancel -> {
|
||||
overview_temptarget_temptarget.value = 0.0
|
||||
overview_temptarget_duration.value = 0.0
|
||||
overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.cancel)))
|
||||
}
|
||||
R.id.overview_temptarget_eating_soon -> {
|
||||
overview_temptarget_temptarget.value = defaultValueHelper.determineEatingSoonTT()
|
||||
overview_temptarget_duration.value = defaultValueHelper.determineEatingSoonTTDuration().toDouble()
|
||||
|
|
|
@ -31,11 +31,7 @@ import info.nightscout.androidaps.Config
|
|||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.dialogs.CalibrationDialog
|
||||
import info.nightscout.androidaps.dialogs.CarbsDialog
|
||||
import info.nightscout.androidaps.dialogs.InsulinDialog
|
||||
import info.nightscout.androidaps.dialogs.TreatmentDialog
|
||||
import info.nightscout.androidaps.dialogs.WizardDialog
|
||||
import info.nightscout.androidaps.dialogs.*
|
||||
import info.nightscout.androidaps.events.*
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
|
@ -187,6 +183,12 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
|||
overviewMenus.setupChartMenu(overview_chartMenuButton)
|
||||
prepareGraphs()
|
||||
|
||||
overviewMenus.setupPopupMenu(overview_apsmode, requireContext(), childFragmentManager)
|
||||
//overviewMenus.setupPopupMenu(overview_activeprofile, requireContext(), childFragmentManager)
|
||||
overview_activeprofile?.setOnClickListener(this)
|
||||
overview_activeprofile?.setOnLongClickListener(this)
|
||||
overview_temptarget?.setOnClickListener(this)
|
||||
overview_temptarget?.setOnLongClickListener(this)
|
||||
overview_accepttempbutton?.setOnClickListener(this)
|
||||
overview_treatmentbutton?.setOnClickListener(this)
|
||||
overview_wizardbutton?.setOnClickListener(this)
|
||||
|
@ -196,15 +198,14 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
|||
overview_carbsbutton?.setOnClickListener(this)
|
||||
overview_quickwizardbutton?.setOnClickListener(this)
|
||||
overview_quickwizardbutton?.setOnLongClickListener(this)
|
||||
overview_apsmode?.setOnLongClickListener(this)
|
||||
overview_activeprofile?.setOnLongClickListener(this)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
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() {
|
||||
|
@ -276,20 +277,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
|
||||
|
@ -302,7 +292,15 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
|||
R.id.overview_insulinbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { InsulinDialog().show(childFragmentManager, "Overview") })
|
||||
R.id.overview_quickwizardbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { onClickQuickWizard() })
|
||||
R.id.overview_carbsbutton -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { CarbsDialog().show(childFragmentManager, "Overview") })
|
||||
|
||||
R.id.overview_temptarget -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { TempTargetDialog().show(childFragmentManager, "Overview") })
|
||||
R.id.overview_activeprofile -> {
|
||||
val args = Bundle()
|
||||
args.putLong("time", DateUtil.now())
|
||||
args.putInt("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal)
|
||||
val pvd = ProfileViewerDialog()
|
||||
pvd.arguments = args
|
||||
pvd.show(childFragmentManager, "ProfileViewDialog")
|
||||
}
|
||||
R.id.overview_cgmbutton -> {
|
||||
if (xdripPlugin.isEnabled(PluginType.BGSOURCE))
|
||||
openCgmApp("com.eveningoutpost.dexdrip")
|
||||
|
@ -370,6 +368,13 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
|||
startActivity(Intent(v.context, QuickWizardListActivity::class.java))
|
||||
return true
|
||||
}
|
||||
R.id.overview_apsmode -> {
|
||||
OverviewMenus.showOKCancel = false
|
||||
v.performClick()
|
||||
}
|
||||
R.id.overview_temptarget -> v.performClick()
|
||||
R.id.overview_activeprofile -> activity?.let { activity -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { ProfileSwitchDialog().show(childFragmentManager, "Overview") })}
|
||||
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -38,6 +37,7 @@ import info.nightscout.androidaps.queue.Callback
|
|||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||
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
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
|
@ -75,6 +75,7 @@ class OverviewMenus @Inject constructor(
|
|||
|
||||
companion object {
|
||||
const val MAX_GRAPHS = 5 // including main
|
||||
var showOKCancel = true
|
||||
}
|
||||
|
||||
fun enabledTypes(graph: Int): String {
|
||||
|
@ -175,65 +176,83 @@ class OverviewMenus @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun createContextMenu(menu: ContextMenu, v: View) {
|
||||
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")) return
|
||||
menu.setHeaderTitle(resourceHelper.gs(R.string.loop))
|
||||
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)) {
|
||||
menu.add(resourceHelper.gs(R.string.disableloop))
|
||||
popup.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))
|
||||
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) {
|
||||
menu.add(resourceHelper.gs(R.string.resume))
|
||||
popup.menu.add(resourceHelper.gs(R.string.resume))
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!loopPlugin.isEnabled(PluginType.LOOP)) {
|
||||
menu.add(resourceHelper.gs(R.string.enableloop))
|
||||
popup.menu.add(resourceHelper.gs(R.string.enableloop))
|
||||
}
|
||||
if (!loopPlugin.isDisconnected) {
|
||||
showSuspendPump(menu, pumpDescription)
|
||||
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 {
|
||||
menu.add(resourceHelper.gs(R.string.reconnect))
|
||||
popup.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))
|
||||
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) {
|
||||
menu.add(resourceHelper.gs(R.string.careportal_profileswitch))
|
||||
popup.menu.add(resourceHelper.gs(R.string.careportal_profileswitch))
|
||||
}
|
||||
}
|
||||
}
|
||||
popup.setOnMenuItemClickListener {
|
||||
if (it.itemId != 1) {
|
||||
if (showOKCancel) {
|
||||
when (it.title) {
|
||||
resourceHelper.gs(R.string.careportal_profileswitch),
|
||||
resourceHelper.gs(R.string.viewprofile) -> onItemSelected(it, manager)
|
||||
|
||||
else -> {
|
||||
OKDialog.showConfirmation(context, resourceHelper.gs(R.string.confirm), it.title.toString(),
|
||||
Runnable {
|
||||
onItemSelected(it, manager)
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
onItemSelected(it, manager)
|
||||
}
|
||||
}
|
||||
return@setOnMenuItemClickListener true
|
||||
}
|
||||
popup.setOnDismissListener { showOKCancel = true }
|
||||
popup.show()
|
||||
}
|
||||
}
|
||||
|
||||
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) -> {
|
||||
|
@ -360,60 +379,6 @@ class OverviewMenus @Inject constructor(
|
|||
pvd.arguments = args
|
||||
pvd.show(manager, "ProfileViewDialog")
|
||||
}
|
||||
|
||||
resourceHelper.gs(R.string.eatingsoon) -> {
|
||||
aapsLogger.debug("USER ENTRY: TEMP TARGET EATING SOON")
|
||||
val target = Profile.toMgdl(defaultValueHelper.determineEatingSoonTT(), profileFunction.getUnits())
|
||||
val tempTarget = TempTarget()
|
||||
.date(System.currentTimeMillis())
|
||||
.duration(defaultValueHelper.determineEatingSoonTTDuration())
|
||||
.reason(resourceHelper.gs(R.string.eatingsoon))
|
||||
.source(Source.USER)
|
||||
.low(target)
|
||||
.high(target)
|
||||
activePlugin.activeTreatments.addToHistoryTempTarget(tempTarget)
|
||||
}
|
||||
|
||||
resourceHelper.gs(R.string.activity) -> {
|
||||
aapsLogger.debug("USER ENTRY: TEMP TARGET ACTIVITY")
|
||||
val target = Profile.toMgdl(defaultValueHelper.determineActivityTT(), profileFunction.getUnits())
|
||||
val tempTarget = TempTarget()
|
||||
.date(DateUtil.now())
|
||||
.duration(defaultValueHelper.determineActivityTTDuration())
|
||||
.reason(resourceHelper.gs(R.string.activity))
|
||||
.source(Source.USER)
|
||||
.low(target)
|
||||
.high(target)
|
||||
activePlugin.activeTreatments.addToHistoryTempTarget(tempTarget)
|
||||
}
|
||||
|
||||
resourceHelper.gs(R.string.hypo) -> {
|
||||
aapsLogger.debug("USER ENTRY: TEMP TARGET HYPO")
|
||||
val target = Profile.toMgdl(defaultValueHelper.determineHypoTT(), profileFunction.getUnits())
|
||||
val tempTarget = TempTarget()
|
||||
.date(DateUtil.now())
|
||||
.duration(defaultValueHelper.determineHypoTTDuration())
|
||||
.reason(resourceHelper.gs(R.string.hypo))
|
||||
.source(Source.USER)
|
||||
.low(target)
|
||||
.high(target)
|
||||
activePlugin.activeTreatments.addToHistoryTempTarget(tempTarget)
|
||||
}
|
||||
|
||||
resourceHelper.gs(R.string.custom) -> {
|
||||
TempTargetDialog().show(manager, "Overview")
|
||||
}
|
||||
|
||||
resourceHelper.gs(R.string.cancel) -> {
|
||||
aapsLogger.debug("USER ENTRY: TEMP TARGET CANCEL")
|
||||
val tempTarget = TempTarget()
|
||||
.source(Source.USER)
|
||||
.date(DateUtil.now())
|
||||
.duration(0)
|
||||
.low(0.0)
|
||||
.high(0.0)
|
||||
activePlugin.activeTreatments.addToHistoryTempTarget(tempTarget)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -142,27 +142,12 @@
|
|||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/datetime" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<info.nightscout.androidaps.utils.ui.SingleClickButton
|
||||
android:id="@+id/overview_temptarget_custom"
|
||||
style="?android:attr/buttonStyle"
|
||||
android:layout_width="0px"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_marginEnd="-4dp"
|
||||
android:layout_weight="0.5"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:drawableTop="@drawable/ic_target_manual"
|
||||
android:text="@string/manual"
|
||||
android:textColor="@color/tempTargetConfirmation"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:visibility="gone"
|
||||
android:textSize="11sp" />
|
||||
|
||||
<info.nightscout.androidaps.utils.ui.SingleClickButton
|
||||
android:id="@+id/overview_temptarget_cancel"
|
||||
style="?android:attr/buttonStyle"
|
||||
|
|
Loading…
Reference in a new issue