use of de.geeksfactory.opacclient.objects.Account in project opacclient by opacapp.
the class SyncAccountJob method syncAccounts.
boolean syncAccounts(OpacClient app, AccountDataSource data, SharedPreferences sp, ReminderHelper helper) {
boolean failed = false;
List<Account> accounts = data.getAccountsWithPassword();
if (!sp.contains("update_151_clear_cache")) {
data.invalidateCachedData();
sp.edit().putBoolean("update_151_clear_cache", true).apply();
}
for (Account account : accounts) {
if (BuildConfig.DEBUG) {
Log.i(TAG, "Loading data for Account " + account.toString());
}
AccountData res;
try {
Library library = app.getLibrary(account.getLibrary());
if (!library.isAccountSupported()) {
data.deleteAccountData(account);
continue;
}
OpacApi api = app.getNewApi(library);
res = api.account(account);
if (res == null) {
failed = true;
continue;
}
} catch (JSONException | IOException | OpacApi.OpacErrorException e) {
e.printStackTrace();
failed = true;
continue;
} catch (OpacClient.LibraryRemovedException e) {
continue;
}
account.setPasswordKnownValid(true);
try {
data.update(account);
data.storeCachedAccountData(account, res);
} finally {
helper.generateAlarms();
}
}
return failed;
}
use of de.geeksfactory.opacclient.objects.Account in project opacclient by opacapp.
the class AccountDataSource method getAllAccounts.
public List<Account> getAllAccounts(String bib) {
List<Account> accs = new ArrayList<>();
String[] selA = { bib };
Cursor cursor = database.query("accounts", allColumns, "bib = ?", selA, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Account acc = cursorToAccount(cursor);
accs.add(acc);
cursor.moveToNext();
}
// Make sure to close the cursor
cursor.close();
return accs;
}
use of de.geeksfactory.opacclient.objects.Account in project opacclient by opacapp.
the class AccountDataSource method getAllAccounts.
public List<Account> getAllAccounts() {
List<Account> accs = new ArrayList<>();
Cursor cursor = database.query("accounts", allColumns, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Account acc = cursorToAccount(cursor);
accs.add(acc);
cursor.moveToNext();
}
// Make sure to close the cursor
cursor.close();
return accs;
}
use of de.geeksfactory.opacclient.objects.Account in project opacclient by opacapp.
the class AccountDataSource method getAccountsWithPassword.
public List<Account> getAccountsWithPassword(String ident) {
List<Account> accs = new ArrayList<>();
Cursor cursor = database.query("accounts", allColumns, "name is not null AND name != '' AND password is not null AND bib = ?", new String[] { ident }, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Account acc = cursorToAccount(cursor);
accs.add(acc);
cursor.moveToNext();
}
// Make sure to close the cursor
cursor.close();
return accs;
}
use of de.geeksfactory.opacclient.objects.Account in project opacclient by opacapp.
the class AccountEditActivity method delete.
private void delete() {
AccountDataSource data = new AccountDataSource(this);
data.remove(account);
// Check whether he deleted account was selected
if (((OpacClient) getApplication()).getAccount().getId() == account.getId()) {
List<Account> available_accounts = data.getAllAccounts();
if (available_accounts.size() == 0) {
((OpacClient) getApplication()).setAccount(0);
((OpacClient) getApplication()).addFirstAccount(this);
} else {
((OpacClient) getApplication()).setAccount(available_accounts.get(0).getId());
}
}
new ReminderHelper((OpacClient) getApplication()).generateAlarms();
}
Aggregations