Refactored featured list preference code to be easier to read, introduce an ab test for the presence of featured lists

pull/14/head
Sam Bosley 13 years ago
parent 2978c9dad1
commit 696bf298db

@ -77,6 +77,7 @@ import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.service.abtesting.ABTestEventReportingService; import com.todoroo.astrid.service.abtesting.ABTestEventReportingService;
import com.todoroo.astrid.sync.SyncV2Provider.SyncExceptionHandler; import com.todoroo.astrid.sync.SyncV2Provider.SyncExceptionHandler;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.tags.reusable.FeaturedListFilterExposer;
import com.todoroo.astrid.utility.Flags; import com.todoroo.astrid.utility.Flags;
/** /**
@ -859,7 +860,7 @@ public final class ActFmSyncService {
"token", token, "modified_after", serverTime); "token", token, "modified_after", serverTime);
JSONArray featuredLists = result.getJSONArray("list"); JSONArray featuredLists = result.getJSONArray("list");
if (featuredLists.length() > 0) if (featuredLists.length() > 0)
Preferences.setBoolean(R.string.p_show_featured_lists, true); Preferences.setBoolean(FeaturedListFilterExposer.PREF_SHOULD_SHOW_FEATURED_LISTS, true);
for (int i = 0; i < featuredLists.length(); i++) { for (int i = 0; i < featuredLists.length(); i++) {
JSONObject featObject = featuredLists.getJSONObject(i); JSONObject featObject = featuredLists.getJSONObject(i);

@ -295,7 +295,7 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
public void run() { public void run() {
int time = Preferences.getInt(LAST_FEATURED_TAG_FETCH_TIME, 0); int time = Preferences.getInt(LAST_FEATURED_TAG_FETCH_TIME, 0);
try { try {
if (Preferences.getBoolean(R.string.p_show_featured_lists_labs, false)) { if (Preferences.getBoolean(R.string.p_show_featured_lists, false)) {
time = actFmSyncService.fetchFeaturedLists(time); time = actFmSyncService.fetchFeaturedLists(time);
Preferences.setInt(LAST_FEATURED_TAG_FETCH_TIME, time); Preferences.setInt(LAST_FEATURED_TAG_FETCH_TIME, time);
} }

@ -31,6 +31,8 @@ import com.todoroo.astrid.tags.TagService.Tag;
public class FeaturedListFilterExposer extends TagFilterExposer { public class FeaturedListFilterExposer extends TagFilterExposer {
public static final String PREF_SHOULD_SHOW_FEATURED_LISTS = "show_featured_lists"; //$NON-NLS-1$
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
addUntaggedFilter = false; addUntaggedFilter = false;

@ -55,9 +55,6 @@
<!-- show friends view preference --> <!-- show friends view preference -->
<string name="p_show_friends_view">show_friends_view</string> <string name="p_show_friends_view">show_friends_view</string>
<!-- show featured lists preference -->
<string name="p_show_featured_lists">show_featured_lists</string>
<!-- enable third party addons preference --> <!-- enable third party addons preference -->
<string name="p_third_party_addons">third_party_addons</string> <string name="p_third_party_addons">third_party_addons</string>
@ -68,7 +65,7 @@
<string name="p_force_phone_layout">force_phone_layout</string> <string name="p_force_phone_layout">force_phone_layout</string>
<!-- show featured lists --> <!-- show featured lists -->
<string name="p_show_featured_lists_labs">show_featured_lists_labs</string> <string name="p_show_featured_lists">show_featured_lists_labs</string>
<!-- account status section key --> <!-- account status section key -->
<string name="p_account">account</string> <string name="p_account">account</string>

@ -90,7 +90,7 @@
<CheckBoxPreference <CheckBoxPreference
android:title="@string/EPr_show_featured_lists" android:title="@string/EPr_show_featured_lists"
android:key="@string/p_show_featured_lists_labs" android:key="@string/p_show_featured_lists"
android:defaultValue="false"/> android:defaultValue="false"/>
<CheckBoxPreference <CheckBoxPreference

@ -13,7 +13,7 @@ public class DefaultFilterMode implements FilterModeSpec {
@Override @Override
public int[] getForbiddenMenuItems() { public int[] getForbiddenMenuItems() {
if (Preferences.getBoolean(R.string.p_show_featured_lists_labs, false)) if (Preferences.getBoolean(R.string.p_show_featured_lists, false))
return new int[0]; return new int[0];
else else
return new int[] { MainMenuPopover.MAIN_MENU_ITEM_FEATURED_LISTS }; return new int[] { MainMenuPopover.MAIN_MENU_ITEM_FEATURED_LISTS };

@ -574,7 +574,7 @@ public class EditPreferences extends TodorooPreferenceActivity {
return super.onPreferenceChange(p, newValue); return super.onPreferenceChange(p, newValue);
} }
}); });
} else if (r.getString(R.string.p_show_featured_lists_labs).equals(preference.getKey())) { } else if (r.getString(R.string.p_show_featured_lists).equals(preference.getKey())) {
preference.setOnPreferenceChangeListener(new SetResultOnPreferenceChangeListener(SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE) { preference.setOnPreferenceChangeListener(new SetResultOnPreferenceChangeListener(SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE) {
@Override @Override
public boolean onPreferenceChange(Preference p, Object newValue) { public boolean onPreferenceChange(Preference p, Object newValue) {

@ -123,10 +123,15 @@ public class ABTests {
public static final String AB_CALENDAR_REMINDERS = "android_cal_reminders"; //$NON-NLS-1$ public static final String AB_CALENDAR_REMINDERS = "android_cal_reminders"; //$NON-NLS-1$
public static final String AB_FEATURED_LISTS = "android_featured_lists"; //$NON-NLS-1$
private void initialize() { private void initialize() {
addTest(AB_FEATURED_LISTS, new int[] { 1, 1 },
new int[] { 1, 1 }, new String[] { "featured-lists-disabled", "featured-lists-enabled" }); //$NON-NLS-1$ //$NON-NLS-2$
addTest(AB_SIMPLE_TASK_ROW, new int[] { 1, 1 }, addTest(AB_SIMPLE_TASK_ROW, new int[] { 1, 1 },
new int[] { 1, 0 }, new String[] { "original-row-style", "simple-row-style" });//$NON-NLS-1$ //$NON-NLS-2$ new int[] { 1, 0 }, new String[] { "original-row-style", "simple-row-style" }); //$NON-NLS-1$ //$NON-NLS-2$
addTest(AB_CALENDAR_REMINDERS, new int[] { 0, 1 }, addTest(AB_CALENDAR_REMINDERS, new int[] { 0, 1 },
new int[] { 0, 1 }, new String[] { "no-cal-reminders", "show-cal-reminders" }); //$NON-NLS-1$ //$NON-NLS-2$ new int[] { 0, 1 }, new String[] { "no-cal-reminders", "show-cal-reminders" }); //$NON-NLS-1$ //$NON-NLS-2$

@ -22,6 +22,7 @@ import android.widget.TextView;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.tags.reusable.FeaturedListFilterExposer;
import com.todoroo.astrid.ui.TouchInterceptingFrameLayout.InterceptTouchListener; import com.todoroo.astrid.ui.TouchInterceptingFrameLayout.InterceptTouchListener;
import com.todoroo.astrid.utility.AstridPreferences; import com.todoroo.astrid.utility.AstridPreferences;
@ -120,7 +121,7 @@ public class MainMenuPopover extends FragmentPopover implements InterceptTouchLi
ThemeService.getDrawable(R.drawable.icn_menu_friends, themeFlags), ThemeService.getDrawable(R.drawable.icn_menu_friends, themeFlags),
MAIN_MENU_ITEM_FRIENDS, null, topFixed); MAIN_MENU_ITEM_FRIENDS, null, topFixed);
if (Preferences.getBoolean(R.string.p_show_featured_lists, false)) if (Preferences.getBoolean(FeaturedListFilterExposer.PREF_SHOULD_SHOW_FEATURED_LISTS, false))
addMenuItem(R.string.TLA_menu_featured_lists, addMenuItem(R.string.TLA_menu_featured_lists,
ThemeService.getDrawable(R.drawable.icn_featured_lists, themeFlags), ThemeService.getDrawable(R.drawable.icn_featured_lists, themeFlags),
MAIN_MENU_ITEM_FEATURED_LISTS, null, topFixed); MAIN_MENU_ITEM_FEATURED_LISTS, null, topFixed);

@ -25,6 +25,7 @@ import com.todoroo.astrid.data.User;
import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.service.abtesting.ABChooser; import com.todoroo.astrid.service.abtesting.ABChooser;
import com.todoroo.astrid.service.abtesting.ABTests; import com.todoroo.astrid.service.abtesting.ABTests;
import com.todoroo.astrid.tags.reusable.FeaturedListFilterExposer;
public class AstridPreferences { public class AstridPreferences {
@ -71,6 +72,9 @@ public class AstridPreferences {
Preferences.setIfUnset(prefs, editor, r, R.string.p_ideas_tab_enabled, true); Preferences.setIfUnset(prefs, editor, r, R.string.p_ideas_tab_enabled, true);
Preferences.setIfUnset(prefs, editor, r, R.string.p_show_featured_lists,
ABChooser.readChoiceForTest(ABTests.AB_FEATURED_LISTS) != 0);
Preferences.setIfUnset(prefs, editor, r, R.string.p_taskRowStyle, Preferences.setIfUnset(prefs, editor, r, R.string.p_taskRowStyle,
ABChooser.readChoiceForTest(ABTests.AB_SIMPLE_TASK_ROW) != 0); ABChooser.readChoiceForTest(ABTests.AB_SIMPLE_TASK_ROW) != 0);
@ -114,7 +118,7 @@ public class AstridPreferences {
} finally { } finally {
featLists.close(); featLists.close();
} }
Preferences.setBoolean(R.string.p_show_featured_lists, showFeaturedLists); Preferences.setBoolean(FeaturedListFilterExposer.PREF_SHOULD_SHOW_FEATURED_LISTS, showFeaturedLists);
} }
/* ====================================================================== /* ======================================================================

Loading…
Cancel
Save