public ArrayList<String> tags_of_item(long itemId) { Cursor cursor = DBAdapter.getInstance(mCtx) .db() .query( true, DB_TABLE, new String[] {TAG_ID}, ITEM_ID + "=" + itemId, null, null, null, null, null); ArrayList<String> ids = new ArrayList<String>(); while (cursor.moveToNext()) { ids.add(cursor.getString(cursor.getColumnIndexOrThrow(TAG_ID))); } if (ids.isEmpty()) { // We don't have any tags for this item, return an empty tag list return new ArrayList<String>(); } ArrayList<String> tags = TagDBManager.instance(mCtx).getTagsByIds(ids.toArray(new String[ids.size()])); return tags; }
public void Untag_item(long tagId, long itemId) { String where = TAG_ID + "=" + tagId + " AND " + ITEM_ID + "=" + itemId; DBAdapter.getInstance(mCtx).db().delete(DB_TABLE, where, null); // Delete the tag in the tag table if no item is referencing it if (!tagExists(tagId)) { TagDBManager.instance(mCtx).deleteTag(tagId); } }
// This gets called when an item is deleted, we need to clean up both the TagItem table // and the Tag table public void Remove_tags_by_item(long itemId) { ArrayList<Long> tagIds = tagIds_by_item(itemId); // delete all the entries referencing this item in the TagItem table String where = ITEM_ID + "=" + itemId; DBAdapter.getInstance(mCtx).db().delete(DB_TABLE, where, null); // Delete the tags in the tag table if no other items are referencing it for (long tagId : tagIds) { if (!tagExists(tagId)) { TagDBManager.instance(mCtx).deleteTag(tagId); } } }
public ArrayList<Long> ItemIds_by_tag(String tagName) { long tagId = TagDBManager.instance(mCtx).getIdByName(tagName); Cursor cursor = DBAdapter.getInstance(mCtx) .db() .query( true, DB_TABLE, new String[] {ITEM_ID}, TAG_ID + "=" + tagId, null, null, null, null, null); ArrayList<Long> ItemIds = new ArrayList<Long>(); while (cursor.moveToNext()) { long item_id = cursor.getLong(cursor.getColumnIndexOrThrow(ITEM_ID)); ItemIds.add(new Long(item_id)); } return ItemIds; }
public void Untag_item(String tagName, long itemId) { long tagId = TagDBManager.instance(mCtx).getIdByName(tagName); Untag_item(tagId, itemId); }
public long Tag_item(String tagName, long itemId) { long tagId = TagDBManager.instance(mCtx).createTag(tagName); return Tag_item(tagId, itemId); }