public void parse(
      String filename,
      String filenameAlias,
      String checksum,
      BufferedReader breader,
      Context context) {
    this.useTitleField =
        PreferenceManager.getDefaultSharedPreferences(context).getBoolean("useAgendaTitle", false);

    this.file_id = addNewFile(filename, filenameAlias, checksum, true);

    this.todos = db.getGroupedTodos();

    this.starStack = new Stack<Integer>();
    this.parentIdStack = new Stack<Long>();

    this.starStack.push(0);
    Long fileID = db.getFileId(filename);
    this.parentIdStack.push(fileID);

    this.payload = new StringBuilder();

    db.getDB().beginTransaction();

    try {
      String currentLine;

      while ((currentLine = breader.readLine()) != null) {

        if (TextUtils.isEmpty(currentLine)) continue;

        int lineLength = currentLine.length();
        int numstars = numberOfStars(currentLine, lineLength);
        if (numstars > 0) {
          parseHeading(currentLine, numstars);
        } else {
          payload.append(currentLine);
          payload.append("\n");
        }
      }

      // Add payload to the final node
      db.addNodePayload(this.parentIdStack.peek(), this.payload.toString());

    } catch (IOException e) {
    }

    if (filename.equals("agendas.org")
        && PreferenceManager.getDefaultSharedPreferences(context)
            .getBoolean("combineBlockAgendas", false)
        && useTitleField) {
      combineBlockAgendas();
    }

    db.getDB().setTransactionSuccessful();
    db.getDB().endTransaction();

    updateCalendar(filename, context);
  }
  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();
  }