Skip to content

Commit

Permalink
For mozilla-mobile#20892 add menu item for customizing the home screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejia481 committed Sep 8, 2021
1 parent 04a4cd5 commit e4a2e49
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/src/main/java/org/mozilla/fenix/FeatureFlags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ object FeatureFlags {
* Enables showing the home screen behind the search dialog
*/
val showHomeBehindSearch = Config.channel.isNightlyOrDebug

/**
* Enables customizing the home screen
*/
val customizeHome = Config.channel.isNightlyOrDebug
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ class DefaultBrowserToolbarMenuController(
val directions = BrowserFragmentDirections.actionBrowserFragmentToSettingsFragment()
navController.nav(R.id.browserFragment, directions)
}
is ToolbarMenu.Item.CustomizeHome -> browserAnimator.captureEngineViewAndDrawStatically {
val directions = BrowserFragmentDirections.actionBrowserFragmentToCustomFragment()
navController.nav(R.id.browserFragment, directions)
}
is ToolbarMenu.Item.SyncAccount -> {
val directions = when (item.accountState) {
AccountState.AUTHENTICATED ->
Expand Down Expand Up @@ -384,6 +388,7 @@ class DefaultBrowserToolbarMenuController(
is ToolbarMenu.Item.Stop -> Event.BrowserMenuItemTapped.Item.STOP
is ToolbarMenu.Item.Share -> Event.BrowserMenuItemTapped.Item.SHARE
is ToolbarMenu.Item.Settings -> Event.BrowserMenuItemTapped.Item.SETTINGS
is ToolbarMenu.Item.CustomizeHome -> return
is ToolbarMenu.Item.RequestDesktop ->
if (item.isChecked) {
Event.BrowserMenuItemTapped.Item.DESKTOP_VIEW_ON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import mozilla.components.feature.webcompat.reporter.WebCompatReporterFeature
import mozilla.components.lib.state.ext.flowScoped
import mozilla.components.support.ktx.android.content.getColorFromAttr
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifAnyChanged
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.R
import org.mozilla.fenix.components.accounts.FenixAccountManager
import org.mozilla.fenix.experiments.ExperimentBranch
Expand Down Expand Up @@ -308,6 +309,14 @@ open class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.Settings)
}

val customizeHomeItem = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_customize_home),
imageResource = R.drawable.ic_customize,
iconTintColorResource = primaryTextColor()
) {
onItemTapped.invoke(ToolbarMenu.Item.CustomizeHome)
}

val bookmarksItem = BrowserMenuImageTextCheckboxButton(
imageResource = R.drawable.ic_bookmarks_menu,
iconTintColorResource = primaryTextColor(),
Expand Down Expand Up @@ -372,6 +381,7 @@ open class DefaultToolbarMenu(
addToTopSitesItem,
saveToCollectionItem,
BrowserMenuDivider(),
if (FeatureFlags.customizeHome) customizeHomeItem else null,
settingsItem,
if (shouldDeleteDataOnQuit) deleteDataOnQuit else null,
if (shouldUseBottomToolbar) BrowserMenuDivider() else null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface ToolbarMenu {
object History : Item()
object Downloads : Item()
object NewTab : Item()
object CustomizeHome : Item()
}

val menuBuilder: BrowserMenuBuilder
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,13 @@ class HomeFragment : Fragment() {
)
requireComponents.analytics.metrics.track(Event.HomeMenuSettingsItemClicked)
}
HomeMenu.Item.CustomizeHome -> {
hideOnboardingIfNeeded()
nav(
R.id.homeFragment,
HomeFragmentDirections.actionGlobalCustomizationFragment()
)
}
is HomeMenu.Item.SyncAccount -> {
hideOnboardingIfNeeded()
val directions = when (it.accountState) {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.support.ktx.android.content.getColorFromAttr
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.R
import org.mozilla.fenix.components.accounts.AccountState
import org.mozilla.fenix.components.accounts.FenixAccountManager
Expand All @@ -49,6 +50,7 @@ class HomeMenu(
data class SyncAccount(val accountState: AccountState) : Item()
object WhatsNew : Item()
object Help : Item()
object CustomizeHome : Item()
object Settings : Item()
object Quit : Item()
object ReconnectSync : Item()
Expand Down Expand Up @@ -167,6 +169,14 @@ class HomeMenu(
onItemTapped.invoke(Item.Help)
}

val customizeHomeItem = BrowserMenuImageText(
context.getString(R.string.browser_menu_customize_home),
R.drawable.ic_customize,
primaryTextColor
) {
onItemTapped.invoke(Item.CustomizeHome)
}

// Use nimbus to set the icon and title.
val variables = experiments.getVariables(FeatureId.NIMBUS_VALIDATION)
val settingsItem = BrowserMenuImageText(
Expand Down Expand Up @@ -200,6 +210,7 @@ class HomeMenu(
BrowserMenuDivider(),
whatsNewItem,
helpItem,
if (FeatureFlags.customizeHome) customizeHomeItem else null,
settingsItem,
if (settings.shouldDeleteBrowsingDataOnQuit) quitItem else null
).also { items ->
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<action
android:id="@+id/action_global_settingsFragment"
app:destination="@id/settingsFragment" />
<action
android:id="@+id/action_global_customizationFragment"
app:destination="@id/customizationFragment" />
<action
android:id="@+id/action_global_privateBrowsingFragment"
app:destination="@id/privateBrowsingFragment" />
Expand Down Expand Up @@ -199,6 +202,9 @@
<action
android:id="@+id/action_browserFragment_to_settingsFragment"
app:destination="@id/settingsFragment" />
<action
android:id="@+id/action_browserFragment_to_customFragment"
app:destination="@id/customizationFragment" />
<action
android:id="@+id/action_browserFragment_to_createShortcutFragment"
app:destination="@id/createShortcutFragment" />
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@
<string name="browser_menu_add">Add</string>
<!-- Browser menu label for editing a bookmark -->
<string name="browser_menu_edit">Edit</string>

<!-- Browser menu button that opens the Customize menu -->
<string name="browser_menu_customize_home">Customize home</string>
<!-- Browser Toolbar -->
<!-- Content description for the Home screen button on the browser toolbar -->
<string name="browser_toolbar_home">Home screen</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,18 @@ class DefaultBrowserToolbarMenuControllerTest {
verify { navController.navigate(directions, null) }
}

@Test
fun `WHEN CustomizeHome menu item is pressed THEN menu item is handled`() = runBlockingTest {
val item = ToolbarMenu.Item.CustomizeHome

val controller = createController(scope = this, store = browserStore)
controller.handleToolbarItemInteraction(item)

val directions = BrowserFragmentDirections.actionBrowserFragmentToCustomFragment()

verify { navController.navigate(directions, null) }
}

@Test
fun `WHEN bookmark menu item is pressed THEN navigate to bookmarks page`() = runBlockingTest {
val item = ToolbarMenu.Item.Bookmarks
Expand Down

0 comments on commit e4a2e49

Please sign in to comment.