Merge pull request #211 from nightscout/dana/fix-menu-crash-plus-i18n

fix menu crash and make graph label translatable
This commit is contained in:
Milos Kozak 2021-01-10 19:50:25 +01:00 committed by GitHub
commit c5afc6daca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -88,7 +88,8 @@ class OverviewMenus @Inject constructor(
fun setupChartMenu(chartButton: ImageButton) { fun setupChartMenu(chartButton: ImageButton) {
loadGraphConfig() loadGraphConfig()
val numOfGraphs = _setting.size // 1 main + x secondary val settingsCopy = setting
val numOfGraphs = settingsCopy.size // 1 main + x secondary
chartButton.setOnClickListener { v: View -> chartButton.setOnClickListener { v: View ->
val predictionsAvailable: Boolean = when { val predictionsAvailable: Boolean = when {
@ -100,7 +101,7 @@ class OverviewMenus @Inject constructor(
for (g in 0 until numOfGraphs) { for (g in 0 until numOfGraphs) {
if (g != 0 && g < numOfGraphs) { if (g != 0 && g < numOfGraphs) {
val dividerItem = popup.menu.add(Menu.NONE, g, Menu.NONE, "------- " + "Graph" + " " + g + " -------") val dividerItem = popup.menu.add(Menu.NONE, g, Menu.NONE, "------- ${resourceHelper.gs(R.string.graph_menu_divider_header)} $g -------")
dividerItem.isCheckable = true dividerItem.isCheckable = true
dividerItem.isChecked = true dividerItem.isChecked = true
} }
@ -117,12 +118,12 @@ class OverviewMenus @Inject constructor(
s.setSpan(ForegroundColorSpan(resourceHelper.gc(m.colorId)), 0, s.length, 0) s.setSpan(ForegroundColorSpan(resourceHelper.gc(m.colorId)), 0, s.length, 0)
item.title = s item.title = s
item.isCheckable = true item.isCheckable = true
item.isChecked = _setting[g][m.ordinal] item.isChecked = settingsCopy[g][m.ordinal]
} }
} }
} }
if (numOfGraphs < MAX_GRAPHS) { if (numOfGraphs < MAX_GRAPHS) {
val dividerItem = popup.menu.add(Menu.NONE, numOfGraphs, Menu.NONE, "------- " + "Graph" + " " + numOfGraphs + " -------") val dividerItem = popup.menu.add(Menu.NONE, numOfGraphs, Menu.NONE, "------- ${resourceHelper.gs(R.string.graph_menu_divider_header)} $numOfGraphs -------")
dividerItem.isCheckable = true dividerItem.isCheckable = true
dividerItem.isChecked = false dividerItem.isChecked = false
} }

View file

@ -1429,5 +1429,6 @@
<string name="time_to_eat">Time to eat!\nRun Bolus wizard and do calculation again.</string> <string name="time_to_eat">Time to eat!\nRun Bolus wizard and do calculation again.</string>
<string name="timetoeat">Time to eat</string> <string name="timetoeat">Time to eat</string>
<string name="fabric_upload_disabled">Crash logs upload disabled!</string> <string name="fabric_upload_disabled">Crash logs upload disabled!</string>
<string name="graph_menu_divider_header">Graph</string>
</resources> </resources>