Bug 1265351 - HomeScreenPrompt: Save rejection and send telemetry only once. r?margaret draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Mon, 18 Apr 2016 14:38:06 +0200
changeset 352706 c48c59f9ff106d0e26250466486c1dedc198b5b1
parent 352654 4bc053de842538e99e56927b3c03fdc539374a16
child 518704 c42345cb9df097cc87477e8062a74734de298c74
push id15751
push users.kaspari@gmail.com
push dateMon, 18 Apr 2016 13:43:53 +0000
reviewersmargaret
bugs1265351
milestone48.0a1
Bug 1265351 - HomeScreenPrompt: Save rejection and send telemetry only once. r?margaret Additionally this patch: * unifies the telemetry for declining the prompt to always be: (cancel,back,'home_screen_promotion') * moves saving the rejection in the database to a background thread MozReview-Commit-ID: HywutUDtGcY
mobile/android/base/java/org/mozilla/gecko/promotion/HomeScreenPrompt.java
--- a/mobile/android/base/java/org/mozilla/gecko/promotion/HomeScreenPrompt.java
+++ b/mobile/android/base/java/org/mozilla/gecko/promotion/HomeScreenPrompt.java
@@ -41,16 +41,17 @@ public class HomeScreenPrompt extends Lo
     private static final String TELEMETRY_EXTRA = "home_screen_promotion";
 
     private View containerView;
     private ImageView iconView;
     private String title;
     private String url;
     private boolean isAnimating;
     private boolean hasAccepted;
+    private boolean hasDeclined;
 
     public static void show(Context context, String url, String title) {
         Intent intent = new Intent(context, HomeScreenPrompt.class);
         intent.putExtra(EXTRA_TITLE, title);
         intent.putExtra(EXTRA_URL, url);
         context.startActivity(intent);
     }
 
@@ -103,20 +104,17 @@ public class HomeScreenPrompt extends Lo
 
                 addToHomeScreen();
             }
         });
 
         findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                rememberRejection();
-                slideOut();
-
-                Telemetry.sendUIEvent(TelemetryContract.Event.CANCEL, TelemetryContract.Method.BUTTON, TELEMETRY_EXTRA);
+                onDecline();
             }
         });
     }
 
     private void addToHomeScreen() {
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
@@ -168,23 +166,23 @@ public class HomeScreenPrompt extends Lo
 
         set.start();
     }
 
     /**
      * Remember that the user rejected creating a home screen shortcut for this URL.
      */
     private void rememberRejection() {
-        if (hasAccepted) {
-            // User has already accepted to create a shortcut.
-            return;
-        }
-
-        final UrlAnnotations urlAnnotations = GeckoProfile.get(this).getDB().getUrlAnnotations();
-        urlAnnotations.insertHomeScreenShortcut(getContentResolver(), url, false);
+        ThreadUtils.postToBackgroundThread(new Runnable() {
+            @Override
+            public void run() {
+                final UrlAnnotations urlAnnotations = GeckoProfile.get(HomeScreenPrompt.this).getDB().getUrlAnnotations();
+                urlAnnotations.insertHomeScreenShortcut(getContentResolver(), url, false);
+            }
+        });
     }
 
     private void slideOut() {
         if (isAnimating) {
             return;
         }
 
         isAnimating = true;
@@ -205,33 +203,40 @@ public class HomeScreenPrompt extends Lo
         super.finish();
 
         // Don't perform an activity-dismiss animation.
         overridePendingTransition(0, 0);
     }
 
     @Override
     public void onBackPressed() {
+        onDecline();
+    }
+
+    private synchronized void onDecline() {
+        if (hasDeclined || hasAccepted) {
+            return;
+        }
+
         rememberRejection();
         slideOut();
 
+        // Technically not always an action triggered by the "back" button but with the same effect: Finishing this
+        // activity and going back to the previous one.
         Telemetry.sendUIEvent(TelemetryContract.Event.CANCEL, TelemetryContract.Method.BACK, TELEMETRY_EXTRA);
+
+        hasDeclined = true;
     }
 
     /**
      * User clicked outside of the prompt.
      */
     @Override
     public boolean onTouchEvent(MotionEvent event) {
-        rememberRejection();
-        slideOut();
-
-        // Not really an action triggered by the "back" button but with the same effect: Finishing this
-        // activity and going back to the previous one.
-        Telemetry.sendUIEvent(TelemetryContract.Event.CANCEL, TelemetryContract.Method.BACK, TELEMETRY_EXTRA);
+        onDecline();
 
         return true;
     }
 
     @Override
     public void onFaviconLoaded(String url, String faviconURL, final Bitmap favicon) {
         if (favicon == null) {
             return;