For #355 - Present the Library when the menu item is tapped
parent
19dd468639
commit
98a1ae578e
|
@ -35,9 +35,10 @@ import org.mozilla.fenix.components.FindInPageIntegration
|
||||||
import org.mozilla.fenix.mvi.ActionBusFactory
|
import org.mozilla.fenix.mvi.ActionBusFactory
|
||||||
import org.mozilla.fenix.mvi.getSafeManagedObservable
|
import org.mozilla.fenix.mvi.getSafeManagedObservable
|
||||||
import org.mozilla.fenix.search.toolbar.SearchAction
|
import org.mozilla.fenix.search.toolbar.SearchAction
|
||||||
import org.mozilla.fenix.search.toolbar.SearchState
|
|
||||||
import org.mozilla.fenix.search.toolbar.ToolbarComponent
|
import org.mozilla.fenix.search.toolbar.ToolbarComponent
|
||||||
|
import org.mozilla.fenix.search.toolbar.SearchState
|
||||||
import org.mozilla.fenix.search.toolbar.ToolbarUIView
|
import org.mozilla.fenix.search.toolbar.ToolbarUIView
|
||||||
|
import org.mozilla.fenix.search.toolbar.ToolbarMenu
|
||||||
|
|
||||||
class BrowserFragment : Fragment(), BackHandler {
|
class BrowserFragment : Fragment(), BackHandler {
|
||||||
|
|
||||||
|
@ -87,8 +88,10 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||||
|
|
||||||
getSafeManagedObservable<SearchAction>()
|
getSafeManagedObservable<SearchAction>()
|
||||||
.subscribe {
|
.subscribe {
|
||||||
if (it is SearchAction.ToolbarTapped) {
|
when (it) {
|
||||||
navigateToSearch()
|
is SearchAction.ToolbarTapped -> Navigation.findNavController(toolbar)
|
||||||
|
.navigate(R.id.action_browserFragment_to_searchFragment, null, null)
|
||||||
|
is SearchAction.ToolbarMenuItemTapped -> handleToolbarItemInteraction(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,8 +142,7 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||||
customTabsToolbarFeature = CustomTabsToolbarFeature(
|
customTabsToolbarFeature = CustomTabsToolbarFeature(
|
||||||
sessionManager,
|
sessionManager,
|
||||||
toolbar,
|
toolbar,
|
||||||
sessionId,
|
sessionId
|
||||||
requireComponents.toolbar.menuBuilder
|
|
||||||
) { requireActivity().finish() }
|
) { requireActivity().finish() }
|
||||||
|
|
||||||
lifecycle.addObservers(
|
lifecycle.addObservers(
|
||||||
|
@ -182,9 +184,18 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||||
promptsFeature.onActivityResult(requestCode, resultCode, data)
|
promptsFeature.onActivityResult(requestCode, resultCode, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun navigateToSearch() {
|
private fun handleToolbarItemInteraction(action: SearchAction.ToolbarMenuItemTapped) {
|
||||||
Navigation.findNavController(toolbar)
|
val sessionUseCases = requireComponents.useCases.sessionUseCases
|
||||||
.navigate(R.id.action_browserFragment_to_searchFragment, null, null)
|
when (action.item) {
|
||||||
|
is ToolbarMenu.Item.Back -> sessionUseCases.goBack.invoke()
|
||||||
|
is ToolbarMenu.Item.Forward -> sessionUseCases.goForward.invoke()
|
||||||
|
is ToolbarMenu.Item.Reload -> sessionUseCases.reload.invoke()
|
||||||
|
is ToolbarMenu.Item.Settings -> Navigation.findNavController(toolbar)
|
||||||
|
.navigate(R.id.action_browserFragment_to_settingsActivity, null, null)
|
||||||
|
is ToolbarMenu.Item.Library -> Navigation.findNavController(toolbar)
|
||||||
|
.navigate(R.id.action_browserFragment_to_libraryFragment, null, null)
|
||||||
|
else -> return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package org.mozilla.fenix.components
|
package org.mozilla.fenix.components
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import org.mozilla.fenix.components.toolbar.Toolbar
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides access to all components.
|
* Provides access to all components.
|
||||||
|
@ -14,7 +13,6 @@ class Components(private val context: Context) {
|
||||||
val core by lazy { Core(context) }
|
val core by lazy { Core(context) }
|
||||||
val search by lazy { Search(context) }
|
val search by lazy { Search(context) }
|
||||||
val useCases by lazy { UseCases(context, core.sessionManager, search.searchEngineManager) }
|
val useCases by lazy { UseCases(context, core.sessionManager, search.searchEngineManager) }
|
||||||
val toolbar by lazy { Toolbar(context, useCases.sessionUseCases, core.sessionManager) }
|
|
||||||
val utils by lazy { Utilities(context, core.sessionManager, useCases.sessionUseCases, useCases.searchUseCases) }
|
val utils by lazy { Utilities(context, core.sessionManager, useCases.sessionUseCases, useCases.searchUseCases) }
|
||||||
val analytics by lazy { Analytics(context) }
|
val analytics by lazy { Analytics(context) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ sealed class SearchAction : Action {
|
||||||
data class UrlCommitted(val url: String) : SearchAction()
|
data class UrlCommitted(val url: String) : SearchAction()
|
||||||
data class TextChanged(val query: String) : SearchAction()
|
data class TextChanged(val query: String) : SearchAction()
|
||||||
object ToolbarTapped : SearchAction()
|
object ToolbarTapped : SearchAction()
|
||||||
|
data class ToolbarMenuItemTapped(val item: ToolbarMenu.Item) : SearchAction()
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class SearchChange : Change {
|
sealed class SearchChange : Change {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
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/. */
|
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
package org.mozilla.fenix.components.toolbar
|
package org.mozilla.fenix.search.toolbar
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
|
@ -23,13 +23,14 @@ import org.mozilla.fenix.ext.components
|
||||||
class ToolbarIntegration(
|
class ToolbarIntegration(
|
||||||
context: Context,
|
context: Context,
|
||||||
toolbar: BrowserToolbar,
|
toolbar: BrowserToolbar,
|
||||||
|
toolbarMenu: ToolbarMenu,
|
||||||
domainAutocompleteProvider: DomainAutocompleteProvider,
|
domainAutocompleteProvider: DomainAutocompleteProvider,
|
||||||
historyStorage: HistoryStorage,
|
historyStorage: HistoryStorage,
|
||||||
sessionManager: SessionManager,
|
sessionManager: SessionManager,
|
||||||
sessionId: String? = null
|
sessionId: String? = null
|
||||||
) : LifecycleObserver {
|
) : LifecycleObserver {
|
||||||
init {
|
init {
|
||||||
toolbar.setMenuBuilder(context.components.toolbar.menuBuilder)
|
toolbar.setMenuBuilder(toolbarMenu.menuBuilder)
|
||||||
|
|
||||||
val home = BrowserToolbar.Button(
|
val home = BrowserToolbar.Button(
|
||||||
context.resources.getDrawable(R.drawable.ic_home, context.application.theme),
|
context.resources.getDrawable(R.drawable.ic_home, context.application.theme),
|
|
@ -1,52 +1,41 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
/* 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
|
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/. */
|
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
package org.mozilla.fenix.components.toolbar
|
package org.mozilla.fenix.search.toolbar
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
|
||||||
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
|
|
||||||
import mozilla.components.browser.menu.BrowserMenuBuilder
|
import mozilla.components.browser.menu.BrowserMenuBuilder
|
||||||
import mozilla.components.browser.menu.item.BrowserMenuDivider
|
import mozilla.components.browser.menu.item.BrowserMenuDivider
|
||||||
import mozilla.components.browser.menu.item.BrowserMenuImageText
|
import mozilla.components.browser.menu.item.BrowserMenuImageText
|
||||||
import mozilla.components.browser.menu.item.BrowserMenuItemToolbar
|
import mozilla.components.browser.menu.item.BrowserMenuItemToolbar
|
||||||
import mozilla.components.browser.menu.item.BrowserMenuSwitch
|
import mozilla.components.browser.menu.item.BrowserMenuSwitch
|
||||||
import mozilla.components.browser.session.SessionManager
|
|
||||||
import mozilla.components.feature.session.SessionUseCases
|
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.ext.share
|
|
||||||
import org.mozilla.fenix.settings.SettingsActivity
|
|
||||||
import org.mozilla.fenix.components.FindInPageIntegration
|
|
||||||
|
|
||||||
/**
|
class ToolbarMenu(private val context: Context, private val onItemTapped: (Item) -> Unit = {}) {
|
||||||
* Component group for all functionality related to the browser toolbar.
|
sealed class Item {
|
||||||
*/
|
object Help : Item()
|
||||||
class Toolbar(
|
object Settings : Item()
|
||||||
private val context: Context,
|
object Library : Item()
|
||||||
private val sessionUseCases: SessionUseCases,
|
data class RequestDesktop(val isChecked: Boolean) : Item()
|
||||||
private val sessionManager: SessionManager
|
object FindInPage : Item()
|
||||||
) {
|
object NewPrivateTab : Item()
|
||||||
|
object NewTab : Item()
|
||||||
/**
|
object Share : Item()
|
||||||
* Helper class for building browser menus.app
|
object Back : Item()
|
||||||
*/
|
object Forward : Item()
|
||||||
val menuBuilder by lazy { BrowserMenuBuilder(menuItems) }
|
object Reload : Item()
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides autocomplete functionality for shipped / provided domain lists.
|
|
||||||
*/
|
|
||||||
val shippedDomainsProvider by lazy {
|
|
||||||
ShippedDomainsProvider().also { it.initialize(context) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val menuBuilder by lazy { BrowserMenuBuilder(menuItems) }
|
||||||
|
|
||||||
val menuToolbar by lazy {
|
val menuToolbar by lazy {
|
||||||
val back = BrowserMenuItemToolbar.Button(
|
val back = BrowserMenuItemToolbar.Button(
|
||||||
mozilla.components.ui.icons.R.drawable.mozac_ic_back,
|
mozilla.components.ui.icons.R.drawable.mozac_ic_back,
|
||||||
iconTintColorResource = R.color.icons,
|
iconTintColorResource = R.color.icons,
|
||||||
contentDescription = context.getString(R.string.browser_menu_back)
|
contentDescription = context.getString(R.string.browser_menu_back)
|
||||||
) {
|
) {
|
||||||
sessionUseCases.goBack.invoke()
|
onItemTapped.invoke(Item.Back)
|
||||||
}
|
}
|
||||||
|
|
||||||
val forward = BrowserMenuItemToolbar.Button(
|
val forward = BrowserMenuItemToolbar.Button(
|
||||||
|
@ -54,7 +43,7 @@ class Toolbar(
|
||||||
iconTintColorResource = R.color.icons,
|
iconTintColorResource = R.color.icons,
|
||||||
contentDescription = context.getString(R.string.browser_menu_forward)
|
contentDescription = context.getString(R.string.browser_menu_forward)
|
||||||
) {
|
) {
|
||||||
sessionUseCases.goForward.invoke()
|
onItemTapped.invoke(Item.Forward)
|
||||||
}
|
}
|
||||||
|
|
||||||
val refresh = BrowserMenuItemToolbar.Button(
|
val refresh = BrowserMenuItemToolbar.Button(
|
||||||
|
@ -62,7 +51,7 @@ class Toolbar(
|
||||||
iconTintColorResource = R.color.icons,
|
iconTintColorResource = R.color.icons,
|
||||||
contentDescription = context.getString(R.string.browser_menu_refresh)
|
contentDescription = context.getString(R.string.browser_menu_refresh)
|
||||||
) {
|
) {
|
||||||
sessionUseCases.reload.invoke()
|
onItemTapped.invoke(Item.Reload)
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserMenuItemToolbar(listOf(back, forward, refresh))
|
BrowserMenuItemToolbar(listOf(back, forward, refresh))
|
||||||
|
@ -76,7 +65,7 @@ class Toolbar(
|
||||||
context.getString(R.string.browser_menu_help),
|
context.getString(R.string.browser_menu_help),
|
||||||
R.color.icons
|
R.color.icons
|
||||||
) {
|
) {
|
||||||
// TODO Help
|
onItemTapped.invoke(Item.Help)
|
||||||
},
|
},
|
||||||
|
|
||||||
BrowserMenuImageText(
|
BrowserMenuImageText(
|
||||||
|
@ -85,7 +74,7 @@ class Toolbar(
|
||||||
context.getString(R.string.browser_menu_settings),
|
context.getString(R.string.browser_menu_settings),
|
||||||
R.color.icons
|
R.color.icons
|
||||||
) {
|
) {
|
||||||
openSettingsActivity()
|
onItemTapped.invoke(Item.Settings)
|
||||||
},
|
},
|
||||||
|
|
||||||
BrowserMenuImageText(
|
BrowserMenuImageText(
|
||||||
|
@ -94,17 +83,15 @@ class Toolbar(
|
||||||
context.getString(R.string.browser_menu_library),
|
context.getString(R.string.browser_menu_library),
|
||||||
R.color.icons
|
R.color.icons
|
||||||
) {
|
) {
|
||||||
// TODO Your Library
|
onItemTapped.invoke(Item.Library)
|
||||||
},
|
},
|
||||||
|
|
||||||
BrowserMenuDivider(),
|
BrowserMenuDivider(),
|
||||||
|
|
||||||
BrowserMenuSwitch(context.getString(R.string.browser_menu_desktop_site), {
|
BrowserMenuSwitch(context.getString(R.string.browser_menu_desktop_site), {
|
||||||
sessionManager.selectedSessionOrThrow.desktopMode
|
false
|
||||||
}) { checked ->
|
}) { checked ->
|
||||||
sessionUseCases.requestDesktopSite.invoke(checked)
|
onItemTapped.invoke(Item.RequestDesktop(checked))
|
||||||
}.apply {
|
|
||||||
visible = { sessionManager.selectedSession != null }
|
|
||||||
},
|
},
|
||||||
|
|
||||||
BrowserMenuImageText(
|
BrowserMenuImageText(
|
||||||
|
@ -113,9 +100,7 @@ class Toolbar(
|
||||||
context.getString(R.string.browser_menu_find_in_page),
|
context.getString(R.string.browser_menu_find_in_page),
|
||||||
R.color.icons
|
R.color.icons
|
||||||
) {
|
) {
|
||||||
FindInPageIntegration.launch?.invoke()
|
onItemTapped.invoke(Item.FindInPage)
|
||||||
}.apply {
|
|
||||||
visible = { sessionManager.selectedSession != null }
|
|
||||||
},
|
},
|
||||||
|
|
||||||
BrowserMenuImageText(
|
BrowserMenuImageText(
|
||||||
|
@ -124,7 +109,7 @@ class Toolbar(
|
||||||
context.getString(R.string.browser_menu_private_tab),
|
context.getString(R.string.browser_menu_private_tab),
|
||||||
R.color.icons
|
R.color.icons
|
||||||
) {
|
) {
|
||||||
// TODO Private Tab
|
onItemTapped.invoke(Item.NewPrivateTab)
|
||||||
},
|
},
|
||||||
|
|
||||||
BrowserMenuImageText(
|
BrowserMenuImageText(
|
||||||
|
@ -133,7 +118,7 @@ class Toolbar(
|
||||||
context.getString(R.string.browser_menu_new_tab),
|
context.getString(R.string.browser_menu_new_tab),
|
||||||
R.color.icons
|
R.color.icons
|
||||||
) {
|
) {
|
||||||
// TODO New Tab
|
onItemTapped.invoke(Item.NewTab)
|
||||||
},
|
},
|
||||||
|
|
||||||
BrowserMenuImageText(
|
BrowserMenuImageText(
|
||||||
|
@ -142,10 +127,7 @@ class Toolbar(
|
||||||
context.getString(R.string.browser_menu_share),
|
context.getString(R.string.browser_menu_share),
|
||||||
R.color.icons
|
R.color.icons
|
||||||
) {
|
) {
|
||||||
val url = sessionManager.selectedSession?.url ?: ""
|
onItemTapped.invoke(Item.Share)
|
||||||
context.share(url)
|
|
||||||
}.apply {
|
|
||||||
visible = { sessionManager.selectedSession != null }
|
|
||||||
},
|
},
|
||||||
|
|
||||||
BrowserMenuDivider(),
|
BrowserMenuDivider(),
|
||||||
|
@ -153,10 +135,4 @@ class Toolbar(
|
||||||
menuToolbar
|
menuToolbar
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openSettingsActivity() {
|
|
||||||
val intent = Intent(context, SettingsActivity::class.java)
|
|
||||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
||||||
context.startActivity(intent)
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -14,7 +14,6 @@ import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
|
||||||
import mozilla.components.browser.toolbar.BrowserToolbar
|
import mozilla.components.browser.toolbar.BrowserToolbar
|
||||||
import mozilla.components.support.ktx.android.content.res.pxToDp
|
import mozilla.components.support.ktx.android.content.res.pxToDp
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.components.toolbar.ToolbarIntegration
|
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.mvi.UIView
|
import org.mozilla.fenix.mvi.UIView
|
||||||
|
|
||||||
|
@ -65,6 +64,7 @@ class ToolbarUIView(
|
||||||
toolbarIntegration = ToolbarIntegration(
|
toolbarIntegration = ToolbarIntegration(
|
||||||
this,
|
this,
|
||||||
view,
|
view,
|
||||||
|
ToolbarMenu(this) { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) },
|
||||||
ShippedDomainsProvider().also { it.initialize(this) },
|
ShippedDomainsProvider().also { it.initialize(this) },
|
||||||
components.core.historyStorage,
|
components.core.historyStorage,
|
||||||
components.core.sessionManager,
|
components.core.sessionManager,
|
||||||
|
|
|
@ -36,6 +36,13 @@
|
||||||
app:popUpTo="@id/homeFragment" />
|
app:popUpTo="@id/homeFragment" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/libraryFragment"
|
||||||
|
android:name="org.mozilla.fenix.library.LibraryFragment"
|
||||||
|
android:label="fragment_library"
|
||||||
|
tools:layout="@layout/fragment_library">
|
||||||
|
</fragment>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/browserFragment"
|
android:id="@+id/browserFragment"
|
||||||
android:name="org.mozilla.fenix.browser.BrowserFragment"
|
android:name="org.mozilla.fenix.browser.BrowserFragment"
|
||||||
|
@ -47,11 +54,16 @@
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_browserFragment_to_searchFragment"
|
android:id="@+id/action_browserFragment_to_searchFragment"
|
||||||
app:destination="@id/searchFragment" />
|
app:destination="@id/searchFragment" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_browserFragment_to_libraryFragment"
|
||||||
|
app:destination="@id/libraryFragment" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_browserFragment_to_settingsActivity"
|
android:id="@+id/action_browserFragment_to_settingsActivity"
|
||||||
app:destination="@id/settingsActivity" />
|
app:destination="@id/settingsActivity" />
|
||||||
|
|
||||||
<argument android:name="session_id" app:argType="string" app:nullable="true" />
|
<argument android:name="session_id" app:argType="string" app:nullable="true" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:id="@+id/settingsActivity"
|
android:id="@+id/settingsActivity"
|
||||||
android:name="org.mozilla.fenix.settings.SettingsActivity"
|
android:name="org.mozilla.fenix.settings.SettingsActivity"
|
||||||
|
|
Loading…
Reference in New Issue