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
|
2019-05-31 01:21:52 +02:00
|
|
|
import android.view.View
|
2019-11-29 00:39:33 +01:00
|
|
|
import android.view.ViewGroup.MarginLayoutParams
|
2019-09-16 22:52:06 +02:00
|
|
|
import androidx.appcompat.content.res.AppCompatResources
|
2019-09-10 22:29:21 +02:00
|
|
|
import com.airbnb.lottie.LottieCompositionFactory
|
|
|
|
import com.airbnb.lottie.LottieDrawable
|
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
|
|
|
|
import org.mozilla.fenix.theme.ThemeManager
|
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-05-31 01:21:52 +02:00
|
|
|
engineLayout: View,
|
2019-12-06 19:57:54 +01:00
|
|
|
onItemTapped: (ToolbarMenu.Item) -> Unit = {},
|
|
|
|
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
|
|
|
|
|
|
|
// Reduce margin height of EngineView from the top for the toolbar
|
|
|
|
engineLayout.run {
|
2019-11-29 00:39:33 +01:00
|
|
|
(layoutParams as MarginLayoutParams).apply {
|
2019-05-31 01:21:52 +02:00
|
|
|
val toolbarHeight = resources.getDimension(R.dimen.browser_toolbar_height).toInt()
|
|
|
|
setMargins(0, toolbarHeight, 0, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 22:29:21 +02:00
|
|
|
val task = LottieCompositionFactory
|
|
|
|
.fromRawRes(
|
2019-09-20 19:28:49 +02:00
|
|
|
activity,
|
|
|
|
ThemeManager.resolveAttribute(R.attr.shieldLottieFile, activity)
|
2019-09-10 22:29:21 +02:00
|
|
|
)
|
|
|
|
task.addListener { result ->
|
|
|
|
val lottieDrawable = LottieDrawable()
|
|
|
|
lottieDrawable.composition = result
|
|
|
|
|
2019-10-15 17:54:04 +02:00
|
|
|
toolbar.display.displayIndicatorSeparator = false
|
2019-11-06 01:10:13 +01:00
|
|
|
if (activity.settings().shouldUseTrackingProtection) {
|
2019-10-15 17:54:04 +02:00
|
|
|
toolbar.display.indicators = listOf(
|
|
|
|
DisplayToolbar.Indicators.SECURITY,
|
|
|
|
DisplayToolbar.Indicators.TRACKING_PROTECTION
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
toolbar.display.indicators = listOf(
|
|
|
|
DisplayToolbar.Indicators.SECURITY
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
toolbar.display.icons = toolbar.display.icons.copy(
|
|
|
|
trackingProtectionTrackersBlocked = lottieDrawable,
|
|
|
|
trackingProtectionNothingBlocked = AppCompatResources.getDrawable(
|
2019-09-20 19:28:49 +02:00
|
|
|
activity,
|
2019-09-16 22:52:06 +02:00
|
|
|
R.drawable.ic_tracking_protection_enabled
|
|
|
|
)!!,
|
2019-10-15 17:54:04 +02:00
|
|
|
trackingProtectionException = AppCompatResources.getDrawable(
|
2019-09-20 19:28:49 +02:00
|
|
|
activity,
|
2019-09-16 22:52:06 +02:00
|
|
|
R.drawable.ic_tracking_protection_disabled
|
|
|
|
)!!
|
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) {
|
|
|
|
toolbar.background = AppCompatResources.getDrawable(
|
|
|
|
activity,
|
|
|
|
R.drawable.toolbar_background
|
|
|
|
)
|
|
|
|
}
|
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-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,
|
|
|
|
closeListener = { activity.finish() }
|
2019-08-20 19:13:01 +02:00
|
|
|
)
|
2019-03-15 18:51:04 +01:00
|
|
|
|
|
|
|
override fun start() {
|
|
|
|
feature.start()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun stop() {
|
|
|
|
feature.stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBackPressed(): Boolean {
|
|
|
|
return feature.onBackPressed()
|
|
|
|
}
|
2019-04-26 22:54:38 +02:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
const val START_OF_MENU_ITEMS_INDEX = 2
|
|
|
|
}
|
2019-03-15 18:51:04 +01:00
|
|
|
}
|