public RedditAccount getAccount(String username) { final ArrayList<RedditAccount> accounts = getAccounts(); RedditAccount selectedAccount = null; for (RedditAccount account : accounts) { if (!account.isAnonymous() && account.username.equalsIgnoreCase(username)) { selectedAccount = account; break; } } return selectedAccount; }
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); row.put(FIELD_COOKIES, account.getCookieBytes()); row.put(FIELD_MODHASH, account.modhash); row.put(FIELD_PRIORITY, account.priority); db.insert(TABLE, null, row); reloadAccounts(db); updateNotifier.updateAllListeners(); if (inDb == null) db.close(); }