2019-03-15 18:51:04 +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/. */
|
|
|
|
|
|
|
|
package org.mozilla.fenix.customtabs
|
|
|
|
|
|
|
|
import android.app.Activity
|
2020-06-24 18:58:30 +02:00
|
|
|
import androidx.appcompat.content.res.AppCompatResources.getDrawable
|
2019-03-15 18:51:04 +01:00
|
|
|
import mozilla.components.browser.session.SessionManager
|
|
|
|
import mozilla.components.browser.toolbar.BrowserToolbar
|
2019-10-15 17:54:04 +02:00
|
|
|
import mozilla.components.browser.toolbar.display.DisplayToolbar
|
2019-03-15 18:51:04 +01:00
|
|
|
import mozilla.components.feature.customtabs.CustomTabsToolbarFeature
|
|
|
|
import mozilla.components.support.base.feature.LifecycleAwareFeature
|
2019-11-29 00:39:33 +01:00
|
|
|
import mozilla.components.support.base.feature.UserInteractionHandler
|
2019-05-31 01:21:52 +02:00
|
|
|
import org.mozilla.fenix.R
|
2019-03-15 18:51:04 +01:00
|
|
|
import org.mozilla.fenix.components.toolbar.ToolbarMenu
|
2019-09-10 22:29:21 +02:00
|
|
|
import org.mozilla.fenix.ext.settings
|
2019-03-15 18:51:04 +01:00
|
|
|
|
|
|
|
class CustomTabsIntegration(
|
|
|
|
sessionManager: SessionManager,
|
2019-05-31 01:21:52 +02:00
|
|
|
toolbar: BrowserToolbar,
|
2019-03-15 18:51:04 +01:00
|
|
|
sessionId: String,
|
2019-09-20 19:28:49 +02:00
|
|
|
activity: Activity,
|
2019-12-06 19:57:54 +01:00
|
|
|
onItemTapped: (ToolbarMenu.Item) -> Unit = {},
|
2019-12-30 13:11:24 +01:00
|
|
|
shouldReverseItems: Boolean,
|
2019-12-06 19:57:54 +01:00
|
|
|
isPrivate: Boolean
|
2019-11-28 00:02:47 +01:00
|
|
|
) : LifecycleAwareFeature, UserInteractionHandler {
|
2019-03-15 18:51:04 +01:00
|
|
|
|
2019-05-14 23:32:28 +02:00
|
|
|
init {
|
2019-05-31 01:21:52 +02:00
|
|
|
// Remove toolbar shadow
|
2019-05-15 18:37:05 +02:00
|
|
|
toolbar.elevation = 0f
|
2019-05-31 01:21:52 +02:00
|
|
|
|
2020-06-24 18:58:30 +02:00
|
|
|
val uncoloredEtpShield = getDrawable(activity, R.drawable.ic_tracking_protection_enabled)!!
|
2019-09-10 22:29:21 +02:00
|
|
|
|
2019-12-06 20:28:52 +01:00
|
|
|
toolbar.display.icons = toolbar.display.icons.copy(
|
|
|
|
// Custom private tab backgrounds have bad contrast against the colored shield
|
|
|
|
trackingProtectionTrackersBlocked = uncoloredEtpShield,
|
|
|
|
trackingProtectionNothingBlocked = uncoloredEtpShield,
|
2020-06-24 18:58:30 +02:00
|
|
|
trackingProtectionException = getDrawable(
|
2019-12-06 20:28:52 +01:00
|
|
|
activity,
|
|
|
|
R.drawable.ic_tracking_protection_disabled
|
|
|
|
)!!
|
|
|
|
)
|
2019-10-15 17:54:04 +02:00
|
|
|
|
2019-12-06 20:28:52 +01:00
|
|
|
toolbar.display.displayIndicatorSeparator = false
|
|
|
|
if (activity.settings().shouldUseTrackingProtection) {
|
|
|
|
toolbar.display.indicators = listOf(
|
|
|
|
DisplayToolbar.Indicators.SECURITY,
|
|
|
|
DisplayToolbar.Indicators.TRACKING_PROTECTION
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
toolbar.display.indicators = listOf(
|
|
|
|
DisplayToolbar.Indicators.SECURITY
|
2019-09-10 22:29:21 +02:00
|
|
|
)
|
|
|
|
}
|
2019-12-06 19:57:54 +01:00
|
|
|
|
|
|
|
// If in private mode, override toolbar background to use private color
|
|
|
|
// See #5334
|
|
|
|
if (isPrivate) {
|
2019-12-20 03:17:52 +01:00
|
|
|
sessionManager.findSessionById(sessionId)?.apply {
|
2020-02-06 18:49:01 +01:00
|
|
|
val config = customTabConfig
|
|
|
|
customTabConfig = config?.copy(
|
|
|
|
// Don't set toolbar background automatically
|
|
|
|
toolbarColor = null,
|
|
|
|
// Force tinting the action button
|
|
|
|
actionButtonConfig = config.actionButtonConfig?.copy(tint = true)
|
|
|
|
)
|
2019-12-20 03:17:52 +01:00
|
|
|
}
|
|
|
|
|
2020-06-25 18:54:15 +02:00
|
|
|
toolbar.background = getDrawable(activity, R.drawable.toolbar_background)
|
2019-12-06 19:57:54 +01:00
|
|
|
}
|
2019-05-14 23:32:28 +02:00
|
|
|
}
|
|
|
|
|
2019-04-01 17:47:25 +02:00
|
|
|
private val customTabToolbarMenu by lazy {
|
2019-04-23 21:50:17 +02:00
|
|
|
CustomTabToolbarMenu(
|
2019-09-20 19:28:49 +02:00
|
|
|
activity,
|
2019-05-02 21:32:04 +02:00
|
|
|
sessionManager,
|
|
|
|
sessionId,
|
2019-12-30 13:11:24 +01:00
|
|
|
shouldReverseItems,
|
2019-04-01 17:47:25 +02:00
|
|
|
onItemTapped = onItemTapped
|
2019-03-15 18:51:04 +01:00
|
|
|
)
|
|
|
|
}
|
2019-04-01 17:47:25 +02:00
|
|
|
|
2019-03-15 18:51:04 +01:00
|
|
|
private val feature = CustomTabsToolbarFeature(
|
|
|
|
sessionManager,
|
|
|
|
toolbar,
|
|
|
|
sessionId,
|
2019-08-20 19:13:01 +02:00
|
|
|
menuBuilder = customTabToolbarMenu.menuBuilder,
|
|
|
|
menuItemIndex = START_OF_MENU_ITEMS_INDEX,
|
2019-09-20 19:28:49 +02:00
|
|
|
window = activity.window,
|
2020-01-11 07:55:08 +01:00
|
|
|
shareListener = { onItemTapped.invoke(ToolbarMenu.Item.Share) },
|
2019-09-20 19:28:49 +02:00
|
|
|
closeListener = { activity.finish() }
|
2019-08-20 19:13:01 +02:00
|
|
|
)
|
2019-03-15 18:51:04 +01:00
|
|
|
|
2020-01-11 07:55:08 +01:00
|
|
|
override fun start() = feature.start()
|
|
|
|
override fun stop() = feature.stop()
|
|
|
|
override fun onBackPressed() = feature.onBackPressed()
|
2019-04-26 22:54:38 +02:00
|
|
|
|
|
|
|
companion object {
|
2020-01-11 07:55:08 +01:00
|
|
|
private const val START_OF_MENU_ITEMS_INDEX = 2
|
2019-04-26 22:54:38 +02:00
|
|
|
}
|
2019-03-15 18:51:04 +01:00
|
|
|
}
|