Skip to content

Commit

Permalink
For mozilla-mobile#9365: Partially reverse menu items order when usin…
Browse files Browse the repository at this point in the history
…g top toolbar
  • Loading branch information
mcarare committed Apr 1, 2020
1 parent 2f8a6f3 commit 2dda9e8
Showing 1 changed file with 47 additions and 22 deletions.
69 changes: 47 additions & 22 deletions app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.support.ktx.android.content.getColorFromAttr
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.theme.ThemeManager
import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.whatsnew.WhatsNew
Expand Down Expand Up @@ -50,6 +51,8 @@ class HomeMenu(

private val menuCategoryTextColor =
ThemeManager.resolveAttribute(R.attr.menuCategoryText, context)
private val shouldUseBottomToolbar = context.settings().shouldUseBottomToolbar


// 'Reconnect' and 'Quit' items aren't needed most of the time, so we'll only create the if necessary.
private val reconnectToSyncItem by lazy {
Expand Down Expand Up @@ -102,7 +105,8 @@ class HomeMenu(
val historyItem = BrowserMenuImageText(
context.getString(R.string.library_history),
R.drawable.ic_history,
primaryTextColor) {
primaryTextColor
) {
onItemTapped.invoke(Item.History)
}

Expand All @@ -124,28 +128,49 @@ class HomeMenu(

// Only query account manager if it has been initialized.
// We don't want to cause its initialization just for this check.
val accountAuthItem = if (context.components.backgroundServices.accountManagerAvailableQueue.isReady()) {
if (context.components.backgroundServices.accountManager.accountNeedsReauth()) reconnectToSyncItem else null
} else {
null
}
val accountAuthItem =
if (context.components.backgroundServices.accountManagerAvailableQueue.isReady()) {
if (context.components.backgroundServices.accountManager.accountNeedsReauth()) reconnectToSyncItem else null
} else {
null
}

listOfNotNull(
accountAuthItem,
whatsNewItem,
BrowserMenuDivider(),
BrowserMenuCategory(
context.getString(R.string.browser_menu_library),
textColorResource = menuCategoryTextColor
),
bookmarksItem,
historyItem,
BrowserMenuDivider(),
settingsItem,
helpItem,
if (Settings.getInstance(context).shouldDeleteBrowsingDataOnQuit) quitItem else null
).also { items ->
items.getHighlight()?.let { onHighlightPresent(it) }
if (shouldUseBottomToolbar) {
listOfNotNull(
accountAuthItem,
whatsNewItem,
BrowserMenuDivider(),
BrowserMenuCategory(
context.getString(R.string.browser_menu_library),
textColorResource = menuCategoryTextColor
),
bookmarksItem,
historyItem,
BrowserMenuDivider(),
settingsItem,
helpItem,
if (Settings.getInstance(context).shouldDeleteBrowsingDataOnQuit) quitItem else null
).also { items ->
items.getHighlight()?.let { onHighlightPresent(it) }
}
} else {
listOfNotNull(
if (Settings.getInstance(context).shouldDeleteBrowsingDataOnQuit) quitItem else null,
helpItem,
settingsItem,
accountAuthItem,
BrowserMenuDivider(),
BrowserMenuCategory(
context.getString(R.string.browser_menu_library),
textColorResource = menuCategoryTextColor
),
bookmarksItem,
historyItem,
BrowserMenuDivider(),
whatsNewItem
).also { items ->
items.getHighlight()?.let { onHighlightPresent(it) }
}
}
}

Expand Down

0 comments on commit 2dda9e8

Please sign in to comment.