Text filter, and Now we can turn on or off the text filter based on what's inside so we can still change priorities

pull/14/head
Tim Su 15 years ago
parent 03399811f7
commit 7c5ba12073

@ -17,8 +17,15 @@ public class BackupConstants {
// Do NOT edit the constants in this file! You will break compatibility with old backups
/** Astrid tag (contains everything else) */
public static final String ASTRID_TAG = "astrid";
/** Attribute indicating application version */
public static final String ASTRID_ATTR_VERSION = "version";
/** Attribute indicating backup file format */
public static final String ASTRID_ATTR_FORMAT = "format";
public static final String TASK_TAG = "task";
public static final String TAG_TAG = "tag";
public static final String TAG_ATTR_NAME = "name";

@ -136,20 +136,27 @@ public class TasksXmlImporter {
if (tag != null) {
// Process <astrid ... >
if (tag.equals(BackupConstants.ASTRID_TAG)) {
String version = xpp.getAttributeValue(null, BackupConstants.ASTRID_ATTR_VERSION);
String version = xpp.getAttributeValue(null, BackupConstants.ASTRID_ATTR_FORMAT);
int intVersion;
try {
intVersion = Integer.parseInt(version);
intVersion = version == null ? 1 : Integer.parseInt(version);
} catch (Exception e) {
throw new UnsupportedOperationException(
"Did not know how to import tasks with version '" +
"Did not know how to import tasks with xml format '" +
version + "'");
}
if(intVersion <= 135)
switch(intVersion) {
case 1:
new Astrid2TaskImporter(xpp);
else
break;
case 2:
new Astrid3TaskImporter(xpp);
break;
default:
throw new UnsupportedOperationException(
"Did not know how to import tasks with xml format number '" +
version + "'");
}
}
}
}

@ -68,7 +68,7 @@ public class LocaleReceiver extends BroadcastReceiver {
DependencyInjectionService.getInstance().inject(this);
Filter filter = new Filter(title, title, null, null);
filter.sqlQuery = sql;
TodorooCursor<Task> cursor = taskService.fetchFiltered(filter, Task.ID);
TodorooCursor<Task> cursor = taskService.fetchFiltered(filter, null, Task.ID);
try {
if(cursor.getCount() == 0)
return;

@ -54,7 +54,6 @@
<ListView android:id="@android:id/list"
android:scrollbars="vertical"
android:cacheColorHint="#00000000"
android:textFilterEnabled="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

@ -17,6 +17,7 @@ import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@ -229,17 +230,28 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
getListView().setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View view, int keyCode, KeyEvent event) {
if(event.getAction() != KeyEvent.ACTION_UP)
if(event.getAction() != KeyEvent.ACTION_UP || view == null)
return false;
boolean filterOn = getListView().isTextFilterEnabled();
View selected = getListView().getSelectedView();
// hot-key to set task priority - 1-4 or ALT + Q-R
if(event.getNumber() >= '1' && event.getNumber() <= '4') {
view = getListView().getSelectedView();
if(!filterOn && event.getNumber() >= '1' && event.getNumber() <= '4' && selected != null) {
int importance = event.getNumber() - '1';
Task task = ((ViewHolder)view.getTag()).task;
Task task = ((ViewHolder)selected.getTag()).task;
task.setValue(Task.IMPORTANCE, importance);
taskService.save(task, false);
taskAdapter.setFieldContentsAndVisibility(view);
taskAdapter.setFieldContentsAndVisibility(selected);
}
// filter
else if(!filterOn && event.getUnicodeChar() != 0) {
getListView().setTextFilterEnabled(true);
getListView().setFilterText(Character.toString((char)event.getUnicodeChar()));
}
// turn off filter if nothing is selected
else if(filterOn && TextUtils.isEmpty(getListView().getTextFilter())) {
getListView().setTextFilterEnabled(false);
}
return false;
@ -498,12 +510,12 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
// perform query
TodorooCursor<Task> currentCursor = taskService.fetchFiltered(
filter, TaskAdapter.PROPERTIES);
filter, null, TaskAdapter.PROPERTIES);
startManagingCursor(currentCursor);
// set up list adapters
taskAdapter = new TaskAdapter(this, R.layout.task_adapter_row,
currentCursor, false, null);
currentCursor, filter, false, null);
setListAdapter(taskAdapter);
getListView().setOnScrollListener(this);
registerForContextMenu(getListView());
@ -534,7 +546,8 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
else
filter.sqlQuery = filter.sqlQuery.replace("WHERE ", "WHERE " +
TaskCriteria.byId(withCustomId) + " OR ");
currentCursor = taskService.fetchFiltered(filter, TaskAdapter.PROPERTIES);
currentCursor = taskService.fetchFiltered(filter, null, TaskAdapter.PROPERTIES);
getListView().setFilterText("");
startManagingCursor(currentCursor);
taskAdapter.changeCursor(currentCursor);

@ -41,6 +41,7 @@ import com.todoroo.andlib.utility.SoftHashMap;
import com.todoroo.astrid.activity.TaskEditActivity;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.DetailExposer;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.TaskAction;
import com.todoroo.astrid.api.TaskDecoration;
import com.todoroo.astrid.model.Task;
@ -104,6 +105,8 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
private final LayoutInflater inflater;
private int fontSize;
private final Filter filter;
// the task that's expanded
private long expanded = -1;
@ -129,7 +132,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
* task listener. can be null
*/
public TaskAdapter(ListActivity activity, int resource,
TodorooCursor<Task> c, boolean autoRequery,
Cursor c, Filter filter, boolean autoRequery,
OnCompletedTaskListener onCompletedTaskListener) {
super(activity, c, autoRequery);
DependencyInjectionService.getInstance().inject(this);
@ -137,6 +140,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
inflater = (LayoutInflater) activity.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
this.filter = filter;
this.resource = resource;
this.activity = activity;
this.onCompletedTaskListener = onCompletedTaskListener;
@ -150,6 +154,23 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
}
}
/* ======================================================================
* =========================================================== filterable
* ====================================================================== */
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
if (getFilterQueryProvider() != null) {
return getFilterQueryProvider().runQuery(constraint);
}
// perform query
TodorooCursor<Task> newCursor = taskService.fetchFiltered(
filter, constraint, TaskAdapter.PROPERTIES);
activity.startManagingCursor(newCursor);
return newCursor;
}
/* ======================================================================
* =========================================================== view setup
* ====================================================================== */

@ -4,6 +4,7 @@ import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
@ -151,14 +152,34 @@ public class TaskService {
/**
* Fetch tasks for the given filter
* @param properties
* @param constraint text constraint, or null
* @param filter
* @return
*/
public TodorooCursor<Task> fetchFiltered(Filter filter, Property<?>... properties) {
if(filter == null || filter.sqlQuery == null)
@SuppressWarnings("nls")
public TodorooCursor<Task> fetchFiltered(Filter filter, CharSequence constraint,
Property<?>... properties) {
Criterion whereConstraint = null;
if(constraint != null)
whereConstraint = Functions.upper(Task.TITLE).like("%" +
constraint.toString().toUpperCase() + "%");
if(filter == null || filter.sqlQuery == null) {
if(whereConstraint == null)
return taskDao.query(Query.select(properties));
else
return taskDao.query(Query.select(properties).withQueryTemplate(filter.sqlQuery));
return taskDao.query(Query.select(properties).where(whereConstraint));
}
String sql;
if(whereConstraint != null) {
if(!filter.sqlQuery.toUpperCase().contains("WHERE"))
sql = filter.sqlQuery + " WHERE " + whereConstraint;
else
sql = filter.sqlQuery.replace("WHERE ", "WHERE " + whereConstraint + " AND ");
} else
sql = filter.sqlQuery;
return taskDao.query(Query.select(properties).withQueryTemplate(sql));
}
/**

@ -28,7 +28,7 @@ public final class Constants {
/**
* Whether to turn on debugging logging and UI
*/
public static final boolean DEBUG = true;
public static final boolean DEBUG = false;
// --- notification id's

@ -97,7 +97,7 @@ public class TasksWidget extends AppWidgetProvider {
inboxFilter.sqlQuery += "ORDER BY " + TaskService.defaultTaskOrder() + " LIMIT " + numberOfTasks;
database.openForReading();
cursor = taskService.fetchFiltered(inboxFilter, Task.TITLE, Task.DUE_DATE);
cursor = taskService.fetchFiltered(inboxFilter, null, Task.TITLE, Task.DUE_DATE);
Task task = new Task();
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToPosition(i);

Loading…
Cancel
Save