Пример #1
0
  @Override
  public void add(Thread thread, User user) {
    SQLiteDatabase db = null;
    ContentValues values = null;

    values = new ContentValues(3);
    values.put(Thread.Columns.SECTION_ID, thread.getSection().getSectionId());
    values.put(Thread.Columns.THREAD_ID, thread.getThreadId());
    values.put(Thread.Columns.FLOOR, thread.getFloor());
    values.put(Thread.Columns.USER_ID, user.getUserId());

    db = DatabaseHelper.getWriteDatabase();
    db.insert(Constants.APOLLO_DATA_TABLE_BOOKMARK, null, values);
    db.close();
  }
Пример #2
0
  @Override
  public void delete(Thread thread, User user) {
    SQLiteDatabase db = null;
    String whereClause = null;
    String[] whereArgs = null;

    whereClause =
        Thread.Columns.USER_ID
            + "=? AND "
            + Thread.Columns.SECTION_ID
            + "=? AND "
            + Thread.Columns.THREAD_ID
            + "=?";
    whereArgs =
        new String[] {
          Integer.toString(user.getUserId()),
          thread.getSection().getSectionId(),
          Integer.toString(thread.getThreadId())
        };
    db = DatabaseHelper.getWriteDatabase();
    db.delete(Constants.APOLLO_DATA_TABLE_BOOKMARK, whereClause, whereArgs);
    db.close();
  }
Пример #3
0
  @Override
  public int getPosition(Thread thread, User user) {
    SQLiteDatabase db = null;
    Cursor cursor = null;
    String[] columns = null;
    String selection = null;
    int pos = 0;
    String[] args = null;

    db = DatabaseHelper.getReadDatabase();
    columns = new String[] {Thread.Columns.FLOOR};
    selection =
        Thread.Columns.USER_ID
            + "=? AND "
            + Thread.Columns.SECTION_ID
            + "=? AND "
            + Thread.Columns.THREAD_ID
            + "=?";
    args =
        new String[] {
          Integer.toString(user.getUserId()),
          thread.getSection().getSectionId(),
          Integer.toString(thread.getThreadId())
        };

    cursor =
        db.query(Constants.APOLLO_DATA_TABLE_BOOKMARK, columns, selection, args, null, null, null);
    if (cursor != null) {
      for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
        pos = cursor.getInt(0);
      }
      cursor.close();
    }
    db.close();
    return pos;
  }