private void combineBlockAgendas() { final String filename = "agendas.org"; long agendaFileNodeID = db.getFileId(filename); Cursor cursor = db.getNodeChildren(agendaFileNodeID); cursor.moveToFirst(); String previousBlockTitle = ""; long previousBlockNode = -1; while (cursor.isAfterLast() == false) { String name = cursor.getString(cursor.getColumnIndex("name")); if (name.indexOf(">") == -1) continue; String blockTitle = name.substring(0, name.indexOf(">")); if (TextUtils.isEmpty(blockTitle) == false) { // Is a block agenda if (blockTitle.equals(previousBlockTitle) == false) { // Create new node to contain block agenda previousBlockNode = db.addNode(agendaFileNodeID, blockTitle, "", "", "", db.getFilenameId(filename)); } String blockEntryName = name.substring(name.indexOf(">") + 1); long nodeId = cursor.getLong(cursor.getColumnIndex("_id")); Cursor children = db.getNodeChildren(nodeId); children.moveToFirst(); if (blockEntryName.startsWith("Day-agenda") && children.getCount() == 1) { blockEntryName = children.getString(children.getColumnIndex("name")); children = db.getNodeChildren(children.getLong(children.getColumnIndex("_id"))); children.moveToFirst(); cloneChildren(children, previousBlockNode, agendaFileNodeID, blockEntryName, filename); } else if (blockEntryName.startsWith("Week-agenda")) { while (children.isAfterLast() == false) { blockEntryName = children.getString(children.getColumnIndex("name")); Cursor children2 = db.getNodeChildren(children.getLong(children.getColumnIndex("_id"))); children2.moveToFirst(); cloneChildren(children2, previousBlockNode, agendaFileNodeID, blockEntryName, filename); children2.close(); children.moveToNext(); } } else cloneChildren(children, previousBlockNode, agendaFileNodeID, blockEntryName, filename); previousBlockTitle = blockTitle; db.deleteNode(cursor.getLong(cursor.getColumnIndex("_id"))); children.close(); } cursor.moveToNext(); } cursor.close(); }
private long parseLineIntoNode(String thisLine, int numstars) { String heading = thisLine.substring(numstars + 1); String name = ""; String priority = ""; String todo = ""; String tags = ""; Pattern pattern = prepareTitlePattern(); Matcher matcher = pattern.matcher(heading); if (matcher.find()) { if (matcher.group(TODO_GROUP) != null) { String tempTodo = matcher.group(TODO_GROUP).trim(); if (tempTodo.length() > 0 && isValidTodo(tempTodo)) { todo = tempTodo; } else { name = tempTodo + " "; } } if (matcher.group(PRIORITY_GROUP) != null) priority = matcher.group(PRIORITY_GROUP); name += matcher.group(TITLE_GROUP); if (this.useTitleField && matcher.group(AFTER_GROUP) != null) { int start = matcher.group(AFTER_GROUP).indexOf("TITLE:"); int end = matcher.group(AFTER_GROUP).indexOf("</after>"); if (start > -1 && end > -1) { String title = matcher.group(AFTER_GROUP).substring(start + 7, end); name = title + ">" + name; } } tags = matcher.group(TAGS_GROUP); if (tags == null) tags = ""; } else { Log.w(LT, "Title not matched: " + heading); name = heading; } long nodeId = db.addNode(this.parentIdStack.peek(), name, todo, priority, tags, this.file_id); return nodeId; }
private void cloneChildren( Cursor children, long previousBlockNode, Long agendaNodeFileID, String blockEntryName, String filename) { db.addNode( previousBlockNode, BLOCK_SEPARATOR_PREFIX + blockEntryName, "", "", "", db.getFilenameId(filename)); while (children.isAfterLast() == false) { db.cloneNode( children.getLong(children.getColumnIndex("_id")), previousBlockNode, db.getFilenameId("agendas.org")); children.moveToNext(); } }