|
|
|
@ -9,11 +9,12 @@ import android.util.AttributeSet
|
|
|
|
|
import android.view.Gravity
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.widget.FrameLayout
|
|
|
|
|
import androidx.appcompat.content.res.AppCompatResources
|
|
|
|
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|
|
|
|
import androidx.core.view.doOnNextLayout
|
|
|
|
|
import androidx.core.view.isVisible
|
|
|
|
|
import androidx.core.view.updateLayoutParams
|
|
|
|
|
import mozilla.components.browser.menu.view.MenuButton
|
|
|
|
|
import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
|
|
|
|
|
import mozilla.components.browser.state.selector.selectedTab
|
|
|
|
|
import mozilla.components.browser.thumbnails.loader.ThumbnailLoader
|
|
|
|
@ -21,23 +22,30 @@ import mozilla.components.concept.base.images.ImageLoadRequest
|
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
|
import org.mozilla.fenix.components.toolbar.IncompleteRedesignToolbarFeature
|
|
|
|
|
import org.mozilla.fenix.components.toolbar.ToolbarPosition
|
|
|
|
|
import org.mozilla.fenix.components.toolbar.navbar.BottomToolbarContainerView
|
|
|
|
|
import org.mozilla.fenix.databinding.TabPreviewBinding
|
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
|
import org.mozilla.fenix.ext.settings
|
|
|
|
|
import org.mozilla.fenix.theme.ThemeManager
|
|
|
|
|
import kotlin.math.min
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A 'dummy' view of a tab used by [ToolbarGestureHandler] to support switching tabs by swiping the address bar.
|
|
|
|
|
*
|
|
|
|
|
* The view is responsible for showing the preview and a dummy toolbar of the inactive tab during swiping.
|
|
|
|
|
*/
|
|
|
|
|
class TabPreview @JvmOverloads constructor(
|
|
|
|
|
context: Context,
|
|
|
|
|
attrs: AttributeSet? = null,
|
|
|
|
|
defStyle: Int = 0,
|
|
|
|
|
) : FrameLayout(context, attrs, defStyle) {
|
|
|
|
|
) : CoordinatorLayout(context, attrs, defStyle) {
|
|
|
|
|
|
|
|
|
|
private val binding = TabPreviewBinding.inflate(LayoutInflater.from(context), this)
|
|
|
|
|
private val thumbnailLoader = ThumbnailLoader(context.components.core.thumbnailStorage)
|
|
|
|
|
|
|
|
|
|
init {
|
|
|
|
|
if (context.settings().toolbarPosition == ToolbarPosition.TOP) {
|
|
|
|
|
val isToolbarAtTop = context.settings().toolbarPosition == ToolbarPosition.TOP
|
|
|
|
|
if (isToolbarAtTop) {
|
|
|
|
|
binding.fakeToolbar.updateLayoutParams<LayoutParams> {
|
|
|
|
|
gravity = Gravity.TOP
|
|
|
|
|
}
|
|
|
|
@ -52,6 +60,16 @@ class TabPreview @JvmOverloads constructor(
|
|
|
|
|
binding.tabButton.isVisible = !isNavBarEnabled
|
|
|
|
|
binding.menuButton.isVisible = !isNavBarEnabled
|
|
|
|
|
|
|
|
|
|
if (isNavBarEnabled) {
|
|
|
|
|
BottomToolbarContainerView(
|
|
|
|
|
context = context,
|
|
|
|
|
parent = this,
|
|
|
|
|
androidToolbarView = if (!isToolbarAtTop) binding.fakeToolbar else null,
|
|
|
|
|
menuButton = MenuButton(context),
|
|
|
|
|
)
|
|
|
|
|
removeView(binding.fakeToolbar)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Change view properties to avoid confusing the UI tests
|
|
|
|
|
binding.tabButton.findViewById<View>(R.id.counter_box).id = View.NO_ID
|
|
|
|
|
binding.tabButton.findViewById<View>(R.id.counter_text).id = View.NO_ID
|
|
|
|
|