[fenix] For https://github.com/mozilla-mobile/fenix/issues/26777 - Part 2: Refactor the Jump Back In onboarding CFR to use the CFRPopup
parent
13e8bf7c45
commit
4a46d19da0
@ -1,118 +0,0 @@
|
|||||||
/* 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.onboarding
|
|
||||||
|
|
||||||
import android.app.Dialog
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.Color
|
|
||||||
import android.graphics.drawable.ColorDrawable
|
|
||||||
import android.view.Gravity
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import mozilla.telemetry.glean.private.NoExtras
|
|
||||||
import org.mozilla.fenix.GleanMetrics.RecentTabs
|
|
||||||
import org.mozilla.fenix.databinding.OnboardingJumpBackInCfrBinding
|
|
||||||
import org.mozilla.fenix.ext.settings
|
|
||||||
import org.mozilla.fenix.home.recentsyncedtabs.view.RecentSyncedTabViewHolder
|
|
||||||
import org.mozilla.fenix.home.recenttabs.view.RecentTabsHeaderViewHolder
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dialog displayed once when the jump back in section is shown in the home screen.
|
|
||||||
*/
|
|
||||||
class JumpBackInCFRDialog(val recyclerView: RecyclerView) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Try to show the crf dialog if it hasn't been shown before.
|
|
||||||
*/
|
|
||||||
fun showIfNeeded() {
|
|
||||||
val jumpBackInView = findJumpBackInView()
|
|
||||||
jumpBackInView?.let {
|
|
||||||
val crfDialog = createJumpCRF(anchor = jumpBackInView)
|
|
||||||
crfDialog?.let {
|
|
||||||
RecentTabs.jumpBackInCfrShown.record(NoExtras())
|
|
||||||
|
|
||||||
val context = jumpBackInView.context
|
|
||||||
context.settings().shouldShowJumpBackInCFR = false
|
|
||||||
it.show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun findJumpBackInView(): View? {
|
|
||||||
val count = recyclerView.adapter?.itemCount ?: return null
|
|
||||||
|
|
||||||
for (index in 0..count) {
|
|
||||||
val viewHolder = recyclerView.findViewHolderForAdapterPosition(index)
|
|
||||||
if (viewHolder is RecentTabsHeaderViewHolder) {
|
|
||||||
return viewHolder.composeView
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun hasSyncTabsView(): Boolean {
|
|
||||||
val count = recyclerView.adapter?.itemCount ?: return false
|
|
||||||
|
|
||||||
for (index in count downTo 0) {
|
|
||||||
val viewHolder = recyclerView.findViewHolderForAdapterPosition(index)
|
|
||||||
if (viewHolder is RecentSyncedTabViewHolder) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createJumpCRF(anchor: View): Dialog? {
|
|
||||||
val context: Context = recyclerView.context
|
|
||||||
|
|
||||||
if (context.settings().showSyncCFR && hasSyncTabsView()) {
|
|
||||||
context.settings().shouldShowJumpBackInCFR = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!context.settings().shouldShowJumpBackInCFR) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
val anchorPosition = IntArray(2)
|
|
||||||
val popupBinding = OnboardingJumpBackInCfrBinding.inflate(LayoutInflater.from(context))
|
|
||||||
val popup = Dialog(context)
|
|
||||||
|
|
||||||
popup.apply {
|
|
||||||
setContentView(popupBinding.root)
|
|
||||||
setCanceledOnTouchOutside(true)
|
|
||||||
setOnCancelListener {
|
|
||||||
RecentTabs.jumpBackInCfrCancelled.record(NoExtras())
|
|
||||||
}
|
|
||||||
// removing title or setting it as an empty string does not prevent a11y services from assigning one
|
|
||||||
setTitle(" ")
|
|
||||||
}
|
|
||||||
popupBinding.closeInfoBanner.setOnClickListener {
|
|
||||||
RecentTabs.jumpBackInCfrDismissed.record(NoExtras())
|
|
||||||
popup.dismiss()
|
|
||||||
}
|
|
||||||
|
|
||||||
anchor.getLocationOnScreen(anchorPosition)
|
|
||||||
val (x, y) = anchorPosition
|
|
||||||
|
|
||||||
if (x == 0 && y == 0) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
popupBinding.root.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
|
|
||||||
|
|
||||||
popup.window?.apply {
|
|
||||||
val attr = attributes
|
|
||||||
setGravity(Gravity.START or Gravity.TOP)
|
|
||||||
attr.x = x
|
|
||||||
attr.y = y - popupBinding.root.measuredHeight
|
|
||||||
attributes = attr
|
|
||||||
setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
|
||||||
setDimAmount(0f)
|
|
||||||
}
|
|
||||||
return popup
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- 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/. -->
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:paddingStart="12dp"
|
|
||||||
android:paddingEnd="12dp"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:id="@+id/banner_container"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="@drawable/onboarding_popup_shape">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/banner_info_message"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:layout_marginEnd="8dp"
|
|
||||||
android:layout_marginBottom="16dp"
|
|
||||||
android:maxWidth="279dp"
|
|
||||||
android:text="@string/onboarding_home_screen_jump_back_contextual_hint_2"
|
|
||||||
android:textAppearance="@style/Body16TextStyle"
|
|
||||||
android:textColor="@color/fx_mobile_private_text_color_primary"
|
|
||||||
android:textSize="16sp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toStartOf="@+id/close_info_banner"
|
|
||||||
app:layout_constraintHorizontal_bias="1.0"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:layout_constraintVertical_bias="0.0" />
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/close_info_banner"
|
|
||||||
android:layout_width="24dp"
|
|
||||||
android:layout_height="24dp"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_marginEnd="8dp"
|
|
||||||
android:background="?selectableItemBackgroundBorderless"
|
|
||||||
android:contentDescription="@string/content_description_close_button"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:srcCompat="@drawable/mozac_ic_close_20"
|
|
||||||
app:tint="@color/fx_mobile_private_text_color_primary" />
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="@dimen/cfr_triangle_width"
|
|
||||||
android:layout_height="@dimen/cfr_triangle_height"
|
|
||||||
android:layout_gravity="start"
|
|
||||||
android:layout_marginStart="15dp"
|
|
||||||
android:layout_marginEnd="@dimen/cfr_triangle_margin_edge"
|
|
||||||
android:importantForAccessibility="no"
|
|
||||||
app:srcCompat="@drawable/ic_cfr_triangle"
|
|
||||||
android:rotation="180"
|
|
||||||
app:tint="@color/fx_mobile_layer_color_gradient_start" />
|
|
||||||
</LinearLayout>
|
|
Loading…
Reference in New Issue