Ejemplo n.º 1
0
  private void insertItem(WaitItem waitItem) {
    ContentValues values = new ContentValues();
    values.put(GoalDatabase.WaitItemEntry.COL_TEXT, waitItem.getName());
    values.put(GoalDatabase.WaitItemEntry.COL_GOAL_ID, waitItem.getGoalId());
    values.put(GoalDatabase.WaitItemEntry.COL_RESPONSIBLE, waitItem.getResponsible());
    Calendar dueDate = waitItem.getDueDate();
    if (dueDate != null) {
      values.put(GoalDatabase.WaitItemEntry.COL_DUE_YEAR, dueDate.get(Calendar.YEAR));
      values.put(GoalDatabase.WaitItemEntry.COL_DUE_MONTH, dueDate.get(Calendar.MONTH));
      values.put(GoalDatabase.WaitItemEntry.COL_DUE_DAY, dueDate.get(Calendar.DAY_OF_MONTH));
    }
    Calendar requestDate = waitItem.getRequestDate();
    if (requestDate != null) {
      values.put(GoalDatabase.WaitItemEntry.COL_REQUEST_YEAR, requestDate.get(Calendar.YEAR));
      values.put(GoalDatabase.WaitItemEntry.COL_REQUEST_MONTH, requestDate.get(Calendar.MONTH));
      values.put(
          GoalDatabase.WaitItemEntry.COL_REQUEST_DAY, requestDate.get(Calendar.DAY_OF_MONTH));
    }

    if (waitItem.getId() == 0) {
      mContext.getContentResolver().insert(WaitItemProvider.CONTENT_URI, values);
    } else {
      String selection = GoalDatabase.WaitItemEntry._ID + "=?";
      String[] args = new String[] {Integer.valueOf(waitItem.getId()).toString()};
      mContext.getContentResolver().update(WaitItemProvider.CONTENT_URI, values, selection, args);
    }
  }
Ejemplo n.º 2
0
 protected WaitItem readCursor(Cursor cursor) {
   WaitItem item = null;
   try {
     item =
         new WaitItem(
             cursor.getString(cursor.getColumnIndexOrThrow(GoalDatabase.WaitItemEntry.COL_TEXT)));
     item.setId(cursor.getInt(cursor.getColumnIndexOrThrow(GoalDatabase.WaitItemEntry._ID)));
     item.setGoalId(
         cursor.getInt(cursor.getColumnIndexOrThrow(GoalDatabase.WaitItemEntry.COL_GOAL_ID)));
     item.setResponsible(
         cursor.getString(
             cursor.getColumnIndexOrThrow(GoalDatabase.WaitItemEntry.COL_RESPONSIBLE)));
     int dueYear = cursor.getInt(cursor.getColumnIndex(GoalDatabase.WaitItemEntry.COL_DUE_YEAR));
     int dueMonth = cursor.getInt(cursor.getColumnIndex(GoalDatabase.WaitItemEntry.COL_DUE_MONTH));
     int dueDay = cursor.getInt(cursor.getColumnIndex(GoalDatabase.WaitItemEntry.COL_DUE_DAY));
     item.setDueDate(new GregorianCalendar(dueYear, dueMonth, dueDay));
     int requestYear =
         cursor.getInt(cursor.getColumnIndex(GoalDatabase.WaitItemEntry.COL_REQUEST_YEAR));
     int requestMonth =
         cursor.getInt(cursor.getColumnIndex(GoalDatabase.WaitItemEntry.COL_REQUEST_MONTH));
     int requestDay =
         cursor.getInt(cursor.getColumnIndex(GoalDatabase.WaitItemEntry.COL_REQUEST_DAY));
     item.setRequestDate(new GregorianCalendar(requestYear, requestMonth, requestDay));
   } catch (android.database.CursorIndexOutOfBoundsException e) {
     // nothing found - that is ok
   }
   return item;
 }