Added quick-add markup

pull/14/head
Tim Su 14 years ago
parent a5dfaf119d
commit 8c3bee018c

@ -14,11 +14,11 @@ import android.net.Uri;
import com.todoroo.andlib.data.AbstractModel; import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Table;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.data.Property.IntegerProperty; import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.data.Property.LongProperty; import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty; import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.Table;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.R; import com.todoroo.astrid.api.R;
@ -172,8 +172,8 @@ public final class Task extends AbstractModel {
}; };
} }
public static final int IMPORTANCE_MOST = IMPORTANCE_DO_OR_DIE; public static int IMPORTANCE_MOST = IMPORTANCE_DO_OR_DIE;
public static final int IMPORTANCE_LEAST = IMPORTANCE_NONE; public static int IMPORTANCE_LEAST = IMPORTANCE_NONE;
// --- defaults // --- defaults

@ -1,8 +1,9 @@
package com.todoroo.astrid.producteev; package com.todoroo.astrid.producteev;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.astrid.sync.SyncProviderUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.sync.SyncProviderUtilities;
/** /**
* Displays synchronization preferences and an action panel so users can * Displays synchronization preferences and an action panel so users can
@ -27,6 +28,10 @@ public class ProducteevUtilities extends SyncProviderUtilities {
/** setting for dashboard to use default one */ /** setting for dashboard to use default one */
public static final int DASHBOARD_DEFAULT = 0; public static final int DASHBOARD_DEFAULT = 0;
static {
Task.IMPORTANCE_LEAST = 5;
}
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return IDENTIFIER; return IDENTIFIER;

@ -731,10 +731,6 @@ public final class TaskEditActivity extends TabActivity {
int min = Task.IMPORTANCE_MOST; int min = Task.IMPORTANCE_MOST;
int max = Task.IMPORTANCE_LEAST; int max = Task.IMPORTANCE_LEAST;
int importanceOffset = max; int importanceOffset = max;
if(ProducteevUtilities.INSTANCE.isLoggedIn()) {
max = 5;
importanceOffset = max - 1;
}
for(int i = min; i <= max; i++) { for(int i = min; i <= max; i++) {
final ToggleButton button = new ToggleButton(TaskEditActivity.this); final ToggleButton button = new ToggleButton(TaskEditActivity.this);

@ -757,6 +757,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener,
Task task = new Task(); Task task = new Task();
if(title != null) if(title != null)
task.setValue(Task.TITLE, title); task.setValue(Task.TITLE, title);
ContentValues forMetadata = null; ContentValues forMetadata = null;
if(values != null && values.size() > 0) { if(values != null && values.size() > 0) {
ContentValues forTask = new ContentValues(); ContentValues forTask = new ContentValues();
@ -777,7 +778,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener,
} }
task.mergeWith(forTask); task.mergeWith(forTask);
} }
taskService.save(task); taskService.quickAdd(task);
if(forMetadata != null && forMetadata.size() > 0) { if(forMetadata != null && forMetadata.size() > 0) {
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
metadata.setValue(Metadata.TASK, task.getId()); metadata.setValue(Metadata.TASK, task.getId());

@ -1,5 +1,9 @@
package com.todoroo.astrid.service; package com.todoroo.astrid.service;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.content.ContentValues; import android.content.ContentValues;
import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.Property;
@ -13,13 +17,14 @@ import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.PermaSql; import com.todoroo.astrid.api.PermaSql;
import com.todoroo.astrid.dao.MetadataDao; import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gtasks.GtasksMetadata; import com.todoroo.astrid.gtasks.GtasksMetadata;
import com.todoroo.astrid.producteev.sync.ProducteevTask; import com.todoroo.astrid.producteev.sync.ProducteevTask;
import com.todoroo.astrid.tags.TagService;
/** /**
* Service layer for {@link Task}-centered activities. * Service layer for {@link Task}-centered activities.
@ -287,4 +292,57 @@ public class TaskService {
taskDao.deleteWhere(criteria); taskDao.deleteWhere(criteria);
} }
/**
* Save task, parsing quick-add mark-up:
* <ul>
* <li>#tag - add the tag "tag"
* <li>@context - add the tag "@context"
* <li>!4 - set priority to !!!!
*/
public void quickAdd(Task task) {
ArrayList<String> tags = new ArrayList<String>();
parseQuickAddMarkup(task, tags);
save(task);
Metadata metadata = new Metadata();
for(String tag : tags) {
metadata.setValue(Metadata.KEY, TagService.KEY);
metadata.setValue(Metadata.TASK, task.getId());
metadata.setValue(TagService.TAG, tag);
metadataDao.createNew(metadata);
}
}
@SuppressWarnings("nls")
public static void parseQuickAddMarkup(Task task, ArrayList<String> tags) {
String title = task.getValue(Task.TITLE);
Pattern tagPattern = Pattern.compile("(\\s|^)#([^\\s]+)");
Pattern contextPattern = Pattern.compile("(\\s|^)(@[^\\s]+)");
Pattern importancePattern = Pattern.compile("(\\s|^)!(\\d)(\\s|$)");
while(true) {
Matcher m = tagPattern.matcher(title);
if(m.matches()) {
tags.add(m.group(2));
} else {
m = contextPattern.matcher(title);
if(m.matches()) {
tags.add(m.group(2));
} else {
m = importancePattern.matcher(title);
if(m.matches()) {
int importance = Integer.parseInt(m.group(2));
task.setValue(Task.IMPORTANCE, Task.IMPORTANCE_LEAST + 1 - importance);
if(task.getValue(Task.IMPORTANCE) < Task.IMPORTANCE_MOST)
task.setValue(Task.IMPORTANCE, Task.IMPORTANCE_MOST);
} else
break;
}
}
title = title.substring(0, m.start()) + title.substring(m.end() + 1);
}
task.setValue(Task.TITLE, title.trim());
}
} }

@ -0,0 +1,85 @@
package com.todoroo.astrid.service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.todoroo.andlib.test.TodorooTestCase;
import com.todoroo.astrid.data.Task;
public class QuickAddMarkupTest extends TodorooTestCase {
public void testTags() {
whenTitleIs("this #cool");
assertTitleBecomes("this");
assertTagsAre("cool");
whenTitleIs("#cool task");
assertTitleBecomes("task");
assertTagsAre("cool");
whenTitleIs("doggie #nice #cute");
assertTitleBecomes("doggie");
assertTagsAre("nice", "cute");
}
public void testContexts() {
whenTitleIs("eat @home");
assertTitleBecomes("eat");
assertTagsAre("@home");
whenTitleIs("buy oatmeal @store @morning");
assertTitleBecomes("buy oatmeal");
assertTagsAre("@store", "@morning");
whenTitleIs("look @ me");
assertTitleBecomes("look @ me");
assertTagsAre();
}
public void testImportances() {
whenTitleIs("eat !1");
assertTitleBecomes("eat");
assertImportanceIs(Task.IMPORTANCE_NONE);
whenTitleIs("super cool!");
assertTitleBecomes("super cool!");
whenTitleIs("stay alive !4");
assertTitleBecomes("stay alive");
assertImportanceIs(Task.IMPORTANCE_DO_OR_DIE);
}
public void testMixed() {
whenTitleIs("eat #food !2");
assertTitleBecomes("eat");
assertTagsAre("food");
assertImportanceIs(Task.IMPORTANCE_SHOULD_DO);
}
// --- helpers
private Task task;
private ArrayList<String> tags = new ArrayList<String>();
private void assertTagsAre(String... tags) {
List<String> expected = Arrays.asList(tags);
assertEquals(expected.toString(), tags.toString());
}
private void assertTitleBecomes(String title) {
assertEquals(title, task.getValue(Task.TITLE));
}
private void whenTitleIs(String title) {
task = new Task();
task.setValue(Task.TITLE, title);
tags.clear();
TaskService.parseQuickAddMarkup(task, tags);
}
private void assertImportanceIs(int importance) {
assertEquals(importance, (int)task.getValue(Task.IMPORTANCE));
}
}
Loading…
Cancel
Save