Skip to content

Commit

Permalink
For mozilla-mobile#17802: Match the design for three-dot menu navigat…
Browse files Browse the repository at this point in the history
  • Loading branch information
eliserichards authored and pkirakosyan committed Aug 5, 2021
1 parent 7603a88 commit 32941e7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import mozilla.appservices.places.BookmarkRoot
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.R
Expand All @@ -31,6 +32,7 @@ import org.mozilla.fenix.ui.robots.navigationToolbar
/**
* Tests for verifying basic functionality of bookmarks
*/
@Ignore("To be re-implemented in https://github.com/mozilla-mobile/fenix/issues/17979")
class BookmarksTest {
/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.test.uiautomator.UiDevice
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.FenixApplication
Expand Down Expand Up @@ -105,6 +106,7 @@ class SettingsBasicsTest {
}

@Test
@Ignore("To be re-implemented in https://github.com/mozilla-mobile/fenix/issues/17979")
fun toggleShowVisitedSitesAndBookmarks() {
// Bookmarks a few websites, toggles the history and bookmarks setting to off, then verifies if the visited and bookmarked websites do not show in the suggestions.
val page1 = getGenericAsset(mockWebServer, 1)
Expand Down
2 changes: 2 additions & 0 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class SmokeTest {

@Test
// Verifies the Bookmark button in a tab's 3 dot menu
@Ignore("To be re-implemented in https://github.com/mozilla-mobile/fenix/issues/17979")
fun mainMenuBookmarkButtonTest() {
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

Expand Down Expand Up @@ -979,6 +980,7 @@ class SmokeTest {

@Test
// Verifies that deleting a Bookmarks folder also removes the item from inside it.
@Ignore("To be re-implemented in https://github.com/mozilla-mobile/fenix/issues/17799")
fun deleteNonEmptyBookmarkFolderTest() {
val website = TestAssetHelper.getGenericAsset(mockWebServer, 1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ class DefaultToolbarMenu(
val isPinningSupported: Boolean
) : ToolbarMenu {

private var currentUrlIsBookmarked = false
private var isCurrentUrlBookmarked = false
private var isBookmarkedJob: Job? = null

private val selectedSession: TabSessionState? get() = store.state.selectedTab
private val isTopToolbarSelected = shouldReverseItems
private val selectedSession: TabSessionState?
get() = store.state.selectedTab

override val menuBuilder by lazy {
BrowserMenuBuilder(
Expand Down Expand Up @@ -148,24 +149,28 @@ class DefaultToolbarMenu(

registerForIsBookmarkedUpdates()

val bookmark = BrowserMenuItemToolbar.TwoStateButton(
primaryImageResource = R.drawable.ic_bookmark_filled,
primaryContentDescription = context.getString(R.string.browser_menu_edit_bookmark),
primaryImageTintResource = primaryTextColor(),
// TwoStateButton.isInPrimaryState must be synchronous, and checking bookmark state is
// relatively slow. The best we can do here is periodically compute and cache a new "is
// bookmarked" state, and use that whenever the menu has been opened.
isInPrimaryState = { currentUrlIsBookmarked },
secondaryImageResource = R.drawable.ic_bookmark_outline,
secondaryContentDescription = context.getString(R.string.browser_menu_bookmark),
secondaryImageTintResource = primaryTextColor(),
disableInSecondaryState = false
) {
if (!currentUrlIsBookmarked) currentUrlIsBookmarked = true
onItemTapped.invoke(ToolbarMenu.Item.Bookmark)
}
if (FeatureFlags.toolbarMenuFeature) {
BrowserMenuItemToolbar(listOf(back, forward, share, refresh))
} else {
val bookmark = BrowserMenuItemToolbar.TwoStateButton(
primaryImageResource = R.drawable.ic_bookmark_filled,
primaryContentDescription = context.getString(R.string.browser_menu_edit_bookmark),
primaryImageTintResource = primaryTextColor(),
// TwoStateButton.isInPrimaryState must be synchronous, and checking bookmark state is
// relatively slow. The best we can do here is periodically compute and cache a new "is
// bookmarked" state, and use that whenever the menu has been opened.
isInPrimaryState = { isCurrentUrlBookmarked },
secondaryImageResource = R.drawable.ic_bookmark_outline,
secondaryContentDescription = context.getString(R.string.browser_menu_bookmark),
secondaryImageTintResource = primaryTextColor(),
disableInSecondaryState = false
) {
if (!isCurrentUrlBookmarked) isCurrentUrlBookmarked = true
onItemTapped.invoke(ToolbarMenu.Item.Bookmark)
}

BrowserMenuItemToolbar(listOf(back, forward, bookmark, share, refresh))
BrowserMenuItemToolbar(listOf(back, forward, bookmark, share, refresh))
}
}

// Predicates that need to be repeatedly called as the session changes
Expand Down Expand Up @@ -483,6 +488,7 @@ class DefaultToolbarMenu(
}

val menuItems = listOfNotNull(
if (isTopToolbarSelected) menuToolbar else null,
newTabItem,
BrowserMenuDivider(),
bookmarksItem,
Expand All @@ -502,9 +508,9 @@ class DefaultToolbarMenu(
BrowserMenuDivider(),
settingsItem,
BrowserMenuDivider(),
menuToolbar
if (isTopToolbarSelected) null else BrowserMenuDivider(),
if (isTopToolbarSelected) null else menuToolbar
)

menuItems
}

Expand All @@ -527,7 +533,7 @@ class DefaultToolbarMenu(
)
}
.collect {
currentUrlIsBookmarked = false
isCurrentUrlBookmarked = false
updateCurrentUrlIsBookmarked(it.content.url)
}
}
Expand All @@ -537,7 +543,7 @@ class DefaultToolbarMenu(
internal fun updateCurrentUrlIsBookmarked(newUrl: String) {
isBookmarkedJob?.cancel()
isBookmarkedJob = lifecycleOwner.lifecycleScope.launch {
currentUrlIsBookmarked = bookmarksStorage
isCurrentUrlBookmarked = bookmarksStorage
.getBookmarksWithUrl(newUrl)
.any { it.url == newUrl }
}
Expand Down

0 comments on commit 32941e7

Please sign in to comment.