From e88eec54a3f2e4ed0ab898b72aa4b200f48e5702 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Mon, 14 Jan 2013 12:20:09 -0800 Subject: [PATCH] Basic logic and layout for a title-only task adapter row --- .../layout/task_adapter_row_title_only.xml | 50 +++++++++++++++++++ .../astrid/activity/TaskListFragment.java | 1 + .../todoroo/astrid/adapter/TaskAdapter.java | 26 +++++++--- 3 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 astrid/res/layout/task_adapter_row_title_only.xml diff --git a/astrid/res/layout/task_adapter_row_title_only.xml b/astrid/res/layout/task_adapter_row_title_only.xml new file mode 100644 index 000000000..2c7417204 --- /dev/null +++ b/astrid/res/layout/task_adapter_row_title_only.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java index 6268118e6..f36ea0d0b 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java @@ -885,6 +885,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, case 1: return R.layout.task_adapter_row_simple; case 2: + return R.layout.task_adapter_row_title_only; case 0: default: return R.layout.task_adapter_row; diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java index 488820e80..f27d52cea 100644 --- a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java @@ -35,6 +35,7 @@ import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextUtils; +import android.text.TextUtils.TruncateAt; import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; @@ -186,6 +187,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable { protected OnCompletedTaskListener onCompletedTaskListener = null; public boolean isFling = false; protected final int resource; + protected final boolean titleOnly; protected final LayoutInflater inflater; private DetailLoaderThread detailLoader; private ActionsLoaderThread actionsLoader; @@ -229,6 +231,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable { this.query = query; this.resource = resource; + this.titleOnly = resource == R.layout.task_adapter_row_title_only; this.fragment = fragment; this.resources = fragment.getResources(); this.onCompletedTaskListener = onCompletedTaskListener; @@ -336,10 +339,14 @@ public class TaskAdapter extends CursorAdapter implements Filterable { boolean showFullTaskTitle = Preferences.getBoolean(R.string.p_fullTaskTitle, false); boolean showNotes = Preferences.getBoolean(R.string.p_showNotes, false); - if (showFullTaskTitle) { + if (showFullTaskTitle && !titleOnly) { viewHolder.nameView.setMaxLines(Integer.MAX_VALUE); viewHolder.nameView.setSingleLine(false); viewHolder.nameView.setEllipsize(null); + } else if (titleOnly) { + viewHolder.nameView.setMaxLines(1); + viewHolder.nameView.setSingleLine(true); + viewHolder.nameView.setEllipsize(TruncateAt.END); } if (showNotes && !simpleLayout) { @@ -355,7 +362,8 @@ public class TaskAdapter extends CursorAdapter implements Filterable { viewHolder.details1.setTag(viewHolder); // add UI component listeners - addListeners(view); + if (!titleOnly) + addListeners(view); return view; } @@ -374,7 +382,8 @@ public class TaskAdapter extends CursorAdapter implements Filterable { task.readFromCursor(cursor); setFieldContentsAndVisibility(view); - setTaskAppearance(viewHolder, task); + if (!titleOnly) + setTaskAppearance(viewHolder, task); } /** @@ -407,12 +416,14 @@ public class TaskAdapter extends CursorAdapter implements Filterable { public synchronized void setFieldContentsAndVisibility(View view) { ViewHolder viewHolder = (ViewHolder)view.getTag(); Task task = viewHolder.task; - if (fontSize < 16) { + if (fontSize < 16 || titleOnly) { viewHolder.rowBody.setMinimumHeight(0); - viewHolder.completeBox.setMinimumHeight(0); + if (viewHolder.completeBox != null) + viewHolder.completeBox.setMinimumHeight(0); } else { viewHolder.rowBody.setMinimumHeight(minRowHeight); - viewHolder.completeBox.setMinimumHeight(minRowHeight); + if (viewHolder.completeBox != null) + viewHolder.completeBox.setMinimumHeight(minRowHeight); } if (task.isEditable()) @@ -432,6 +443,9 @@ public class TaskAdapter extends CursorAdapter implements Filterable { nameView.setText(nameValue); } + if (titleOnly) + return; + float dueDateTextWidth = setupDueDateAndTags(viewHolder, task); String details;