Search in sources :

Example 16 with Account

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;
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) OpacClient(de.geeksfactory.opacclient.OpacClient) AccountData(de.geeksfactory.opacclient.objects.AccountData) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) JSONException(org.json.JSONException) Library(de.geeksfactory.opacclient.objects.Library) IOException(java.io.IOException)

Example 17 with Account

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;
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 18 with Account

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;
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 19 with Account

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;
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 20 with Account

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();
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) ReminderHelper(de.geeksfactory.opacclient.reminder.ReminderHelper) OpacClient(de.geeksfactory.opacclient.OpacClient)

Aggregations

Account (de.geeksfactory.opacclient.objects.Account)25 AccountDataSource (de.geeksfactory.opacclient.storage.AccountDataSource)8 View (android.view.View)6 TextView (android.widget.TextView)6 Cursor (android.database.Cursor)5 ImageView (android.widget.ImageView)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)4 AlertDialog (android.support.v7.app.AlertDialog)4 LayoutInflater (android.view.LayoutInflater)4 AdapterView (android.widget.AdapterView)4 ListView (android.widget.ListView)4 OpacClient (de.geeksfactory.opacclient.OpacClient)4 AccountData (de.geeksfactory.opacclient.objects.AccountData)4 JSONObject (org.json.JSONObject)4 SuppressLint (android.annotation.SuppressLint)3 SharedPreferences (android.content.SharedPreferences)3 RecyclerView (android.support.v7.widget.RecyclerView)3