use of de.geeksfactory.opacclient.OpacClient 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.OpacClient in project opacclient by opacapp.
the class SyncAccountJob method onRunJob.
@NonNull
@Override
protected Result onRunJob(Params params) {
if (BuildConfig.DEBUG)
Log.i(TAG, "SyncAccountJob started");
if (getParams().getTag().equals(TAG_RETRY) && getParams().getFailureCount() >= 4) {
// too many retries, give up and wait for the next regular scheduled run
return Result.SUCCESS;
}
if (!getParams().getTag().equals(TAG_RETRY)) {
updateLibraryConfig();
}
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
if (!sp.getBoolean(SyncAccountJobCreator.PREF_SYNC_SERVICE, false)) {
if (BuildConfig.DEBUG)
Log.i(TAG, "notifications are disabled");
return Result.SUCCESS;
}
OpacClient app = getApp();
AccountDataSource data = new AccountDataSource(getContext());
ReminderHelper helper = new ReminderHelper(app);
boolean failed = syncAccounts(app, data, sp, helper);
if (BuildConfig.DEBUG) {
Log.i(TAG, "SyncAccountJob finished " + (failed ? " with errors" : " " + "successfully"));
}
if (failed && params.getTag().equals(TAG)) {
// only schedule a retry job if this is not already a retry
scheduleRetryJob(getContext());
}
if (params.getTag().equals(TAG_RETRY)) {
return failed ? Result.RESCHEDULE : Result.SUCCESS;
} else {
return failed ? Result.FAILURE : Result.SUCCESS;
}
}
use of de.geeksfactory.opacclient.OpacClient in project opacclient by opacapp.
the class Utils method getAccountSubtitle.
public static String getAccountSubtitle(Account account, Context context) {
try {
OpacClient app = (OpacClient) context.getApplicationContext();
Library library = app.getLibrary(account.getLibrary());
if (context.getString(R.string.default_account_name).equals(account.getLabel())) {
return library.getTitle();
} else {
return library.getCity() + " ยท " + library.getTitle();
}
} catch (IOException | JSONException e) {
e.printStackTrace();
return null;
}
}
use of de.geeksfactory.opacclient.OpacClient 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();
}
use of de.geeksfactory.opacclient.OpacClient in project opacclient by opacapp.
the class AccountItemDetailActivity method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_account_item_detail, menu);
MenuItem prolong = menu.findItem(R.id.action_prolong);
MenuItem download = menu.findItem(R.id.action_download);
MenuItem cancel = menu.findItem(R.id.action_cancel);
MenuItem booking = menu.findItem(R.id.action_booking);
OpacClient app = (OpacClient) getApplication();
OpacApi api = null;
try {
api = app.getApi();
} catch (OpacClient.LibraryRemovedException e) {
e.printStackTrace();
}
if (item instanceof LentItem) {
final LentItem i = (LentItem) item;
cancel.setVisible(false);
booking.setVisible(false);
if (i.getProlongData() != null) {
prolong.setVisible(true);
// ViewCompat.setAlpha(prolong, item.isRenewable() ? 1f : 0.4f);
download.setVisible(false);
} else if (i.getDownloadData() != null && api != null && api instanceof EbookServiceApi) {
prolong.setVisible(false);
download.setVisible(true);
} else {
prolong.setVisible(false);
download.setVisible(false);
}
} else if (item instanceof ReservedItem) {
final ReservedItem i = (ReservedItem) item;
prolong.setVisible(false);
download.setVisible(false);
if (i.getBookingData() != null) {
booking.setVisible(true);
cancel.setVisible(false);
} else if (i.getCancelData() != null) {
cancel.setVisible(true);
booking.setVisible(false);
} else {
cancel.setVisible(false);
booking.setVisible(false);
}
}
return true;
}
Aggregations