public static int getNoteIdByGUID(Activity activity, string guid) { int id = 0; // get the notes ids string[] whereArgs = { guid }; ICursor cursor = activity.ManagedQuery(Tomdroid.CONTENT_URI, ID_PROJECTION, Note.GUID+"=?", whereArgs, null); // cursor must not be null and must return more than 0 entry if (!(cursor == null || cursor.Count == 0)) { cursor.MoveToFirst(); id = cursor.GetInt(cursor.GetColumnIndexOrThrow(Note.ID)); } else { // TODO send an error to the user TLog.d(TAG, "Cursor returned null or 0 notes"); } return id; }
// gets the titles of the notes present in the db, used in ViewNote.buildLinkifyPattern() public static ICursor getTitles(Activity activity) { string where = Note.TAGS + " NOT LIKE '%system:deleted%'"; // get a cursor containing the notes titles return activity.ManagedQuery(Tomdroid.CONTENT_URI, TITLE_PROJECTION, where, null, null); }
// gets a note from the content provider public static Note getNote(Activity activity, Uri uri) { Note note = null; // can we find a matching note? ICursor cursor = activity.ManagedQuery(uri, FULL_PROJECTION, null, null, null); // cursor must not be null and must return more than 0 entry if (!(cursor == null || cursor.Count == 0)) { // create the note from the cursor cursor.MoveToFirst(); string noteContent = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.NOTE_CONTENT)); string noteTitle = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.TITLE)); string noteChangeDate = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.MODIFIED_DATE)); string noteTags = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.TAGS)); string noteGUID = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.GUID)); int noteDbid = cursor.GetInt(cursor.GetColumnIndexOrThrow(Note.ID)); note = new Note(); note.setTitle(noteTitle); note.setXmlContent(stripTitleFromContent(noteContent, noteTitle)); note.setLastChangeDate(noteChangeDate); note.setTags(noteTags); note.setGuid(noteGUID); note.setDbId(noteDbid); } cursor.Close(); return note; }
/** * getNewNotes * get a guid list of notes that are newer than latest sync date * @param activity */ public static ICursor getNewNotes(Activity activity) { ICursor cursor = activity.ManagedQuery(Tomdroid.CONTENT_URI, DATE_PROJECTION, "strftime('%s', "+Note.MODIFIED_DATE+") > strftime('%s', '"+Preferences.GetString(Preferences.Key.LATEST_SYNC_DATE)+"')", null, null); return cursor; }
// gets the ids of the notes present in the db, used in SyncService.deleteNotes() public static ICursor getGuids(Activity activity) { // get a cursor containing the notes guids return activity.ManagedQuery(Tomdroid.CONTENT_URI, GUID_PROJECTION, null, null, null); }
// this function gets all non-deleted notes as notes in an array public static Note[] getAllNotesAsNotes(Activity activity, bool includeNotebookTemplates) { Uri uri = Tomdroid.CONTENT_URI; string where = "("+Note.TAGS + " NOT LIKE '%" + "system:deleted" + "%')"; string orderBy; if (!includeNotebookTemplates) { where += " AND (" + Note.TAGS + " NOT LIKE '%" + "system:template" + "%')"; } orderBy = Note.MODIFIED_DATE + " DESC"; ICursor cursor = activity.ManagedQuery(uri, FULL_PROJECTION, where, null, orderBy); if (cursor == null || cursor.Count == 0) { TLog.d(TAG, "no notes in cursor"); return null; } TLog.d(TAG, "{0} notes in cursor",cursor.Count); Note[] notes = new Note[cursor.Count]; cursor.MoveToFirst(); int key = 0; while(!cursor.IsAfterLast) { string noteContent = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.NOTE_CONTENT)); string noteTitle = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.TITLE)); string noteChangeDate = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.MODIFIED_DATE)); string noteTags = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.TAGS)); string noteGUID = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.GUID)); int noteDbid = cursor.GetInt(cursor.GetColumnIndexOrThrow(Note.ID)); Note note = new Note(); note.setTitle(noteTitle); note.setXmlContent(stripTitleFromContent(noteContent, noteTitle)); note.setLastChangeDate(noteChangeDate); note.addTag(noteTags); note.setGuid(noteGUID); note.setDbId(noteDbid); notes[key++] = note; cursor.MoveToNext(); } cursor.Close(); return notes; }
public static ICursor getAllNotes(Activity activity, bool includeNotebookTemplates) { // get a cursor representing all notes from the NoteProvider Uri notes = Tomdroid.CONTENT_URI; string where = "("+Note.TAGS + " NOT LIKE '%" + "system:deleted" + "%')"; if (!includeNotebookTemplates) { where += " AND (" + Note.TAGS + " NOT LIKE '%" + "system:template" + "%')"; } return activity.ManagedQuery(notes, LIST_PROJECTION, where, null, sortOrder); }