Permalink
Browse files

Enabled proper support for inherited tags.

  • Loading branch information...
1 parent 8a1148f commit 11190d613e4bb39477461bb69eb845e687035420 @hdweiss hdweiss committed Dec 10, 2012
@@ -64,7 +64,8 @@ public SelectionBuilder getQuery(Context context) {
builder.where(getSelection(todos, OrgData.TODO));
if(tags != null && tags.size() > 0)
- builder.where(getLikeSelection(tags, OrgData.TAGS));
+ builder.where(getLikeSelection(tags, OrgData.TAGS) + " OR "
+ + getLikeSelection(tags, OrgData.TAGS_INHERITED));
if(priorities != null && priorities.size() > 0)
builder.where(getSelection(priorities, OrgData.PRIORITY));
@@ -45,7 +45,7 @@ public void setLevelFormating(boolean enabled) {
}
public void setup(OrgNode node, boolean expanded, DefaultTheme theme, ContentResolver resolver) {
- setupTags(node.tags, theme);
+ setupTags(node.tags, node.tags_inherited, theme);
SpannableStringBuilder titleSpan = new SpannableStringBuilder(node.name);
@@ -157,10 +157,14 @@ private static void formatLinks(DefaultTheme theme, SpannableStringBuilder title
}
}
- public void setupTags(String tags, DefaultTheme theme) {
- if(tags != null && TextUtils.isEmpty(tags) == false) {
+ public void setupTags(String tags, String tagsInherited, DefaultTheme theme) {
+ if(TextUtils.isEmpty(tags) == false || TextUtils.isEmpty(tagsInherited) == false) {
+ if (TextUtils.isEmpty(tagsInherited) == false)
+ tagsView.setText(tags + "::" + tagsInherited);
+ else
+ tagsView.setText(tags);
+
tagsView.setTextColor(theme.gray);
- tagsView.setText(tags);
tagsView.setVisibility(View.VISIBLE);
} else
tagsView.setVisibility(View.GONE);
@@ -22,6 +22,7 @@
String LEVEL = "level";
String PRIORITY = "priority";
String TAGS = "tags";
+ String TAGS_INHERITED = "tags_inherited";
String PAYLOAD = "payload";
}
@@ -90,7 +91,7 @@ public static Uri buildChildrenUri(long node_id) {
public static final String NAME_SORT = NAME + " ASC";
- public static final String[] DEFAULT_COLUMNS = { ID, NAME, TODO, TAGS,
+ public static final String[] DEFAULT_COLUMNS = { ID, NAME, TODO, TAGS, TAGS_INHERITED,
PARENT_ID, PAYLOAD, LEVEL, PRIORITY, FILE_ID };
}
@@ -10,11 +10,12 @@
public class OrgDatabase extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "MobileOrg.db";
- private static final int DATABASE_VERSION = 4;
+ private static final int DATABASE_VERSION = 5;
private int orgdata_nameColumn;
private int orgdata_todoColumn;
private int orgdata_tagsColumn;
+ private int orgdata_tagsInheritedColumn;
private int orgdata_priorityColumn;
private int orgdata_parentidColumn;
private int orgdata_fileidColumn;
@@ -72,6 +73,7 @@ public void onCreate(SQLiteDatabase db) {
+ "priority text,"
+ "todo text,"
+ "tags text,"
+ + "tags_inherited text,"
+ "payload text,"
+ "name text)");
}
@@ -86,6 +88,10 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS edits");
db.execSQL("DROP TABLE IF EXISTS orgdata");
break;
+
+ case 5:
+ db.execSQL("alter table orgdata add tags_inherited text");
+ break;
}
onCreate(db);
}
@@ -98,6 +104,7 @@ public long fastInsertNode(OrgNode node) {
orgdataInsertHelper.bind(orgdata_priorityColumn, node.priority);
orgdataInsertHelper.bind(orgdata_fileidColumn, node.fileId);
orgdataInsertHelper.bind(orgdata_tagsColumn, node.tags);
+ orgdataInsertHelper.bind(orgdata_tagsInheritedColumn, node.tags_inherited);
orgdataInsertHelper.bind(orgdata_levelColumn, node.level);
return orgdataInsertHelper.execute();
}
@@ -121,6 +128,7 @@ private void prepareOrgdataInsert() {
this.orgdata_parentidColumn = orgdataInsertHelper.getColumnIndex(OrgData.PARENT_ID);
this.orgdata_fileidColumn = orgdataInsertHelper.getColumnIndex(OrgData.FILE_ID);
this.orgdata_tagsColumn = orgdataInsertHelper.getColumnIndex(OrgData.TAGS);
+ this.orgdata_tagsInheritedColumn = orgdataInsertHelper.getColumnIndex(OrgData.TAGS_INHERITED);
this.orgdata_levelColumn = orgdataInsertHelper.getColumnIndex(OrgData.LEVEL);
}
orgdataInsertHelper.prepareForInsert();
@@ -40,7 +40,7 @@ private void init(OrgFile orgFile) {
this.orgFile = orgFile;
this.parseStack = new ParseStack();
- this.parseStack.add(0, orgFile.nodeId);
+ this.parseStack.add(0, orgFile.nodeId, "");
this.payload = new StringBuilder();
@@ -98,10 +98,11 @@ private void parseHeading(String thisLine, int numstars) {
}
OrgNode node = this.orgNodeParser.parseLine(thisLine, numstars);
+ node.tags_inherited = parseStack.getCurrentTags();
node.fileId = orgFile.id;
node.parentId = parseStack.getCurrentNodeId();
long newId = db.fastInsertNode(node);
- parseStack.add(numstars, newId);
+ parseStack.add(numstars, newId, node.tags);
}
private static final Pattern starPattern = Pattern.compile("^(\\**)\\s");
@@ -116,17 +117,21 @@ private static int numberOfStars(String thisLine) {
private class ParseStack {
private Stack<Pair<Integer, Long>> parseStack;
+ private Stack<String> tagStack;
public ParseStack() {
this.parseStack = new Stack<Pair<Integer, Long>>();
+ this.tagStack = new Stack<String>();
}
- public void add(int level, long nodeId) {
+ public void add(int level, long nodeId, String tags) {
parseStack.push(new Pair<Integer, Long>(level, nodeId));
+ tagStack.push(tags);
}
public void pop() {
this.parseStack.pop();
+ this.tagStack.pop();
}
public int getCurrentLevel() {
@@ -136,6 +141,10 @@ public int getCurrentLevel() {
public long getCurrentNodeId() {
return parseStack.peek().second;
}
+
+ public String getCurrentTags() {
+ return tagStack.peek();
+ }
}
@@ -26,6 +26,7 @@
public String priority = "";
public String todo = "";
public String tags = "";
+ public String tags_inherited = "";
public String name = "";
private String payload = "";
@@ -39,6 +40,7 @@ public OrgNode(OrgNode node) {
this.priority = node.priority;
this.todo = node.todo;
this.tags = node.tags;
+ this.tags_inherited = node.tags_inherited;
this.name = node.name;
setPayload(node.getPayload());
}
@@ -70,6 +72,8 @@ public void set(Cursor cursor) throws OrgNodeNotFoundException {
.getColumnIndexOrThrow(OrgData.PRIORITY));
todo = cursor.getString(cursor.getColumnIndexOrThrow(OrgData.TODO));
tags = cursor.getString(cursor.getColumnIndexOrThrow(OrgData.TAGS));
+ tags_inherited = cursor.getString(cursor
+ .getColumnIndexOrThrow(OrgData.TAGS_INHERITED));
name = cursor.getString(cursor.getColumnIndexOrThrow(OrgData.NAME));
payload = cursor.getString(cursor
.getColumnIndexOrThrow(OrgData.PAYLOAD));
@@ -169,6 +173,7 @@ private ContentValues getSimpleContentValues() {
values.put(OrgData.PAYLOAD, payload);
values.put(OrgData.PRIORITY, priority);
values.put(OrgData.TAGS, tags);
+ values.put(OrgData.TAGS_INHERITED, tags_inherited);
return values;
}
@@ -182,6 +187,7 @@ private ContentValues getContentValues() {
values.put(OrgData.PAYLOAD, payload);
values.put(OrgData.PRIORITY, priority);
values.put(OrgData.TAGS, tags);
+ values.put(OrgData.TAGS_INHERITED, tags_inherited);
return values;
}

0 comments on commit 11190d6

Please sign in to comment.