2019-01-24 22:07:52 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +02:00
|
|
|
* 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-24 22:07:52 +01:00
|
|
|
|
2019-02-13 00:51:30 +01:00
|
|
|
package org.mozilla.fenix.components.toolbar
|
2019-01-23 22:39:53 +01:00
|
|
|
|
|
|
|
import android.content.Context
|
2019-09-16 22:52:06 +02:00
|
|
|
import androidx.appcompat.content.res.AppCompatResources
|
2020-07-24 03:20:06 +02:00
|
|
|
import androidx.lifecycle.LifecycleOwner
|
2019-09-10 22:29:21 +02:00
|
|
|
import com.airbnb.lottie.LottieCompositionFactory
|
|
|
|
import com.airbnb.lottie.LottieDrawable
|
2019-01-23 22:39:53 +01:00
|
|
|
import mozilla.components.browser.domains.autocomplete.DomainAutocompleteProvider
|
|
|
|
import mozilla.components.browser.toolbar.BrowserToolbar
|
2019-10-15 17:54:04 +02:00
|
|
|
import mozilla.components.browser.toolbar.display.DisplayToolbar
|
2020-03-02 22:21:56 +01:00
|
|
|
import mozilla.components.concept.engine.Engine
|
2019-01-29 21:04:57 +01:00
|
|
|
import mozilla.components.concept.storage.HistoryStorage
|
2019-01-23 22:39:53 +01:00
|
|
|
import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature
|
2019-04-01 17:47:25 +02:00
|
|
|
import mozilla.components.feature.toolbar.ToolbarFeature
|
2019-02-20 22:08:06 +01:00
|
|
|
import mozilla.components.feature.toolbar.ToolbarPresenter
|
2019-04-01 17:47:25 +02:00
|
|
|
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
|
2019-02-08 13:50:22 +01:00
|
|
|
import mozilla.components.support.base.feature.LifecycleAwareFeature
|
2019-05-02 22:08:55 +02:00
|
|
|
import mozilla.components.support.ktx.android.view.hideKeyboard
|
2019-04-01 17:47:25 +02:00
|
|
|
import org.mozilla.fenix.R
|
2019-01-23 22:39:53 +01:00
|
|
|
import org.mozilla.fenix.ext.components
|
2019-09-10 19:11:58 +02:00
|
|
|
import org.mozilla.fenix.ext.settings
|
2019-09-05 23:45:44 +02:00
|
|
|
import org.mozilla.fenix.theme.ThemeManager
|
2019-01-23 22:39:53 +01:00
|
|
|
|
2019-12-17 21:26:46 +01:00
|
|
|
abstract class ToolbarIntegration(
|
2019-01-23 22:39:53 +01:00
|
|
|
context: Context,
|
|
|
|
toolbar: BrowserToolbar,
|
2019-02-07 23:50:55 +01:00
|
|
|
toolbarMenu: ToolbarMenu,
|
2019-12-17 21:26:46 +01:00
|
|
|
sessionId: String?,
|
2019-10-08 01:49:47 +02:00
|
|
|
isPrivate: Boolean,
|
2019-12-17 21:26:46 +01:00
|
|
|
renderStyle: ToolbarFeature.RenderStyle
|
2019-02-08 13:50:22 +01:00
|
|
|
) : LifecycleAwareFeature {
|
2019-04-01 17:47:25 +02:00
|
|
|
|
2019-02-20 22:08:06 +01:00
|
|
|
private val toolbarPresenter: ToolbarPresenter = ToolbarPresenter(
|
2019-01-23 22:39:53 +01:00
|
|
|
toolbar,
|
2019-09-04 12:21:42 +02:00
|
|
|
context.components.core.store,
|
2019-04-01 17:47:25 +02:00
|
|
|
sessionId,
|
2019-05-22 20:46:31 +02:00
|
|
|
ToolbarFeature.UrlRenderConfiguration(
|
|
|
|
PublicSuffixList(context),
|
2019-12-17 21:26:46 +01:00
|
|
|
ThemeManager.resolveAttribute(R.attr.primaryText, context),
|
|
|
|
renderStyle = renderStyle
|
2019-05-22 20:46:31 +02:00
|
|
|
)
|
2019-01-23 22:39:53 +01:00
|
|
|
)
|
2019-10-15 17:54:04 +02:00
|
|
|
|
2020-04-06 23:18:41 +02:00
|
|
|
private val menuPresenter =
|
2019-08-08 00:41:52 +02:00
|
|
|
MenuPresenter(toolbar, context.components.core.sessionManager, sessionId)
|
2019-01-23 22:39:53 +01:00
|
|
|
|
2019-12-17 21:26:46 +01:00
|
|
|
init {
|
|
|
|
toolbar.display.menuBuilder = toolbarMenu.menuBuilder
|
|
|
|
toolbar.private = isPrivate
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:50:22 +01:00
|
|
|
override fun start() {
|
2019-05-23 19:46:23 +02:00
|
|
|
menuPresenter.start()
|
2019-02-20 22:08:06 +01:00
|
|
|
toolbarPresenter.start()
|
2019-01-23 22:39:53 +01:00
|
|
|
}
|
|
|
|
|
2019-02-08 13:50:22 +01:00
|
|
|
override fun stop() {
|
2019-05-23 19:46:23 +02:00
|
|
|
menuPresenter.stop()
|
2019-02-20 22:08:06 +01:00
|
|
|
toolbarPresenter.stop()
|
2019-01-23 22:39:53 +01:00
|
|
|
}
|
2020-04-06 23:18:41 +02:00
|
|
|
|
|
|
|
fun invalidateMenu() {
|
|
|
|
menuPresenter.invalidateActions()
|
|
|
|
}
|
2019-01-23 22:39:53 +01:00
|
|
|
}
|
2019-12-17 21:26:46 +01:00
|
|
|
|
2020-07-24 03:20:06 +02:00
|
|
|
@Suppress("LongParameterList")
|
2019-12-17 21:26:46 +01:00
|
|
|
class DefaultToolbarIntegration(
|
|
|
|
context: Context,
|
|
|
|
toolbar: BrowserToolbar,
|
|
|
|
toolbarMenu: ToolbarMenu,
|
|
|
|
domainAutocompleteProvider: DomainAutocompleteProvider,
|
|
|
|
historyStorage: HistoryStorage,
|
2020-07-24 03:20:06 +02:00
|
|
|
lifecycleOwner: LifecycleOwner,
|
2019-12-17 21:26:46 +01:00
|
|
|
sessionId: String? = null,
|
|
|
|
isPrivate: Boolean,
|
2020-03-02 22:21:56 +01:00
|
|
|
interactor: BrowserToolbarViewInteractor,
|
|
|
|
engine: Engine
|
2019-12-17 21:26:46 +01:00
|
|
|
) : ToolbarIntegration(
|
|
|
|
context = context,
|
|
|
|
toolbar = toolbar,
|
|
|
|
toolbarMenu = toolbarMenu,
|
|
|
|
sessionId = sessionId,
|
|
|
|
isPrivate = isPrivate,
|
|
|
|
renderStyle = ToolbarFeature.RenderStyle.UncoloredUrl
|
|
|
|
) {
|
|
|
|
|
|
|
|
init {
|
|
|
|
toolbar.display.menuBuilder = toolbarMenu.menuBuilder
|
|
|
|
toolbar.private = isPrivate
|
|
|
|
|
|
|
|
val task = LottieCompositionFactory
|
|
|
|
.fromRawRes(
|
|
|
|
context,
|
|
|
|
ThemeManager.resolveAttribute(R.attr.shieldLottieFile, context)
|
|
|
|
)
|
|
|
|
task.addListener { result ->
|
|
|
|
val lottieDrawable = LottieDrawable()
|
|
|
|
lottieDrawable.composition = result
|
|
|
|
|
|
|
|
toolbar.display.indicators =
|
|
|
|
if (context.settings().shouldUseTrackingProtection) {
|
|
|
|
listOf(
|
|
|
|
DisplayToolbar.Indicators.TRACKING_PROTECTION,
|
|
|
|
DisplayToolbar.Indicators.SECURITY,
|
|
|
|
DisplayToolbar.Indicators.EMPTY
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
listOf(
|
|
|
|
DisplayToolbar.Indicators.SECURITY,
|
|
|
|
DisplayToolbar.Indicators.EMPTY
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
toolbar.display.displayIndicatorSeparator =
|
|
|
|
context.settings().shouldUseTrackingProtection
|
|
|
|
|
|
|
|
toolbar.display.icons = toolbar.display.icons.copy(
|
2020-03-17 15:05:41 +01:00
|
|
|
emptyIcon = null,
|
2019-12-17 21:26:46 +01:00
|
|
|
trackingProtectionTrackersBlocked = lottieDrawable,
|
|
|
|
trackingProtectionNothingBlocked = AppCompatResources.getDrawable(
|
|
|
|
context,
|
|
|
|
R.drawable.ic_tracking_protection_enabled
|
|
|
|
)!!,
|
|
|
|
trackingProtectionException = AppCompatResources.getDrawable(
|
|
|
|
context,
|
|
|
|
R.drawable.ic_tracking_protection_disabled
|
|
|
|
)!!
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-06-11 00:34:26 +02:00
|
|
|
val onTabCounterMenuItemTapped = { item: TabCounterMenuItem ->
|
|
|
|
interactor.onTabCounterMenuItemTapped(item)
|
|
|
|
}
|
2020-07-24 03:20:06 +02:00
|
|
|
val tabsAction =
|
|
|
|
TabCounterToolbarButton(lifecycleOwner, isPrivate, onTabCounterMenuItemTapped) {
|
|
|
|
toolbar.hideKeyboard()
|
|
|
|
interactor.onTabCounterClicked()
|
|
|
|
}
|
2019-12-17 21:26:46 +01:00
|
|
|
toolbar.addBrowserAction(tabsAction)
|
|
|
|
|
2020-03-02 22:21:56 +01:00
|
|
|
val engineForSpeculativeConnects = if (!isPrivate) engine else null
|
|
|
|
ToolbarAutocompleteFeature(
|
|
|
|
toolbar,
|
|
|
|
engineForSpeculativeConnects
|
|
|
|
).apply {
|
2019-12-17 21:26:46 +01:00
|
|
|
addDomainProvider(domainAutocompleteProvider)
|
|
|
|
if (context.settings().shouldShowHistorySuggestions) {
|
|
|
|
addHistoryStorageProvider(historyStorage)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|