use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.
the class OpacClient method getAccount.
public Account getAccount() {
if (account != null) {
if (sp.getLong(PREF_SELECTED_ACCOUNT, 0) == account.getId()) {
return account;
}
}
AccountDataSource data = new AccountDataSource(this);
account = data.getAccount(sp.getLong(PREF_SELECTED_ACCOUNT, 0));
return account;
}
use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.
the class ReminderBroadcastReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
this.context = context;
this.intent = intent;
this.prefs = PreferenceManager.getDefaultSharedPreferences(context);
adata = new AccountDataSource(context);
alarm = adata.getAlarm(intent.getLongExtra(EXTRA_ALARM_ID, -1));
if (alarm == null) {
return;
}
switch(intent.getAction()) {
case ACTION_SHOW_NOTIFICATION:
showNotification();
break;
case ACTION_NOTIFICATION_DELETED:
notificationDeleted();
break;
case ACTION_NOTIFICATION_SNOOZE:
notificationSnooze();
break;
case ACTION_NOTIFICATION_CLICK:
notificationClick();
break;
case ACTION_NOTIFICATION_DONT_REMIND_AGAIN:
notificationDontRemindAgain();
break;
}
// reschedule alarms
new ReminderHelper((OpacClient) context.getApplicationContext()).scheduleAlarms();
}
use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.
the class SearchResultDetailFragment method reservationStart.
protected void reservationStart() {
if (invalidated) {
new RestoreSessionTask(false).execute();
}
OpacApi api = null;
try {
api = app.getApi();
} catch (OpacClient.LibraryRemovedException e) {
return;
}
if (api instanceof EbookServiceApi) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
if (sp.getString("email", "").equals("") && ((EbookServiceApi) api).isEbook(item)) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getString(R.string.opac_error_email)).setCancelable(false).setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).setPositiveButton(R.string.prefs, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
app.toPrefs(getActivity());
}
});
AlertDialog alert = builder.create();
alert.show();
return;
}
}
AccountDataSource data = new AccountDataSource(getActivity());
final List<Account> accounts = data.getAccountsWithPassword(app.getLibrary().getIdent());
if (accounts.size() == 0) {
dialog_no_credentials();
} else if (accounts.size() > 1 && !getActivity().getIntent().getBooleanExtra("reservation", false) && (api.getSupportFlags() & OpacApi.SUPPORT_FLAG_CHANGE_ACCOUNT) != 0 && !(SearchResultDetailFragment.this.id == null || SearchResultDetailFragment.this.id.equals("null") || SearchResultDetailFragment.this.id.equals(""))) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_simple_list, null, false);
ListView lv = (ListView) view.findViewById(R.id.lvBibs);
AccountListAdapter adapter = new AccountListAdapter(getActivity(), accounts);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (accounts.get(position).getId() != app.getAccount().getId() || account_switched) {
if (SearchResultDetailFragment.this.id == null || SearchResultDetailFragment.this.id.equals("null") || SearchResultDetailFragment.this.id.equals("")) {
Toast.makeText(getActivity(), R.string.accchange_sorry, Toast.LENGTH_LONG).show();
} else {
if (app.getAccount().getId() != accounts.get(position).getId()) {
app.setAccount(accounts.get(position).getId());
}
Intent intent = new Intent(getActivity(), SearchResultDetailActivity.class);
intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, SearchResultDetailFragment.this.id);
// TODO: refresh fragment instead
intent.putExtra("reservation", true);
startActivity(intent);
}
} else {
reservationDo();
}
adialog.dismiss();
}
});
builder.setTitle(R.string.account_select).setView(view).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
adialog.cancel();
}
});
adialog = builder.create();
adialog.show();
} else {
reservationDo();
}
}
use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.
the class SearchResultDetailFragment method bookingDo.
public void bookingDo() {
MultiStepResultHelper<DetailedItem> msrhBooking = new MultiStepResultHelper<>(getActivity(), item, R.string.doing_booking);
msrhBooking.setCallback(new Callback<DetailedItem>() {
@Override
public void onSuccess(MultiStepResult result) {
if (getActivity() == null) {
return;
}
AccountDataSource adata = new AccountDataSource(getActivity());
adata.invalidateCachedAccountData(app.getAccount());
Intent intent = new Intent(getActivity(), app.getMainActivity());
intent.putExtra(MainActivity.EXTRA_FRAGMENT, "account");
getActivity().startActivity(intent);
getActivity().finish();
}
@Override
public void onError(MultiStepResult result) {
if (getActivity() == null) {
return;
}
dialog_wrong_credentials(result.getMessage(), false);
}
@Override
public void onUnhandledResult(MultiStepResult result) {
}
@Override
public void onUserCancel() {
}
@Override
public StepTask<?> newTask(MultiStepResultHelper helper, int useraction, String selection, DetailedItem item) {
return new BookingTask(helper, useraction, selection, item);
}
});
msrhBooking.start();
}
use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.
the class SearchResultDetailFragment method bookingStart.
protected void bookingStart() {
AccountDataSource data = new AccountDataSource(getActivity());
final List<Account> accounts = data.getAccountsWithPassword(app.getLibrary().getIdent());
if (accounts.size() == 0) {
dialog_no_credentials();
} else if (accounts.size() > 1) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_simple_list, null, false);
ListView lv = (ListView) view.findViewById(R.id.lvBibs);
AccountListAdapter adapter = new AccountListAdapter(getActivity(), accounts);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (app.getAccount().getId() != accounts.get(position).getId()) {
app.setAccount(accounts.get(position).getId());
}
bookingDo();
adialog.dismiss();
}
});
builder.setTitle(R.string.account_select).setView(view).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
adialog.cancel();
}
});
adialog = builder.create();
adialog.show();
} else {
bookingDo();
}
}
Aggregations