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
--- 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;