use of de.geeksfactory.opacclient.apis.EbookServiceApi in project opacclient by opacapp.
the class SearchResultDetailFragment method refreshMenu.
protected void refreshMenu(Menu menu) {
if (item != null) {
if (item.isReservable()) {
menu.findItem(R.id.action_reservation).setVisible(true);
} else {
menu.findItem(R.id.action_reservation).setVisible(false);
}
OpacApi api;
try {
api = app.getApi();
} catch (OpacClient.LibraryRemovedException e) {
return;
}
if (item.isBookable() && api instanceof EbookServiceApi) {
if (((EbookServiceApi) api).isEbook(item)) {
menu.findItem(R.id.action_lendebook).setVisible(true);
} else {
menu.findItem(R.id.action_lendebook).setVisible(false);
}
} else {
menu.findItem(R.id.action_lendebook).setVisible(false);
}
menu.findItem(R.id.action_tocollection).setVisible(item.getCollectionId() != null);
} else {
menu.findItem(R.id.action_reservation).setVisible(false);
menu.findItem(R.id.action_lendebook).setVisible(false);
menu.findItem(R.id.action_tocollection).setVisible(false);
}
String bib = app.getLibrary().getIdent();
StarDataSource data = new StarDataSource(getActivity());
String _id = id;
if (item != null) {
_id = item.getId();
}
if ((_id == null || _id.equals("")) && item != null) {
if (data.isStarredTitle(bib, item.getTitle())) {
menu.findItem(R.id.action_star).setIcon(R.drawable.ic_star_1_white_24dp);
}
} else {
if (data.isStarred(bib, _id)) {
menu.findItem(R.id.action_star).setIcon(R.drawable.ic_star_1_white_24dp);
}
}
}
use of de.geeksfactory.opacclient.apis.EbookServiceApi 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.apis.EbookServiceApi 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