예제 #1
0
  public static boolean addNewArea(Area area, ContentResolver cr) {

    String w = BetaProvider.KEY_AREA_NAME + " = ?";

    Cursor c = cr.query(Area.CONTENT_URI, null, w, new String[] {area.getName()}, null);

    int dbCount;
    if (c != null) dbCount = c.getCount();
    else dbCount = 0;

    c.close();
    if (dbCount == 0) {

      ContentValues values = new ContentValues();

      if (area.getMasterId() > 0) { // coming from web server, put ID and CLEAN state
        values.put(BetaProvider.KEY_AREA_STATE, State.CLEAN);
        values.put(BetaProvider.KEY_AREA_ID_TYPE, IdType.MASTER);
      } else { // coming from user, mark as NEW for future sync AND leave MASTER as 0/default
        values.put(BetaProvider.KEY_AREA_STATE, State.NEW);
        values.put(BetaProvider.KEY_AREA_ID_TYPE, IdType.LOCAL);
      }
      values.put(BetaProvider.KEY_AREA_NAME, area.getName());
      if (null != area.getDateAdded())
        values.put(
            BetaProvider.KEY_AREA_DATE_ADDED,
            BetaProvider.sqliteDateFormater.format(area.getDateAdded()));
      else
        values.put(
            BetaProvider.KEY_AREA_DATE_ADDED,
            BetaProvider.sqliteDateFormater.format(Calendar.getInstance().getTime()));
      if (null != area.getDateModified())
        values.put(
            BetaProvider.KEY_AREA_DATE_MODIFIED,
            BetaProvider.sqliteDateFormater.format(area.getDateModified()));
      else
        values.put(
            BetaProvider.KEY_AREA_DATE_MODIFIED,
            BetaProvider.sqliteDateFormater.format(Calendar.getInstance().getTime()));

      values.put(BetaProvider.KEY_AREA_DETAILS, area.getDetails());
      values.put(BetaProvider.KEY_AREA_LATITUDE, area.getLatitude());
      values.put(BetaProvider.KEY_AREA_LONGITUDE, area.getLongitude());
      values.put(BetaProvider.KEY_AREA_PARENT, area.getParent());
      values.put(BetaProvider.KEY_AREA_MASTER, area.getMasterId());
      values.put(BetaProvider.KEY_AREA_PERMISSION, area.getPermission());

      cr.insert(Area.CONTENT_URI, values);
    }
    return true;
  }
예제 #2
0
  public static boolean updateArea(Area area, ContentResolver contentResolver) {

    ContentValues values = new ContentValues();

    values.put(BetaProvider.KEY_AREA_NAME, area.getName());
    values.put(BetaProvider.KEY_AREA_DETAILS, area.getDetails());
    values.put(BetaProvider.KEY_AREA_LONGITUDE, area.getLongitude());
    values.put(BetaProvider.KEY_AREA_LATITUDE, area.getLatitude());
    values.put(BetaProvider.KEY_AREA_PARENT, area.getParent());
    values.put(BetaProvider.KEY_AREA_STATE, area.getState());
    values.put(BetaProvider.KEY_AREA_MASTER, area.getMasterId());
    values.put(BetaProvider.KEY_AREA_ID_TYPE, area.getIdType());
    values.put(
        BetaProvider.KEY_AREA_DATE_MODIFIED,
        BetaProvider.sqliteDateFormater.format(Calendar.getInstance().getTime()));
    values.put(BetaProvider.KEY_AREA_PERMISSION, area.getPermission());

    String where = BetaProvider.KEY_AREA_ID + " = ?";

    contentResolver.update(
        Area.CONTENT_URI, values, where, new String[] {String.valueOf(area.getId())});

    return true;
  }