2019-02-13 00:51:30 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +02:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2019-02-13 00:51:30 +01:00
|
|
|
|
2019-02-13 01:04:01 +01:00
|
|
|
package org.mozilla.fenix.home
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import mozilla.components.browser.menu.BrowserMenuBuilder
|
|
|
|
import mozilla.components.browser.menu.item.BrowserMenuDivider
|
2019-09-03 22:16:29 +02:00
|
|
|
import mozilla.components.browser.menu.item.BrowserMenuHighlightableItem
|
2019-02-13 01:04:01 +01:00
|
|
|
import mozilla.components.browser.menu.item.BrowserMenuImageText
|
|
|
|
import org.mozilla.fenix.R
|
2019-08-21 17:33:59 +02:00
|
|
|
import org.mozilla.fenix.theme.ThemeManager
|
2019-09-03 22:16:29 +02:00
|
|
|
import org.mozilla.fenix.whatsnew.WhatsNew
|
2019-02-13 01:04:01 +01:00
|
|
|
|
|
|
|
class HomeMenu(
|
|
|
|
private val context: Context,
|
|
|
|
private val onItemTapped: (Item) -> Unit = {}
|
|
|
|
) {
|
|
|
|
sealed class Item {
|
2019-09-03 22:16:29 +02:00
|
|
|
object WhatsNew : Item()
|
2019-02-13 01:04:01 +01:00
|
|
|
object Help : Item()
|
|
|
|
object Settings : Item()
|
|
|
|
object Library : Item()
|
|
|
|
}
|
|
|
|
|
|
|
|
val menuBuilder by lazy { BrowserMenuBuilder(menuItems) }
|
|
|
|
|
|
|
|
private val menuItems by lazy {
|
|
|
|
listOf(
|
|
|
|
BrowserMenuImageText(
|
|
|
|
context.getString(R.string.browser_menu_settings),
|
|
|
|
R.drawable.ic_settings,
|
2019-05-31 00:49:58 +02:00
|
|
|
ThemeManager.resolveAttribute(R.attr.primaryText, context)
|
2019-02-13 01:04:01 +01:00
|
|
|
) {
|
2019-09-03 22:16:29 +02:00
|
|
|
onItemTapped.invoke(Item.Settings)
|
2019-02-13 01:04:01 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
BrowserMenuImageText(
|
2019-04-23 22:49:14 +02:00
|
|
|
context.getString(R.string.browser_menu_your_library),
|
2019-02-13 01:04:01 +01:00
|
|
|
R.drawable.ic_library,
|
2019-05-31 00:49:58 +02:00
|
|
|
ThemeManager.resolveAttribute(R.attr.primaryText, context)
|
2019-02-13 01:04:01 +01:00
|
|
|
) {
|
2019-09-03 22:16:29 +02:00
|
|
|
onItemTapped.invoke(Item.Library)
|
2019-02-13 01:04:01 +01:00
|
|
|
},
|
2019-02-13 00:51:30 +01:00
|
|
|
|
2019-02-13 01:04:01 +01:00
|
|
|
BrowserMenuDivider(),
|
|
|
|
BrowserMenuImageText(
|
|
|
|
context.getString(R.string.browser_menu_help),
|
|
|
|
R.drawable.ic_help,
|
2019-05-31 00:49:58 +02:00
|
|
|
ThemeManager.resolveAttribute(R.attr.primaryText, context)
|
2019-02-13 01:04:01 +01:00
|
|
|
) {
|
2019-09-03 22:16:29 +02:00
|
|
|
onItemTapped.invoke(Item.Help)
|
|
|
|
},
|
|
|
|
|
|
|
|
BrowserMenuHighlightableItem(
|
|
|
|
context.getString(R.string.browser_menu_whats_new),
|
|
|
|
R.drawable.ic_whats_new,
|
|
|
|
highlight = BrowserMenuHighlightableItem.Highlight(
|
|
|
|
startImageResource = R.drawable.ic_whats_new_notification,
|
|
|
|
backgroundResource = ThemeManager.resolveAttribute(R.attr.selectableItemBackground, context),
|
2019-09-11 12:00:28 +02:00
|
|
|
colorResource = R.color.whats_new_notification_color
|
2019-09-03 22:16:29 +02:00
|
|
|
),
|
|
|
|
isHighlighted = { WhatsNew.shouldHighlightWhatsNew(context) }
|
|
|
|
) {
|
|
|
|
onItemTapped.invoke(Item.WhatsNew)
|
|
|
|
}
|
|
|
|
)
|
2019-02-13 01:04:01 +01:00
|
|
|
}
|
|
|
|
}
|