UI: allow graph scale from menu

This commit is contained in:
Milos Kozak 2022-05-11 16:35:20 +02:00
parent 49163c43d3
commit d3c3ef45c3
5 changed files with 49 additions and 10 deletions

View file

@ -17,6 +17,7 @@ import info.nightscout.androidaps.databinding.ActivityHistorybrowseBinding
import info.nightscout.androidaps.events.EventAutosensCalculationFinished
import info.nightscout.androidaps.events.EventCustomCalculationFinished
import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.events.EventScale
import info.nightscout.androidaps.extensions.toVisibility
import info.nightscout.androidaps.extensions.toVisibilityKeepSpace
import info.nightscout.androidaps.interfaces.ActivePlugin
@ -130,10 +131,9 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
loadAll("onClickEnd")
}
binding.zoom.setOnClickListener {
rangeToDisplay += 6
rangeToDisplay = if (rangeToDisplay > 24) 6 else rangeToDisplay
setTime(overviewData.fromTime)
loadAll("rangeChange")
var hours = rangeToDisplay + 6
hours = if (hours > 24) 6 else hours
rxBus.send(EventScale(hours))
}
binding.zoom.setOnLongClickListener {
Calendar.getInstance().also { calendar ->
@ -214,6 +214,14 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
.toObservable(EventUpdateOverviewGraph::class.java)
.observeOn(aapsSchedulers.main)
.subscribe({ updateGUI("EventRefreshOverview") }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventScale::class.java)
.observeOn(aapsSchedulers.main)
.subscribe({
rangeToDisplay = it.hours
setTime(overviewData.fromTime)
loadAll("rangeChange")
}, fabricPrivacy::logException)
if (overviewData.fromTime == 0L) {
// set start of current day

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventScale(val hours: Int) : Event()

View file

@ -245,6 +245,15 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
.toObservable(EventUpdateOverviewNotification::class.java)
.observeOn(aapsSchedulers.main)
.subscribe({ updateNotification() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventScale::class.java)
.observeOn(aapsSchedulers.main)
.subscribe({
overviewData.rangeToDisplay = it.hours
sp.putInt(R.string.key_rangetodisplay, it.hours)
rxBus.send(EventPreferenceChange(rh, R.string.key_rangetodisplay))
sp.putBoolean(R.string.key_objectiveusescale, true)
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventNewBG::class.java)
.debounce(1L, TimeUnit.SECONDS)

View file

@ -13,12 +13,13 @@ import androidx.appcompat.widget.PopupMenu
import com.google.gson.Gson
import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.events.EventScale
import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.Loop
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.sharedPreferences.SP
import javax.inject.Inject
@ -53,6 +54,7 @@ class OverviewMenus @Inject constructor(
companion object {
const val MAX_GRAPHS = 5 // including main
const val SCALE_ID = 1001
}
fun enabledTypes(graph: Int): String {
@ -103,6 +105,13 @@ class OverviewMenus @Inject constructor(
}
val popup = PopupMenu(v.context, v)
popup.menu.addSubMenu(Menu.NONE, SCALE_ID, Menu.NONE, rh.gs(R.string.graph_scale)).also {
it.add(Menu.NONE, SCALE_ID + 6, Menu.NONE, "6")
it.add(Menu.NONE, SCALE_ID + 12, Menu.NONE, "12")
it.add(Menu.NONE, SCALE_ID + 18, Menu.NONE, "18")
it.add(Menu.NONE, SCALE_ID + 24, Menu.NONE, "24")
}
val used = arrayListOf<Int>()
for (g in 0 until numOfGraphs) {
@ -124,7 +133,7 @@ class OverviewMenus @Inject constructor(
if (insert) {
val item = popup.menu.add(Menu.NONE, m.ordinal + 100 * (g + 1), Menu.NONE, rh.gs(m.nameId))
val title = item.title
val s = SpannableString(" " + title + " ")
val s = SpannableString(" $title ")
s.setSpan(ForegroundColorSpan(rh.gac(context, m.attrTextId)), 0, s.length, 0)
s.setSpan(BackgroundColorSpan(rh.gac(context, m.attrId)), 0, s.length, 0)
item.title = s
@ -144,17 +153,26 @@ class OverviewMenus @Inject constructor(
try {
// id < 100 graph header - divider 1, 2, 3 .....
when {
it.itemId == numOfGraphs -> {
it.itemId == SCALE_ID -> {
// do nothing, submenu
}
it.itemId > SCALE_ID && it.itemId < SCALE_ID + 100 -> {
val hours = it.itemId - SCALE_ID // 6,12,....
rxBus.send(EventScale(hours))
}
it.itemId == numOfGraphs -> {
// add new empty
_setting.add(Array(CharType.values().size) { false })
}
it.itemId < 100 -> {
it.itemId < 100 -> {
// remove graph
_setting.removeAt(it.itemId)
}
else -> {
else -> {
val graphNumber = it.itemId / 100 - 1
val item = it.itemId % 100
_setting[graphNumber][item] = !it.isChecked

View file

@ -1213,6 +1213,7 @@
<string name="widget_description">AndroidAPS widget</string>
<string name="configure">Configure opacity</string>
<string name="loop_status">Loop status</string>
<string name="graph_scale">Graph scale</string>
<string name="a11y_otp_qr_code">QR Code for setup one time password</string>
<string name="a11y_open_settings">open settings</string>
@ -1228,5 +1229,5 @@
<string name="aidex">GlucoRx Aidex</string>
<string name="aidex_short">Aidex</string>
<string name="description_source_aidex">Receive BG values from GlucoRx Aidex CGMS.</string>
</resources>