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-04-09 23:15:18 +02:00
|
|
|
import android.content.ClipData
|
|
|
|
import android.content.ClipboardManager
|
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-01-15 02:42:58 +01:00
|
|
|
import androidx.fragment.app.Fragment
|
2019-05-02 17:53:40 +02:00
|
|
|
import androidx.lifecycle.ViewModelProviders
|
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-04-11 17:04:35 +02:00
|
|
|
import kotlinx.android.synthetic.main.fragment_browser.*
|
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
|
2019-04-08 02:24:22 +02:00
|
|
|
import kotlinx.coroutines.Dispatchers
|
2019-03-21 20:41:41 +01:00
|
|
|
import kotlinx.coroutines.Dispatchers.IO
|
|
|
|
import kotlinx.coroutines.Dispatchers.Main
|
2019-04-08 02:24:22 +02:00
|
|
|
import kotlinx.coroutines.Job
|
2019-03-21 20:41:41 +01:00
|
|
|
import kotlinx.coroutines.launch
|
2019-05-06 23:38:32 +02:00
|
|
|
import kotlinx.coroutines.runBlocking
|
2019-03-21 20:41:41 +01:00
|
|
|
import mozilla.appservices.places.BookmarkRoot
|
2019-04-04 16:50:16 +02:00
|
|
|
import mozilla.components.browser.session.Session
|
2019-05-01 03:04:16 +02:00
|
|
|
import mozilla.components.browser.session.SessionManager
|
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-05-02 21:32:04 +02:00
|
|
|
import mozilla.components.feature.intent.IntentProcessor
|
2019-02-08 16:19:46 +01:00
|
|
|
import mozilla.components.feature.prompts.PromptFeature
|
2019-05-03 23:01:45 +02:00
|
|
|
import mozilla.components.feature.readerview.ReaderViewFeature
|
2019-05-16 19:01:03 +02:00
|
|
|
import mozilla.components.feature.session.behavior.EngineViewBottomBehavior
|
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-04-08 02:24:22 +02:00
|
|
|
import mozilla.components.feature.sitepermissions.SitePermissions
|
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-04-08 02:24:22 +02:00
|
|
|
import mozilla.components.support.ktx.kotlin.toUri
|
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-05-15 08:16:48 +02:00
|
|
|
import org.mozilla.fenix.FenixViewModelProvider
|
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-05-02 17:53:40 +02:00
|
|
|
import org.mozilla.fenix.collections.CreateCollectionViewModel
|
|
|
|
import org.mozilla.fenix.collections.SaveCollectionStep
|
2019-04-04 22:40:39 +02:00
|
|
|
import org.mozilla.fenix.components.FenixSnackbar
|
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-05-15 08:16:48 +02:00
|
|
|
import org.mozilla.fenix.components.toolbar.ToolbarViewModel
|
2019-03-15 18:51:04 +01:00
|
|
|
import org.mozilla.fenix.customtabs.CustomTabsIntegration
|
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
|
2019-05-06 20:20:19 +02:00
|
|
|
import org.mozilla.fenix.ext.urlToTrimmedHost
|
|
|
|
import org.mozilla.fenix.home.sessioncontrol.Tab
|
2019-04-06 06:24:28 +02:00
|
|
|
import org.mozilla.fenix.lib.Do
|
2019-02-17 02:04:32 +01:00
|
|
|
import org.mozilla.fenix.mvi.ActionBusFactory
|
|
|
|
import org.mozilla.fenix.mvi.getAutoDisposeObservable
|
2019-04-23 20:32:48 +02:00
|
|
|
import org.mozilla.fenix.mvi.getManagedEmitter
|
2019-03-21 20:41:41 +01:00
|
|
|
import org.mozilla.fenix.quickactionsheet.QuickActionAction
|
2019-04-23 20:32:48 +02:00
|
|
|
import org.mozilla.fenix.quickactionsheet.QuickActionChange
|
2019-03-21 20:41:41 +01:00
|
|
|
import org.mozilla.fenix.quickactionsheet.QuickActionComponent
|
2019-05-06 23:38:32 +02:00
|
|
|
import org.mozilla.fenix.quickactionsheet.QuickActionState
|
2019-05-15 08:16:48 +02:00
|
|
|
import org.mozilla.fenix.quickactionsheet.QuickActionViewModel
|
2019-03-21 20:41:41 +01:00
|
|
|
import org.mozilla.fenix.utils.ItsNotBrokenSnack
|
2019-03-28 19:29:03 +01:00
|
|
|
import org.mozilla.fenix.utils.Settings
|
2019-04-08 02:24:22 +02:00
|
|
|
import kotlin.coroutines.CoroutineContext
|
2019-01-15 02:42:58 +01:00
|
|
|
|
2019-04-04 16:50:16 +02:00
|
|
|
@SuppressWarnings("TooManyFunctions", "LargeClass")
|
2019-05-14 23:34:01 +02:00
|
|
|
class BrowserFragment : Fragment(), BackHandler, CoroutineScope {
|
2019-02-05 00:41:26 +01:00
|
|
|
private lateinit var toolbarComponent: ToolbarComponent
|
2019-02-08 13:50:22 +01:00
|
|
|
|
2019-04-12 20:09:07 +02:00
|
|
|
private var sessionObserver: Session.Observer? = null
|
2019-05-01 03:04:16 +02:00
|
|
|
private var sessionManagerObserver: SessionManager.Observer? = null
|
|
|
|
|
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-05-03 23:01:45 +02:00
|
|
|
private val readerViewFeature = ViewBoundFeatureWrapper<ReaderViewFeature>()
|
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-04-08 02:24:22 +02:00
|
|
|
private lateinit var job: Job
|
2019-03-15 18:51:04 +01:00
|
|
|
|
2019-04-29 17:30:32 +02:00
|
|
|
var customTabSessionId: String? = null
|
2019-01-19 00:33:40 +01:00
|
|
|
|
2019-04-08 02:24:22 +02:00
|
|
|
override val coroutineContext: CoroutineContext get() = Dispatchers.IO + job
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
job = Job()
|
|
|
|
}
|
|
|
|
|
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-05-02 21:32:04 +02:00
|
|
|
customTabSessionId = arguments?.getString(IntentProcessor.ACTIVE_SESSION_ID)
|
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-04-29 17:30:32 +02:00
|
|
|
ActionBusFactory.get(this), customTabSessionId,
|
2019-02-22 18:49:02 +01:00
|
|
|
(activity as HomeActivity).browsingModeManager.isPrivate,
|
2019-05-15 08:16:48 +02:00
|
|
|
search_engine_icon,
|
|
|
|
FenixViewModelProvider.create(
|
|
|
|
this,
|
|
|
|
ToolbarViewModel::class.java
|
|
|
|
) {
|
|
|
|
ToolbarViewModel(
|
|
|
|
SearchState("", getSessionById()?.searchTerms ?: "", isEditing = false)
|
|
|
|
)
|
|
|
|
}
|
2019-02-05 00:41:26 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
toolbarComponent.uiView.view.apply {
|
2019-04-22 19:11:02 +02:00
|
|
|
setBackgroundResource(R.drawable.toolbar_background)
|
2019-02-05 00:41:26 +01:00
|
|
|
|
|
|
|
(layoutParams as CoordinatorLayout.LayoutParams).apply {
|
2019-04-01 17:47:25 +02:00
|
|
|
gravity = getAppropriateLayoutGravity()
|
|
|
|
|
|
|
|
view.nestedScrollQuickAction.visibility = if (gravity == Gravity.TOP) {
|
|
|
|
View.GONE
|
|
|
|
} else {
|
|
|
|
View.VISIBLE
|
|
|
|
}
|
|
|
|
|
2019-02-05 00:41:26 +01:00
|
|
|
height = (resources.displayMetrics.density * TOOLBAR_HEIGHT).toInt()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-06 23:38:32 +02:00
|
|
|
QuickActionComponent(
|
|
|
|
view.nestedScrollQuickAction,
|
|
|
|
ActionBusFactory.get(this),
|
2019-05-15 08:16:48 +02:00
|
|
|
FenixViewModelProvider.create(
|
|
|
|
this,
|
|
|
|
QuickActionViewModel::class.java
|
|
|
|
) {
|
|
|
|
QuickActionViewModel(
|
|
|
|
QuickActionState(
|
|
|
|
readable = getSessionById()?.readerable ?: false,
|
|
|
|
bookmarked = findBookmarkedURL(getSessionById()),
|
|
|
|
readerActive = getSessionById()?.readerMode ?: false,
|
|
|
|
bounceNeeded = false
|
|
|
|
)
|
2019-05-06 23:38:32 +02:00
|
|
|
)
|
2019-05-15 08:16:48 +02:00
|
|
|
}
|
2019-05-06 23:38:32 +02:00
|
|
|
)
|
2019-03-21 20:41:41 +01:00
|
|
|
|
2019-02-12 16:51:42 +01:00
|
|
|
val activity = activity as HomeActivity
|
2019-04-25 16:39:14 +02:00
|
|
|
DefaultThemeManager.applyStatusBarTheme(activity.window, activity.themeManager, activity)
|
2019-02-12 16:51:42 +01:00
|
|
|
|
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-04-01 17:47:25 +02:00
|
|
|
private fun getAppropriateLayoutGravity(): Int {
|
2019-04-29 17:30:32 +02:00
|
|
|
if (customTabSessionId != null) {
|
2019-04-23 20:32:48 +02:00
|
|
|
return Gravity.TOP
|
|
|
|
}
|
2019-04-01 17:47:25 +02:00
|
|
|
|
|
|
|
return Gravity.BOTTOM
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
|
2019-05-16 19:01:03 +02:00
|
|
|
if (customTabSessionId == null) {
|
|
|
|
(engineView.asView().layoutParams as CoordinatorLayout.LayoutParams).apply {
|
|
|
|
behavior = EngineViewBottomBehavior(context, null)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
2019-05-07 22:30:13 +02:00
|
|
|
sessionId = customTabSessionId,
|
2019-02-08 13:50:22 +01:00
|
|
|
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-04-29 17:30:32 +02:00
|
|
|
customTabSessionId
|
2019-03-21 20:41:41 +01:00
|
|
|
),
|
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
|
|
|
|
2019-05-07 18:40:46 +02:00
|
|
|
val accentHighContrastColor = DefaultThemeManager.resolveAttribute(R.attr.accentHighContrast, requireContext())
|
|
|
|
|
2019-02-28 22:10:52 +01:00
|
|
|
sitePermissionsFeature.set(
|
|
|
|
feature = SitePermissionsFeature(
|
2019-05-07 18:40:46 +02:00
|
|
|
context = requireContext(),
|
|
|
|
sessionManager = sessionManager,
|
|
|
|
fragmentManager = requireFragmentManager(),
|
|
|
|
promptsStyling = SitePermissionsFeature.PromptsStyling(
|
|
|
|
gravity = getAppropriateLayoutGravity(),
|
|
|
|
shouldWidthMatchParent = true,
|
|
|
|
positiveButtonBackgroundColor = accentHighContrastColor,
|
|
|
|
positiveButtonTextColor = R.color.photonWhite
|
|
|
|
),
|
|
|
|
sessionId = customTabSessionId
|
2019-02-28 22:10:52 +01:00
|
|
|
) { 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),
|
2019-04-29 17:30:32 +02:00
|
|
|
customTabSessionId
|
2019-03-04 11:42:35 +01:00
|
|
|
) {
|
|
|
|
if (it) {
|
2019-04-24 22:21:26 +02:00
|
|
|
FenixSnackbar.make(view.rootView, Snackbar.LENGTH_LONG)
|
|
|
|
.setText(getString(R.string.full_screen_notification))
|
2019-03-04 11:42:35 +01:00
|
|
|
.show()
|
|
|
|
activity?.enterToImmersiveMode()
|
|
|
|
toolbar.visibility = View.GONE
|
2019-04-11 17:04:35 +02:00
|
|
|
nestedScrollQuickAction.visibility = View.GONE
|
2019-03-04 11:42:35 +01:00
|
|
|
} else {
|
|
|
|
activity?.exitImmersiveModeIfNeeded()
|
2019-04-25 16:39:14 +02:00
|
|
|
(activity as HomeActivity).let { activity: HomeActivity ->
|
|
|
|
DefaultThemeManager.applyStatusBarTheme(
|
|
|
|
activity.window,
|
|
|
|
activity.themeManager,
|
|
|
|
activity
|
|
|
|
)
|
|
|
|
}
|
2019-03-04 11:42:35 +01:00
|
|
|
toolbar.visibility = View.VISIBLE
|
2019-04-11 17:04:35 +02:00
|
|
|
nestedScrollQuickAction.visibility = View.VISIBLE
|
2019-03-04 11:42:35 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
owner = this,
|
|
|
|
view = view
|
|
|
|
)
|
2019-03-13 20:50:39 +01:00
|
|
|
|
|
|
|
thumbnailsFeature.set(
|
2019-04-23 20:32:48 +02:00
|
|
|
feature = ThumbnailsFeature(
|
|
|
|
requireContext(),
|
|
|
|
view.engineView,
|
|
|
|
requireComponents.core.sessionManager
|
|
|
|
),
|
2019-03-13 20:50:39 +01:00
|
|
|
owner = this,
|
|
|
|
view = view
|
|
|
|
)
|
2019-03-15 18:51:04 +01:00
|
|
|
|
2019-05-03 23:01:45 +02:00
|
|
|
readerViewFeature.set(
|
|
|
|
feature = ReaderViewFeature(
|
|
|
|
requireContext(),
|
|
|
|
requireComponents.core.engine,
|
|
|
|
requireComponents.core.sessionManager,
|
|
|
|
view.readerViewControlsBar
|
|
|
|
) {
|
|
|
|
getManagedEmitter<QuickActionChange>().apply {
|
|
|
|
onNext(QuickActionChange.ReadableStateChange(it))
|
2019-05-06 23:38:32 +02:00
|
|
|
onNext(
|
|
|
|
QuickActionChange.ReaderActiveStateChange(
|
|
|
|
sessionManager.selectedSession?.readerMode ?: false
|
|
|
|
)
|
2019-05-03 23:01:45 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
owner = this,
|
|
|
|
view = view
|
|
|
|
)
|
|
|
|
|
2019-03-15 18:51:04 +01:00
|
|
|
val actionEmitter = ActionBusFactory.get(this).getManagedEmitter(SearchAction::class.java)
|
2019-04-01 17:47:25 +02:00
|
|
|
|
2019-04-29 17:30:32 +02:00
|
|
|
customTabSessionId?.let {
|
|
|
|
customTabsIntegration.set(
|
|
|
|
feature = CustomTabsIntegration(
|
|
|
|
requireContext(),
|
|
|
|
requireComponents.core.sessionManager,
|
|
|
|
toolbar,
|
|
|
|
it,
|
|
|
|
activity,
|
|
|
|
onItemTapped = { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) }
|
|
|
|
),
|
|
|
|
owner = this,
|
|
|
|
view = view)
|
2019-03-15 18:51:04 +01:00
|
|
|
}
|
2019-04-01 17:47:25 +02:00
|
|
|
|
2019-04-02 05:40:40 +02:00
|
|
|
toolbarComponent.getView().setOnSiteSecurityClickedListener {
|
2019-04-08 02:24:22 +02:00
|
|
|
showQuickSettingsDialog()
|
2019-04-02 05:40:40 +02:00
|
|
|
}
|
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()
|
2019-04-25 23:50:52 +02:00
|
|
|
context?.components?.core?.let {
|
|
|
|
val preferredColorScheme = it.getPreferredColorScheme()
|
|
|
|
if (it.engine.settings.preferredColorScheme != preferredColorScheme) {
|
|
|
|
it.engine.settings.preferredColorScheme = preferredColorScheme
|
|
|
|
context?.components?.useCases?.sessionUseCases?.reload?.invoke()
|
|
|
|
}
|
|
|
|
}
|
2019-05-09 18:09:34 +02:00
|
|
|
getSessionById()?.let { (activity as HomeActivity).updateThemeForSession(it) }
|
2019-02-25 20:37:20 +01:00
|
|
|
(activity as AppCompatActivity).supportActionBar?.hide()
|
|
|
|
}
|
|
|
|
|
2019-04-06 00:08:55 +02:00
|
|
|
@Suppress("ComplexMethod")
|
2019-02-18 22:18:55 +01:00
|
|
|
override fun onStart() {
|
|
|
|
super.onStart()
|
2019-04-12 20:09:07 +02:00
|
|
|
sessionObserver = subscribeToSession()
|
2019-05-01 03:04:16 +02:00
|
|
|
sessionManagerObserver = subscribeToSessions()
|
2019-05-14 23:34:01 +02:00
|
|
|
val accessibilityManager = activity?.getSystemService(Context.ACCESSIBILITY_SERVICE) as? AccessibilityManager
|
|
|
|
accessibilityManager?.addTouchExplorationStateChangeListener {
|
|
|
|
updateToolbar()
|
|
|
|
}
|
2019-04-25 21:49:56 +02:00
|
|
|
updateToolbar()
|
2019-05-06 23:38:32 +02:00
|
|
|
getSessionById()?.let { updateBookmarkState(it) }
|
2019-02-18 22:18:55 +01:00
|
|
|
getAutoDisposeObservable<SearchAction>()
|
|
|
|
.subscribe {
|
|
|
|
when (it) {
|
2019-04-09 23:15:18 +02:00
|
|
|
is SearchAction.ToolbarClicked -> {
|
2019-03-18 22:54:36 +01:00
|
|
|
Navigation
|
|
|
|
.findNavController(toolbarComponent.getView())
|
|
|
|
.navigate(
|
|
|
|
BrowserFragmentDirections.actionBrowserFragmentToSearchFragment(
|
2019-04-25 22:00:09 +02:00
|
|
|
getSessionById()?.id
|
2019-03-21 20:41:41 +01:00
|
|
|
)
|
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-04-09 23:15:18 +02:00
|
|
|
is SearchAction.ToolbarLongClicked -> {
|
2019-04-25 22:00:09 +02:00
|
|
|
getSessionById()?.let { session ->
|
|
|
|
session.copyUrl(requireContext())
|
|
|
|
FenixSnackbar.make(view!!, Snackbar.LENGTH_LONG)
|
|
|
|
.setText(resources.getString(R.string.url_copied))
|
|
|
|
.show()
|
|
|
|
}
|
2019-04-09 23:15:18 +02:00
|
|
|
}
|
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) {
|
2019-04-06 00:08:55 +02:00
|
|
|
is QuickActionAction.Opened -> {
|
|
|
|
requireComponents.analytics.metrics.track(Event.QuickActionSheetOpened)
|
|
|
|
}
|
|
|
|
is QuickActionAction.Closed -> {
|
|
|
|
requireComponents.analytics.metrics.track(Event.QuickActionSheetClosed)
|
|
|
|
}
|
2019-03-21 20:41:41 +01:00
|
|
|
is QuickActionAction.SharePressed -> {
|
2019-04-06 00:08:55 +02:00
|
|
|
requireComponents.analytics.metrics.track(Event.QuickActionSheetShareTapped)
|
2019-04-25 22:00:09 +02:00
|
|
|
getSessionById()?.let { session ->
|
|
|
|
session.url.apply { requireContext().share(this) }
|
|
|
|
}
|
2019-03-21 20:41:41 +01:00
|
|
|
}
|
|
|
|
is QuickActionAction.DownloadsPressed -> {
|
2019-04-06 00:08:55 +02:00
|
|
|
requireComponents.analytics.metrics.track(Event.QuickActionSheetDownloadTapped)
|
2019-03-21 20:41:41 +01:00
|
|
|
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "348")
|
|
|
|
}
|
|
|
|
is QuickActionAction.BookmarkPressed -> {
|
2019-04-06 00:08:55 +02:00
|
|
|
requireComponents.analytics.metrics.track(Event.QuickActionSheetBookmarkTapped)
|
2019-05-01 19:21:28 +02:00
|
|
|
bookmarkTapped()
|
2019-03-21 20:41:41 +01:00
|
|
|
}
|
|
|
|
is QuickActionAction.ReadPressed -> {
|
2019-05-03 23:01:45 +02:00
|
|
|
readerViewFeature.withFeature { feature ->
|
|
|
|
requireComponents.analytics.metrics.track(Event.QuickActionSheetReadTapped)
|
|
|
|
val actionEmitter = getManagedEmitter<QuickActionChange>()
|
|
|
|
val enabled = requireComponents.core.sessionManager.selectedSession?.readerMode ?: false
|
|
|
|
if (enabled) {
|
|
|
|
feature.hideReaderView()
|
|
|
|
actionEmitter.onNext(QuickActionChange.ReaderActiveStateChange(false))
|
|
|
|
} else {
|
|
|
|
feature.showReaderView()
|
|
|
|
actionEmitter.onNext(QuickActionChange.ReaderActiveStateChange(true))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is QuickActionAction.ReadAppearancePressed -> {
|
|
|
|
// TODO telemetry: https://github.com/mozilla-mobile/fenix/issues/2267
|
|
|
|
readerViewFeature.withFeature { feature ->
|
|
|
|
feature.showControls()
|
|
|
|
}
|
2019-03-21 20:41:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-28 19:29:03 +01:00
|
|
|
assignSitePermissionsRules()
|
2019-02-18 22:18:55 +01:00
|
|
|
}
|
|
|
|
|
2019-05-01 19:21:28 +02:00
|
|
|
private fun bookmarkTapped() {
|
|
|
|
getSessionById()?.let { session ->
|
|
|
|
CoroutineScope(IO).launch {
|
|
|
|
val components = requireComponents
|
|
|
|
val existing = components.core.bookmarksStorage.getBookmarksWithUrl(session.url)
|
|
|
|
val found = existing.isNotEmpty() && existing[0].url == session.url
|
|
|
|
if (found) {
|
|
|
|
launch(Main) {
|
|
|
|
Navigation.findNavController(requireActivity(), R.id.container)
|
|
|
|
.navigate(
|
|
|
|
BrowserFragmentDirections
|
|
|
|
.actionBrowserFragmentToBookmarkEditFragment(existing[0].guid)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
val guid = components.core.bookmarksStorage
|
|
|
|
.addItem(
|
|
|
|
BookmarkRoot.Mobile.id,
|
|
|
|
session.url,
|
|
|
|
session.title,
|
|
|
|
null
|
|
|
|
)
|
|
|
|
launch(Main) {
|
|
|
|
getManagedEmitter<QuickActionChange>()
|
|
|
|
.onNext(QuickActionChange.BookmarkedStateChange(true))
|
|
|
|
requireComponents.analytics.metrics.track(Event.AddBookmark)
|
|
|
|
view?.let {
|
|
|
|
FenixSnackbar.make(
|
|
|
|
it,
|
|
|
|
Snackbar.LENGTH_LONG
|
|
|
|
)
|
|
|
|
.setAction(getString(R.string.edit_bookmark_snackbar_action)) {
|
|
|
|
Navigation.findNavController(
|
|
|
|
requireActivity(),
|
|
|
|
R.id.container
|
|
|
|
)
|
|
|
|
.navigate(
|
|
|
|
BrowserFragmentDirections
|
|
|
|
.actionBrowserFragmentToBookmarkEditFragment(
|
|
|
|
guid
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
.setText(getString(R.string.bookmark_saved_snackbar))
|
|
|
|
.show()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 20:09:07 +02:00
|
|
|
override fun onStop() {
|
|
|
|
super.onStop()
|
|
|
|
sessionObserver?.let {
|
2019-04-29 21:32:30 +02:00
|
|
|
getSessionById()?.unregister(it)
|
2019-04-12 20:09:07 +02:00
|
|
|
}
|
2019-05-01 03:04:16 +02:00
|
|
|
sessionManagerObserver?.let {
|
|
|
|
requireComponents.core.sessionManager.unregister(it)
|
|
|
|
}
|
2019-04-12 20:09:07 +02: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
|
2019-04-24 22:14:24 +02:00
|
|
|
fullScreenFeature.onBackPressed() -> true
|
2019-05-03 23:01:45 +02:00
|
|
|
readerViewFeature.onBackPressed() -> true
|
2019-03-01 01:25:16 +01:00
|
|
|
sessionFeature.onBackPressed() -> true
|
|
|
|
else -> false
|
|
|
|
}
|
2019-02-01 06:52:26 +01:00
|
|
|
}
|
|
|
|
|
2019-04-23 20:32:48 +02:00
|
|
|
override fun onRequestPermissionsResult(
|
|
|
|
requestCode: Int,
|
|
|
|
permissions: Array<String>,
|
|
|
|
grantResults: IntArray
|
|
|
|
) {
|
2019-01-28 22:26:28 +01:00
|
|
|
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-04-08 02:24:22 +02:00
|
|
|
override fun onDestroy() {
|
|
|
|
super.onDestroy()
|
|
|
|
job.cancel()
|
|
|
|
}
|
|
|
|
|
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
|
2019-04-29 20:14:24 +02:00
|
|
|
ToolbarMenu.Item.SaveToCollection -> Item.SAVE_TO_COLLECTION
|
2019-03-27 03:08:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
requireComponents.analytics.metrics.track(Event.BrowserMenuItemTapped(item))
|
|
|
|
}
|
2019-04-12 17:15:56 +02:00
|
|
|
|
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-05-02 21:32:04 +02:00
|
|
|
ToolbarMenu.Item.Back -> sessionUseCases.goBack.invoke(getSessionById())
|
|
|
|
ToolbarMenu.Item.Forward -> sessionUseCases.goForward.invoke(getSessionById())
|
|
|
|
ToolbarMenu.Item.Reload -> sessionUseCases.reload.invoke(getSessionById())
|
|
|
|
ToolbarMenu.Item.Stop -> sessionUseCases.stopLoading.invoke(getSessionById())
|
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-04-25 22:00:09 +02:00
|
|
|
ToolbarMenu.Item.Share -> getSessionById()?.let { session ->
|
2019-04-23 20:32:48 +02:00
|
|
|
session.url.apply {
|
|
|
|
requireContext().share(this)
|
2019-04-25 22:00:09 +02:00
|
|
|
}
|
|
|
|
}
|
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)
|
2019-04-29 17:30:32 +02:00
|
|
|
(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-04-25 22:00:09 +02:00
|
|
|
ToolbarMenu.Item.ReportIssue -> getSessionById()?.let { session ->
|
|
|
|
session.url.apply {
|
|
|
|
val reportUrl = String.format(REPORT_SITE_ISSUE_URL, this)
|
|
|
|
sessionUseCases.loadUrl.invoke(reportUrl)
|
|
|
|
}
|
2019-02-08 16:19:46 +01:00
|
|
|
}
|
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-05-02 17:53:40 +02:00
|
|
|
(activity as HomeActivity).browsingModeManager.mode =
|
|
|
|
BrowsingModeManager.Mode.Normal
|
2019-04-29 20:14:24 +02:00
|
|
|
}
|
2019-05-02 17:53:40 +02:00
|
|
|
ToolbarMenu.Item.SaveToCollection -> showSaveToCollection()
|
2019-03-13 17:47:23 +01:00
|
|
|
ToolbarMenu.Item.OpenInFenix -> {
|
|
|
|
val intent = Intent(context, IntentReceiverActivity::class.java)
|
|
|
|
intent.action = Intent.ACTION_VIEW
|
2019-04-25 22:00:09 +02:00
|
|
|
intent.data = Uri.parse(getSessionById()?.url)
|
2019-03-13 17:47:23 +01:00
|
|
|
startActivity(intent)
|
|
|
|
}
|
2019-02-07 23:50:55 +01:00
|
|
|
}
|
2019-02-05 00:41:26 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 17:53:40 +02:00
|
|
|
private fun showSaveToCollection() {
|
|
|
|
getSessionById()?.let {
|
2019-05-06 20:20:19 +02:00
|
|
|
val tabs = Tab(it.id, it.url, it.url.urlToTrimmedHost(), it.title)
|
2019-05-02 17:53:40 +02:00
|
|
|
val viewModel = activity?.run {
|
|
|
|
ViewModelProviders.of(this).get(CreateCollectionViewModel::class.java)
|
|
|
|
}
|
|
|
|
viewModel?.tabs = listOf(tabs)
|
|
|
|
val selectedSet = setOf(tabs)
|
|
|
|
viewModel?.selectedTabs = selectedSet
|
|
|
|
viewModel?.saveCollectionStep = SaveCollectionStep.SelectCollection
|
2019-05-11 01:42:41 +02:00
|
|
|
view?.let {
|
|
|
|
val directions = BrowserFragmentDirections.actionBrowserFragmentToCreateCollectionFragment()
|
|
|
|
Navigation.findNavController(it).navigate(directions)
|
|
|
|
}
|
2019-05-02 17:53:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-28 19:29:03 +01:00
|
|
|
private fun assignSitePermissionsRules() {
|
|
|
|
val settings = Settings.getInstance(requireContext())
|
|
|
|
|
2019-04-07 23:21:19 +02:00
|
|
|
val rules: SitePermissionsRules = settings.getSitePermissionsCustomSettingsRules()
|
|
|
|
|
2019-03-28 19:29:03 +01:00
|
|
|
sitePermissionsFeature.withFeature {
|
|
|
|
it.sitePermissionsRules = rules
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-08 02:24:22 +02:00
|
|
|
private fun showQuickSettingsDialog() {
|
2019-04-25 22:00:09 +02:00
|
|
|
val session = requireNotNull(getSessionById())
|
2019-04-08 02:24:22 +02:00
|
|
|
launch {
|
2019-05-14 22:02:44 +02:00
|
|
|
val host = session.url.toUri()?.host
|
|
|
|
val sitePermissions: SitePermissions? = host?.let {
|
2019-05-16 23:02:24 +02:00
|
|
|
val storage = requireContext().components.core.permissionStorage
|
2019-05-14 22:02:44 +02:00
|
|
|
storage.findSitePermissionsBy(it)
|
|
|
|
}
|
2019-04-08 02:24:22 +02:00
|
|
|
|
|
|
|
launch(Main) {
|
2019-05-11 01:42:41 +02:00
|
|
|
view?.let {
|
|
|
|
val directions = BrowserFragmentDirections.actionBrowserFragmentToQuickSettingsSheetDialogFragment(
|
2019-05-14 22:02:44 +02:00
|
|
|
sessionId = session.id,
|
2019-05-11 01:42:41 +02:00
|
|
|
url = session.url,
|
|
|
|
isSecured = session.securityInfo.secure,
|
|
|
|
isTrackingProtectionOn = session.trackerBlockingEnabled,
|
|
|
|
sitePermissions = sitePermissions,
|
|
|
|
gravity = getAppropriateLayoutGravity()
|
|
|
|
)
|
|
|
|
Navigation.findNavController(it).navigate(directions)
|
|
|
|
}
|
2019-04-08 02:24:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-25 22:00:09 +02:00
|
|
|
private fun getSessionById(): Session? {
|
2019-04-29 17:30:32 +02:00
|
|
|
return if (customTabSessionId != null) {
|
2019-04-23 20:32:48 +02:00
|
|
|
requireNotNull(
|
|
|
|
requireContext().components.core.sessionManager.findSessionById(
|
2019-04-29 17:30:32 +02:00
|
|
|
customTabSessionId!!
|
2019-04-23 20:32:48 +02:00
|
|
|
)
|
|
|
|
)
|
2019-04-04 16:50:16 +02:00
|
|
|
} else {
|
2019-04-25 22:00:09 +02:00
|
|
|
requireComponents.core.sessionManager.selectedSession
|
2019-04-04 16:50:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-09 23:15:18 +02:00
|
|
|
private fun Session.copyUrl(context: Context) {
|
|
|
|
val clipBoard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
2019-04-20 23:15:37 +02:00
|
|
|
clipBoard.primaryClip = ClipData.newPlainText(url, url)
|
2019-04-09 23:15:18 +02:00
|
|
|
}
|
|
|
|
|
2019-04-12 20:09:07 +02:00
|
|
|
private fun subscribeToSession(): Session.Observer {
|
|
|
|
val observer = object : Session.Observer {
|
|
|
|
override fun onLoadingStateChanged(session: Session, loading: Boolean) {
|
2019-04-23 20:32:48 +02:00
|
|
|
if (!loading) {
|
2019-05-06 23:38:32 +02:00
|
|
|
updateBookmarkState(session)
|
2019-05-14 17:14:41 +02:00
|
|
|
getManagedEmitter<QuickActionChange>().onNext(QuickActionChange.BounceNeededChange)
|
2019-04-23 20:32:48 +02:00
|
|
|
}
|
2019-05-14 17:14:41 +02:00
|
|
|
|
2019-04-12 20:09:07 +02:00
|
|
|
setToolbarBehavior(loading)
|
2019-05-14 17:14:41 +02:00
|
|
|
super.onLoadingStateChanged(session, loading)
|
2019-04-12 20:09:07 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-29 21:32:30 +02:00
|
|
|
getSessionById()?.register(observer)
|
2019-04-12 20:09:07 +02:00
|
|
|
return observer
|
|
|
|
}
|
|
|
|
|
2019-05-01 03:04:16 +02:00
|
|
|
private fun subscribeToSessions(): SessionManager.Observer {
|
|
|
|
return object : SessionManager.Observer {
|
|
|
|
override fun onSessionSelected(session: Session) {
|
|
|
|
super.onSessionSelected(session)
|
|
|
|
(activity as HomeActivity).updateThemeForSession(session)
|
|
|
|
}
|
|
|
|
}.also { requireComponents.core.sessionManager.register(it) }
|
|
|
|
}
|
|
|
|
|
2019-04-25 21:49:56 +02:00
|
|
|
private fun updateToolbar() {
|
|
|
|
getSessionById()?.loading?.let {
|
|
|
|
setToolbarBehavior(it)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-06 23:38:32 +02:00
|
|
|
private fun findBookmarkedURL(session: Session?): Boolean {
|
|
|
|
session?.let {
|
|
|
|
return runBlocking {
|
|
|
|
val list = requireComponents.core.bookmarksStorage.getBookmarksWithUrl(it.url)
|
|
|
|
list.isNotEmpty() && list[0].url == it.url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun updateBookmarkState(session: Session) {
|
2019-04-23 20:32:48 +02:00
|
|
|
launch {
|
2019-05-06 23:38:32 +02:00
|
|
|
val found = findBookmarkedURL(session)
|
2019-04-23 20:32:48 +02:00
|
|
|
launch(Main) {
|
|
|
|
getManagedEmitter<QuickActionChange>()
|
|
|
|
.onNext(QuickActionChange.BookmarkedStateChange(found))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 20:09:07 +02:00
|
|
|
private fun setToolbarBehavior(loading: Boolean) {
|
|
|
|
val toolbarView = toolbarComponent.uiView.view
|
|
|
|
(toolbarView.layoutParams as CoordinatorLayout.LayoutParams).apply {
|
|
|
|
// Stop toolbar from collapsing if TalkBack is enabled or page is loading
|
|
|
|
val accessibilityManager = context
|
2019-04-25 22:54:10 +02:00
|
|
|
?.getSystemService(Context.ACCESSIBILITY_SERVICE) as? AccessibilityManager
|
2019-05-15 18:37:05 +02:00
|
|
|
|
|
|
|
behavior = when {
|
|
|
|
loading || accessibilityManager?.isTouchExplorationEnabled == true -> {
|
|
|
|
(behavior as? BrowserToolbarBottomBehavior)?.forceExpand(toolbarView)
|
|
|
|
(behavior as? BrowserToolbarTopBehavior)?.forceExpand(toolbarView)
|
|
|
|
null
|
|
|
|
}
|
|
|
|
customTabSessionId != null -> {
|
|
|
|
BrowserToolbarTopBehavior(context, null)
|
|
|
|
}
|
|
|
|
else -> {
|
|
|
|
BrowserToolbarBottomBehavior(context, null)
|
|
|
|
}
|
2019-04-12 20:09:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-04-23 20:32:48 +02:00
|
|
|
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
|
|
|
}
|