Bug 1445799 - User Attribute for Leanplum for Android Users that have Opted Out of Pocket in their Top Sites. r=mcomella, a=RyanVM
authorPetru Lingurar <petru.lingurar@softvision.ro>
Wed, 04 Apr 2018 14:03:39 +0300
changeset 463099 50977d34a015f159285f339e8412c927dceb87d8
parent 463098 975203f0114ddcce4a02378a9b7a4e6cbb803db6
child 463100 dc9b50d160e1d7a715055d29fad9c309d41e18e8
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella, RyanVM
bugs1445799
milestone60.0
Bug 1445799 - User Attribute for Leanplum for Android Users that have Opted Out of Pocket in their Top Sites. r=mcomella, a=RyanVM Added a new user attribute in LP: "Top Sites by Pocket" to indicate if the user has the feature enabled or not, which will stored in LP along with the other attributes when the app first starts. Small refactoring to avoid duplicated code and use newly created way of checking if Pocket is recommending Top Sites. MozReview-Commit-ID: IWieAorkB1P
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamPanel.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamPanel.java
@@ -107,20 +107,17 @@ public class ActivityStreamPanel extends
 
     public void load(LoaderManager lm) {
         lm.initLoader(LOADER_ID_TOPSITES, null, new TopSitesCallback());
         if (sharedPreferences.getBoolean(PREF_BOOKMARKS_ENABLED, true) || sharedPreferences.getBoolean(PREF_VISITED_ENABLED, true)) {
             lm.initLoader(LOADER_ID_HIGHLIGHTS, null, new HighlightsCallbacks());
         }
 
         // TODO: we should get the default values from resources for the other Top Sites sections above too.
-        final Context context = getContext();
-        final Resources res = getContext().getResources();
-        if (ActivityStreamConfiguration.isPocketEnabledByLocale(context) &&
-                sharedPreferences.getBoolean(PREF_POCKET_ENABLED, res.getBoolean(R.bool.pref_activitystream_pocket_enabled_default))) {
+        if (isPocketRecommendingTopSites(getContext())) {
             lm.initLoader(LOADER_ID_POCKET, null, new PocketStoriesCallbacks());
         }
 
     }
 
     public void unload() {
         adapter.swapHighlights(Collections.<Highlight>emptyList());
 
@@ -134,16 +131,22 @@ public class ActivityStreamPanel extends
 
         // Destroy loaders so they don't restart loading when returning.
         lm.destroyLoader(LOADER_ID_HIGHLIGHTS);
         lm.destroyLoader(LOADER_ID_POCKET);
 
         load(lm);
     }
 
+    public static boolean isPocketRecommendingTopSites(final Context context) {
+        return ActivityStreamConfiguration.isPocketEnabledByLocale(context) &&
+                GeckoSharedPrefs.forProfile(context).getBoolean(ActivityStreamPanel.PREF_POCKET_ENABLED,
+                        context.getResources().getBoolean(R.bool.pref_activitystream_pocket_enabled_default));
+    }
+
     @Override
     protected void onSizeChanged(int w, int h, int oldw, int oldh) {
         super.onSizeChanged(w, h, oldw, oldh);
 
         // This code does two things:
         //  * Calculate the size of the tiles we want to display (using a desired width as anchor point)
         //  * Add padding to the left/right side if there's too much space that we do not need
 
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
@@ -206,19 +206,17 @@ public class StreamRecyclerAdapter exten
             final SharedPreferences sharedPreferences = GeckoSharedPrefs.forProfile(context);
             final boolean bookmarksEnabled = sharedPreferences.getBoolean(ActivityStreamPanel.PREF_BOOKMARKS_ENABLED,
                     context.getResources().getBoolean(R.bool.pref_activitystream_recentbookmarks_enabled_default));
             final boolean visitedEnabled = sharedPreferences.getBoolean(ActivityStreamPanel.PREF_VISITED_ENABLED,
                     context.getResources().getBoolean(R.bool.pref_activitystream_visited_enabled_default));
             setViewVisible(bookmarksEnabled || visitedEnabled, holder.itemView);
         } else if (type == RowItemType.TOP_STORIES_TITLE.getViewType()) {
             final Context context = holder.itemView.getContext();
-            final boolean pocketEnabled = ActivityStreamConfiguration.isPocketEnabledByLocale(context) &&
-                    GeckoSharedPrefs.forProfile(context).getBoolean(ActivityStreamPanel.PREF_POCKET_ENABLED,
-                    context.getResources().getBoolean(R.bool.pref_activitystream_pocket_enabled_default));
+            final boolean pocketEnabled = ActivityStreamPanel.isPocketRecommendingTopSites(context);
             setViewVisible(pocketEnabled, holder.itemView);
         }
     }
 
     /**
      * This sets a child view of the adapter visible or hidden.
      *
      * This only applies to children whose height and width are WRAP_CONTENT and MATCH_PARENT
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
@@ -18,16 +18,17 @@ import android.support.annotation.NonNul
 import android.text.TextUtils;
 
 import org.mozilla.gecko.Experiments;
 import org.mozilla.gecko.MmaConstants;
 import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
+import org.mozilla.gecko.activitystream.homepanel.ActivityStreamPanel;
 import org.mozilla.gecko.fxa.FirefoxAccounts;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.switchboard.SwitchBoard;
 import org.mozilla.gecko.util.ContextUtils;
 
 import java.lang.ref.WeakReference;
 import java.util.HashMap;
 import java.util.Map;
@@ -50,16 +51,17 @@ public class MmaDelegate {
     public static final String DISMISS_ONBOARDING = "E_Dismiss_Onboarding";
 
 
     public static final String USER_ATT_FOCUS_INSTALLED = "Focus Installed";
     public static final String USER_ATT_KLAR_INSTALLED = "Klar Installed";
     public static final String USER_ATT_POCKET_INSTALLED = "Pocket Installed";
     public static final String USER_ATT_DEFAULT_BROWSER = "Default Browser";
     public static final String USER_ATT_SIGNED_IN = "Signed In Sync";
+    public static final String USER_ATT_TOP_SITES_POCKET = "Top Sites by Pocket";
 
     public static final String PACKAGE_NAME_KLAR = "org.mozilla.klar";
     public static final String PACKAGE_NAME_FOCUS = "org.mozilla.focus";
     public static final String PACKAGE_NAME_POCKET = "com.ideashower.readitlater.pro";
 
     private static final String TAG = "MmaDelegate";
 
     public static final String KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID = "android.not_a_preference.leanplum.device_id";
@@ -97,16 +99,17 @@ public class MmaDelegate {
 
         final Map<String, Object> attributes = new HashMap<>();
 
         attributes.put(USER_ATT_FOCUS_INSTALLED, ContextUtils.isPackageInstalled(context, PACKAGE_NAME_FOCUS));
         attributes.put(USER_ATT_KLAR_INSTALLED, ContextUtils.isPackageInstalled(context, PACKAGE_NAME_KLAR));
         attributes.put(USER_ATT_POCKET_INSTALLED, ContextUtils.isPackageInstalled(context, PACKAGE_NAME_POCKET));
         attributes.put(USER_ATT_DEFAULT_BROWSER, isDefaultBrowser(context));
         attributes.put(USER_ATT_SIGNED_IN, FirefoxAccounts.firefoxAccountsExist(context));
+        attributes.put(USER_ATT_TOP_SITES_POCKET, ActivityStreamPanel.isPocketRecommendingTopSites(context));
 
         return attributes;
     }
 
     public static void track(String event) {
         if (applicationContext != null && isMmaEnabled(applicationContext.get())) {
             mmaHelper.event(event);
         }