forked from penguin86/luna-tracker
MainActivity: inline nested function for dynamic menu
This commit is contained in:
@@ -162,7 +162,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
compareBy({ -1 * (eventTypeStats[it] ?: 0) }, { it.ordinal })
|
compareBy({ -1 * (eventTypeStats[it] ?: 0) }, { it.ordinal })
|
||||||
).filter { it != LunaEvent.Type.UNKNOWN }
|
).filter { it != LunaEvent.Type.UNKNOWN }
|
||||||
|
|
||||||
fun setupMenu(maxButtonCount: Int, sortedEventTypes: List<LunaEvent.Type>): Int {
|
val usedEventCount = eventTypeStats.count { it.value > 0 }
|
||||||
|
val maxButtonCount = if (dynamicMenu) { usedEventCount } else { 7 }
|
||||||
|
|
||||||
val row1 = findViewById<View>(R.id.linear_layout_row1)
|
val row1 = findViewById<View>(R.id.linear_layout_row1)
|
||||||
val row1Button1 = findViewById<TextView>(R.id.button1_row1)
|
val row1Button1 = findViewById<TextView>(R.id.button1_row1)
|
||||||
val row1Button2 = findViewById<TextView>(R.id.button2_row1)
|
val row1Button2 = findViewById<TextView>(R.id.button2_row1)
|
||||||
@@ -188,7 +190,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
fun show(vararg tvs: TextView) {
|
fun show(vararg tvs: TextView) {
|
||||||
for (tv in tvs) {
|
for (tv in tvs) {
|
||||||
val type = sortedEventTypes[showCounter]
|
val type = eventTypesSorted[showCounter]
|
||||||
tv.text = LunaEvent.getHeaderEmoji(applicationContext, type)
|
tv.text = LunaEvent.getHeaderEmoji(applicationContext, type)
|
||||||
tv.setOnClickListener { showCreateDialog(type) }
|
tv.setOnClickListener { showCreateDialog(type) }
|
||||||
tv.visibility = View.VISIBLE
|
tv.visibility = View.VISIBLE
|
||||||
@@ -207,15 +209,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
else -> show(row1Button1, row1Button2, row2Button1, row2Button2, row2Button3, row3Button1, row3Button2)
|
else -> show(row1Button1, row1Button2, row2Button1, row2Button2, row2Button3, row3Button1, row3Button2)
|
||||||
}
|
}
|
||||||
|
|
||||||
return showCounter
|
|
||||||
}
|
|
||||||
|
|
||||||
val usedEventCount = eventTypeStats.count { it.value > 0 }
|
|
||||||
val maxButtonCount = if (dynamicMenu) { usedEventCount } else { 7 }
|
|
||||||
val eventsShown = setupMenu(maxButtonCount, eventTypesSorted)
|
|
||||||
|
|
||||||
// store left over events for popup menu
|
// store left over events for popup menu
|
||||||
currentPopupItems = eventTypesSorted.subList(eventsShown, eventTypesSorted.size)
|
currentPopupItems = eventTypesSorted.subList(showCounter, eventTypesSorted.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
|
|||||||
Reference in New Issue
Block a user