Skip to content

Commit

Permalink
For mozilla-mobile#7506 promote search widget dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
iorgamgabriel authored and mergify[bot] committed Sep 20, 2022
1 parent 0086859 commit ffa0fdf
Show file tree
Hide file tree
Showing 31 changed files with 488 additions and 20 deletions.
9 changes: 2 additions & 7 deletions .experimenter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ onboarding:
is-enabled:
type: boolean
description: "If `true`, the app will show the new onboarding screen"
tabs:
description: Nimbus feature name intended to control the multiple tabs feature in the app.
hasExposure: true
exposureDescription: ""
variables:
is_multi_tab:
is-promote-search-widget-dialog-enabled:
type: boolean
description: "Nimbus variable of [FEATURE_TABS] allowing outside control of whether the multiple tabs feature should be enabled or not."
description: "If `true`, the app will show the new dialog for promote search widget"
50 changes: 50 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1997,3 +1997,53 @@ search_widget:
metadata:
tags:
- Search
promote_dialog_shown:
type: event
description: |
Promote search widget dialog is shown to the user.
bugs:
- https://github.com/mozilla-mobile/focus-android/issues/7506
data_reviews:
- https://github.com/mozilla-mobile/focus-android/pull/
data_sensitivity:
- interaction
notification_emails:
- [email protected]
expires: 119
metadata:
tags:
- Search
add_to_home_screen_button:
type: event
description: |
The user has pressed on add search widget
to home screen button from promote dialog.
bugs:
- https://github.com/mozilla-mobile/focus-android/issues/7506
data_reviews:
- https://github.com/mozilla-mobile/focus-android/pull/
data_sensitivity:
- interaction
notification_emails:
- [email protected]
expires: 119
metadata:
tags:
- Search
widget_was_added:
type: event
description: |
The user has added successfully the search widget from
promote search widget dialog.
bugs:
- https://github.com/mozilla-mobile/focus-android/issues/7506
data_reviews:
- https://github.com/mozilla-mobile/focus-android/pull/
data_sensitivity:
- interaction
notification_emails:
- [email protected]
expires: 119
metadata:
tags:
- Search
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class EnhancedTrackingProtectionSettingsTest {
dispatcher = MockWebServerHelper.AndroidAssetDispatcher()
start()
}
featureSettingsHelper.setSearchWidgetDialogEnabled(false)
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class EraseBrowsingDataTest {
start()
}
featureSettingsHelper.setCfrForTrackingProtectionEnabled(false)
featureSettingsHelper.setSearchWidgetDialogEnabled(false)
}

@After
Expand All @@ -60,6 +61,7 @@ class EraseBrowsingDataTest {
featureSettingsHelper.resetAllFeatureFlags()
}

@Ignore("https://github.com/mozilla-mobile/focus-android/issues/7695")
@SmokeTest
@Test
fun trashButtonTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SafeBrowsingTest {
@Before
fun setUp() {
featureSettingsHelper.setCfrForTrackingProtectionEnabled(false)
featureSettingsHelper.setSearchWidgetDialogEnabled(false)
webServer = MockWebServer().apply {
dispatcher = MockWebServerHelper.AndroidAssetDispatcher()
start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SearchTest {
@Before
fun setUp() {
featureSettingsHelper.setCfrForTrackingProtectionEnabled(false)
featureSettingsHelper.setSearchWidgetDialogEnabled(false)
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SettingsAdvancedTest {
start()
}
featureSettingsHelper.setCfrForTrackingProtectionEnabled(false)
featureSettingsHelper.setSearchWidgetDialogEnabled(false)
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ShortcutsTest {
@Before
fun setUp() {
featureSettingsHelper.setCfrForTrackingProtectionEnabled(false)
featureSettingsHelper.setSearchWidgetDialogEnabled(false)
webServer = MockWebServer().apply {
dispatcher = MockWebServerHelper.AndroidAssetDispatcher()
start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class SitePermissionsTest {
@Before
fun setUp() {
featureSettingsHelper.setCfrForTrackingProtectionEnabled(false)
featureSettingsHelper.setSearchWidgetDialogEnabled(false)
webServer = MockWebServer().apply {
dispatcher = MockWebServerHelper.AndroidAssetDispatcher()
start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class WebControlsTest {
start()
}
featureSettingsHelper.setCfrForTrackingProtectionEnabled(false)
featureSettingsHelper.setSearchWidgetDialogEnabled(false)
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class FeatureSettingsHelper {
settings.shouldShowCfrForTrackingProtection = enabled
}

fun setSearchWidgetDialogEnabled(enabled: Boolean) {
if (enabled) {
settings.addClearBrowsingSessions(4)
} else {
settings.addClearBrowsingSessions(10)
}
}

// Important:
// Use this after each test if you have modified these feature settings
// to make sure the app goes back to the default state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class LocalSessionStorageTest {
start()
}
featureSettingsHelper.setCfrForTrackingProtectionEnabled(false)
featureSettingsHelper.setSearchWidgetDialogEnabled(false)
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ class UrlInputFragment :
binding.browserToolbar.editMode()
isInitialized = true
}

if (
requireComponents.settings.searchWidgetInstalled &&
requireComponents.appStore.state.showSearchWidgetSnackbar
) {
ViewUtils.showBrandedSnackbar(view, R.string.promote_search_widget_snackbar_message, 0)
requireComponents.appStore.dispatch(AppAction.ShowSearchWidgetSnackBar(false))
}
}

override fun onPause() {
Expand Down Expand Up @@ -240,7 +248,6 @@ class UrlInputFragment :
TopSitesOverlay()
}
}

return binding.root
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.mozilla.focus.navigation

import android.os.Build
import org.mozilla.experiments.nimbus.internal.FeatureHolder
import org.mozilla.focus.R
import org.mozilla.focus.activity.MainActivity
import org.mozilla.focus.autocomplete.AutocompleteAddFragment
Expand All @@ -14,6 +15,7 @@ import org.mozilla.focus.autocomplete.AutocompleteSettingsFragment
import org.mozilla.focus.biometrics.BiometricAuthenticationFragment
import org.mozilla.focus.exceptions.ExceptionsListFragment
import org.mozilla.focus.exceptions.ExceptionsRemoveFragment
import org.mozilla.focus.ext.components
import org.mozilla.focus.fragment.BrowserFragment
import org.mozilla.focus.fragment.FirstrunFragment
import org.mozilla.focus.fragment.UrlInputFragment
Expand All @@ -24,6 +26,8 @@ import org.mozilla.focus.fragment.onboarding.OnboardingStep
import org.mozilla.focus.fragment.onboarding.OnboardingStorage
import org.mozilla.focus.locale.screen.LanguageFragment
import org.mozilla.focus.nimbus.FocusNimbus
import org.mozilla.focus.nimbus.Onboarding
import org.mozilla.focus.searchwidget.SearchWidgetUtils
import org.mozilla.focus.settings.GeneralSettingsFragment
import org.mozilla.focus.settings.InstalledSearchEnginesSettingsFragment
import org.mozilla.focus.settings.ManualAddSearchEngineSettingsFragment
Expand Down Expand Up @@ -59,12 +63,19 @@ class MainActivityNavigation(
val isShowingBrowser = browserFragment != null
val crashReporterIsVisible = browserFragment?.crashReporterIsVisible() ?: false

val onboardingFeature = FocusNimbus.features.onboarding
val onboardingConfig = onboardingFeature.value(activity)

if (isShowingBrowser && !crashReporterIsVisible) {
ViewUtils.showBrandedSnackbar(
activity.findViewById(android.R.id.content),
R.string.feedback_erase2,
activity.resources.getInteger(R.integer.erase_snackbar_delay),
)
if (onboardingConfig.isPromoteSearchWidgetDialogEnabled) {
showPromoteSearchWidgetDialog(onboardingFeature)
} else {
ViewUtils.showBrandedSnackbar(
activity.findViewById(android.R.id.content),
R.string.feedback_erase2,
activity.resources.getInteger(R.integer.erase_snackbar_delay),
)
}
}

// We add the url input fragment to the layout if it doesn't exist yet.
Expand All @@ -88,10 +99,33 @@ class MainActivityNavigation(
// Ideally we'd make it possible to pause observers while the app is in the background:
// https://github.com/mozilla-mobile/android-components/issues/876
transaction
.replace(R.id.container, UrlInputFragment.createWithoutSession(), UrlInputFragment.FRAGMENT_TAG)
.replace(
R.id.container,
UrlInputFragment.createWithoutSession(),
UrlInputFragment.FRAGMENT_TAG,
)
.commitAllowingStateLoss()
}

/**
* Display the widget promo at first data clearing action and if it wasn't added after 5th Focus session.
*/
@Suppress("MagicNumber")
private fun showPromoteSearchWidgetDialog(onboardingFeature: FeatureHolder<Onboarding>) {
if (!activity.components.settings.searchWidgetInstalled) {
val clearBrowsingSessions = activity.components.settings.getClearBrowsingSessions()
activity.components.settings.addClearBrowsingSessions(1)
onboardingFeature.recordExposure()

if (
clearBrowsingSessions == 0 ||
clearBrowsingSessions == 4
) {
SearchWidgetUtils.showPromoteSearchWidgetDialog(activity)
}
}
}

/**
* Show browser for tab with the given [tabId].
*/
Expand Down
Loading

0 comments on commit ffa0fdf

Please sign in to comment.