Esempio n. 1
0
  private synchronized void addAccount(final RedditAccount account, final SQLiteDatabase inDb) {

    final SQLiteDatabase db;
    if (inDb == null) db = getWritableDatabase();
    else db = inDb;

    final ContentValues row = new ContentValues();

    row.put(FIELD_USERNAME, account.username);

    if (account.refreshToken == null) {
      row.putNull(FIELD_REFRESH_TOKEN);
    } else {
      row.put(FIELD_REFRESH_TOKEN, account.refreshToken.token);
    }

    row.put(FIELD_PRIORITY, account.priority);

    db.insert(TABLE, null, row);

    reloadAccounts(db);
    updateNotifier.updateAllListeners();

    if (inDb == null) db.close();
  }
Esempio n. 2
0
  public void deleteAccount(RedditAccount account) {

    final SQLiteDatabase db = getWritableDatabase();
    db.delete(TABLE, FIELD_USERNAME + "=?", new String[] {account.username});
    reloadAccounts(db);
    updateNotifier.updateAllListeners();
    db.close();
  }
Esempio n. 3
0
  public synchronized void setDefaultAccount(final RedditAccount newDefault) {

    final SQLiteDatabase db = getWritableDatabase();

    db.execSQL(
        String.format(
            "UPDATE %s SET %s=(SELECT MIN(%s)-1 FROM %s) WHERE %s=?",
            TABLE, FIELD_PRIORITY, FIELD_PRIORITY, TABLE, FIELD_USERNAME),
        new String[] {newDefault.username});

    reloadAccounts(db);
    db.close();

    updateNotifier.updateAllListeners();
  }
Esempio n. 4
0
 public void addUpdateListener(final RedditAccountChangeListener listener) {
   updateNotifier.addListener(listener);
 }