Lots of refactoring to support more than two task row styles in preparation for a 'titles only' style

pull/14/head
Sam Bosley 12 years ago
parent 2e14941b17
commit 6d5a25170c

@ -181,10 +181,8 @@ public class AstridOrderedListFragmentHelper<LIST> implements OrderedListFragmen
public TaskAdapter createTaskAdapter(TodorooCursor<Task> cursor,
AtomicReference<String> sqlQueryTemplate) {
int resource = Preferences.getBoolean(R.string.p_taskRowStyle, false) ?
R.layout.task_adapter_row_simple : R.layout.task_adapter_row;
taskAdapter = new DraggableTaskAdapter(fragment, resource,
taskAdapter = new DraggableTaskAdapter(fragment, TaskListFragment.getTaskRowResource(),
cursor, sqlQueryTemplate, false, null);
getTouchListView().setItemHightNormal(taskAdapter.computeFullRowHeight());

@ -194,10 +194,8 @@ public class OrderedMetadataListFragmentHelper<LIST> implements OrderedListFragm
public TaskAdapter createTaskAdapter(TodorooCursor<Task> cursor,
AtomicReference<String> sqlQueryTemplate) {
int resource = Preferences.getBoolean(R.string.p_taskRowStyle, false) ?
R.layout.task_adapter_row_simple : R.layout.task_adapter_row;
taskAdapter = new DraggableTaskAdapter(fragment, resource,
taskAdapter = new DraggableTaskAdapter(fragment, TaskListFragment.getTaskRowResource(),
cursor, sqlQueryTemplate, false, null);
taskAdapter.addOnCompletedTaskListener(new OnCompletedTaskListener() {

@ -217,7 +217,13 @@
<!-- ======================================================= APPEARANCE == -->
<string name="p_fontSize">font_size</string>
<string name="p_taskRowStyle">p_taskRowStyle</string>
<string name="p_taskRowStyle">p_taskRowStyle</string> <!-- DEPRECATED -->
<string name="p_taskRowStyle_v2">p_taskRowStyle_v2</string>
<string-array name="EPr_task_row_style_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string name="p_showNotes">notesVisible</string>
<string name="p_beastMode">beastMode</string>
<string name="p_transparent_deprecated">transparent</string>

@ -707,10 +707,20 @@
<string name="EPr_ideaAuto_desc_disabled">Web searches for ideas tab will be performed only when manually requested</string>
<!-- Preferences: task row style -->
<string name="EPr_task_row_style_title_simple">Row style: Simple</string>
<string name="EPr_task_row_style_title_legacy">Row style: Original</string>
<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>
<string-array name="EPr_task_row_styles">
<item>Original</item>
<item>Simple</item>
<item>Title only</item>
</string-array>
<string-array name="EPr_task_row_style_descriptions">
<item>Truncate title to two lines with date on right</item>
<item>Truncate title to one line with date and lists below</item>
<item>Single line title only</item>
</string-array>
<!-- task row style title (%s -> style) -->
<string name="EPr_task_row_style_title">Row style: %s</string>
<!-- Preference: custom filters enabled -->
<string name="EPr_use_filters_title">Use filters</string>

@ -49,9 +49,10 @@
android:title="@string/EPr_fontSize_title"
android:summary="@string/EPr_fontSize_desc" />
<com.todoroo.astrid.ui.MultilineCheckboxPreference
android:key="@string/p_taskRowStyle"
android:defaultValue="false"/>
<com.todoroo.astrid.ui.MultilineListPreference
android:key="@string/p_taskRowStyle_v2"
android:entries="@array/EPr_task_row_styles"
android:entryValues="@array/EPr_task_row_style_values" />
<com.todoroo.astrid.ui.MultilineCheckboxPreference
android:key="@string/p_fullTaskTitle"

@ -253,7 +253,7 @@ public class EditPreferences extends TodorooPreferenceActivity {
}
preference = screen.findPreference(getString(R.string.p_showNotes));
preference.setEnabled(!Preferences.getBoolean(R.string.p_taskRowStyle, false));
preference.setEnabled(Preferences.getIntegerFromString(R.string.p_taskRowStyle_v2, 0) == 0);
removeForbiddenPreferences(screen, r);
}
@ -500,14 +500,18 @@ public class EditPreferences extends TodorooPreferenceActivity {
}
preference.setTitle(title);
preference.setSummary(summary);
} else if (r.getString(R.string.p_taskRowStyle).equals(preference.getKey())) {
if (value != null && !(Boolean)value) {
preference.setTitle(R.string.EPr_task_row_style_title_legacy);
preference.setSummary(R.string.EPr_task_row_style_summary_legacy);
} else {
preference.setTitle(R.string.EPr_task_row_style_title_simple);
preference.setSummary(R.string.EPr_task_row_style_summary_simple);
} else if (r.getString(R.string.p_taskRowStyle_v2).equals(preference.getKey())) {
try {
Integer valueInt = Integer.parseInt((String) value);
String[] titles = getResources().getStringArray(R.array.EPr_task_row_styles);
String[] descriptions = getResources().getStringArray(R.array.EPr_task_row_style_descriptions);
preference.setTitle(getString(R.string.EPr_task_row_style_title, titles[valueInt]));
preference.setSummary(descriptions[valueInt]);
} catch (Exception e) {
//
}
preference.setOnPreferenceChangeListener(new SetResultOnPreferenceChangeListener(RESULT_CODE_PERFORMANCE_PREF_CHANGED) {
@Override
public boolean onPreferenceChange(Preference p, Object newValue) {
@ -515,7 +519,11 @@ public class EditPreferences extends TodorooPreferenceActivity {
StatisticsService.reportEvent(StatisticsConstants.PREF_CHANGED_PREFIX + "row-style", //$NON-NLS-1$
"changed-to", valueString); //$NON-NLS-1$
Preference notes = findPreference(getString(R.string.p_showNotes));
notes.setEnabled(!(Boolean) newValue);
try {
notes.setEnabled(Integer.parseInt((String) newValue) == 0);
} catch (Exception e) {
e.printStackTrace();
}
return super.onPreferenceChange(p, newValue);
};
});

@ -879,11 +879,21 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
syncActionHelper.request();
}
public static int getTaskRowResource() {
int rowStyle = Preferences.getIntegerFromString(R.string.p_taskRowStyle_v2, 0);
switch(rowStyle) {
case 1:
return R.layout.task_adapter_row_simple;
case 2:
case 0:
default:
return R.layout.task_adapter_row;
}
}
protected TaskAdapter createTaskAdapter(TodorooCursor<Task> cursor) {
int resource = Preferences.getBoolean(R.string.p_taskRowStyle, false) ?
R.layout.task_adapter_row_simple : R.layout.task_adapter_row;
return new TaskAdapter(this, resource,
return new TaskAdapter(this, getTaskRowResource(),
cursor, sqlQueryTemplate, false,
new OnCompletedTaskListener() {
@Override

@ -50,6 +50,7 @@ import com.todoroo.astrid.utility.Constants;
public final class UpgradeService {
public static final int V4_5_1 = 292;
public static final int V4_5_0 = 291;
public static final int V4_4_4_1 = 290;
public static final int V4_4_4 = 289;
@ -182,6 +183,8 @@ public final class UpgradeService {
Preferences.setInt(AstridPreferences.P_UPGRADE_FROM, from);
inlineUpgrades(context, from); // Migrations that are short or don't require launching a separate activity
if(from < maxWithUpgrade) {
Intent upgrade = new Intent(context, UpgradeActivity.class);
upgrade.putExtra(UpgradeActivity.TOKEN_FROM_VERSION, from);
@ -251,6 +254,17 @@ public final class UpgradeService {
}
}
private void inlineUpgrades(Context context, int from) {
if (from < V4_5_1) {
String key = context.getString(R.string.p_taskRowStyle);
if (Preferences.isSet(key)) {
boolean value = Preferences.getBoolean(key, true);
Preferences.clear(key);
Preferences.setString(R.string.p_taskRowStyle_v2, value ? "1" : "0"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
/**
* Return a change log string. Releases occur often enough that we don't
* expect change sets to be localized.

@ -117,8 +117,6 @@ public class AstridDefaultPreferenceSpec extends AstridPreferenceSpec {
setPreference(prefs, editor, r, R.string.p_show_menu_sort, true, ifUnset);
setPreference(prefs, editor, r, R.string.p_show_menu_addons, true, ifUnset);
setPreference(prefs, editor, r, R.string.p_taskRowStyle, false, ifUnset);
setPreference(prefs, editor, r, R.string.p_calendar_reminders, true, ifUnset);
setPreference(prefs, editor, r, R.string.p_use_filters, true, ifUnset);
@ -136,6 +134,8 @@ public class AstridDefaultPreferenceSpec extends AstridPreferenceSpec {
setPreference(prefs, editor, r, R.string.p_show_task_edit_comments, true, ifUnset);
setPreference(prefs, editor, r, R.string.p_taskRowStyle_v2, "0", ifUnset); //$NON-NLS-1$
setPreference(prefs, editor, r, R.string.p_use_date_shortcuts,
ABChooser.readChoiceForTest(ABTests.AB_USE_DATE_SHORTCUTS) != 0, ifUnset);

@ -91,8 +91,6 @@ public class AstridLitePreferenceSpec extends AstridPreferenceSpec {
setPreference(prefs, editor, r, R.string.p_ideas_tab_enabled, false, ifUnset);
setPreference(prefs, editor, r, R.string.p_autoIdea, false, ifUnset);
setPreference(prefs, editor, r, R.string.p_taskRowStyle, true, ifUnset);
setPreference(prefs, editor, r, R.string.p_calendar_reminders, true, ifUnset);
setPreference(prefs, editor, r, R.string.p_use_filters, false, ifUnset);
@ -122,6 +120,8 @@ public class AstridLitePreferenceSpec extends AstridPreferenceSpec {
setPreference(prefs, editor, r, R.string.p_show_task_edit_comments, false, ifUnset);
setPreference(prefs, editor, r, R.string.p_taskRowStyle_v2, "0", ifUnset); //$NON-NLS-1$
setPreference(prefs, editor, r, R.string.p_use_date_shortcuts, false, ifUnset);
extras.setExtras(context, prefs, editor, r, ifUnset);

Loading…
Cancel
Save