Remove Tag class

pull/189/head
Alex Baker 10 years ago
parent def919ef9a
commit d252e86f50

@ -43,7 +43,6 @@ import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.tags.DeleteTagActivity;
import com.todoroo.astrid.tags.RenameTagActivity;
import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.ui.QuickAddBar;
import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.utility.Flags;
@ -527,17 +526,17 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList
}
return true;
case R.id.menu_delete_list:
TagService.Tag deleteTag = new TagService.Tag(tlf.getActiveTagData());
TagData deleteTag = tlf.getActiveTagData();
Intent ret = new Intent(this, DeleteTagActivity.class);
ret.putExtra("tag", deleteTag.tag);
ret.putExtra(TagViewFragment.EXTRA_TAG_UUID, deleteTag.uuid);
ret.putExtra("tag", deleteTag.getName());
ret.putExtra(TagViewFragment.EXTRA_TAG_UUID, deleteTag.getUuid());
startActivityForResult(ret, FilterListFragment.REQUEST_CUSTOM_INTENT);
return true;
case R.id.menu_rename_list:
TagService.Tag renameTag = new TagService.Tag(tlf.getActiveTagData());
TagData renameTag = tlf.getActiveTagData();
Intent rename = new Intent(this, RenameTagActivity.class);
rename.putExtra("tag", renameTag.tag);
rename.putExtra(TagViewFragment.EXTRA_TAG_UUID, renameTag.uuid);
rename.putExtra("tag", renameTag.getName());
rename.putExtra(TagViewFragment.EXTRA_TAG_UUID, renameTag.getUuid());
startActivityForResult(rename, FilterListFragment.REQUEST_CUSTOM_INTENT);
return true;
case R.id.menu_support:

@ -19,10 +19,10 @@ import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.core.SortHelper;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.tags.TagService.Tag;
import com.todoroo.astrid.tags.TaskToTagMetadata;
import org.slf4j.Logger;
@ -119,15 +119,15 @@ public class Astrid2TaskProvider extends InjectingContentProvider {
*/
public Cursor getTags() {
Tag[] tags = tagService.get().getGroupedTags(TagService.GROUPED_TAGS_BY_SIZE,
TagData[] tags = tagService.get().getGroupedTags(TagService.GROUPED_TAGS_BY_SIZE,
Criterion.all);
MatrixCursor ret = new MatrixCursor(TAGS_FIELD_LIST);
for (Tag tag : tags) {
for (TagData tag : tags) {
Object[] values = new Object[2];
values[0] = tagNameToLong(tag.tag);
values[1] = tag.tag;
values[0] = tagNameToLong(tag.getName());
values[1] = tag.getName();
ret.addRow(values);
}

@ -22,6 +22,7 @@ import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import org.tasks.R;
@ -53,11 +54,11 @@ public class TagCustomFilterCriteriaExposer extends InjectingBroadcastReceiver {
// built in criteria: tags
{
TagService.Tag[] tags = tagService.getGroupedTags(TagService.GROUPED_TAGS_BY_SIZE,
TagData[] tags = tagService.getGroupedTags(TagService.GROUPED_TAGS_BY_SIZE,
TaskDao.TaskCriteria.activeAndVisible());
String[] tagNames = new String[tags.length];
for(int i = 0; i < tags.length; i++) {
tagNames[i] = tags[i].tag;
tagNames[i] = tags[i].getName();
}
ContentValues values = new ContentValues();
values.put(Metadata.KEY.name, TaskToTagMetadata.KEY);

@ -16,6 +16,8 @@ import android.text.TextUtils;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Field;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.actfm.TagViewFragment;
@ -30,7 +32,6 @@ import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.tags.TagService.Tag;
import org.tasks.R;
import org.tasks.injection.ForApplication;
@ -58,18 +59,18 @@ public class TagFilterExposer extends InjectingBroadcastReceiver implements Astr
@Inject Preferences preferences;
/** Create filter from new tag object */
public static FilterWithCustomIntent filterFromTag(Context context, Tag tag, Criterion criterion) {
String title = tag.tag;
public static FilterWithCustomIntent filterFromTag(Context context, TagData tag, Criterion criterion) {
String title = tag.getName();
if (TextUtils.isEmpty(title)) {
return null;
}
QueryTemplate tagTemplate = tag.queryTemplate(criterion);
QueryTemplate tagTemplate = queryTemplate(tag.getUuid(), criterion);
ContentValues contentValues = new ContentValues();
contentValues.put(Metadata.KEY.name, TaskToTagMetadata.KEY);
contentValues.put(TaskToTagMetadata.TAG_NAME.name, tag.tag);
contentValues.put(TaskToTagMetadata.TAG_UUID.name, tag.uuid);
contentValues.put(TaskToTagMetadata.TAG_NAME.name, tag.getName());
contentValues.put(TaskToTagMetadata.TAG_UUID.name, tag.getUuid());
FilterWithUpdate filter = new FilterWithUpdate(tag.tag,
FilterWithUpdate filter = new FilterWithUpdate(tag.getName(),
title, tagTemplate,
contentValues);
@ -78,14 +79,14 @@ public class TagFilterExposer extends InjectingBroadcastReceiver implements Astr
context.getString(R.string.tag_cm_delete)
};
filter.contextMenuIntents = new Intent[] {
newTagIntent(context, RenameTagActivity.class, tag, tag.uuid),
newTagIntent(context, DeleteTagActivity.class, tag, tag.uuid)
newTagIntent(context, RenameTagActivity.class, tag, tag.getUuid()),
newTagIntent(context, DeleteTagActivity.class, tag, tag.getUuid())
};
filter.customTaskList = new ComponentName(context, TagViewFragment.class);
Bundle extras = new Bundle();
extras.putString(TagViewFragment.EXTRA_TAG_NAME, tag.tag);
extras.putString(TagViewFragment.EXTRA_TAG_UUID, tag.uuid);
extras.putString(TagViewFragment.EXTRA_TAG_NAME, tag.getName());
extras.putString(TagViewFragment.EXTRA_TAG_UUID, tag.getUuid());
filter.customExtras = extras;
return filter;
@ -93,13 +94,12 @@ public class TagFilterExposer extends InjectingBroadcastReceiver implements Astr
/** Create a filter from tag data object */
public static FilterWithCustomIntent filterFromTagData(Context context, TagData tagData) {
Tag tag = new Tag(tagData);
return filterFromTag(context, tag, TaskCriteria.activeAndVisible());
return filterFromTag(context, tagData, TaskCriteria.activeAndVisible());
}
private static Intent newTagIntent(Context context, Class<? extends Activity> activity, Tag tag, String uuid) {
private static Intent newTagIntent(Context context, Class<? extends Activity> activity, TagData tag, String uuid) {
Intent ret = new Intent(context, activity);
ret.putExtra(TAG, tag.tag);
ret.putExtra(TAG, tag.getName());
ret.putExtra(TagViewFragment.EXTRA_TAG_UUID, uuid);
return ret;
}
@ -126,7 +126,7 @@ public class TagFilterExposer extends InjectingBroadcastReceiver implements Astr
return list.toArray(new FilterListItem[list.size()]);
}
private List<Filter> filterFromTags(List<Tag> tags) {
private List<Filter> filterFromTags(List<TagData> tags) {
boolean shouldAddUntagged = preferences.getBoolean(R.string.p_show_not_in_list_filter, true);
List<Filter> filters = new ArrayList<>();
@ -142,7 +142,7 @@ public class TagFilterExposer extends InjectingBroadcastReceiver implements Astr
filters.add(untagged);
}
for (Tag tag : tags) {
for (TagData tag : tags) {
Filter f = constructFilter(context, tag);
if (f != null) {
filters.add(f);
@ -151,7 +151,7 @@ public class TagFilterExposer extends InjectingBroadcastReceiver implements Astr
return filters;
}
protected Filter constructFilter(Context context, Tag tag) {
protected Filter constructFilter(Context context, TagData tag) {
return filterFromTag(context, tag, TaskCriteria.activeAndVisible());
}
@ -169,4 +169,14 @@ public class TagFilterExposer extends InjectingBroadcastReceiver implements Astr
TaskCriteria.isActive(),
TaskCriteria.isVisible()));
}
private static QueryTemplate queryTemplate(String uuid, Criterion criterion) {
Criterion fullCriterion = Criterion.and(
Field.field("mtags." + Metadata.KEY.name).eq(TaskToTagMetadata.KEY),
Field.field("mtags." + TaskToTagMetadata.TAG_UUID.name).eq(uuid),
Field.field("mtags." + Metadata.DELETION_DATE.name).eq(0),
criterion);
return new QueryTemplate().join(Join.inner(Metadata.TABLE.as("mtags"), Task.UUID.eq(Field.field("mtags." + TaskToTagMetadata.TASK_UUID.name))))
.where(fullCriterion);
}
}

@ -11,12 +11,10 @@ import com.todoroo.andlib.data.Callback;
import com.todoroo.andlib.data.Property.CountProperty;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Field;
import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TagDataDao;
@ -54,41 +52,6 @@ public final class TagService {
private static final CountProperty COUNT = new CountProperty();
public static final Order GROUPED_TAGS_BY_SIZE = Order.desc(COUNT);
/**
* Helper class for returning a tag/task count pair
*
* @author Tim Su <tim@todoroo.com>
*
*/
// TODO: get rid of this
public static final class Tag {
public String tag;
public String uuid;
public Tag(TagData tagData) {
tag = tagData.getName();
uuid = tagData.getUUID();
}
@Override
public String toString() {
return tag;
}
/**
* Return SQL selector query for getting tasks with a given tagData
*/
public QueryTemplate queryTemplate(Criterion criterion) {
Criterion fullCriterion = Criterion.and(
Field.field("mtags." + Metadata.KEY.name).eq(TaskToTagMetadata.KEY),
Field.field("mtags." + TaskToTagMetadata.TAG_UUID.name).eq(uuid),
Field.field("mtags." + Metadata.DELETION_DATE.name).eq(0),
criterion);
return new QueryTemplate().join(Join.inner(Metadata.TABLE.as("mtags"), Task.UUID.eq(Field.field("mtags." + TaskToTagMetadata.TASK_UUID.name))))
.where(fullCriterion);
}
}
/**
* Return all tags ordered by given clause
*
@ -96,7 +59,7 @@ 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 TagData[] getGroupedTags(Order order, Criterion activeStatus) {
Criterion criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(TaskToTagMetadata.KEY));
Query query = Query.select(TaskToTagMetadata.TAG_NAME, TaskToTagMetadata.TAG_UUID, COUNT).
join(Join.inner(Task.TABLE, Metadata.TASK.eq(Task.ID))).
@ -104,23 +67,22 @@ public final class TagService {
orderBy(order).groupBy(TaskToTagMetadata.TAG_NAME);
TodorooCursor<Metadata> cursor = metadataDao.query(query);
try {
ArrayList<Tag> array = new ArrayList<>();
ArrayList<TagData> array = new ArrayList<>();
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToNext();
Tag tag = tagFromUUID(cursor.get(TaskToTagMetadata.TAG_UUID));
TagData tag = tagFromUUID(cursor.get(TaskToTagMetadata.TAG_UUID));
if (tag != null) {
array.add(tag);
}
}
return array.toArray(new Tag[array.size()]);
return (TagData[]) array.toArray();
} finally {
cursor.close();
}
}
private Tag tagFromUUID(String uuid) {
TagData tagData = tagDataDao.getByUuid(uuid, TagData.PROPERTIES);
return tagData == null ? null : new Tag(tagData);
private TagData tagFromUUID(String uuid) {
return tagDataDao.getByUuid(uuid, TagData.PROPERTIES);
}
/**
@ -138,13 +100,13 @@ public final class TagService {
/**
* Return all tags (including metadata tags and TagData tags) in an array list
*/
public List<Tag> getTagList() {
final List<Tag> tagList = new ArrayList<>();
public List<TagData> getTagList() {
final List<TagData> tagList = new ArrayList<>();
tagDataDao.tagDataOrderedByName(new Callback<TagData>() {
@Override
public void apply(TagData tagData) {
if (!TextUtils.isEmpty(tagData.getName())) {
tagList.add(new Tag(tagData));
tagList.add(tagData);
}
}
});

@ -33,7 +33,6 @@ import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.tags.TagService.Tag;
import com.todoroo.astrid.ui.PopupControlSet;
import com.todoroo.astrid.utility.Flags;
@ -44,7 +43,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import static org.tasks.preferences.ResourceResolver.getResource;
@ -85,9 +83,8 @@ public final class TagsControlSet extends PopupControlSet {
image = (ImageView) getDisplayView().findViewById(R.id.display_row_icon);
}
private Tag[] getTagArray() {
List<Tag> tagsList = tagService.getTagList();
return tagsList.toArray(new Tag[tagsList.size()]);
private TagData[] getTagArray() {
return (TagData[]) tagService.getTagList().toArray();
}
private HashMap<String, Integer> buildTagIndices(ArrayList<String> tagNames) {
@ -98,11 +95,11 @@ public final class TagsControlSet extends PopupControlSet {
return indices;
}
private ArrayList<String> getTagNames(Tag[] tags) {
private ArrayList<String> getTagNames(TagData[] tags) {
ArrayList<String> names = new ArrayList<>();
for (Tag tag : tags) {
if (!names.contains(tag.tag)) {
names.add(tag.tag);
for (TagData tag : tags) {
if (!names.contains(tag.getName())) {
names.add(tag.getName());
}
}
return names;
@ -298,7 +295,7 @@ public final class TagsControlSet extends PopupControlSet {
@Override
protected void afterInflate() {
Tag[] allTags = getTagArray();
TagData[] allTags = getTagArray();
allTagNames = getTagNames(allTags);
tagIndices = buildTagIndices(allTagNames);

Loading…
Cancel
Save