jenkins-bot has submitted this change and it was merged.

Change subject: Add Beta A/B test for scrolling the link preview to different 
heights.
......................................................................


Add Beta A/B test for scrolling the link preview to different heights.

- Brought back the LinkPreviewVersion generator.
- The split is now as follows: 50% of users will see no preview, 25% will
  see the preview scrolled up a short amount, and 25% will see it scrolled
  up a medium amount.
- The test only applies to Beta. The production app will have link
  previews for everyone, and no height a/b split.

Change-Id: I219ac0ba1e3889146a2de626b3fbf15a61b0c15f
---
M app/src/main/java/org/wikipedia/WikipediaApp.java
M app/src/main/java/org/wikipedia/analytics/LinkPreviewFunnel.java
M app/src/main/java/org/wikipedia/page/PageFragment.java
M app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
A app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewVersion.java
M app/src/main/java/org/wikipedia/settings/Prefs.java
M app/src/main/res/layout/dialog_link_preview.xml
M app/src/main/res/values/dimens.xml
M app/src/main/res/values/preference_keys.xml
M app/src/main/res/xml/developer_preferences.xml
10 files changed, 87 insertions(+), 5 deletions(-)

Approvals:
  BearND: Looks good to me, but someone else must approve
  Sniedzielski: Looks good to me, approved
  Niedzielski: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/app/src/main/java/org/wikipedia/WikipediaApp.java 
b/app/src/main/java/org/wikipedia/WikipediaApp.java
index 850727f..4f6e900 100644
--- a/app/src/main/java/org/wikipedia/WikipediaApp.java
+++ b/app/src/main/java/org/wikipedia/WikipediaApp.java
@@ -37,6 +37,7 @@
 import org.wikipedia.onboarding.OnboardingStateMachine;
 import org.wikipedia.onboarding.PrefsOnboardingStateMachine;
 import org.wikipedia.page.PageCache;
+import org.wikipedia.page.linkpreview.LinkPreviewVersion;
 import org.wikipedia.pageimages.PageImage;
 import org.wikipedia.pageimages.PageImagePersister;
 import org.wikipedia.savedpages.SavedPage;
@@ -438,6 +439,15 @@
         return EVENT_LOG_TESTING_ID;
     }
 
+    public int getLinkPreviewVersion() {
+        if (Prefs.hasLinkPreviewVersion()) {
+            return Prefs.getLinkPreviewVersion();
+        }
+        int version = LinkPreviewVersion.generateVersion();
+        Prefs.setLinkPreviewVersion(version);
+        return version;
+    }
+
     public boolean isFeatureSelectTextAndShareTutorialEnabled() {
         boolean enabled = false;
         // Select text does not work on Gingerbread.
diff --git a/app/src/main/java/org/wikipedia/analytics/LinkPreviewFunnel.java 
b/app/src/main/java/org/wikipedia/analytics/LinkPreviewFunnel.java
index 141fa40..e3c2b82 100644
--- a/app/src/main/java/org/wikipedia/analytics/LinkPreviewFunnel.java
+++ b/app/src/main/java/org/wikipedia/analytics/LinkPreviewFunnel.java
@@ -9,18 +9,20 @@
 public class LinkPreviewFunnel extends TimedFunnel {
     private static final String SCHEMA_NAME = "MobileWikiAppLinkPreview";
     private static final int REV_ID = 12143205;
-    private static final int LINK_PREVIEW_VERSION = 3;
+    private static final int PROD_LINK_PREVIEW_VERSION = 3;
+    private final int version;
 
     private final PageTitle title;
 
     public LinkPreviewFunnel(WikipediaApp app, PageTitle title) {
-        super(app, SCHEMA_NAME, REV_ID, Funnel.SAMPLE_LOG_100);
+        super(app, SCHEMA_NAME, REV_ID, app.isProdRelease() ? 
Funnel.SAMPLE_LOG_100 : Funnel.SAMPLE_LOG_ALL);
         this.title = title;
+        version = app.isProdRelease() ? PROD_LINK_PREVIEW_VERSION : 
app.getLinkPreviewVersion();
     }
 
     @Override
     protected JSONObject preprocessData(@NonNull JSONObject eventData) {
-        preprocessData(eventData, "version", LINK_PREVIEW_VERSION);
+        preprocessData(eventData, "version", version);
         return super.preprocessData(eventData);
     }
 
diff --git a/app/src/main/java/org/wikipedia/page/PageFragment.java 
b/app/src/main/java/org/wikipedia/page/PageFragment.java
index c81a43b..1601878 100755
--- a/app/src/main/java/org/wikipedia/page/PageFragment.java
+++ b/app/src/main/java/org/wikipedia/page/PageFragment.java
@@ -9,6 +9,7 @@
 import org.wikipedia.WikipediaApp;
 import org.wikipedia.analytics.ConnectionIssueFunnel;
 import org.wikipedia.analytics.GalleryFunnel;
+import org.wikipedia.analytics.LinkPreviewFunnel;
 import org.wikipedia.analytics.SavedPagesFunnel;
 import org.wikipedia.analytics.TabFunnel;
 import org.wikipedia.bridge.CommunicationBridge;
@@ -395,7 +396,13 @@
         if (referenceDialog != null && referenceDialog.isShowing()) {
             referenceDialog.dismiss();
         }
-        getPageActivity().showLinkPreview(title, 
HistoryEntry.SOURCE_INTERNAL_LINK);
+        if (!app.isProdRelease() && app.getLinkPreviewVersion() == 0) {
+            HistoryEntry historyEntry = new HistoryEntry(title, 
HistoryEntry.SOURCE_INTERNAL_LINK);
+            getPageActivity().displayNewPage(title, historyEntry);
+            new LinkPreviewFunnel(app, title).logNavigate();
+        } else {
+            getPageActivity().showLinkPreview(title, 
HistoryEntry.SOURCE_INTERNAL_LINK);
+        }
     }
 
     private TabsProvider.TabsProviderListener tabsProviderListener = new 
TabsProvider.TabsProviderListener() {
diff --git 
a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java 
b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
index b34878a..9fab470 100755
--- a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
+++ b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
@@ -79,7 +79,12 @@
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setStyle(STYLE_NO_TITLE, R.style.LinkPreviewDialog);
-        setDialogPeekHeight((int) 
getResources().getDimension(R.dimen.linkPreviewPeekHeight));
+        int dimenId = R.dimen.linkPreviewPeekHeight;
+        if (!WikipediaApp.getInstance().isProdRelease()) {
+            dimenId = WikipediaApp.getInstance().getLinkPreviewVersion() == 1
+                    ? R.dimen.linkPreviewPeekHeight : 
R.dimen.linkPreviewPeekHeightB;
+        }
+        setDialogPeekHeight((int) getResources().getDimension(dimenId));
     }
 
     @Override
diff --git 
a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewVersion.java 
b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewVersion.java
new file mode 100644
index 0000000..8f53693
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewVersion.java
@@ -0,0 +1,35 @@
+package org.wikipedia.page.linkpreview;
+
+import java.util.Random;
+
+public final class LinkPreviewVersion {
+
+    // TODO: remove toggle when ready for production.
+    // Let's toggle between three possible behaviors:
+    // A) not show a link preview, and go directly to the target article 
(weight: 50%)
+    // B) show link preview prototype 1 (weight: 25%)
+    // C) show link preview prototype 2 (weight: 25%)
+    private static final int LINK_PREVIEW_TOGGLE_WEIGHT = 4;
+
+    // Take the app install id modulo 4 to get our toggle value.
+    // Values per the schema at 
https://meta.wikimedia.org/w/index.php?title=Schema:MobileWikiAppLinkPreview:
+    // 0: No link preview prototype
+    // 1: Link preview prototype A
+    // 2: Link preview prototype B
+    // Return results 0, 1, or 2.  For result of 3, also return 0 (no preview).
+    // (For building one-off APKs for testing specific prototypes, hard-code 
version to 1 or 2.)
+    public static int generateVersion() {
+        int number = new Random().nextInt(LINK_PREVIEW_TOGGLE_WEIGHT);
+        switch (number) {
+            case 0:
+            case 1:
+            case 2:
+                return number;
+            default:
+                return 0;
+        }
+    }
+
+    private LinkPreviewVersion() {
+    }
+}
diff --git a/app/src/main/java/org/wikipedia/settings/Prefs.java 
b/app/src/main/java/org/wikipedia/settings/Prefs.java
index a75a903..853e409 100644
--- a/app/src/main/java/org/wikipedia/settings/Prefs.java
+++ b/app/src/main/java/org/wikipedia/settings/Prefs.java
@@ -121,6 +121,18 @@
         remove(getEditTokenForWikiKey(wiki));
     }
 
+    public static int getLinkPreviewVersion() {
+        return getInt(R.string.preference_key_link_preview_version, 0);
+    }
+
+    public static void setLinkPreviewVersion(int version) {
+        setInt(R.string.preference_key_link_preview_version, version);
+    }
+
+    public static boolean hasLinkPreviewVersion() {
+        return contains(R.string.preference_key_link_preview_version);
+    }
+
     public static void removeLoginUsername() {
         remove(R.string.preference_key_login_username);
     }
diff --git a/app/src/main/res/layout/dialog_link_preview.xml 
b/app/src/main/res/layout/dialog_link_preview.xml
index 81f89e3..09d0cdc 100755
--- a/app/src/main/res/layout/dialog_link_preview.xml
+++ b/app/src/main/res/layout/dialog_link_preview.xml
@@ -36,6 +36,7 @@
                     android:layout_marginTop="16dp"
                     android:layout_marginBottom="10dp"
                     android:layout_weight="1"
+                    android:layout_gravity="center_vertical"
                     style="@style/RtlAwareTextView"
                     android:textColor="?attr/link_preview_text_color"
                     android:paddingLeft="16dp"
diff --git a/app/src/main/res/values/dimens.xml 
b/app/src/main/res/values/dimens.xml
index 253c88f..113b9a9 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -40,6 +40,9 @@
     <dimen name="linkPreviewImageSize">112dp</dimen>
     <!-- Default height with which the Link Preview peeks out from the bottom 
-->
     <dimen name="linkPreviewPeekHeight">320dp</dimen>
+    <!-- Smaller height for Beta A/B test -->
+    <dimen name="linkPreviewPeekHeightB">190dp</dimen>
+
     <item type="dimen" format="float" 
name="linkPreviewThumbPressScale">1.03</item>
     <item type="dimen" format="float" 
name="linkPreviewThumbPressOverScale">1.05</item>
 
diff --git a/app/src/main/res/values/preference_keys.xml 
b/app/src/main/res/values/preference_keys.xml
index 5b59933..b9d8ecb 100644
--- a/app/src/main/res/values/preference_keys.xml
+++ b/app/src/main/res/values/preference_keys.xml
@@ -27,6 +27,7 @@
     <string name="preference_key_login_username">username</string>
     <string name="preference_key_login_password">password</string>
     <string name="preference_key_login_user_id">userID</string>
+    <string 
name="preference_key_link_preview_version">linkPreviewVersion</string>
     <string 
name="preference_key_show_developer_settings">showDeveloperSettings</string>
     <string name="preference_key_last_run_time_format">%s-lastrun</string>
     <string name="preference_key_tabs">tabs</string>
diff --git a/app/src/main/res/xml/developer_preferences.xml 
b/app/src/main/res/xml/developer_preferences.xml
index d1a683a..2e16b43 100644
--- a/app/src/main/res/xml/developer_preferences.xml
+++ b/app/src/main/res/xml/developer_preferences.xml
@@ -7,6 +7,12 @@
             
android:key="@string/preference_key_feature_select_text_and_share_tutorials_enabled"
             
android:title="@string/preference_key_feature_select_text_and_share_tutorials_enabled"
 />
 
+        <!--suppress AndroidUnknownAttribute -->
+        <org.wikipedia.settings.IntPreference
+            style="@style/IntPreference"
+            android:key="@string/preference_key_link_preview_version"
+            android:title="@string/preference_key_link_preview_version" />
+
         <!--<CheckBoxPreference-->
         <!--android:key="@string/preference_key_exp_html_page_load"-->
         <!--android:title="@string/preference_key_exp_html_page_load" />-->

-- 
To view, visit https://gerrit.wikimedia.org/r/233056
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I219ac0ba1e3889146a2de626b3fbf15a61b0c15f
Gerrit-PatchSet: 3
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org>
Gerrit-Reviewer: Niedzielski <sniedziel...@wikimedia.org>
Gerrit-Reviewer: Sniedzielski <sniedziel...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to