From d1a41ce4cf1bb5f03d31990ad171441051b950b4 Mon Sep 17 00:00:00 2001 From: jhugman Date: Thu, 3 Dec 2020 12:24:46 +0000 Subject: [PATCH] [fenix] Adding menu configuration for A/A experiment and A/B experiment (https://github.com/mozilla-mobile/fenix/pull/16692) --- .../mozilla/fenix/experiments/Experiments.kt | 21 +++++++++++++ .../java/org/mozilla/fenix/home/HomeMenu.kt | 30 +++++++++++++++++-- .../main/res/drawable/ic_bookmark_list.xml | 15 ++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/org/mozilla/fenix/experiments/Experiments.kt create mode 100644 app/src/main/res/drawable/ic_bookmark_list.xml diff --git a/app/src/main/java/org/mozilla/fenix/experiments/Experiments.kt b/app/src/main/java/org/mozilla/fenix/experiments/Experiments.kt new file mode 100644 index 0000000000..5b5f67b34c --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/experiments/Experiments.kt @@ -0,0 +1,21 @@ +/* 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.experiments + +class Experiments { + companion object { + const val A_A_NIMBUS_VALIDATION = "fenix-nimbus-validation" + const val BOOKMARK_ICON = "fenix-bookmark-list-icon" + } +} + +class ExperimentBranch { + companion object { + const val TREATMENT = "treatment" + const val CONTROL = "control" + const val A1 = "A1" + const val A2 = "A2" + } +} diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt index 3e172e8f81..b497958691 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt @@ -22,6 +22,8 @@ import mozilla.components.concept.sync.AuthType import mozilla.components.concept.sync.OAuthAccount import mozilla.components.support.ktx.android.content.getColorFromAttr import org.mozilla.fenix.R +import org.mozilla.fenix.experiments.ExperimentBranch +import org.mozilla.fenix.experiments.Experiments import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.settings import org.mozilla.fenix.theme.ThemeManager @@ -96,17 +98,41 @@ class HomeMenu( onItemTapped.invoke(Item.WhatsNew) } + val experiments = context.components.analytics.experiments + val bookmarksIcon = experiments.getExperimentBranch(Experiments.BOOKMARK_ICON) + .let { + when (it) { + ExperimentBranch.TREATMENT -> R.drawable.ic_bookmark_list + else -> R.drawable.ic_bookmark_filled + } + } + val bookmarksItem = BrowserMenuImageText( context.getString(R.string.library_bookmarks), - R.drawable.ic_bookmark_filled, + bookmarksIcon, primaryTextColor ) { onItemTapped.invoke(Item.Bookmarks) } + // We want to validate that the Nimbus experiments library is working, from the android UI + // all the way back to the data science backend. We're not testing the user's preference + // or response, we're end-to-end testing the experiments platform. + // So here, we're running multiple identical branches with the same treatment, and if the + // user isn't targeted, then we get still get the same treatment. + // The `let` block is degenerate here, but left here so as to document the form of how experiments + // are implemented here. + val historyIcon = experiments.getExperimentBranch(Experiments.A_A_NIMBUS_VALIDATION) + .let { + when (it) { + ExperimentBranch.A1 -> R.drawable.ic_history + ExperimentBranch.A2 -> R.drawable.ic_history + else -> R.drawable.ic_history + } + } val historyItem = BrowserMenuImageText( context.getString(R.string.library_history), - R.drawable.ic_history, + historyIcon, primaryTextColor ) { onItemTapped.invoke(Item.History) diff --git a/app/src/main/res/drawable/ic_bookmark_list.xml b/app/src/main/res/drawable/ic_bookmark_list.xml new file mode 100644 index 0000000000..eec7c8ffe9 --- /dev/null +++ b/app/src/main/res/drawable/ic_bookmark_list.xml @@ -0,0 +1,15 @@ + + + + +