diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java index dd5c7eeb4..908e08f96 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java @@ -241,7 +241,7 @@ public class EditPeopleControlSet extends PopupControlSet { @Override public void run() { ArrayList collaborators = new ArrayList(); - TodorooCursor tags = TagService.getInstance().getTags(task.getId()); + TodorooCursor tags = TagService.getInstance().getTags(task.getId(), true); try { Metadata metadata = new Metadata(); for(tags.moveToFirst(); !tags.isAfterLast(); tags.moveToNext()) { diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java index f71c8256d..79c4f3ccc 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -394,7 +394,7 @@ public final class ActFmSyncService { } if(Flags.checkAndClear(Flags.TAGS_CHANGED) || newlyCreated) { - TodorooCursor cursor = TagService.getInstance().getTags(task.getId()); + TodorooCursor cursor = TagService.getInstance().getTags(task.getId(), false); try { if(cursor.getCount() == 0) { params.add("tags"); diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/TagCaseMigrator.java b/astrid/plugin-src/com/todoroo/astrid/tags/TagCaseMigrator.java index 48fa80430..c29998099 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/TagCaseMigrator.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/TagCaseMigrator.java @@ -38,7 +38,7 @@ public class TagCaseMigrator { public void performTagCaseMigration(@SuppressWarnings("unused") Context context) { if (!Preferences.getBoolean(PREF_CASE_MIGRATION_PERFORMED, false)) { TagService.Tag[] allTagData = TagService.getInstance().getGroupedTags( - TagService.GROUPED_TAGS_BY_ALPHA, Criterion.all); + TagService.GROUPED_TAGS_BY_ALPHA, Criterion.all, false); boolean shouldShowDialog = false; for (int i = 0; i < allTagData.length - 1; i++) { diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/TagCustomFilterCriteriaExposer.java b/astrid/plugin-src/com/todoroo/astrid/tags/TagCustomFilterCriteriaExposer.java index be9d7d32d..ebb821d15 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/TagCustomFilterCriteriaExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/TagCustomFilterCriteriaExposer.java @@ -35,7 +35,7 @@ public class TagCustomFilterCriteriaExposer extends BroadcastReceiver { // built in criteria: tags { TagService.Tag[] tags = TagService.getInstance().getGroupedTags(TagService.GROUPED_TAGS_BY_SIZE, - TaskDao.TaskCriteria.activeAndVisible()); + TaskDao.TaskCriteria.activeAndVisible(), false); String[] tagNames = new String[tags.length]; for(int i = 0; i < tags.length; i++) tagNames[i] = tags[i].tag; diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/TagDetailExposer.java b/astrid/plugin-src/com/todoroo/astrid/tags/TagDetailExposer.java index 3d890d606..70ef269e0 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/TagDetailExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/TagDetailExposer.java @@ -37,7 +37,7 @@ public class TagDetailExposer extends BroadcastReceiver { } public String getTaskDetails(long id) { - String tagList = TagService.getInstance().getTagsAsString(id); + String tagList = TagService.getInstance().getTagsAsString(id, false); if(tagList.length() == 0) return null; diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java b/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java index e65dc142e..45482efdd 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java @@ -193,10 +193,15 @@ public final class TagService { * @param activeStatus criterion for specifying completed or uncompleted * @return empty array if no tags, otherwise array */ - public Tag[] getGroupedTags(Order order, Criterion activeStatus) { + public Tag[] getGroupedTags(Order order, Criterion activeStatus, boolean includeEmergent) { + Criterion criterion; + if (includeEmergent) + criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(KEY)); + else + criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(KEY), Criterion.not(TAG.in(getEmergentTags()))); Query query = Query.select(TAG, REMOTE_ID, COUNT). join(Join.inner(Task.TABLE, Metadata.TASK.eq(Task.ID))). - where(Criterion.and(activeStatus, MetadataCriteria.withKey(KEY))). + where(criterion). orderBy(order).groupBy(TAG); TodorooCursor cursor = metadataDao.query(query); try { @@ -211,15 +216,38 @@ public final class TagService { } } + private String[] getEmergentTags() { + TodorooCursor emergent = tagDataService.query(Query.select(TagData.NAME) + .where(Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_EMERGENT).gt(0))); + try { + String[] tags = new String[emergent.getCount()]; + TagData data = new TagData(); + for (int i = 0; i < emergent.getCount(); i++) { + emergent.moveToPosition(i); + data.readFromCursor(emergent); + tags[i] = data.getValue(TagData.NAME); + } + return tags; + } finally { + emergent.close(); + } + } + /** * Return tags on the given task * * @param taskId * @return cursor. PLEASE CLOSE THE CURSOR! */ - public TodorooCursor getTags(long taskId) { - Query query = Query.select(TAG, REMOTE_ID).where(Criterion.and(MetadataCriteria.withKey(KEY), - MetadataCriteria.byTask(taskId))).orderBy(Order.asc(Functions.upper(TAG))); + public TodorooCursor getTags(long taskId, boolean includeEmergent) { + Criterion criterion; + if (includeEmergent) + criterion = Criterion.and(MetadataCriteria.withKey(KEY), + MetadataCriteria.byTask(taskId)); + else + criterion = Criterion.and(MetadataCriteria.withKey(KEY), + MetadataCriteria.byTask(taskId), Criterion.not(TAG.in(getEmergentTags()))); + Query query = Query.select(TAG, REMOTE_ID).where(criterion).orderBy(Order.asc(Functions.upper(TAG))); return metadataDao.query(query); } @@ -229,8 +257,8 @@ public final class TagService { * @param taskId * @return empty string if no tags, otherwise string */ - public String getTagsAsString(long taskId) { - return getTagsAsString(taskId, ", "); + public String getTagsAsString(long taskId, boolean includeEmergent) { + return getTagsAsString(taskId, ", ", includeEmergent); } /** @@ -239,9 +267,9 @@ public final class TagService { * @param taskId * @return empty string if no tags, otherwise string */ - public String getTagsAsString(long taskId, String separator) { + protected String getTagsAsString(long taskId, String separator, boolean includeEmergent) { StringBuilder tagBuilder = new StringBuilder(); - TodorooCursor tags = getTags(taskId); + TodorooCursor tags = getTags(taskId, includeEmergent); try { int length = tags.getCount(); Metadata metadata = new Metadata(); @@ -285,7 +313,7 @@ public final class TagService { HashMap tags = new HashMap(); Tag[] tagsByAlpha = getGroupedTags(TagService.GROUPED_TAGS_BY_ALPHA, - TaskCriteria.activeAndVisible()); + TaskCriteria.activeAndVisible(), false); for(Tag tag : tagsByAlpha) if(!TextUtils.isEmpty(tag.tag)) tags.put(tag.tag, tag); diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java b/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java index d538975c6..c1334d12a 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/TagsControlSet.java @@ -223,7 +223,7 @@ public final class TagsControlSet extends PopupControlSet { public void readFromTask(Task task) { super.readFromTask(task); if(model.getId() != AbstractModel.NO_ID) { - TodorooCursor cursor = tagService.getTags(model.getId()); + TodorooCursor cursor = tagService.getTags(model.getId(), false); LinkedHashSet tags = new LinkedHashSet(cursor.getCount()); try { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { diff --git a/astrid/src/com/todoroo/astrid/provider/Astrid2TaskProvider.java b/astrid/src/com/todoroo/astrid/provider/Astrid2TaskProvider.java index ca5345d6a..5b4fc9f01 100644 --- a/astrid/src/com/todoroo/astrid/provider/Astrid2TaskProvider.java +++ b/astrid/src/com/todoroo/astrid/provider/Astrid2TaskProvider.java @@ -138,7 +138,7 @@ public class Astrid2TaskProvider extends ContentProvider { public Cursor getTags() { Tag[] tags = TagService.getInstance().getGroupedTags(TagService.GROUPED_TAGS_BY_SIZE, - Criterion.all); + Criterion.all, true); MatrixCursor ret = new MatrixCursor(TAGS_FIELD_LIST); @@ -195,7 +195,7 @@ public class Astrid2TaskProvider extends ContentProvider { task.readFromCursor(cursor); StringBuilder taskTags = new StringBuilder(); - TodorooCursor tagCursor = TagService.getInstance().getTags(task.getId()); + TodorooCursor tagCursor = TagService.getInstance().getTags(task.getId(), true); try { for(tagCursor.moveToFirst(); !tagCursor.isAfterLast(); tagCursor.moveToNext()) taskTags.append(tagCursor.get(TagService.TAG)).append(TAG_SEPARATOR);