예제 #1
0
  // Getting All notes
  public List<Note> getAllNotes() {
    SQLiteDatabase db = DBHelper.getWritableDatabase();

    List<Note> noteList = new ArrayList<>();
    // Select All Query
    String selectQuery =
        "SELECT  * FROM " + com.subhrajyoti.babai.noteworthy.DB.DBHelper.TABLE_NAME;

    Cursor cursor = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
      do {
        Note note = new Note();
        note.setId(Integer.parseInt(cursor.getString(0)));
        note.setTitle(cursor.getString(1));
        note.setDesc(cursor.getString(2));
        note.setDate(cursor.getString(3));
        // Adding note to list
        noteList.add(note);
      } while (cursor.moveToNext());
    }
    cursor.close();

    // return note list
    return noteList;
  }
예제 #2
0
  public void addNoteToTrash(Note note) {

    database = DBHelper.getWritableDatabase();

    ContentValues values = new ContentValues();

    values.put(com.subhrajyoti.babai.noteworthy.DB.DBHelper.COL_NOTE_TITLE_TRASH, note.getTitle());
    values.put(com.subhrajyoti.babai.noteworthy.DB.DBHelper.COL_NOTE_DESC_TRASH, note.getDesc());
    values.put(com.subhrajyoti.babai.noteworthy.DB.DBHelper.COL_NOTE_DATE_TRASH, note.getDate());

    database.insert(com.subhrajyoti.babai.noteworthy.DB.DBHelper.TABLE_NAME_TRASH, null, values);
    database.close();
  }
예제 #3
0
  // Updating single note
  public int updateNote(Note note) {
    SQLiteDatabase db = DBHelper.getWritableDatabase();

    ContentValues values = new ContentValues();

    values.put(com.subhrajyoti.babai.noteworthy.DB.DBHelper.COL_NOTE_TITLE, note.getTitle());
    values.put(com.subhrajyoti.babai.noteworthy.DB.DBHelper.COL_NOTE_DESC, note.getDesc());
    values.put(com.subhrajyoti.babai.noteworthy.DB.DBHelper.COL_NOTE_DATE, note.getDate());

    // updating row
    return db.update(
        com.subhrajyoti.babai.noteworthy.DB.DBHelper.TABLE_NAME,
        values,
        com.subhrajyoti.babai.noteworthy.DB.DBHelper.COL_ID + " = ?",
        new String[] {String.valueOf(note.getId())});
  }
예제 #4
0
  // Deleting single note
  public void deleteNote(Note note) {
    SQLiteDatabase db = DBHelper.getWritableDatabase();

    db.delete(
        com.subhrajyoti.babai.noteworthy.DB.DBHelper.TABLE_NAME,
        com.subhrajyoti.babai.noteworthy.DB.DBHelper.COL_ID + " = ?",
        new String[] {String.valueOf(note.getId())});
    db.close();
  }