Ejemplo n.º 1
0
  // Update check-in data
  public synchronized DBError updateCheckInData(CheckInData data) {
    Assert.assertTrue(data != null);

    DBError result = DBError.DB_ERROR_NONE;
    try {
      // Append new shortcut item to mDatabase
      ContentValues values = new ContentValues();
      values.put("lat", data.lat);
      values.put("lng", data.lng);
      values.put("time", data.time);
      values.put("date", Utility.getDateString(data.time, DATE_FORMAT));
      values.put("place", data.place);

      long ret =
          mDatabase.update(
              "tbl_checkin", values, "time=?", new String[] {String.valueOf(data.time)});
      if (ret == -1) result = DBError.DB_ERROR_FAILED;
      else if (ret == 0) result = DBError.DB_ERROR_NOT_EXIST;

    } catch (SQLiteException e) {
      result = DBError.DB_ERROR_FAILED;
    }

    return result;
  }
Ejemplo n.º 2
0
  /** *********************************** CHECKIN ************************************ */
  public synchronized DBError loadCheckedinDateList(ArrayList<Long> dateList) {
    // clear all favorite list
    Assert.assertTrue(dateList != null);
    dateList.clear();

    try {
      String rawQuery = "select distinct date from tbl_checkin";
      Cursor listCursor = mDatabase.rawQuery(rawQuery, null);

      if (listCursor == null) return DBError.DB_ERROR_FAILED;

      if (listCursor.getCount() > 0) {
        while (listCursor.moveToNext() == true) {
          String dateStr = listCursor.getString(listCursor.getColumnIndex("date"));
          long date = Utility.getDate(dateStr, DATE_FORMAT).getTime();
          dateList.add(date);
        }
      }

      // Close query
      listCursor.close();
    } catch (SQLiteException e) {
      return DBError.DB_ERROR_FAILED;
    }

    return DBError.DB_ERROR_NONE;
  }
Ejemplo n.º 3
0
  /** Add check-in data */
  public synchronized DBError addCheckInData(CheckInData data) {
    ContentValues values = new ContentValues();
    long result;

    Assert.assertTrue(data != null);

    values.put("lat", data.lat);
    values.put("lng", data.lng);
    values.put("time", data.time);

    String dateStr = Utility.getDateString(data.time, DATE_FORMAT);
    values.put("date", dateStr);
    values.put("place", data.place);

    result = mDatabase.insert("tbl_checkin", null, values);
    if (result == -1) return DBError.DB_ERROR_FAILED;

    return DBError.DB_ERROR_NONE;
  }
Ejemplo n.º 4
0
  // Load all check-in data on specified date
  public synchronized DBError loadCheckinDataListOnDate(
      ArrayList<CheckInData> dataList, long date) {
    // clear all favorite list
    Assert.assertTrue(dataList != null);
    dataList.clear();

    long startTime;
    long endTime;

    startTime = Utility.getDateTimeMilis(date);
    endTime = startTime + Constant.DATE_MILISECONDS;
    try {
      String rawQuery =
          "select * from tbl_checkin where time >= "
              + startTime
              + " and time < "
              + endTime
              + " order by time";
      Cursor listCursor = mDatabase.rawQuery(rawQuery, null);

      if (listCursor == null) return DBError.DB_ERROR_FAILED;

      if (listCursor.getCount() > 0) {
        while (listCursor.moveToNext() == true) {
          CheckInData newData = new CheckInData();
          newData.lat = listCursor.getDouble(listCursor.getColumnIndex("lat"));
          newData.lng = listCursor.getDouble(listCursor.getColumnIndex("lng"));
          newData.time = listCursor.getLong(listCursor.getColumnIndex("time"));
          newData.place = listCursor.getString(listCursor.getColumnIndex("place"));

          dataList.add(newData);
        }
      }

      // Close query
      listCursor.close();
    } catch (SQLiteException e) {
      return DBError.DB_ERROR_FAILED;
    }

    return DBError.DB_ERROR_NONE;
  }