From 841dacb69e1381e4f2941efc623ecb6b063350cf Mon Sep 17 00:00:00 2001 From: Kate Glazko Date: Tue, 23 Mar 2021 13:23:06 -0700 Subject: [PATCH] For 17798: Sync Menu Item --- .../fenix/ui/robots/SyncedTabsRobot.kt | 4 +++- .../components/toolbar/DefaultToolbarMenu.kt | 22 +++++++++++++------ .../java/org/mozilla/fenix/home/HomeMenu.kt | 22 ++++++++++++------- app/src/main/res/values/strings.xml | 4 ++++ 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SyncedTabsRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SyncedTabsRobot.kt index 9add0cd59b..43aad7ccfc 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SyncedTabsRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SyncedTabsRobot.kt @@ -39,6 +39,8 @@ private fun goBackButton() = onView(allOf(withContentDescription("Navigate up"))) private fun assertSyncedTabsMenuHeader() { - onView(withText(R.string.synced_tabs)) + // Replaced with the new string here, the test is assuming we are NOT signed in + // Sync tests in SettingsSyncTest are still TO-DO, so I'm not sure that we have a test for signing into Sync + onView(withText(R.string.sync_menu_sign_in)) .check((matches(withEffectiveVisibility(Visibility.VISIBLE)))) } diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/DefaultToolbarMenu.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/DefaultToolbarMenu.kt index b8397e209a..ca3c39ba5d 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/DefaultToolbarMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/DefaultToolbarMenu.kt @@ -402,13 +402,21 @@ open class DefaultToolbarMenu( id = WebExtensionPlaceholderMenuItem.MAIN_EXTENSIONS_MENU_ID ) - val syncedTabs = BrowserMenuImageText( - label = context.getString(R.string.synced_tabs), - imageResource = R.drawable.ic_synced_tabs, - iconTintColorResource = primaryTextColor() - ) { - onItemTapped.invoke(ToolbarMenu.Item.SyncedTabs) - } + val accountManager = context.components.backgroundServices.accountManager + val account = accountManager.authenticatedAccount() + val syncItemTitle = if (account != null && accountManager.accountProfile()?.email != null) { + context.getString(R.string.sync_signed_as, accountManager.accountProfile()?.email) + } else { + context.getString(R.string.sync_menu_sign_in) + } + + val syncedTabs = BrowserMenuImageText( + syncItemTitle, + R.drawable.ic_synced_tabs, + primaryTextColor() + ) { + onItemTapped.invoke(ToolbarMenu.Item.SyncedTabs) + } val findInPageItem = BrowserMenuImageText( label = context.getString(R.string.browser_menu_find_in_page), diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt index 7d95afed2b..87002ce56e 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt @@ -189,8 +189,16 @@ class HomeMenu( onItemTapped.invoke(Item.Settings) } + val accountManager = context.components.backgroundServices.accountManager + val account = accountManager.authenticatedAccount() + val syncItemTitle = if (account != null && accountManager.accountProfile()?.email != null) { + context.getString(R.string.sync_signed_as, accountManager.accountProfile()?.email) + } else { + context.getString(R.string.sync_menu_sign_in) + } + val syncedTabsItem = BrowserMenuImageText( - context.getString(R.string.library_synced_tabs), + syncItemTitle, R.drawable.ic_synced_tabs, primaryTextColor ) { @@ -215,13 +223,11 @@ 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() && - context.components.backgroundServices.accountManager.accountNeedsReauth()) { - reconnectToSyncItem - } else { - null - } + val accountAuthItem = if (context.components.backgroundServices.accountManagerAvailableQueue.isReady()) { + if (context.components.backgroundServices.accountManager.accountNeedsReauth()) reconnectToSyncItem else null + } else { + null + } val settings = context.components.settings diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 217fc9d8aa..58f6ff7d36 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -954,6 +954,10 @@ All actions Recently used + + Signed in as %1$s + + Sign in to sync Sign in to Sync