Ejemplo n.º 1
0
  /*
   * Updating a tag
   */
  public int updateTag(Tag tag) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_TAG_NAME, tag.getTagName());

    // updating row
    return db.update(
        TABLE_TAG, values, KEY_ID + " = ?", new String[] {String.valueOf(tag.getId())});
  }
Ejemplo n.º 2
0
  /*
   * Deleting a tag
   */
  public void deleteTag(Tag tag, boolean should_delete_all_tag_todos) {
    SQLiteDatabase db = this.getWritableDatabase();

    // before deleting tag
    // check if todos under this tag should also be deleted
    if (should_delete_all_tag_todos) {
      // get all todos under this tag
      List<Todo> allTagToDos = getAllToDosByTag(tag.getTagName());

      // delete all todos
      for (Todo todo : allTagToDos) {
        // delete todo
        deleteToDo(todo.getId());
      }
    }

    // now delete the tag
    db.delete(TABLE_TAG, KEY_ID + " = ?", new String[] {String.valueOf(tag.getId())});
  }
Ejemplo n.º 3
0
  /*
   * Creating tag
   */
  public long createTag(Tag tag) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_TAG_NAME, tag.getTagName());
    values.put(KEY_CREATED_AT, getDateTime());

    // insert row
    long tag_id = db.insert(TABLE_TAG, null, values);

    return tag_id;
  }
Ejemplo n.º 4
0
  /** getting all tags */
  public List<Tag> getAllTags() {
    List<Tag> tags = new ArrayList<Tag>();
    String selectQuery = "SELECT  * FROM " + TABLE_TAG;

    Log.e(LOG, selectQuery);

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (c.moveToFirst()) {
      do {
        Tag t = new Tag();
        t.setId(c.getInt((c.getColumnIndex(KEY_ID))));
        t.setTagName(c.getString(c.getColumnIndex(KEY_TAG_NAME)));

        // adding to tags list
        tags.add(t);
      } while (c.moveToNext());
    }
    return tags;
  }