use of de.geeksfactory.opacclient.apis.OpacApi 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.OpacApi in project opacclient by opacapp.
the class SearchResultDetailFragment method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final String bib = app.getLibrary().getIdent();
if (item.getItemId() == R.id.action_reservation) {
reservationStart();
return true;
} else if (item.getItemId() == R.id.action_lendebook) {
bookingStart();
return true;
} else if (item.getItemId() == R.id.action_tocollection) {
if (getActivity().getIntent().getBooleanExtra("from_collection", false)) {
getActivity().finish();
} else {
Intent intent = new Intent(getActivity(), SearchResultDetailActivity.class);
intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, getItem().getCollectionId());
startActivity(intent);
getActivity().finish();
}
return true;
} else if (item.getItemId() == R.id.action_share) {
if (getItem() == null) {
Toast toast = Toast.makeText(getActivity(), getString(R.string.share_wait), Toast.LENGTH_SHORT);
toast.show();
} else {
final String title = getItem().getTitle();
final String id = getItem().getId();
final CharSequence[] items = { getString(R.string.share_link), getString(R.string.share_details) };
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.share_dialog_select);
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int di) {
OpacApi api = null;
try {
api = app.getApi();
} catch (OpacClient.LibraryRemovedException e) {
return;
}
if (di == 0) {
// Share link
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.addFlags(CompatibilityUtils.getNewDocumentIntentFlag());
// Add data to the intent, the receiving app will
// decide
// what to do with it.
intent.putExtra(Intent.EXTRA_SUBJECT, title);
String t = title;
try {
t = java.net.URLEncoder.encode(t, "UTF-8");
} catch (UnsupportedEncodingException e) {
}
String shareUrl = api.getShareUrl(id, t);
if (shareUrl != null) {
intent.putExtra(Intent.EXTRA_TEXT, shareUrl);
startActivity(Intent.createChooser(intent, getResources().getString(R.string.share)));
} else {
Toast toast = Toast.makeText(getActivity(), getString(R.string.share_notsupported), Toast.LENGTH_SHORT);
toast.show();
}
} else {
// Share details
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.addFlags(CompatibilityUtils.getNewDocumentIntentFlag());
// Add data to the intent, the receiving app will
// decide
// what to do with it.
intent.putExtra(Intent.EXTRA_SUBJECT, title);
String t = title;
try {
t = t != null ? java.net.URLEncoder.encode(t, "UTF-8") : "";
} catch (UnsupportedEncodingException e) {
}
String text = title + "\n\n";
for (Detail detail : getItem().getDetails()) {
String colon = "";
if (!detail.getDesc().endsWith(":")) {
colon = ":";
}
text += detail.getDesc() + colon + "\n" + detail.getContent() + "\n\n";
}
List<Copy> copies = getItem().getCopies();
if (copies.size() > 0) {
text += getString(R.string.copies_head) + ":\n\n";
}
for (Copy copy : copies) {
String labelSeparator = ": ";
String infoTypeSeparator = "\n";
String branch = copy.getBranch();
String branchTxt = "";
if (branch != null && !branch.isEmpty()) {
branchTxt += getString(R.string.branch) + labelSeparator + branch + infoTypeSeparator;
}
String dept = copy.getDepartment();
String deptTxt = "";
if (dept != null && !dept.isEmpty()) {
deptTxt += getString(R.string.department) + labelSeparator + dept + infoTypeSeparator;
}
String loc = copy.getLocation();
String locTxt = "";
if (loc != null && !loc.isEmpty()) {
locTxt += getString(R.string.location) + labelSeparator + loc + infoTypeSeparator;
}
String shelfMark = copy.getShelfmark();
String shelfMarkTxt = "";
if (shelfMark != null && !shelfMark.isEmpty()) {
shelfMarkTxt += getString(R.string.shelfmark) + labelSeparator + shelfMark + infoTypeSeparator;
}
String status = copy.getStatus();
String statusTxt = "";
if (status != null && !status.isEmpty()) {
statusTxt += getString(R.string.status) + labelSeparator + status + infoTypeSeparator;
}
String res = copy.getReservations();
String resTxt = "";
if (res != null && !res.isEmpty()) {
resTxt += getString(R.string.reservations) + labelSeparator + res + infoTypeSeparator;
}
String url = copy.getUrl();
String urlTxt = "";
if (url != null && !url.isEmpty()) {
urlTxt += getString(R.string.url) + labelSeparator + url + infoTypeSeparator;
}
LocalDate retDate = copy.getReturnDate();
String retDateTxt = "";
if (retDate != null) {
retDateTxt += getString(R.string.return_date) + labelSeparator + DateTimeFormat.shortDate().print(copy.getReturnDate()) + infoTypeSeparator;
}
text += branchTxt + deptTxt + locTxt + shelfMarkTxt + statusTxt + resTxt + urlTxt + retDateTxt + "\n";
}
String shareUrl = api.getShareUrl(id, t);
if (shareUrl != null) {
text += shareUrl;
}
intent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(intent, getResources().getString(R.string.share)));
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
return true;
} else if (item.getItemId() == R.id.action_star) {
StarDataSource star = new StarDataSource(getActivity());
if (getItem() == null) {
Toast toast = Toast.makeText(getActivity(), getString(R.string.star_wait), Toast.LENGTH_SHORT);
toast.show();
} else if (getItem().getId() == null || getItem().getId().equals("")) {
final String title = getItem().getTitle();
if (title == null || title.equals("")) {
Toast toast = Toast.makeText(getActivity(), getString(R.string.star_unsupported), Toast.LENGTH_LONG);
toast.show();
} else {
if (star.isStarredTitle(bib, title)) {
star.remove(star.getItemByTitle(bib, title));
item.setIcon(R.drawable.ic_star_0_white_24dp);
} else {
star.star(null, title, bib, getItem().getMediaType());
Toast toast = Toast.makeText(getActivity(), getString(R.string.starred), Toast.LENGTH_SHORT);
toast.show();
item.setIcon(R.drawable.ic_star_1_white_24dp);
}
}
} else {
final String title = getItem().getTitle();
final String id = getItem().getId();
if (star.isStarred(bib, id)) {
star.remove(star.getItem(bib, id));
item.setIcon(R.drawable.ic_star_0_white_24dp);
} else {
star.star(id, title, bib, getItem().getMediaType());
Toast toast = Toast.makeText(getActivity(), getString(R.string.starred), Toast.LENGTH_SHORT);
toast.show();
item.setIcon(R.drawable.ic_star_1_white_24dp);
}
}
return true;
} else if (item.getItemId() == R.id.action_print) {
if (getItem() == null) {
Toast toast = Toast.makeText(getActivity(), getString(R.string.print_wait), Toast.LENGTH_SHORT);
toast.show();
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
print();
}
}
return true;
} else {
return super.onOptionsItemSelected(item);
}
}
use of de.geeksfactory.opacclient.apis.OpacApi in project opacclient by opacapp.
the class SearchResultDetailFragment method reservationDo.
public void reservationDo() {
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
OpacApi api;
try {
api = app.getApi();
} catch (OpacClient.LibraryRemovedException e) {
return;
}
if (sp.getBoolean("reservation_fee_warning_ignore", false) || app.getLibrary().isSuppressFeeWarnings() || (api.getSupportFlags() & OpacApi.SUPPORT_FLAG_WARN_RESERVATION_FEES) > 0) {
reservationPerform();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View content = getActivity().getLayoutInflater().inflate(R.layout.dialog_reservation_fees, null);
final CheckBox check = (CheckBox) content.findViewById(R.id.check_box1);
builder.setView(content).setCancelable(false).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).setPositiveButton(R.string.reservation_fee_continue, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
if (check.isChecked()) {
sp.edit().putBoolean("reservation_fee_warning_ignore", true).apply();
}
reservationPerform();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
use of de.geeksfactory.opacclient.apis.OpacApi in project opacclient by opacapp.
the class AccountFragment method accountSelected.
@Override
public void accountSelected(Account account) {
swipeRefreshLayout.setVisibility(View.GONE);
unsupportedErrorView.setVisibility(View.GONE);
answerErrorView.setVisibility(View.GONE);
errorView.removeAllViews();
llLoading.setVisibility(View.VISIBLE);
setRefreshing(false);
supported = true;
this.account = app.getAccount();
OpacApi api;
try {
api = app.getApi();
} catch (NullPointerException e) {
e.printStackTrace();
return;
} catch (OpacClient.LibraryRemovedException e) {
show_connectivity_error(e);
return;
}
if (api != null && !app.getLibrary().isAccountSupported()) {
if (app.getLibrary().getReplacedBy() != null && !"".equals(app.getLibrary().getReplacedBy()) && app.promotePlusApps()) {
rlReplaced.setVisibility(View.VISIBLE);
tvErrBodyU.setVisibility(View.GONE);
ivReplacedStore.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(app.getLibrary().getReplacedBy().replace("https://play.google.com/store/apps/details?id=", "market://details?id=")));
startActivity(i);
} catch (ActivityNotFoundException e) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(app.getLibrary().getReplacedBy()));
startActivity(i);
}
}
});
} else {
rlReplaced.setVisibility(View.GONE);
tvErrBodyU.setVisibility(View.VISIBLE);
}
supported = false;
// Not supported with this api at all
llLoading.setVisibility(View.GONE);
unsupportedErrorView.setVisibility(View.VISIBLE);
tvErrBodyU.setText(R.string.account_unsupported_api);
} else if (account.getPassword() == null || account.getPassword().equals("null") || account.getPassword().equals("") || account.getName() == null || account.getName().equals("null") || account.getName().equals("")) {
// No credentials entered
llLoading.setVisibility(View.GONE);
answerErrorView.setVisibility(View.VISIBLE);
btPrefs.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), AccountEditActivity.class);
intent.putExtra(AccountEditActivity.EXTRA_ACCOUNT_ID, app.getAccount().getId());
startActivity(intent);
}
});
tvErrHeadA.setText("");
tvErrBodyA.setText(R.string.status_nouser);
} else {
// Supported
Context ctx = getActivity() != null ? getActivity() : OpacClient.getEmergencyContext();
AccountDataSource adatasource = new AccountDataSource(ctx);
refreshtime = adatasource.getCachedAccountDataTime(account);
if (refreshtime > 0) {
display(adatasource.getCachedAccountData(account), true);
if (System.currentTimeMillis() - refreshtime > MAX_CACHE_AGE) {
refresh();
}
} else {
refresh();
}
}
}
use of de.geeksfactory.opacclient.apis.OpacApi in project opacclient by opacapp.
the class GetSearchFieldsCallable method call.
@Override
public Map<String, List<SearchField>> call() {
OpacApi api = OpacApiFactory.create(lib, "OpacApp/Test");
if (api instanceof ApacheBaseApi) {
((ApacheBaseApi) api).setHttpLoggingEnabled(false);
}
Set<String> langs = null;
try {
langs = api.getSupportedLanguages();
} catch (IOException e) {
}
if (langs == null) {
// Use default language
try {
Map<String, List<SearchField>> map = new HashMap<>();
map.put("default", api.getSearchFields());
return map;
} catch (IOException | OpacErrorException | JSONException e) {
}
} else {
Map<String, List<SearchField>> map = new HashMap<>();
for (String lang : langs) {
api.setLanguage(lang);
try {
map.put(lang, api.getSearchFields());
} catch (IOException | OpacErrorException | JSONException e) {
}
}
return map;
}
return null;
}
Aggregations