OverviewMenus: catch exception

This commit is contained in:
Milos Kozak 2022-04-25 10:59:42 +02:00
parent a943307f68
commit 6c05b9d17f

View file

@ -15,10 +15,11 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.interfaces.Loop
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.utils.FabricPrivacy
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.shared.logging.AAPSLogger
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -31,8 +32,10 @@ class OverviewMenus @Inject constructor(
private val rxBus: RxBus, private val rxBus: RxBus,
private val buildHelper: BuildHelper, private val buildHelper: BuildHelper,
private val loop: Loop, private val loop: Loop,
private val config: Config private val config: Config,
private val fabricPrivacy: FabricPrivacy
) { ) {
enum class CharType(@StringRes val nameId: Int, @AttrRes val attrId: Int, @AttrRes val attrTextId: Int, val primary: Boolean, val secondary: Boolean, @StringRes val shortnameId: Int) { enum class CharType(@StringRes val nameId: Int, @AttrRes val attrId: Int, @AttrRes val attrTextId: Int, val primary: Boolean, val secondary: Boolean, @StringRes val shortnameId: Int) {
PRE(R.string.overview_show_predictions, R.attr.predictionColor, R.attr.menuTextColor, primary = true, secondary = false, shortnameId = R.string.prediction_shortname), PRE(R.string.overview_show_predictions, R.attr.predictionColor, R.attr.menuTextColor, primary = true, secondary = false, shortnameId = R.string.prediction_shortname),
TREAT(R.string.overview_show_treatments, R.attr.predictionColor, R.attr.menuTextColor, primary = true, secondary = false, shortnameId = R.string.treatments_shortname), TREAT(R.string.overview_show_treatments, R.attr.predictionColor, R.attr.menuTextColor, primary = true, secondary = false, shortnameId = R.string.treatments_shortname),
@ -138,22 +141,28 @@ class OverviewMenus @Inject constructor(
} }
popup.setOnMenuItemClickListener { popup.setOnMenuItemClickListener {
try {
// id < 100 graph header - divider 1, 2, 3 ..... // id < 100 graph header - divider 1, 2, 3 .....
when { when {
it.itemId == numOfGraphs -> { it.itemId == numOfGraphs -> {
// add new empty // add new empty
_setting.add(Array(CharType.values().size) { false }) _setting.add(Array(CharType.values().size) { false })
} }
it.itemId < 100 -> { it.itemId < 100 -> {
// remove graph // remove graph
_setting.removeAt(it.itemId) _setting.removeAt(it.itemId)
} }
else -> { else -> {
val graphNumber = it.itemId / 100 - 1 val graphNumber = it.itemId / 100 - 1
val item = it.itemId % 100 val item = it.itemId % 100
_setting[graphNumber][item] = !it.isChecked _setting[graphNumber][item] = !it.isChecked
} }
} }
} catch (exception: Exception) {
fabricPrivacy.logException(exception)
}
storeGraphConfig() storeGraphConfig()
setupChartMenu(context, chartButton) setupChartMenu(context, chartButton)
rxBus.send(EventRefreshOverview("OnMenuItemClickListener", now = true)) rxBus.send(EventRefreshOverview("OnMenuItemClickListener", now = true))