1
0
Fork 0

For #10343: Remove 'Library' functionality from the app

Also adds Bookmarks and History items to browser menu.
master
ValentinTimisica 2020-05-07 19:24:20 +03:00 committed by Emily Kager
parent ca7695854a
commit b2e5820364
14 changed files with 37 additions and 274 deletions

View File

@ -411,7 +411,8 @@ sealed class Event {
SETTINGS, LIBRARY, HELP, DESKTOP_VIEW_ON, DESKTOP_VIEW_OFF, FIND_IN_PAGE, NEW_TAB,
NEW_PRIVATE_TAB, SHARE, REPORT_SITE_ISSUE, BACK, FORWARD, RELOAD, STOP, OPEN_IN_FENIX,
SAVE_TO_COLLECTION, ADD_TO_TOP_SITES, ADD_TO_HOMESCREEN, QUIT, READER_MODE_ON,
READER_MODE_OFF, OPEN_IN_APP, BOOKMARK, READER_MODE_APPEARANCE, ADDONS_MANAGER
READER_MODE_OFF, OPEN_IN_APP, BOOKMARK, READER_MODE_APPEARANCE, ADDONS_MANAGER,
BOOKMARKS, HISTORY
}
override val extras: Map<Events.browserMenuActionKeys, String>?

View File

@ -16,6 +16,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.selector.findTab
@ -156,10 +157,6 @@ class DefaultBrowserToolbarController(
val directions = BrowserFragmentDirections.actionBrowserFragmentToSettingsFragment()
navController.nav(R.id.browserFragment, directions)
}
ToolbarMenu.Item.Library -> browserAnimator.captureEngineViewAndDrawStatically {
val directions = BrowserFragmentDirections.actionBrowserFragmentToLibraryFragment()
navController.nav(R.id.browserFragment, directions)
}
is ToolbarMenu.Item.RequestDesktop -> sessionUseCases.requestDesktopSite.invoke(
item.isChecked,
currentSession
@ -310,6 +307,18 @@ class DefaultBrowserToolbarController(
bookmarkTapped(it)
}
}
ToolbarMenu.Item.Bookmarks -> {
navController.nav(
R.id.browserFragment,
BrowserFragmentDirections.actionGlobalBookmarkFragment(BookmarkRoot.Mobile.id)
)
}
ToolbarMenu.Item.History -> {
navController.nav(
R.id.browserFragment,
BrowserFragmentDirections.actionGlobalHistoryFragment()
)
}
}
}
@ -350,7 +359,6 @@ class DefaultBrowserToolbarController(
ToolbarMenu.Item.Reload -> Event.BrowserMenuItemTapped.Item.RELOAD
ToolbarMenu.Item.Stop -> Event.BrowserMenuItemTapped.Item.STOP
ToolbarMenu.Item.Settings -> Event.BrowserMenuItemTapped.Item.SETTINGS
ToolbarMenu.Item.Library -> Event.BrowserMenuItemTapped.Item.LIBRARY
is ToolbarMenu.Item.RequestDesktop ->
if (item.isChecked) {
Event.BrowserMenuItemTapped.Item.DESKTOP_VIEW_ON
@ -378,6 +386,8 @@ class DefaultBrowserToolbarController(
ToolbarMenu.Item.OpenInApp -> Event.BrowserMenuItemTapped.Item.OPEN_IN_APP
ToolbarMenu.Item.Bookmark -> Event.BrowserMenuItemTapped.Item.BOOKMARK
ToolbarMenu.Item.AddonsManager -> Event.BrowserMenuItemTapped.Item.ADDONS_MANAGER
ToolbarMenu.Item.Bookmarks -> Event.BrowserMenuItemTapped.Item.BOOKMARKS
ToolbarMenu.Item.History -> Event.BrowserMenuItemTapped.Item.HISTORY
}
activity.components.analytics.metrics.track(Event.BrowserMenuItemTapped(eventItem))

View File

@ -184,7 +184,8 @@ class DefaultToolbarMenu(
)
val menuItems = listOfNotNull(
library,
historyItem,
bookmarksItem,
addons,
settings,
if (shouldDeleteDataOnQuit) deleteDataOnQuit else null,
@ -237,14 +238,6 @@ class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.Settings)
}
private val library = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_library),
imageResource = R.drawable.ic_library,
iconTintColorResource = primaryTextColor()
) {
onItemTapped.invoke(ToolbarMenu.Item.Library)
}
private val desktopMode = BrowserMenuImageSwitch(
imageResource = R.drawable.ic_desktop,
label = context.getString(R.string.browser_menu_desktop_site),
@ -356,6 +349,22 @@ class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.OpenInApp)
}
val historyItem = BrowserMenuImageText(
context.getString(R.string.library_history),
R.drawable.ic_history,
primaryTextColor()
) {
onItemTapped.invoke(ToolbarMenu.Item.History)
}
val bookmarksItem = BrowserMenuImageText(
context.getString(R.string.library_bookmarks),
R.drawable.ic_bookmark_filled,
primaryTextColor()
) {
onItemTapped.invoke(ToolbarMenu.Item.Bookmarks)
}
@ColorRes
private fun primaryTextColor() = ThemeManager.resolveAttribute(R.attr.primaryText, context)

View File

@ -10,7 +10,6 @@ import mozilla.components.browser.menu.item.BrowserMenuItemToolbar
interface ToolbarMenu {
sealed class Item {
object Settings : Item()
object Library : Item()
data class RequestDesktop(val isChecked: Boolean) : Item()
object FindInPage : Item()
object Share : Item()
@ -30,6 +29,8 @@ interface ToolbarMenu {
object OpenInApp : Item()
object Bookmark : Item()
object ReaderModeAppearance : Item()
object Bookmarks : Item()
object History : Item()
}
val menuBuilder: BrowserMenuBuilder

View File

@ -11,7 +11,6 @@ import androidx.lifecycle.LifecycleOwner
import mozilla.components.browser.menu.BrowserMenuBuilder
import mozilla.components.browser.menu.BrowserMenuHighlight
import mozilla.components.browser.menu.ext.getHighlight
import mozilla.components.browser.menu.item.BrowserMenuCategory
import mozilla.components.browser.menu.item.BrowserMenuDivider
import mozilla.components.browser.menu.item.BrowserMenuHighlightableItem
import mozilla.components.browser.menu.item.BrowserMenuImageText
@ -37,7 +36,6 @@ class HomeMenu(
object WhatsNew : Item()
object Help : Item()
object Settings : Item()
object Library : Item()
object History : Item()
object Bookmarks : Item()
object Quit : Item()
@ -138,10 +136,6 @@ class HomeMenu(
accountAuthItem,
whatsNewItem,
BrowserMenuDivider(),
BrowserMenuCategory(
context.getString(R.string.browser_menu_library),
textColorResource = menuCategoryTextColor
),
bookmarksItem,
historyItem,
BrowserMenuDivider(),
@ -158,10 +152,6 @@ class HomeMenu(
settingsItem,
accountAuthItem,
BrowserMenuDivider(),
BrowserMenuCategory(
context.getString(R.string.browser_menu_library),
textColorResource = menuCategoryTextColor
),
bookmarksItem,
historyItem,
BrowserMenuDivider(),

View File

@ -1,82 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.library
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.fragment_library.*
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.support.ktx.android.content.getColorFromAttr
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.setToolbarColors
import org.mozilla.fenix.ext.showToolbar
/**
* Displays buttons to navigate to library sections, such as bookmarks and history.
*/
class LibraryFragment : Fragment(R.layout.fragment_library) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}
override fun onResume() {
super.onResume()
initToolbar()
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
libraryHistory.setOnClickListener {
requireComponents.analytics.metrics
.track(Event.LibrarySelectedItem(Event.LibrarySelectedItem.LibraryItem.HISTORY))
nav(
R.id.libraryFragment,
LibraryFragmentDirections.actionLibraryFragmentToHistoryFragment()
)
}
libraryBookmarks.setOnClickListener {
requireComponents.analytics.metrics
.track(Event.LibrarySelectedItem(Event.LibrarySelectedItem.LibraryItem.BOOKMARKS))
nav(
R.id.libraryFragment,
LibraryFragmentDirections.actionLibraryFragmentToBookmarksFragment(BookmarkRoot.Mobile.id)
)
}
requireComponents.analytics.metrics.track(Event.LibraryOpened)
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.library_menu, menu)
}
override fun onDestroy() {
super.onDestroy()
requireComponents.analytics.metrics.track(Event.LibraryClosed)
}
private fun initToolbar() {
(activity as? AppCompatActivity)?.let { activity ->
val toolbar = activity.findViewById<Toolbar>(R.id.navigationToolbar)
toolbar?.setToolbarColors(
foreground = activity.getColorFromAttr(R.attr.primaryText),
background = activity.getColorFromAttr(R.attr.foundation)
)
showToolbar(getString(R.string.library_title))
}
}
}

View File

@ -1,38 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.library
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.withStyledAttributes
import kotlinx.android.synthetic.main.library_list_item.view.libraryIcon
import kotlinx.android.synthetic.main.library_list_item.view.libraryItemTitle
import org.mozilla.fenix.R
class LibraryListItem @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
init {
LayoutInflater.from(context).inflate(R.layout.library_list_item, this, true)
context.withStyledAttributes(attrs, R.styleable.LibraryListItem, defStyleAttr, 0) {
val id = getResourceId(
R.styleable.LibraryListItem_listItemIcon,
R.drawable.library_icon_reading_list_circle_background
)
libraryIcon?.background = resources.getDrawable(id, context.theme)
libraryItemTitle?.text = resources.getString(
getResourceId(
R.styleable.LibraryListItem_listItemTitle,
R.string.browser_menu_library
)
)
}
}
}

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size
android:width="40dp"
android:height="40dp" />
<solid android:color="@color/library_reading_list_icon_background" />
</shape>
</item>
<item
android:bottom="8dp"
android:left="8dp"
android:right="8dp"
android:top="8dp">
<vector
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/library_reading_list_icon"
android:pathData="M16.7 21H7.3A3.3 3.3 0 0 1 4 17.7V6.3C4 4.5 5.5 3 7.3 3h9.4C18.5 3 20 4.5 20 6.3v11.4c0 1.8-1.5 3.3-3.3 3.3zM7.3 5C6.6 5 6 5.6 6 6.3v11.4c0 0.7 0.6 1.3 1.3 1.3h9.4c0.7 0 1.3-0.6 1.3-1.3V6.3c0-0.7-0.6-1.3-1.3-1.3H7.3zM15 8H9a0.5 0.5 0 0 1 0-1h6a0.5 0.5 0 0 1 0 1zm0 3H9a0.5 0.5 0 0 1 0-1h6a0.5 0.5 0 0 1 0 1zm0 3H9a0.5 0.5 0 0 1 0-1h6a0.5 0.5 0 0 1 0 1zm-3.4 3H9a0.5 0.5 0 0 1 0-1h2.6a0.5 0.5 0 0 1 0 1z" />
</vector>
</item>
</layer-list>

View File

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="org.mozilla.fenix.library.LibraryFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<org.mozilla.fenix.library.LibraryListItem
android:id="@+id/libraryBookmarks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:contentDescription="@string/library_bookmarks"
android:focusable="true"
app:listItemIcon="@drawable/bookmarks_circle_background_outline"
app:listItemTitle="@string/library_bookmarks" />
<org.mozilla.fenix.library.LibraryListItem
android:id="@+id/libraryHistory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
app:listItemIcon="@drawable/library_icon_history_circle_background"
app:listItemTitle="@string/library_history" />
</LinearLayout>
</ScrollView>

View File

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/library_item_height"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<ImageView
android:id="@+id/libraryIcon"
android:layout_width="@dimen/library_item_icon_height"
android:layout_height="@dimen/library_item_icon_height"
android:layout_marginStart="@dimen/library_item_icon_margin_horizontal"
android:layout_marginTop="@dimen/library_item_icon_margin_vertical"
android:layout_marginEnd="@dimen/library_item_icon_margin_horizontal"
android:layout_marginBottom="@dimen/library_item_icon_margin_vertical"
android:background="@drawable/library_icon_reading_list_circle_background"
android:clickable="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/libraryItemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/library_item_icon_margin_horizontal"
android:clickable="false"
android:gravity="center_vertical"
android:textAppearance="@style/ListItemTextStyle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/libraryIcon"
app:layout_constraintTop_toTopOf="parent" />
</merge>

View File

@ -160,9 +160,6 @@
<action
android:id="@+id/action_browserFragment_to_settingsFragment"
app:destination="@id/settingsFragment" />
<action
android:id="@+id/action_browserFragment_to_libraryFragment"
app:destination="@id/libraryFragment" />
<action
android:id="@+id/action_browserFragment_to_createShortcutFragment"
app:destination="@id/createShortcutFragment" />
@ -194,19 +191,6 @@
app:nullable="true" />
</fragment>
<fragment
android:id="@+id/libraryFragment"
android:name="org.mozilla.fenix.library.LibraryFragment"
android:label="@string/library_title"
tools:layout="@layout/fragment_library">
<action
android:id="@+id/action_libraryFragment_to_historyFragment"
app:destination="@+id/historyFragment" />
<action
android:id="@+id/action_libraryFragment_to_bookmarksFragment"
app:destination="@+id/bookmarkFragment" />
</fragment>
<fragment
android:id="@+id/historyFragment"
android:name="org.mozilla.fenix.library.history.HistoryFragment"

View File

@ -58,11 +58,6 @@
<attr name="tabTrayToolbarBackground" format="reference" />
<attr name="tabTrayItemDivider" format="reference" />
<declare-styleable name="LibraryListItem">
<attr name="listItemTitle" format="reference" />
<attr name="listItemIcon" format="reference" />
</declare-styleable>
<declare-styleable name="TrackingProtectionCategory">
<attr name="categoryItemTitle" format="reference" />
<attr name="categoryItemDescription" format="reference" />

View File

@ -12,7 +12,6 @@
<dimen name="mozac_browser_menu_corner_radius">8dp</dimen>
<dimen name="toolbar_elevation">7dp</dimen>
<dimen name="library_item_height">56dp</dimen>
<dimen name="library_item_icon_height">48dp</dimen>
<dimen name="library_item_icon_margin_horizontal">16dp</dimen>
<dimen name="library_item_icon_margin_vertical">8dp</dimen>
<dimen name="history_favicon_width_height">40dp</dimen>

View File

@ -408,8 +408,6 @@
<string name="library_reading_list">Reading List</string>
<!-- Menu Item Label for Search in Library -->
<string name="library_search">Search</string>
<!-- Library Page Title -->
<string name="library_title">Library</string>
<!-- Settings Page Title -->
<string name="settings_title">Settings</string>
<!-- Content description (not visible, for screen readers etc.): "Menu icon for items on a history item" -->