2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00

No issue: Cleanup default toolbar menu

This commit is contained in:
Roger Yang 2022-05-31 14:25:13 -04:00 committed by mergify[bot]
parent 2103448b61
commit 519f3f96fc

View File

@ -12,7 +12,6 @@ import androidx.core.content.ContextCompat.getColor
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.launch
import mozilla.components.browser.menu.BrowserMenuHighlight
@ -44,13 +43,14 @@ import org.mozilla.fenix.theme.ThemeManager
/**
* Builds the toolbar object used with the 3-dot menu in the browser fragment.
* @param context a [Context] for accessing system resources.
* @param store reference to the application's [BrowserStore].
* @param hasAccountProblem If true, there was a problem signing into the Firefox account.
* @param shouldReverseItems If true, reverse the menu items.
* @param pinnedSiteStorage Used to check if the current url is a pinned site.
* @param onItemTapped Called when a menu item is tapped.
* @param lifecycleOwner View lifecycle owner used to determine when to cancel UI jobs.
* @param bookmarksStorage Used to check if a page is bookmarked.
* @param pinnedSiteStorage Used to check if the current url is a pinned site.
* @param isPinningSupported true if the launcher supports adding shortcuts.
*/
@Suppress("LargeClass", "LongParameterList", "TooManyFunctions")
open class DefaultToolbarMenu(
@ -61,7 +61,7 @@ open class DefaultToolbarMenu(
private val lifecycleOwner: LifecycleOwner,
private val bookmarksStorage: BookmarksStorage,
private val pinnedSiteStorage: PinnedSiteStorage,
val isPinningSupported: Boolean
@get:VisibleForTesting internal val isPinningSupported: Boolean
) : ToolbarMenu {
private var isCurrentUrlPinned = false
@ -177,7 +177,7 @@ open class DefaultToolbarMenu(
} ?: false
// End of predicates //
val installToHomescreen = BrowserMenuHighlightableItem(
private val installToHomescreen = BrowserMenuHighlightableItem(
label = context.getString(R.string.browser_menu_install_on_homescreen),
startImageResource = R.drawable.mozac_ic_add_to_home_screen,
iconTintColorResource = primaryTextColor(),
@ -192,7 +192,8 @@ open class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.InstallPwaToHomeScreen)
}
val newTabItem = BrowserMenuImageText(
@VisibleForTesting
internal val newTabItem = BrowserMenuImageText(
context.getString(R.string.library_new_tab),
R.drawable.ic_new,
primaryTextColor()
@ -200,7 +201,7 @@ open class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.NewTab)
}
val historyItem = BrowserMenuImageText(
private val historyItem = BrowserMenuImageText(
context.getString(R.string.library_history),
R.drawable.ic_history,
primaryTextColor()
@ -208,7 +209,7 @@ open class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.History)
}
val downloadsItem = BrowserMenuImageText(
private val downloadsItem = BrowserMenuImageText(
context.getString(R.string.library_downloads),
R.drawable.ic_download,
primaryTextColor()
@ -216,11 +217,11 @@ open class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.Downloads)
}
val extensionsItem = WebExtensionPlaceholderMenuItem(
private val extensionsItem = WebExtensionPlaceholderMenuItem(
id = WebExtensionPlaceholderMenuItem.MAIN_EXTENSIONS_MENU_ID
)
val findInPageItem = BrowserMenuImageText(
private val findInPageItem = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_find_in_page),
imageResource = R.drawable.mozac_ic_search,
iconTintColorResource = primaryTextColor()
@ -228,7 +229,7 @@ open class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.FindInPage)
}
val desktopSiteItem = BrowserMenuImageSwitch(
private val desktopSiteItem = BrowserMenuImageSwitch(
imageResource = R.drawable.ic_desktop,
label = context.getString(R.string.browser_menu_desktop_site),
initialState = {
@ -238,7 +239,7 @@ open class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.RequestDesktop(checked))
}
val customizeReaderView = BrowserMenuImageText(
private val customizeReaderView = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_customize_reader_view),
imageResource = R.drawable.ic_readermode_appearance,
iconTintColorResource = primaryTextColor()
@ -246,7 +247,7 @@ open class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.CustomizeReaderView)
}
val openInApp = BrowserMenuHighlightableItem(
private val openInApp = BrowserMenuHighlightableItem(
label = context.getString(R.string.browser_menu_open_app_link),
startImageResource = R.drawable.ic_open_in_app,
iconTintColorResource = primaryTextColor(),
@ -259,12 +260,12 @@ open class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.OpenInApp)
}
val reportSiteIssuePlaceholder = WebExtensionPlaceholderMenuItem(
private val reportSiteIssuePlaceholder = WebExtensionPlaceholderMenuItem(
id = WebCompatReporterFeature.WEBCOMPAT_REPORTER_EXTENSION_ID,
iconTintColorResource = primaryTextColor()
)
val addToHomeScreenItem = BrowserMenuImageText(
private val addToHomeScreenItem = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_add_to_homescreen),
imageResource = R.drawable.mozac_ic_add_to_home_screen,
iconTintColorResource = primaryTextColor(),
@ -273,7 +274,7 @@ open class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.AddToHomeScreen)
}
val addRemoveTopSitesItem = TwoStateBrowserMenuImageText(
private val addRemoveTopSitesItem = TwoStateBrowserMenuImageText(
primaryLabel = context.getString(R.string.browser_menu_add_to_shortcuts),
secondaryLabel = context.getString(R.string.browser_menu_remove_from_shortcuts),
primaryStateIconResource = R.drawable.ic_top_sites,
@ -291,7 +292,7 @@ open class DefaultToolbarMenu(
}
)
val saveToCollectionItem = BrowserMenuImageText(
private val saveToCollectionItem = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_save_to_collection_2),
imageResource = R.drawable.ic_tab_collection,
iconTintColorResource = primaryTextColor()
@ -299,7 +300,8 @@ open class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.SaveToCollection)
}
val settingsItem = BrowserMenuHighlightableItem(
@VisibleForTesting
internal val settingsItem = BrowserMenuHighlightableItem(
label = context.getString(R.string.browser_menu_settings),
startImageResource = R.drawable.mozac_ic_settings,
iconTintColorResource = if (hasAccountProblem) {
@ -322,7 +324,7 @@ open class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.Settings)
}
val bookmarksItem = BrowserMenuImageTextCheckboxButton(
private val bookmarksItem = BrowserMenuImageTextCheckboxButton(
imageResource = R.drawable.ic_bookmarks_menu,
iconTintColorResource = primaryTextColor(),
label = context.getString(R.string.library_bookmarks),
@ -339,7 +341,7 @@ open class DefaultToolbarMenu(
handleBookmarkItemTapped()
}
val deleteDataOnQuit = BrowserMenuImageText(
private val deleteDataOnQuit = BrowserMenuImageText(
label = context.getString(R.string.delete_browsing_data_on_quit_action),
imageResource = R.drawable.mozac_ic_quit,
iconTintColorResource = primaryTextColor()
@ -350,7 +352,7 @@ open class DefaultToolbarMenu(
private fun getSyncItemTitle() =
accountManager.accountProfileEmail ?: context.getString(R.string.sync_menu_sign_in)
val syncMenuItem = BrowserMenuImageText(
private val syncMenuItem = BrowserMenuImageText(
getSyncItemTitle(),
R.drawable.ic_signed_out,
primaryTextColor()