All new preference defaults for Astrid Lite version

pull/14/head
Sam Bosley 12 years ago
parent c8fd358efb
commit dec4a0d335

@ -51,6 +51,20 @@ public class Preferences {
editor.putBoolean(key, value);
}
/**
* Helper to write to editor if key specified is null
* @param prefs
* @param editor
* @param r
* @param keyResource
* @param value
*/
public static void setIfUnset(SharedPreferences prefs, Editor editor, Resources r, int keyResource, String value) {
String key = r.getString(keyResource);
if(!prefs.contains(key) || !(prefs.getAll().get(key) instanceof Boolean))
editor.putString(key, value);
}
/* ======================================================================
* ======================================================= helper methods
* ====================================================================== */

@ -17,6 +17,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
@ -78,6 +79,7 @@ public class TagViewFragment extends TaskListFragment {
public static final String EXTRA_TAG_DATA = "tagData"; //$NON-NLS-1$
protected static final int MENU_REFRESH_ID = MENU_SUPPORT_ID + 1;
protected static final int MENU_LIST_SETTINGS_ID = R.string.tag_settings_title;
private static final int REQUEST_CODE_SETTINGS = 0;
@ -183,6 +185,16 @@ public class TagViewFragment extends TaskListFragment {
}
}
@Override
protected void addMenuItems(Menu menu, Activity activity) {
super.addMenuItems(menu, activity);
if (!Preferences.getBoolean(R.string.p_show_list_members, true)) {
MenuItem item = menu.add(Menu.NONE, MENU_LIST_SETTINGS_ID, 0, R.string.tag_settings_title);
item.setIcon(R.drawable.list_settings);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
}
// --- data loading
@Override
@ -310,6 +322,10 @@ public class TagViewFragment extends TaskListFragment {
}
protected void setUpMembersGallery() {
if (!Preferences.getBoolean(R.string.p_show_list_members, true)) {
getView().findViewById(R.id.members_header).setVisibility(View.GONE);
return;
}
if (tagData == null)
return;
LinearLayout membersView = (LinearLayout)getView().findViewById(R.id.shared_with);
@ -546,6 +562,9 @@ public class TagViewFragment extends TaskListFragment {
case MENU_REFRESH_ID:
refreshData(true);
return true;
case MENU_LIST_SETTINGS_ID:
settingsListener.onClick(null);
return true;
}
return super.handleOptionsMenuItemSelected(id, intent);

@ -27,6 +27,7 @@ import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.activity.FilterListFragment;
import com.todoroo.astrid.api.AstridApiConstants;
@ -100,11 +101,18 @@ public final class CustomFilterExposer extends BroadcastReceiver implements Astr
private Filter[] buildSavedFilters(Context context, Resources r) {
int themeFlags = ThemeService.getFilterThemeFlags();
boolean useCustomFilters = Preferences.getBoolean(R.string.p_use_filters, true);
StoreObjectDao dao = PluginServices.getStoreObjectDao();
TodorooCursor<StoreObject> cursor = dao.query(Query.select(StoreObject.PROPERTIES).where(
TodorooCursor<StoreObject> cursor = null;
if (useCustomFilters)
cursor = dao.query(Query.select(StoreObject.PROPERTIES).where(
StoreObject.TYPE.eq(SavedFilter.TYPE)).orderBy(Order.asc(SavedFilter.NAME)));
try {
Filter[] list = new Filter[cursor.getCount() + 3];
Filter[] list;
if (useCustomFilters && cursor != null)
list = new Filter[cursor.getCount() + 3];
else
list = new Filter[3];
// stock filters
list[0] = getTodayFilter(r);
@ -120,24 +128,27 @@ public final class CustomFilterExposer extends BroadcastReceiver implements Astr
list[2] = getAssignedByMeFilter(r);
StoreObject savedFilter = new StoreObject();
for(int i = 3; i < list.length; i++) {
cursor.moveToNext();
savedFilter.readFromCursor(cursor);
list[i] = SavedFilter.load(savedFilter);
Intent deleteIntent = new Intent(context, DeleteActivity.class);
deleteIntent.putExtra(TOKEN_FILTER_ID, savedFilter.getId());
deleteIntent.putExtra(TOKEN_FILTER_NAME, list[i].title);
list[i].contextMenuLabels = new String[] { context.getString(R.string.BFE_Saved_delete) };
list[i].contextMenuIntents = new Intent[] { deleteIntent };
list[i].listingIcon = ((BitmapDrawable)r.getDrawable(
ThemeService.getDrawable(R.drawable.filter_sliders, themeFlags))).getBitmap();
if (useCustomFilters && cursor != null) {
StoreObject savedFilter = new StoreObject();
for(int i = 3; i < list.length; i++) {
cursor.moveToNext();
savedFilter.readFromCursor(cursor);
list[i] = SavedFilter.load(savedFilter);
Intent deleteIntent = new Intent(context, DeleteActivity.class);
deleteIntent.putExtra(TOKEN_FILTER_ID, savedFilter.getId());
deleteIntent.putExtra(TOKEN_FILTER_NAME, list[i].title);
list[i].contextMenuLabels = new String[] { context.getString(R.string.BFE_Saved_delete) };
list[i].contextMenuIntents = new Intent[] { deleteIntent };
list[i].listingIcon = ((BitmapDrawable)r.getDrawable(
ThemeService.getDrawable(R.drawable.filter_sliders, themeFlags))).getBitmap();
}
}
return list;
} finally {
cursor.close();
if (cursor != null)
cursor.close();
}
}

@ -10,7 +10,6 @@ import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.Menu;
import android.view.MenuInflater;
import android.widget.TextView;
import com.timsu.astrid.R;
@ -110,8 +109,8 @@ public class GtasksListFragment extends SubtasksListFragment {
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
protected void addMenuItems(Menu menu, Activity activity) {
super.addMenuItems(menu, activity);
addMenuItem(menu, R.string.gtasks_GTA_clear_completed, android.R.drawable.ic_input_delete, MENU_CLEAR_COMPLETED_ID, false);
}

@ -9,7 +9,6 @@ import android.support.v4.view.MenuItem;
import android.text.TextUtils;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
@ -64,10 +63,8 @@ public class FeaturedTaskListFragment extends TagViewFragment {
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
if (!isCurrentTaskListFragment())
return;
protected void addMenuItems(Menu menu, Activity activity) {
super.addMenuItems(menu, activity);
MenuItem item = menu.add(Menu.NONE, MENU_CLONE_LIST, 0, R.string.actfm_feat_list_clone);
item.setIcon(R.drawable.ic_menu_list_copy);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

@ -12,6 +12,7 @@
android:layout_weight="100">
<LinearLayout
android:id="@+id/members_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

@ -316,6 +316,12 @@
<!-- on calendar end at dealline if true, start at deadline if false -->
<string name="p_end_at_deadline">p_end_at_deadline</string>
<!-- whether custom filters are enabled -->
<string name="p_use_filters">p_use_filters</string>
<!-- whether list members header should be shown -->
<string name="p_show_list_members">p_show_list_members</string>
<string-array name="EPr_default_addtocalendar_values">
<!-- addtocalendar: labels that map EPr_default_addtocalendar items to calendar selection in settings. -->
<item>-1</item>

@ -698,6 +698,14 @@
<string name="EPr_task_row_style_summary_simple">Truncate title to one line with date and lists below</string>
<string name="EPr_task_row_style_summary_legacy">Truncate title to two lines with date on right</string>
<!-- Preference: custom filters enabled -->
<string name="EPr_use_filters_title">Use filters</string>
<string name="EPr_use_filters_subtitle">Lets you create custom filters</string>
<!-- Preference: show list members in shared list -->
<string name="EPr_show_list_members_title">Show list members in shared lists</string>
<!-- slide 30f/ 36f: Preference: Theme -->
<string name="EPr_theme_title">Color theme</string>
<!-- Preference: Theme Description (%s => value) -->

@ -78,6 +78,12 @@
android:title="@string/EPr_ideaAuto_title"
android:defaultValue="true" />
<com.todoroo.astrid.ui.MultilineCheckboxPreference
android:key="@string/p_use_filters"
android:title="@string/EPr_use_filters_title"
android:summary="@string/EPr_use_filters_subtitle"
android:defaultValue="true"/>
<CheckBoxPreference
android:title="@string/EPr_force_phone_layout"
android:key="@string/p_force_phone_layout"
@ -88,6 +94,11 @@
android:title="@string/EPr_swipe_lists_performance_title"
android:defaultValue="false"/>
<com.todoroo.astrid.ui.MultilineCheckboxPreference
android:key="@string/p_show_list_members"
android:title="@string/EPr_show_list_members_title"
android:defaultValue="true"/>
<CheckBoxPreference
android:title="@string/EPr_show_featured_lists"
android:key="@string/p_show_featured_lists"

@ -77,6 +77,31 @@ public class BeastModePreferences extends ListActivity {
Preferences.setBoolean(BEAST_MODE_ASSERTED_HIDE_ALWAYS, true);
}
public static void setDefaultLiteModeOrder(Context context) {
if (Preferences.getStringValue(BEAST_MODE_ORDER_PREF) != null)
return;
ArrayList<String> list = constructOrderedControlList(context);
String moreSeparator = context.getResources().getString(R.string.TEA_ctrl_more_pref);
String importancePref = context.getResources().getString(R.string.TEA_ctrl_importance_pref);
String listsPref = context.getResources().getString(R.string.TEA_ctrl_lists_pref);
list.remove(importancePref);
list.remove(listsPref);
int moreIndex = list.indexOf(moreSeparator);
if (moreIndex >= 0) {
list.add(moreIndex + 1, listsPref);
list.add(moreIndex + 1, importancePref);
}
StringBuilder newSetting = new StringBuilder(30);
for (String item : list) {
newSetting.append(item);
newSetting.append(BEAST_MODE_PREF_ITEM_SEPARATOR);
}
Preferences.setString(BEAST_MODE_ORDER_PREF, newSetting.toString());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

@ -170,8 +170,8 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
ThemeService.applyTheme(this);
super.onCreate(savedInstanceState);
ThemeService.applyTheme(this);
DependencyInjectionService.getInstance().inject(this);
int contentView = getContentView();

@ -428,20 +428,23 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
* @return true if menu should be displayed
*/
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
public final void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Activity activity = getActivity();
if (activity == null)
return;
if (!isCurrentTaskListFragment())
return;
addMenuItems(menu, activity);
}
protected void addMenuItems(Menu menu, Activity activity) {
boolean isTablet = AstridPreferences.useTabletLayout(activity);
TaskListActivity tla = null;
if (activity instanceof TaskListActivity) {
tla = (TaskListActivity) activity;
tla.getMainMenuPopover().clear();
}
// --- sync
if (tla == null || tla.getTaskEditFragment() == null)
addSyncRefreshMenuItem(menu, isTablet ? ThemeService.FLAG_INVERT : 0);
@ -453,8 +456,9 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
}
// --- new filter
addMenuItem(menu, R.string.FLA_new_filter,
ThemeService.getDrawable(R.drawable.icn_menu_filters, isTablet ? ThemeService.FLAG_FORCE_DARK: 0), MENU_NEW_FILTER_ID, false);
if (Preferences.getBoolean(R.string.p_use_filters, true))
addMenuItem(menu, R.string.FLA_new_filter,
ThemeService.getDrawable(R.drawable.icn_menu_filters, isTablet ? ThemeService.FLAG_FORCE_DARK: 0), MENU_NEW_FILTER_ID, false);
// --- addons
if(Constants.MARKET_STRATEGY.showAddonMenu())

@ -143,9 +143,11 @@ public class ABTests {
* (i.e. the arrays should be the same length if this one exists)
*
*/
public void addTest(String testKey, int[] newUserProbs, int[] existingUserProbs, String[] descriptions) {
ABTestBundle bundle = new ABTestBundle(newUserProbs, existingUserProbs, descriptions);
bundles.put(testKey, bundle);
public void addTest(String testKey, int[] newUserProbs, int[] existingUserProbs, String[] descriptions, boolean appliesToAstridLite) {
if (appliesToAstridLite) {
ABTestBundle bundle = new ABTestBundle(newUserProbs, existingUserProbs, descriptions);
bundles.put(testKey, bundle);
}
}
public static final String AB_FEATURED_LISTS = "android_featured_lists"; //$NON-NLS-1$
@ -163,15 +165,15 @@ public class ABTests {
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$
new int[] { 1, 1 }, new String[] { "featured-lists-disabled", "featured-lists-enabled" }, false); //$NON-NLS-1$ //$NON-NLS-2$
addTest(AB_SOCIAL_REMINDERS, new int[] { 1, 1 },
new int[] { 1, 1 }, new String[] { "no-faces", "show-faces" }); //$NON-NLS-1$ //$NON-NLS-2$
new int[] { 1, 1 }, new String[] { "no-faces", "show-faces" }, true); //$NON-NLS-1$ //$NON-NLS-2$
addTest(AB_DRAG_DROP, new int[] { 3, 1 },
new int[] { 1, 0 }, new String[] { "off-by-default", "on-by-default" }); //$NON-NLS-1$ //$NON-NLS-2$
new int[] { 1, 0 }, new String[] { "off-by-default", "on-by-default" }, false); //$NON-NLS-1$ //$NON-NLS-2$
addTest(AB_DEFAULT_EDIT_TAB, new int[] { 1, 1 },
new int[] { 1, 1 }, new String[] { "activity-tab", "details-tab" }); //$NON-NLS-1$ //$NON-NLS-2$
new int[] { 1, 1 }, new String[] { "activity-tab", "details-tab" }, true); //$NON-NLS-1$ //$NON-NLS-2$
}
}

@ -17,6 +17,7 @@ import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.BeastModePreferences;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.core.SortHelper;
@ -51,6 +52,13 @@ public class AstridPreferences {
/** Set preference defaults, if unset. called at startup */
public static void setPreferenceDefaults() {
if (Constants.ASTRID_LITE)
setLitePreferenceDefaults();
else
setNormalPreferenceDefaults();
}
private static void setNormalPreferenceDefaults() {
Context context = ContextManager.getContext();
SharedPreferences prefs = Preferences.getPrefs(context);
Editor editor = prefs.edit();
@ -116,6 +124,70 @@ public class AstridPreferences {
editor.commit();
}
private static void setLitePreferenceDefaults() {
Context context = ContextManager.getContext();
SharedPreferences prefs = Preferences.getPrefs(context);
Editor editor = prefs.edit();
Resources r = context.getResources();
Preferences.setIfUnset(prefs, editor, r, R.string.p_default_urgency_key, 4);
Preferences.setIfUnset(prefs, editor, r, R.string.p_default_importance_key, 2);
Preferences.setIfUnset(prefs, editor, r, R.string.p_default_hideUntil_key, 0);
Preferences.setIfUnset(prefs, editor, r, R.string.p_default_reminders_key, Task.NOTIFY_AT_DEADLINE | Task.NOTIFY_AFTER_DEADLINE);
Preferences.setIfUnset(prefs, editor, r, R.string.p_default_reminders_mode_key, 16);
Preferences.setIfUnset(prefs, editor, r, R.string.p_rmd_default_random_hours, 0);
Preferences.setIfUnset(prefs, editor, r, R.string.p_fontSize, 18);
Preferences.setIfUnset(prefs, editor, r, R.string.p_showNotes, false);
Preferences.setIfUnset(prefs, editor, r, R.string.p_use_contact_picker, false);
Preferences.setIfUnset(prefs, editor, r, R.string.p_field_missed_calls, true);
Preferences.setIfUnset(prefs, editor, r, R.string.p_third_party_addons, false);
Preferences.setIfUnset(prefs, editor, r, R.string.p_end_at_deadline, true);
Preferences.setIfUnset(prefs, editor, r, R.string.p_rmd_persistent, true);
Preferences.setIfUnset(prefs, editor, r, R.string.p_ideas_tab_enabled, false);
Preferences.setIfUnset(prefs, editor, r, R.string.p_autoIdea, false);
Preferences.setIfUnset(prefs, editor, r, R.string.p_show_featured_lists, false);
Preferences.setIfUnset(prefs, editor, r, R.string.p_taskRowStyle, true);
Preferences.setIfUnset(prefs, editor, r, R.string.p_calendar_reminders, true);
Preferences.setIfUnset(prefs, editor, r, R.string.p_social_reminders,
ABChooser.readChoiceForTest(ABTests.AB_SOCIAL_REMINDERS) != 0);
Preferences.setIfUnset(prefs, editor, r, R.string.p_use_filters, false);
Preferences.setIfUnset(prefs, editor, r, R.string.p_show_list_members, false);
SharedPreferences publicPrefs = getPublicPrefs(context);
if (publicPrefs != null) {
Editor edit = publicPrefs.edit();
if (edit != null) {
edit.putInt(SortHelper.PREF_SORT_FLAGS, SortHelper.FLAG_DRAG_DROP);
edit.putInt(SortHelper.PREF_SORT_SORT, SortHelper.SORT_AUTO);
edit.commit();
Preferences.setInt(P_SUBTASKS_HELP, 1);
}
}
BeastModePreferences.setDefaultLiteModeOrder(context);
Preferences.setIfUnset(prefs, editor, r, R.string.p_theme, ThemeService.THEME_WHITE_RED);
Preferences.setIfUnset(prefs, editor, r, R.string.p_force_phone_layout, true);
setShowFriendsView();
setShowFeaturedLists();
editor.commit();
}
/**
* Reset preferences based on archived AB tests
* @param fromVersion

@ -43,6 +43,11 @@ public final class Constants {
*/
public static final boolean DEBUG = false;
/**
* Whether this version is Astrid Lite
*/
public static final boolean ASTRID_LITE = true;
/**
* Astrid Help URL
*/

@ -91,7 +91,7 @@ public class ABTestingServiceTest extends DatabaseTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
abTests.addTest(TEST_NAME, new int[] { 9, 1 } , new int[] { 1, 9 }, TEST_OPTIONS);
abTests.addTest(TEST_NAME, new int[] { 9, 1 } , new int[] { 1, 9 }, TEST_OPTIONS, true);
Preferences.clear(TEST_NAME);
}

Loading…
Cancel
Save