2019-01-15 02:42:58 +01:00
|
|
|
/* 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/. */
|
2019-01-29 20:20:29 +01:00
|
|
|
|
2019-01-15 02:42:58 +01:00
|
|
|
package org.mozilla.fenix.browser
|
|
|
|
|
2019-01-28 19:14:51 +01:00
|
|
|
import android.content.Context
|
2019-01-30 20:41:01 +01:00
|
|
|
import android.content.Intent
|
2019-03-13 17:47:23 +01:00
|
|
|
import android.net.Uri
|
2019-01-15 02:42:58 +01:00
|
|
|
import android.os.Bundle
|
2019-02-05 00:41:26 +01:00
|
|
|
import android.view.Gravity
|
2019-01-15 02:42:58 +01:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2019-01-28 19:14:51 +01:00
|
|
|
import android.view.accessibility.AccessibilityManager
|
2019-02-08 00:37:52 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2019-01-29 20:20:29 +01:00
|
|
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
2019-02-05 00:41:26 +01:00
|
|
|
import androidx.core.content.ContextCompat
|
2019-01-15 02:42:58 +01:00
|
|
|
import androidx.fragment.app.Fragment
|
2019-02-01 02:23:10 +01:00
|
|
|
import androidx.navigation.Navigation
|
2019-03-04 11:42:35 +01:00
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
import kotlinx.android.synthetic.main.component_search.*
|
2019-02-05 00:41:26 +01:00
|
|
|
import kotlinx.android.synthetic.main.fragment_browser.view.*
|
2019-03-29 21:49:50 +01:00
|
|
|
import kotlinx.android.synthetic.main.fragment_search.*
|
2019-03-21 20:41:41 +01:00
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
import kotlinx.coroutines.Dispatchers.IO
|
|
|
|
import kotlinx.coroutines.Dispatchers.Main
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import mozilla.appservices.places.BookmarkRoot
|
2019-02-05 00:41:26 +01:00
|
|
|
import mozilla.components.browser.toolbar.behavior.BrowserToolbarBottomBehavior
|
2019-01-30 21:47:27 +01:00
|
|
|
import mozilla.components.feature.contextmenu.ContextMenuCandidate
|
|
|
|
import mozilla.components.feature.contextmenu.ContextMenuFeature
|
2019-01-28 22:26:28 +01:00
|
|
|
import mozilla.components.feature.downloads.DownloadsFeature
|
2019-02-08 16:19:46 +01:00
|
|
|
import mozilla.components.feature.prompts.PromptFeature
|
2019-03-04 11:42:35 +01:00
|
|
|
import mozilla.components.feature.session.FullScreenFeature
|
2019-01-19 00:33:40 +01:00
|
|
|
import mozilla.components.feature.session.SessionFeature
|
|
|
|
import mozilla.components.feature.session.SessionUseCases
|
2019-03-13 20:50:39 +01:00
|
|
|
import mozilla.components.feature.session.ThumbnailsFeature
|
2019-02-28 22:10:52 +01:00
|
|
|
import mozilla.components.feature.sitepermissions.SitePermissionsFeature
|
2019-03-28 19:29:03 +01:00
|
|
|
import mozilla.components.feature.sitepermissions.SitePermissionsRules
|
2019-02-08 13:50:22 +01:00
|
|
|
import mozilla.components.support.base.feature.BackHandler
|
|
|
|
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
|
2019-03-04 11:42:35 +01:00
|
|
|
import mozilla.components.support.ktx.android.view.enterToImmersiveMode
|
|
|
|
import mozilla.components.support.ktx.android.view.exitImmersiveModeIfNeeded
|
2019-02-15 18:31:03 +01:00
|
|
|
import org.mozilla.fenix.BrowsingModeManager
|
2019-02-11 23:12:18 +01:00
|
|
|
import org.mozilla.fenix.DefaultThemeManager
|
2019-02-12 16:51:42 +01:00
|
|
|
import org.mozilla.fenix.HomeActivity
|
2019-03-13 17:47:23 +01:00
|
|
|
import org.mozilla.fenix.IntentReceiverActivity
|
2019-02-08 16:19:46 +01:00
|
|
|
import org.mozilla.fenix.R
|
2019-02-02 06:03:04 +01:00
|
|
|
import org.mozilla.fenix.components.FindInPageIntegration
|
2019-03-18 22:54:36 +01:00
|
|
|
import org.mozilla.fenix.components.metrics.Event
|
2019-03-27 03:08:16 +01:00
|
|
|
import org.mozilla.fenix.components.metrics.Event.BrowserMenuItemTapped.Item
|
2019-02-13 00:51:30 +01:00
|
|
|
import org.mozilla.fenix.components.toolbar.SearchAction
|
|
|
|
import org.mozilla.fenix.components.toolbar.SearchState
|
|
|
|
import org.mozilla.fenix.components.toolbar.ToolbarComponent
|
|
|
|
import org.mozilla.fenix.components.toolbar.ToolbarIntegration
|
|
|
|
import org.mozilla.fenix.components.toolbar.ToolbarMenu
|
|
|
|
import org.mozilla.fenix.components.toolbar.ToolbarUIView
|
2019-03-15 18:51:04 +01:00
|
|
|
import org.mozilla.fenix.customtabs.CustomTabsIntegration
|
2019-03-21 20:41:41 +01:00
|
|
|
import org.mozilla.fenix.ext.asActivity
|
2019-03-13 17:47:23 +01:00
|
|
|
import org.mozilla.fenix.ext.components
|
2019-02-17 02:04:32 +01:00
|
|
|
import org.mozilla.fenix.ext.requireComponents
|
|
|
|
import org.mozilla.fenix.ext.share
|
|
|
|
import org.mozilla.fenix.mvi.ActionBusFactory
|
|
|
|
import org.mozilla.fenix.mvi.getAutoDisposeObservable
|
2019-03-21 20:41:41 +01:00
|
|
|
import org.mozilla.fenix.quickactionsheet.QuickActionAction
|
|
|
|
import org.mozilla.fenix.quickactionsheet.QuickActionComponent
|
|
|
|
import org.mozilla.fenix.utils.ItsNotBrokenSnack
|
2019-03-28 19:29:03 +01:00
|
|
|
import org.mozilla.fenix.utils.Settings
|
2019-04-02 05:40:40 +02:00
|
|
|
import org.mozilla.fenix.settings.quicksettings.QuickSettingsSheetDialogFragment
|
2019-01-15 02:42:58 +01:00
|
|
|
|
2019-03-14 14:27:54 +01:00
|
|
|
class BrowserFragment : Fragment(), BackHandler {
|
2019-02-05 00:41:26 +01:00
|
|
|
private lateinit var toolbarComponent: ToolbarComponent
|
2019-02-08 13:50:22 +01:00
|
|
|
|
|
|
|
private val sessionFeature = ViewBoundFeatureWrapper<SessionFeature>()
|
|
|
|
private val contextMenuFeature = ViewBoundFeatureWrapper<ContextMenuFeature>()
|
|
|
|
private val downloadsFeature = ViewBoundFeatureWrapper<DownloadsFeature>()
|
|
|
|
private val promptsFeature = ViewBoundFeatureWrapper<PromptFeature>()
|
|
|
|
private val findInPageIntegration = ViewBoundFeatureWrapper<FindInPageIntegration>()
|
|
|
|
private val toolbarIntegration = ViewBoundFeatureWrapper<ToolbarIntegration>()
|
2019-02-28 22:10:52 +01:00
|
|
|
private val sitePermissionsFeature = ViewBoundFeatureWrapper<SitePermissionsFeature>()
|
2019-03-04 11:42:35 +01:00
|
|
|
private val fullScreenFeature = ViewBoundFeatureWrapper<FullScreenFeature>()
|
2019-03-13 20:50:39 +01:00
|
|
|
private val thumbnailsFeature = ViewBoundFeatureWrapper<ThumbnailsFeature>()
|
2019-03-15 18:51:04 +01:00
|
|
|
private val customTabsIntegration = ViewBoundFeatureWrapper<CustomTabsIntegration>()
|
|
|
|
|
2019-02-08 19:35:48 +01:00
|
|
|
var sessionId: String? = null
|
2019-01-19 00:33:40 +01:00
|
|
|
|
2019-01-15 02:42:58 +01:00
|
|
|
override fun onCreateView(
|
2019-01-30 17:36:14 +01:00
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
2019-01-15 02:42:58 +01:00
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
2019-02-15 18:31:03 +01:00
|
|
|
require(arguments != null)
|
2019-02-08 19:35:48 +01:00
|
|
|
sessionId = BrowserFragmentArgs.fromBundle(arguments!!).sessionId
|
2019-02-15 18:31:03 +01:00
|
|
|
|
2019-02-05 00:41:26 +01:00
|
|
|
val view = inflater.inflate(R.layout.fragment_browser, container, false)
|
2019-03-19 21:26:36 +01:00
|
|
|
|
2019-02-05 00:41:26 +01:00
|
|
|
toolbarComponent = ToolbarComponent(
|
|
|
|
view.browserLayout,
|
2019-02-08 19:35:48 +01:00
|
|
|
ActionBusFactory.get(this), sessionId,
|
2019-02-22 18:49:02 +01:00
|
|
|
(activity as HomeActivity).browsingModeManager.isPrivate,
|
2019-03-29 21:49:50 +01:00
|
|
|
SearchState("", isEditing = false),
|
|
|
|
search_engine_icon
|
2019-02-05 00:41:26 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
toolbarComponent.uiView.view.apply {
|
2019-03-21 20:41:41 +01:00
|
|
|
setBackgroundColor(
|
|
|
|
ContextCompat.getColor(
|
|
|
|
view.context,
|
|
|
|
DefaultThemeManager.resolveAttribute(R.attr.browserToolbarBackground, context)
|
|
|
|
)
|
|
|
|
)
|
2019-02-05 00:41:26 +01:00
|
|
|
|
|
|
|
(layoutParams as CoordinatorLayout.LayoutParams).apply {
|
|
|
|
// Stop toolbar from collapsing if TalkBack is enabled
|
|
|
|
val accessibilityManager = context
|
|
|
|
?.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
|
|
|
|
|
2019-02-11 01:51:30 +01:00
|
|
|
if (!accessibilityManager.isTouchExplorationEnabled) {
|
2019-02-05 00:41:26 +01:00
|
|
|
behavior = BrowserToolbarBottomBehavior(view.context, null)
|
|
|
|
}
|
|
|
|
|
|
|
|
gravity = Gravity.BOTTOM
|
|
|
|
height = (resources.displayMetrics.density * TOOLBAR_HEIGHT).toInt()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-21 20:41:41 +01:00
|
|
|
QuickActionComponent(view.nestedScrollQuickAction, ActionBusFactory.get(this))
|
|
|
|
|
2019-02-12 16:51:42 +01:00
|
|
|
val activity = activity as HomeActivity
|
|
|
|
DefaultThemeManager.applyStatusBarTheme(activity.window, activity.themeManager, activity, false)
|
|
|
|
|
2019-02-05 00:41:26 +01:00
|
|
|
return view
|
2019-01-15 02:42:58 +01:00
|
|
|
}
|
2019-01-19 00:33:40 +01:00
|
|
|
|
2019-02-17 02:04:32 +01:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2019-01-19 00:33:40 +01:00
|
|
|
|
2019-02-09 23:54:47 +01:00
|
|
|
sessionId = BrowserFragmentArgs.fromBundle(arguments!!).sessionId
|
|
|
|
|
2019-01-23 22:39:53 +01:00
|
|
|
val sessionManager = requireComponents.core.sessionManager
|
2019-01-19 00:33:40 +01:00
|
|
|
|
2019-02-08 13:50:22 +01:00
|
|
|
contextMenuFeature.set(
|
|
|
|
feature = ContextMenuFeature(
|
|
|
|
requireFragmentManager(),
|
|
|
|
sessionManager,
|
|
|
|
ContextMenuCandidate.defaultCandidates(
|
|
|
|
requireContext(),
|
|
|
|
requireComponents.useCases.tabsUseCases,
|
2019-03-21 20:41:41 +01:00
|
|
|
view
|
|
|
|
),
|
|
|
|
view.engineView
|
|
|
|
),
|
2019-02-08 13:50:22 +01:00
|
|
|
owner = this,
|
2019-03-21 20:41:41 +01:00
|
|
|
view = view
|
|
|
|
)
|
2019-02-08 13:50:22 +01:00
|
|
|
|
|
|
|
downloadsFeature.set(
|
|
|
|
feature = DownloadsFeature(
|
2019-01-30 21:47:27 +01:00
|
|
|
requireContext(),
|
2019-02-08 13:50:22 +01:00
|
|
|
sessionManager = sessionManager,
|
|
|
|
fragmentManager = childFragmentManager,
|
|
|
|
onNeedToRequestPermissions = { permissions ->
|
|
|
|
requestPermissions(permissions, REQUEST_CODE_DOWNLOAD_PERMISSIONS)
|
|
|
|
}),
|
|
|
|
owner = this,
|
2019-03-21 20:41:41 +01:00
|
|
|
view = view
|
|
|
|
)
|
2019-02-08 13:50:22 +01:00
|
|
|
|
|
|
|
promptsFeature.set(
|
|
|
|
feature = PromptFeature(
|
|
|
|
fragment = this,
|
|
|
|
sessionManager = sessionManager,
|
|
|
|
fragmentManager = requireFragmentManager(),
|
|
|
|
onNeedToRequestPermissions = { permissions ->
|
|
|
|
requestPermissions(permissions, REQUEST_CODE_PROMPT_PERMISSIONS)
|
|
|
|
}),
|
|
|
|
owner = this,
|
2019-03-21 20:41:41 +01:00
|
|
|
view = view
|
|
|
|
)
|
2019-02-08 13:50:22 +01:00
|
|
|
|
|
|
|
sessionFeature.set(
|
|
|
|
feature = SessionFeature(
|
|
|
|
sessionManager,
|
|
|
|
SessionUseCases(sessionManager),
|
|
|
|
view.engineView,
|
2019-03-21 20:41:41 +01:00
|
|
|
sessionId
|
|
|
|
),
|
2019-02-08 13:50:22 +01:00
|
|
|
owner = this,
|
2019-03-21 20:41:41 +01:00
|
|
|
view = view
|
|
|
|
)
|
2019-02-08 13:50:22 +01:00
|
|
|
|
|
|
|
findInPageIntegration.set(
|
2019-03-21 19:26:02 +01:00
|
|
|
feature = FindInPageIntegration(
|
|
|
|
requireComponents.core.sessionManager, view.findInPageView, view.engineView
|
|
|
|
),
|
2019-02-08 13:50:22 +01:00
|
|
|
owner = this,
|
2019-03-21 20:41:41 +01:00
|
|
|
view = view
|
|
|
|
)
|
2019-02-08 13:50:22 +01:00
|
|
|
|
|
|
|
toolbarIntegration.set(
|
|
|
|
feature = (toolbarComponent.uiView as ToolbarUIView).toolbarIntegration,
|
|
|
|
owner = this,
|
2019-03-21 20:41:41 +01:00
|
|
|
view = view
|
|
|
|
)
|
2019-02-28 22:10:52 +01:00
|
|
|
|
|
|
|
sitePermissionsFeature.set(
|
|
|
|
feature = SitePermissionsFeature(
|
|
|
|
anchorView = view.findInPageView,
|
|
|
|
sessionManager = sessionManager
|
|
|
|
) { permissions ->
|
|
|
|
requestPermissions(permissions, REQUEST_CODE_APP_PERMISSIONS)
|
|
|
|
},
|
|
|
|
owner = this,
|
|
|
|
view = view
|
|
|
|
)
|
2019-03-04 11:42:35 +01:00
|
|
|
|
|
|
|
fullScreenFeature.set(
|
|
|
|
feature = FullScreenFeature(
|
|
|
|
sessionManager,
|
|
|
|
SessionUseCases(sessionManager),
|
|
|
|
sessionId
|
|
|
|
) {
|
|
|
|
if (it) {
|
|
|
|
Snackbar.make(view.rootView, getString(R.string.full_screen_notification), Snackbar.LENGTH_LONG)
|
|
|
|
.show()
|
|
|
|
activity?.enterToImmersiveMode()
|
|
|
|
toolbar.visibility = View.GONE
|
|
|
|
} else {
|
|
|
|
activity?.exitImmersiveModeIfNeeded()
|
|
|
|
toolbar.visibility = View.VISIBLE
|
|
|
|
}
|
|
|
|
},
|
|
|
|
owner = this,
|
|
|
|
view = view
|
|
|
|
)
|
2019-03-13 20:50:39 +01:00
|
|
|
|
|
|
|
thumbnailsFeature.set(
|
|
|
|
feature = ThumbnailsFeature(requireContext(), view.engineView, requireComponents.core.sessionManager),
|
|
|
|
owner = this,
|
|
|
|
view = view
|
|
|
|
)
|
2019-03-15 18:51:04 +01:00
|
|
|
|
|
|
|
val actionEmitter = ActionBusFactory.get(this).getManagedEmitter(SearchAction::class.java)
|
|
|
|
sessionId?.let { id ->
|
|
|
|
customTabsIntegration.set(
|
|
|
|
feature = CustomTabsIntegration(
|
|
|
|
requireContext(),
|
|
|
|
requireComponents.core.sessionManager,
|
|
|
|
toolbar,
|
|
|
|
id,
|
|
|
|
requireActivity(),
|
|
|
|
onItemTapped = { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) }
|
|
|
|
),
|
|
|
|
owner = this,
|
|
|
|
view = view
|
|
|
|
)
|
|
|
|
}
|
2019-04-02 05:40:40 +02:00
|
|
|
toolbarComponent.getView().setOnSiteSecurityClickedListener {
|
|
|
|
sessionId?.run {
|
|
|
|
val session = requireNotNull(requireContext().components.core.sessionManager.findSessionById(this))
|
|
|
|
val quickSettingsSheet = QuickSettingsSheetDialogFragment.newInstance(
|
|
|
|
url = session.url,
|
|
|
|
isSecured = session.securityInfo.secure,
|
|
|
|
isSiteInExceptionList = false
|
|
|
|
)
|
|
|
|
quickSettingsSheet.show(requireFragmentManager(), QuickSettingsSheetDialogFragment.FRAGMENT_TAG)
|
|
|
|
}
|
|
|
|
}
|
2019-02-04 20:47:20 +01:00
|
|
|
}
|
2019-01-28 22:26:28 +01:00
|
|
|
|
2019-02-25 20:37:20 +01:00
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
|
|
|
(activity as AppCompatActivity).supportActionBar?.hide()
|
|
|
|
}
|
|
|
|
|
2019-02-18 22:18:55 +01:00
|
|
|
override fun onStart() {
|
|
|
|
super.onStart()
|
|
|
|
getAutoDisposeObservable<SearchAction>()
|
|
|
|
.subscribe {
|
|
|
|
when (it) {
|
2019-03-18 22:54:36 +01:00
|
|
|
is SearchAction.ToolbarTapped -> {
|
|
|
|
Navigation
|
|
|
|
.findNavController(toolbarComponent.getView())
|
|
|
|
.navigate(
|
|
|
|
BrowserFragmentDirections.actionBrowserFragmentToSearchFragment(
|
2019-03-21 20:41:41 +01:00
|
|
|
requireComponents.core.sessionManager.selectedSession?.id
|
|
|
|
)
|
2019-03-18 22:54:36 +01:00
|
|
|
)
|
|
|
|
|
2019-03-19 04:49:17 +01:00
|
|
|
requireComponents.analytics.metrics.track(
|
|
|
|
Event.SearchBarTapped(Event.SearchBarTapped.Source.BROWSER)
|
|
|
|
)
|
2019-03-18 22:54:36 +01:00
|
|
|
}
|
2019-03-27 03:08:16 +01:00
|
|
|
is SearchAction.ToolbarMenuItemTapped -> {
|
|
|
|
trackToolbarItemInteraction(it)
|
|
|
|
handleToolbarItemInteraction(it)
|
|
|
|
}
|
2019-02-18 22:18:55 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-28 19:29:03 +01:00
|
|
|
|
2019-03-21 20:41:41 +01:00
|
|
|
getAutoDisposeObservable<QuickActionAction>()
|
|
|
|
.subscribe {
|
|
|
|
when (it) {
|
|
|
|
is QuickActionAction.SharePressed -> {
|
|
|
|
requireComponents.core.sessionManager
|
|
|
|
.selectedSession?.url?.apply { requireContext().share(this) }
|
|
|
|
}
|
|
|
|
is QuickActionAction.DownloadsPressed -> {
|
|
|
|
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "348")
|
|
|
|
}
|
|
|
|
is QuickActionAction.BookmarkPressed -> {
|
|
|
|
val session = requireComponents.core.sessionManager.selectedSession
|
|
|
|
CoroutineScope(IO).launch {
|
|
|
|
requireComponents.core.bookmarksStorage
|
|
|
|
.addItem(BookmarkRoot.Mobile.id, session!!.url, session.title, null)
|
|
|
|
launch(Main) {
|
|
|
|
val rootView =
|
|
|
|
context?.asActivity()?.window?.decorView?.findViewById<View>(android.R.id.content)
|
|
|
|
rootView?.let { view ->
|
|
|
|
Snackbar.make(
|
|
|
|
view,
|
|
|
|
getString(R.string.bookmark_created_snackbar),
|
|
|
|
Snackbar.LENGTH_LONG
|
|
|
|
)
|
|
|
|
.setAction(getString(R.string.edit_bookmark_snackbar_action)) {
|
|
|
|
ItsNotBrokenSnack(
|
|
|
|
context!!
|
|
|
|
).showSnackbar(issueNumber = "90")
|
|
|
|
}
|
|
|
|
.show()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is QuickActionAction.ReadPressed -> {
|
|
|
|
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "908")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-28 19:29:03 +01:00
|
|
|
assignSitePermissionsRules()
|
2019-02-18 22:18:55 +01:00
|
|
|
}
|
|
|
|
|
2019-02-01 06:52:26 +01:00
|
|
|
override fun onBackPressed(): Boolean {
|
2019-03-01 01:25:16 +01:00
|
|
|
return when {
|
|
|
|
findInPageIntegration.onBackPressed() -> true
|
|
|
|
sessionFeature.onBackPressed() -> true
|
2019-03-15 23:10:13 +01:00
|
|
|
customTabsIntegration.onBackPressed() -> true
|
2019-03-01 01:25:16 +01:00
|
|
|
else -> false
|
|
|
|
}
|
2019-02-01 06:52:26 +01:00
|
|
|
}
|
|
|
|
|
2019-01-28 22:26:28 +01:00
|
|
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
|
|
|
|
when (requestCode) {
|
2019-02-08 13:50:22 +01:00
|
|
|
REQUEST_CODE_DOWNLOAD_PERMISSIONS -> downloadsFeature.withFeature {
|
|
|
|
it.onPermissionsResult(permissions, grantResults)
|
|
|
|
}
|
|
|
|
REQUEST_CODE_PROMPT_PERMISSIONS -> promptsFeature.withFeature {
|
|
|
|
it.onPermissionsResult(permissions, grantResults)
|
|
|
|
}
|
2019-02-28 22:10:52 +01:00
|
|
|
REQUEST_CODE_APP_PERMISSIONS -> sitePermissionsFeature.withFeature {
|
|
|
|
it.onPermissionsResult(grantResults)
|
|
|
|
}
|
2019-01-28 22:26:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-30 20:41:01 +01:00
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
2019-02-08 13:50:22 +01:00
|
|
|
promptsFeature.withFeature { it.onActivityResult(requestCode, resultCode, data) }
|
2019-01-30 20:41:01 +01:00
|
|
|
}
|
|
|
|
|
2019-03-27 03:08:16 +01:00
|
|
|
// This method triggers the complexity warning. However it's actually not that hard to understand.
|
|
|
|
@SuppressWarnings("ComplexMethod")
|
|
|
|
private fun trackToolbarItemInteraction(action: SearchAction.ToolbarMenuItemTapped) {
|
|
|
|
val item = when (action.item) {
|
|
|
|
ToolbarMenu.Item.Back -> Item.BACK
|
|
|
|
ToolbarMenu.Item.Forward -> Item.FORWARD
|
|
|
|
ToolbarMenu.Item.Reload -> Item.RELOAD
|
|
|
|
ToolbarMenu.Item.Stop -> Item.STOP
|
|
|
|
ToolbarMenu.Item.Settings -> Item.SETTINGS
|
|
|
|
ToolbarMenu.Item.Library -> Item.LIBRARY
|
|
|
|
is ToolbarMenu.Item.RequestDesktop ->
|
|
|
|
if (action.item.isChecked) Item.DESKTOP_VIEW_ON else Item.DESKTOP_VIEW_OFF
|
|
|
|
ToolbarMenu.Item.NewPrivateTab -> Item.NEW_PRIVATE_TAB
|
|
|
|
ToolbarMenu.Item.FindInPage -> Item.FIND_IN_PAGE
|
|
|
|
ToolbarMenu.Item.ReportIssue -> Item.REPORT_SITE_ISSUE
|
|
|
|
ToolbarMenu.Item.Help -> Item.HELP
|
|
|
|
ToolbarMenu.Item.NewTab -> Item.NEW_TAB
|
|
|
|
ToolbarMenu.Item.OpenInFenix -> Item.OPEN_IN_FENIX
|
|
|
|
ToolbarMenu.Item.Share -> Item.SHARE
|
|
|
|
}
|
|
|
|
|
|
|
|
requireComponents.analytics.metrics.track(Event.BrowserMenuItemTapped(item))
|
|
|
|
}
|
2019-02-08 00:26:18 +01:00
|
|
|
// This method triggers the complexity warning. However it's actually not that hard to understand.
|
|
|
|
@SuppressWarnings("ComplexMethod")
|
2019-02-07 23:50:55 +01:00
|
|
|
private fun handleToolbarItemInteraction(action: SearchAction.ToolbarMenuItemTapped) {
|
|
|
|
val sessionUseCases = requireComponents.useCases.sessionUseCases
|
2019-02-11 23:12:18 +01:00
|
|
|
Do exhaustive when (action.item) {
|
2019-02-12 00:38:27 +01:00
|
|
|
ToolbarMenu.Item.Back -> sessionUseCases.goBack.invoke()
|
|
|
|
ToolbarMenu.Item.Forward -> sessionUseCases.goForward.invoke()
|
|
|
|
ToolbarMenu.Item.Reload -> sessionUseCases.reload.invoke()
|
2019-03-13 20:32:36 +01:00
|
|
|
ToolbarMenu.Item.Stop -> sessionUseCases.stopLoading.invoke()
|
2019-02-20 22:20:36 +01:00
|
|
|
ToolbarMenu.Item.Settings -> Navigation.findNavController(toolbarComponent.getView())
|
2019-02-08 19:35:48 +01:00
|
|
|
.navigate(BrowserFragmentDirections.actionBrowserFragmentToSettingsFragment())
|
2019-02-20 22:20:36 +01:00
|
|
|
ToolbarMenu.Item.Library -> Navigation.findNavController(toolbarComponent.getView())
|
2019-02-08 19:35:48 +01:00
|
|
|
.navigate(BrowserFragmentDirections.actionBrowserFragmentToLibraryFragment())
|
2019-02-08 00:26:18 +01:00
|
|
|
is ToolbarMenu.Item.RequestDesktop -> sessionUseCases.requestDesktopSite.invoke(action.item.isChecked)
|
2019-02-12 00:38:27 +01:00
|
|
|
ToolbarMenu.Item.Share -> requireComponents.core.sessionManager
|
2019-02-08 00:26:18 +01:00
|
|
|
.selectedSession?.url?.apply { requireContext().share(this) }
|
2019-02-12 00:38:27 +01:00
|
|
|
ToolbarMenu.Item.NewPrivateTab -> {
|
2019-02-15 18:31:03 +01:00
|
|
|
val directions = BrowserFragmentDirections
|
2019-03-05 00:50:58 +01:00
|
|
|
.actionBrowserFragmentToSearchFragment(null)
|
2019-03-06 20:48:00 +01:00
|
|
|
Navigation.findNavController(view!!).navigate(directions)
|
|
|
|
(activity as HomeActivity).browsingModeManager.mode = BrowsingModeManager.Mode.Private
|
2019-02-11 23:12:18 +01:00
|
|
|
}
|
2019-04-03 01:29:26 +02:00
|
|
|
ToolbarMenu.Item.FindInPage -> {
|
|
|
|
FindInPageIntegration.launch?.invoke()
|
|
|
|
requireComponents.analytics.metrics.track(Event.FindInPageOpened)
|
|
|
|
}
|
2019-02-12 00:38:27 +01:00
|
|
|
ToolbarMenu.Item.ReportIssue -> requireComponents.core.sessionManager
|
2019-02-08 16:19:46 +01:00
|
|
|
.selectedSession?.url?.apply {
|
|
|
|
val reportUrl = String.format(REPORT_SITE_ISSUE_URL, this)
|
|
|
|
sessionUseCases.loadUrl.invoke(reportUrl)
|
|
|
|
}
|
2019-02-11 23:12:18 +01:00
|
|
|
ToolbarMenu.Item.Help -> {
|
2019-03-22 01:08:03 +01:00
|
|
|
// TODO Help #1016
|
2019-03-22 20:38:59 +01:00
|
|
|
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "1016")
|
2019-02-11 23:12:18 +01:00
|
|
|
}
|
|
|
|
ToolbarMenu.Item.NewTab -> {
|
2019-02-15 18:31:03 +01:00
|
|
|
val directions = BrowserFragmentDirections
|
2019-02-22 18:49:02 +01:00
|
|
|
.actionBrowserFragmentToSearchFragment(null)
|
2019-02-11 23:12:18 +01:00
|
|
|
Navigation.findNavController(view!!).navigate(directions)
|
2019-02-15 18:31:03 +01:00
|
|
|
(activity as HomeActivity).browsingModeManager.mode = BrowsingModeManager.Mode.Normal
|
2019-02-11 23:12:18 +01:00
|
|
|
}
|
2019-03-13 17:47:23 +01:00
|
|
|
ToolbarMenu.Item.OpenInFenix -> {
|
|
|
|
val intent = Intent(context, IntentReceiverActivity::class.java)
|
|
|
|
val session = context!!.components.core.sessionManager.findSessionById(sessionId!!)
|
|
|
|
intent.action = Intent.ACTION_VIEW
|
|
|
|
intent.data = Uri.parse(session?.url)
|
|
|
|
startActivity(intent)
|
|
|
|
}
|
2019-02-07 23:50:55 +01:00
|
|
|
}
|
2019-02-05 00:41:26 +01:00
|
|
|
}
|
|
|
|
|
2019-03-28 19:29:03 +01:00
|
|
|
private fun assignSitePermissionsRules() {
|
|
|
|
val settings = Settings.getInstance(requireContext())
|
|
|
|
|
2019-03-29 18:57:49 +01:00
|
|
|
val rules: SitePermissionsRules = if (settings.shouldRecommendedSettingsBeActivated) {
|
|
|
|
settings.getSitePermissionsRecommendedSettingsRules()
|
2019-03-28 19:29:03 +01:00
|
|
|
} else {
|
2019-03-29 18:57:49 +01:00
|
|
|
settings.getSitePermissionsCustomSettingsRules()
|
2019-03-28 19:29:03 +01:00
|
|
|
}
|
|
|
|
sitePermissionsFeature.withFeature {
|
|
|
|
it.sitePermissionsRules = rules
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-11 23:12:18 +01:00
|
|
|
object Do {
|
|
|
|
inline infix fun <reified T> exhaustive(any: T?) = any
|
|
|
|
}
|
|
|
|
|
2019-01-28 22:26:28 +01:00
|
|
|
companion object {
|
|
|
|
private const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1
|
2019-01-30 20:41:01 +01:00
|
|
|
private const val REQUEST_CODE_PROMPT_PERMISSIONS = 2
|
2019-02-28 22:10:52 +01:00
|
|
|
private const val REQUEST_CODE_APP_PERMISSIONS = 3
|
2019-02-05 00:41:26 +01:00
|
|
|
private const val TOOLBAR_HEIGHT = 56f
|
2019-02-08 16:19:46 +01:00
|
|
|
private const val REPORT_SITE_ISSUE_URL = "https://webcompat.com/issues/new?url=%s&label=browser-fenix"
|
2019-01-19 00:33:40 +01:00
|
|
|
}
|
2019-01-15 02:42:58 +01:00
|
|
|
}
|