Closes #9561: Fix initialization order in HomeMenu

`init` blocks are executed before `val` initialization which is declared afterwards
in the class. In this case, we had `quitItem` and `reconnectToSyncItem` as lazy,
but declared after the `init` block which may need them. And so, while this compiles
just fine, in practice we run into an NPE as the `init` block tries to get the lazy's value.

Simply re-ordering initialization fixes the problem.
fennec/production
Grisha Kruglov 4 years ago committed by Grisha Kruglov
parent 804eb0f5ba
commit 60943df6d9

@ -51,6 +51,32 @@ class HomeMenu(
private val menuCategoryTextColor =
ThemeManager.resolveAttribute(R.attr.menuCategoryText, context)
// 'Reconnect' and 'Quit' items aren't needed most of the time, so we'll only create the if necessary.
private val reconnectToSyncItem by lazy {
BrowserMenuHighlightableItem(
context.getString(R.string.sync_reconnect),
R.drawable.ic_sync_disconnected,
iconTintColorResource = syncDisconnectedColor,
textColorResource = primaryTextColor,
highlight = BrowserMenuHighlight.HighPriority(
backgroundTint = syncDisconnectedBackgroundColor
),
isHighlighted = { true }
) {
onItemTapped.invoke(Item.Sync)
}
}
private val quitItem by lazy {
BrowserMenuImageText(
context.getString(R.string.delete_browsing_data_on_quit_action),
R.drawable.ic_exit,
primaryTextColor
) {
onItemTapped.invoke(Item.Quit)
}
}
private val coreMenuItems by lazy {
val whatsNewItem = BrowserMenuHighlightableItem(
context.getString(R.string.browser_menu_whats_new),
@ -144,30 +170,4 @@ class HomeMenu(
}, lifecycleOwner)
}
}
// 'Reconnect' and 'Quit' items aren't needed most of the time, so we'll only create the if necessary.
private val reconnectToSyncItem by lazy {
BrowserMenuHighlightableItem(
context.getString(R.string.sync_reconnect),
R.drawable.ic_sync_disconnected,
iconTintColorResource = syncDisconnectedColor,
textColorResource = primaryTextColor,
highlight = BrowserMenuHighlight.HighPriority(
backgroundTint = syncDisconnectedBackgroundColor
),
isHighlighted = { true }
) {
onItemTapped.invoke(Item.Sync)
}
}
private val quitItem by lazy {
BrowserMenuImageText(
context.getString(R.string.delete_browsing_data_on_quit_action),
R.drawable.ic_exit,
primaryTextColor
) {
onItemTapped.invoke(Item.Quit)
}
}
}

Loading…
Cancel
Save