Bug 1148431 - Create UI to inform users of Tab Queue and allow them to turn on or ignore (r=mcomella)

This commit is contained in:
Martyn Haigh
2015-04-09 10:55:13 +01:00
parent 57195bf3bc
commit a1e4d477ca
22 changed files with 436 additions and 8 deletions

View File

@@ -34,6 +34,54 @@ public class TabQueueHelper {
public static final int TAB_QUEUE_NOTIFICATION_ID = R.id.tabQueueNotification;
public static final String PREF_TAB_QUEUE_COUNT = "tab_queue_count";
public static final String PREF_TAB_QUEUE_LAUNCHES = "tab_queue_launches";
public static final String PREF_TAB_QUEUE_TIMES_PROMPT_SHOWN = "tab_queue_times_prompt_shown";
public static final int MAX_TIMES_TO_SHOW_PROMPT = 3;
public static final int EXTERNAL_LAUNCHES_BEFORE_SHOWING_PROMPT = 3;
// result codes for returning from the prompt
public static final int TAB_QUEUE_YES = 201;
public static final int TAB_QUEUE_NO = 202;
/**
* Check if we should show the tab queue prompt
*
* @param context
* @return true if we should display the prompt, false if not.
*/
public static boolean shouldShowTabQueuePrompt(Context context) {
final SharedPreferences prefs = GeckoSharedPrefs.forApp(context);
boolean isTabQueueEnabled = prefs.getBoolean(GeckoPreferences.PREFS_TAB_QUEUE, false);
int numberOfTimesTabQueuePromptSeen = prefs.getInt(PREF_TAB_QUEUE_TIMES_PROMPT_SHOWN, 0);
// Exit early if the feature is already enabled or the user has seen the
// prompt more than MAX_TIMES_TO_SHOW_PROMPT times.
if (isTabQueueEnabled || numberOfTimesTabQueuePromptSeen >= MAX_TIMES_TO_SHOW_PROMPT) {
return false;
}
final int viewActionIntentLaunches = prefs.getInt(PREF_TAB_QUEUE_LAUNCHES, 0) + 1;
if (viewActionIntentLaunches < EXTERNAL_LAUNCHES_BEFORE_SHOWING_PROMPT) {
// Allow a few external links to open before we prompt the user.
prefs.edit().putInt(PREF_TAB_QUEUE_LAUNCHES, viewActionIntentLaunches).apply();
} else if (viewActionIntentLaunches == EXTERNAL_LAUNCHES_BEFORE_SHOWING_PROMPT) {
// Reset to avoid repeatedly showing the prompt if the user doesn't interact with it and
// we get more external VIEW action intents in.
final SharedPreferences.Editor editor = prefs.edit();
editor.remove(TabQueueHelper.PREF_TAB_QUEUE_LAUNCHES);
int timesPromptShown = prefs.getInt(TabQueueHelper.PREF_TAB_QUEUE_TIMES_PROMPT_SHOWN, 0) + 1;
editor.putInt(TabQueueHelper.PREF_TAB_QUEUE_TIMES_PROMPT_SHOWN, timesPromptShown);
editor.apply();
// Show the prompt
return true;
}
return false;
}
/**
* Reads file and converts any content to JSON, adds passed in URL to the data and writes back to the file,
@@ -147,4 +195,37 @@ public class TabQueueHelper {
final SharedPreferences prefs = GeckoSharedPrefs.forApp(context);
prefs.edit().remove(PREF_TAB_QUEUE_COUNT).apply();
}
public static void processTabQueuePromptResponse(int resultCode, Context context) {
final SharedPreferences prefs = GeckoSharedPrefs.forApp(context);
final SharedPreferences.Editor editor = prefs.edit();
switch (resultCode) {
case TAB_QUEUE_YES:
editor.putBoolean(GeckoPreferences.PREFS_TAB_QUEUE, true);
// By making this one more than EXTERNAL_LAUNCHES_BEFORE_SHOWING_PROMPT we ensure the prompt
// will never show again without having to keep track of an extra pref.
editor.putInt(TabQueueHelper.PREF_TAB_QUEUE_LAUNCHES,
TabQueueHelper.EXTERNAL_LAUNCHES_BEFORE_SHOWING_PROMPT + 1);
break;
case TAB_QUEUE_NO:
// The user clicked the 'no' button, so let's make sure the user never sees the prompt again by
// maxing out the pref used to count the VIEW action intents received and times they've seen the prompt.
editor.putInt(TabQueueHelper.PREF_TAB_QUEUE_LAUNCHES,
TabQueueHelper.EXTERNAL_LAUNCHES_BEFORE_SHOWING_PROMPT + 1);
editor.putInt(TabQueueHelper.PREF_TAB_QUEUE_TIMES_PROMPT_SHOWN,
TabQueueHelper.MAX_TIMES_TO_SHOW_PROMPT + 1);
break;
default:
// We shouldn't ever get here.
Log.w(LOGTAG, "Unrecognized result code received from the tab queue prompt: " + resultCode);
}
editor.apply();
}
}