For # 15929: Remove the search widget discoverability experiment. (#16081)
* For #15929: Remove SearchWidgetCFR telemetry. * For #15929: Remove SearchWidgetCFR and search widget experiment. * For #15929: Remove unit tests references to search widget experiment.upstream-sync
parent
dec63564a3
commit
0ee7e1c28d
@ -1,39 +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
|
||||
|
||||
import android.content.Context
|
||||
import mozilla.components.service.experiments.Experiments
|
||||
import org.mozilla.fenix.ext.settings
|
||||
|
||||
object ExperimentsManager {
|
||||
|
||||
fun optOutSearchWidgetExperiment(context: Context) {
|
||||
// Release user has opted out of search widget CFR experiment, reset them to not see it.
|
||||
context.settings().setSearchWidgetExperiment(false)
|
||||
}
|
||||
|
||||
fun initSearchWidgetExperiment(context: Context) {
|
||||
// When the `search-widget-discoverability` experiment is active,set the pref to either
|
||||
// show or hide the search widget CFR (given other criteria are met as well).
|
||||
// Note that this will not take effect the first time the application has launched,
|
||||
// since there won't be enough time for the experiments library to get a list of experiments.
|
||||
// It will take effect the second time the application is launched.
|
||||
Experiments.withExperiment("fenix-search-widget") { branchName ->
|
||||
when (branchName) {
|
||||
"control_no_cfr" -> {
|
||||
context.settings().setSearchWidgetExperiment(false)
|
||||
}
|
||||
"treatment_cfr" -> {
|
||||
context.settings().setSearchWidgetExperiment(true)
|
||||
}
|
||||
else -> {
|
||||
// No branch matches so we're defaulting to no CFR
|
||||
context.settings().setSearchWidgetExperiment(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,107 +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.cfr
|
||||
|
||||
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.core.view.isVisible
|
||||
import androidx.core.view.marginTop
|
||||
import kotlinx.android.synthetic.main.search_widget_cfr.view.*
|
||||
import kotlinx.android.synthetic.main.tracking_protection_onboarding_popup.view.drop_down_triangle
|
||||
import kotlinx.android.synthetic.main.tracking_protection_onboarding_popup.view.pop_up_triangle
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.SearchWidgetCreator
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.components.metrics.MetricController
|
||||
import org.mozilla.fenix.components.toolbar.ToolbarPosition
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
|
||||
/**
|
||||
* Displays a CFR above the HomeFragment toolbar that recommends usage / installation of the search widget.
|
||||
*/
|
||||
class SearchWidgetCFR(
|
||||
private val context: Context,
|
||||
private val settings: Settings,
|
||||
private val metrics: MetricController,
|
||||
private val getToolbar: () -> View
|
||||
) {
|
||||
|
||||
fun displayIfNecessary() {
|
||||
if (settings.isInSearchWidgetExperiment &&
|
||||
settings.shouldDisplaySearchWidgetCfr() &&
|
||||
!isShown
|
||||
) {
|
||||
isShown = true
|
||||
showSearchWidgetCFR()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("InflateParams")
|
||||
private fun showSearchWidgetCFR() {
|
||||
settings.lastCfrShownTimeInMillis = System.currentTimeMillis()
|
||||
settings.incrementSearchWidgetCFRDisplayed()
|
||||
|
||||
val searchWidgetCFRDialog = Dialog(context)
|
||||
val layout = LayoutInflater.from(context)
|
||||
.inflate(R.layout.search_widget_cfr, null)
|
||||
val toolbarPosition = settings.toolbarPosition
|
||||
|
||||
layout.drop_down_triangle.isVisible = toolbarPosition == ToolbarPosition.TOP
|
||||
layout.pop_up_triangle.isVisible = toolbarPosition == ToolbarPosition.BOTTOM
|
||||
|
||||
val toolbar = getToolbar()
|
||||
|
||||
val gravity = Gravity.CENTER_HORIZONTAL or toolbarPosition.androidGravity
|
||||
|
||||
layout.cfr_neg_button.setOnClickListener {
|
||||
metrics.track(Event.SearchWidgetCFRNotNowPressed)
|
||||
searchWidgetCFRDialog.dismiss()
|
||||
settings.manuallyDismissSearchWidgetCFR()
|
||||
}
|
||||
|
||||
layout.cfr_pos_button.setOnClickListener {
|
||||
metrics.track(Event.SearchWidgetCFRAddWidgetPressed)
|
||||
SearchWidgetCreator.createSearchWidget(context)
|
||||
searchWidgetCFRDialog.dismiss()
|
||||
settings.manuallyDismissSearchWidgetCFR()
|
||||
}
|
||||
|
||||
searchWidgetCFRDialog.apply {
|
||||
setContentView(layout)
|
||||
}
|
||||
|
||||
searchWidgetCFRDialog.window?.let {
|
||||
it.setGravity(gravity)
|
||||
val attr = it.attributes
|
||||
attr.y =
|
||||
(toolbar.y + toolbar.height - toolbar.marginTop - toolbar.paddingTop).toInt()
|
||||
it.attributes = attr
|
||||
it.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||
}
|
||||
|
||||
searchWidgetCFRDialog.setOnCancelListener {
|
||||
isShown = false
|
||||
metrics.track(Event.SearchWidgetCFRCanceled)
|
||||
}
|
||||
|
||||
searchWidgetCFRDialog.setOnDismissListener {
|
||||
isShown = false
|
||||
settings.incrementSearchWidgetCFRDismissed()
|
||||
}
|
||||
|
||||
searchWidgetCFRDialog.show()
|
||||
metrics.track(Event.SearchWidgetCFRDisplayed)
|
||||
}
|
||||
|
||||
companion object {
|
||||
// Used to ensure multiple dialogs are not shown on top of each other
|
||||
var isShown = false
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 23 KiB |
@ -1,102 +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_gravity="center_horizontal"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:visibility="gone"
|
||||
android:id="@+id/drop_down_triangle"
|
||||
android:layout_width="@dimen/cfr_triangle_width"
|
||||
android:layout_height="@dimen/cfr_triangle_height"
|
||||
android:importantForAccessibility="no"
|
||||
android:rotation="0"
|
||||
app:srcCompat="@drawable/ic_cfr_triangle"
|
||||
app:tint="#7542E5"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/message"
|
||||
android:layout_width="@dimen/etp_onboarding_popup_width"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/cfr_background_gradient"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/cfr_image"
|
||||
app:srcCompat="@drawable/search_widget_illustration"
|
||||
android:padding="16dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="140dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cfr_message"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:lineSpacingExtra="2dp"
|
||||
android:text="@string/search_widget_cfr_message"
|
||||
android:textColor="@color/primary_text_dark_theme"
|
||||
android:textSize="16sp"
|
||||
app:fontFamily="@font/metropolis_medium"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cfr_image" />
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/cfr_pos_button"
|
||||
style="@style/MetropolisButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:background="@drawable/rounded_gray_corners"
|
||||
android:text="@string/search_widget_cfr_pos_button_text"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@color/above_dark_theme"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintBottom_toTopOf="@id/cfr_neg_button"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cfr_message" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/cfr_neg_button"
|
||||
style="@style/MetropolisButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent"
|
||||
android:text="@string/search_widget_cfr_neg_button_text"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@color/white_color"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cfr_pos_button" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/pop_up_triangle"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="@dimen/cfr_triangle_height"
|
||||
android:importantForAccessibility="no"
|
||||
android:rotation="180"
|
||||
app:srcCompat="@drawable/ic_cfr_triangle"
|
||||
app:tint="#7542E5"
|
||||
android:layout_gravity="center" />
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue