use of de.geeksfactory.opacclient.objects.ReservedItem in project opacclient by opacapp.
the class TouchPoint method account.
@Override
public AccountData account(Account acc) throws IOException, JSONException, OpacErrorException {
start();
LoginResponse login = login(acc);
if (!login.success) {
return null;
}
AccountData adata = new AccountData(acc.getId());
if (login.warning != null) {
adata.setWarning(login.warning);
}
// Lent media
httpGet(opac_url + "/userAccount.do?methodToCall=start", ENCODING);
String html = httpGet(opac_url + "/userAccount.do?methodToCall=showAccount&accountTyp=loaned", ENCODING);
List<LentItem> lent = new ArrayList<>();
Document doc = Jsoup.parse(html);
doc.setBaseUri(opac_url);
List<LentItem> nextpageLent = parse_medialist(doc);
if (nextpageLent != null) {
lent.addAll(nextpageLent);
}
if (doc.select(".pagination").size() > 0 && lent != null) {
Element pagination = doc.select(".pagination").first();
Elements pages = pagination.select("a");
for (Element page : pages) {
if (!page.hasAttr("href")) {
continue;
}
html = httpGet(page.attr("abs:href"), ENCODING);
doc = Jsoup.parse(html);
doc.setBaseUri(opac_url);
nextpageLent = parse_medialist(doc);
if (nextpageLent != null) {
lent.addAll(nextpageLent);
}
}
}
adata.setLent(lent);
// Requested media ("Vormerkungen")
html = httpGet(opac_url + "/userAccount.do?methodToCall=showAccount&accountTyp=requested", ENCODING);
doc = Jsoup.parse(html);
doc.setBaseUri(opac_url);
List<ReservedItem> requested = new ArrayList<>();
List<ReservedItem> nextpageRes = parse_reslist(doc);
if (nextpageRes != null) {
requested.addAll(nextpageRes);
}
if (doc.select(".pagination").size() > 0 && requested != null) {
Element pagination = doc.select(".pagination").first();
Elements pages = pagination.select("a");
for (Element page : pages) {
if (!page.hasAttr("href")) {
continue;
}
html = httpGet(page.attr("abs:href"), ENCODING);
doc = Jsoup.parse(html);
doc.setBaseUri(opac_url);
nextpageRes = parse_reslist(doc);
if (nextpageRes != null) {
requested.addAll(nextpageRes);
}
}
}
// Ordered media ("Bestellungen")
html = httpGet(opac_url + "/userAccount.do?methodToCall=showAccount&accountTyp=ordered", ENCODING);
doc = Jsoup.parse(html);
doc.setBaseUri(opac_url);
List<ReservedItem> nextpageOrd = parse_reslist(doc);
if (nextpageOrd != null) {
requested.addAll(nextpageOrd);
}
if (doc.select(".pagination").size() > 0 && requested != null) {
Element pagination = doc.select(".pagination").first();
Elements pages = pagination.select("a");
for (Element page : pages) {
if (!page.hasAttr("href")) {
continue;
}
html = httpGet(page.attr("abs:href"), ENCODING);
doc = Jsoup.parse(html);
doc.setBaseUri(opac_url);
nextpageOrd = parse_reslist(doc);
if (nextpageOrd != null) {
requested.addAll(nextpageOrd);
}
}
}
adata.setReservations(requested);
// Fees
if (doc.select("#fees").size() > 0) {
String text = doc.select("#fees").first().text().trim();
if (text.matches("Geb.+hren[^\\(]+\\(([0-9.,]+)[^0-9€A-Z]*(€|EUR|CHF|Fr)\\)")) {
text = text.replaceAll("Geb.+hren[^\\(]+\\(([0-9.,]+)[^0-9€A-Z]*(€|EUR|CHF|Fr)\\)", "$1 $2");
adata.setPendingFees(text);
}
}
return adata;
}
use of de.geeksfactory.opacclient.objects.ReservedItem in project opacclient by opacapp.
the class Zones method parseResList.
static List<ReservedItem> parseResList(Document doc) {
List<ReservedItem> reservations = new ArrayList<>();
for (Element table : doc.select(".MessageBrowseItemDetailsCell table, " + ".MessageBrowseItemDetailsCellStripe" + " table")) {
ReservedItem item = new ReservedItem();
for (Element tr : table.select("tr")) {
String desc = tr.select(".MessageBrowseFieldNameCell").text().trim();
String value = tr.select(".MessageBrowseFieldDataCell").text().trim();
if (desc.equals("Titel"))
item.setTitle(value);
if (desc.equals("Publikationsform"))
item.setFormat(value);
if (desc.equals("Liefern an"))
item.setBranch(value);
if (desc.equals("Status"))
item.setStatus(value);
}
if ("Gelöscht".equals(item.getStatus()))
continue;
reservations.add(item);
}
return reservations;
}
use of de.geeksfactory.opacclient.objects.ReservedItem in project opacclient by opacapp.
the class AccountFragment method display.
public void display(final AccountData result, boolean fromcache) {
accountData = result;
if (getActivity() == null) {
return;
}
swipeRefreshLayout.setVisibility(View.VISIBLE);
llLoading.setVisibility(View.GONE);
unsupportedErrorView.setVisibility(View.GONE);
answerErrorView.setVisibility(View.GONE);
errorView.removeAllViews();
this.fromcache = fromcache;
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(app.getApplicationContext());
displayHeader();
/*
Lent items
*/
final boolean notification_on = sp.getBoolean(SyncAccountJobCreator.PREF_SYNC_SERVICE, false);
boolean notification_problems = false;
displayWarning();
displayLentHeader();
displayLentItems();
if (lentEmpty != null) {
// phone
lentEmpty.setVisible(result.getLent().size() == 0);
} else {
// tablet
tvLentEmpty.setVisibility(result.getLent().size() == 0 ? View.VISIBLE : View.GONE);
}
for (final LentItem item : result.getLent()) {
try {
if (notification_on && item.getDeadline() == null && !item.isEbook()) {
notification_problems = true;
}
} catch (Exception e) {
notification_problems = true;
}
}
if (notification_problems) {
if (tvError != null) {
tvError.setVisibility(View.VISIBLE);
tvError.setText(R.string.notification_problems);
}
}
/*
Reservations
*/
displayResHeader();
displayReservedItems();
if (reservationsEmpty != null) {
// phone
reservationsEmpty.setVisible(result.getReservations().size() == 0);
} else {
// tablet
tvReservationsEmpty.setVisibility(result.getReservations().size() == 0 ? View.VISIBLE : View.GONE);
}
displayAge();
boolean hideCovers = true;
for (LentItem item : result.getLent()) {
if (item.getMediaType() != null || item.getCover() != null)
hideCovers = false;
}
for (ReservedItem item : result.getReservations()) {
if (item.getMediaType() != null || item.getCover() != null)
hideCovers = false;
}
lentAdapter.setCoversHidden(hideCovers);
resAdapter.setCoversHidden(hideCovers);
}
use of de.geeksfactory.opacclient.objects.ReservedItem in project opacclient by opacapp.
the class AccountFragment method export.
private void export() {
if (refreshing) {
Toast.makeText(getActivity(), R.string.account_no_concurrent, Toast.LENGTH_LONG).show();
if (!refreshing) {
refresh();
}
return;
}
Context ctx = getActivity() != null ? getActivity() : OpacClient.getEmergencyContext();
AccountDataSource adatasource = new AccountDataSource(ctx);
AccountData data = adatasource.getCachedAccountData(account);
LocalDateTime dt = new LocalDateTime(adatasource.getCachedAccountDataTime(account));
if (data == null)
return;
StringBuilder string = new StringBuilder();
DateTimeFormatter fmt1 = DateTimeFormat.shortDateTime().withLocale(getResources().getConfiguration().locale);
DateTimeFormatter fmt2 = DateTimeFormat.shortDate().withLocale(getResources().getConfiguration().locale);
String dateStr = fmt1.print(dt);
string.append(getResources().getString(R.string.accountdata_export_header, account.getLabel(), dateStr));
string.append("\n\n");
string.append(getResources().getString(R.string.lent_head));
string.append("\n\n");
for (LentItem item : data.getLent()) {
appendIfNotEmpty(string, item.getTitle(), R.string.accountdata_title);
appendIfNotEmpty(string, item.getAuthor(), R.string.accountdata_author);
appendIfNotEmpty(string, item.getFormat(), R.string.accountdata_format);
appendIfNotEmpty(string, item.getStatus(), R.string.accountdata_status);
appendIfNotEmpty(string, item.getBarcode(), R.string.accountdata_lent_barcode);
if (item.getDeadline() != null) {
appendIfNotEmpty(string, fmt2.print(item.getDeadline()), R.string.accountdata_lent_deadline);
}
appendIfNotEmpty(string, item.getHomeBranch(), R.string.accountdata_lent_home_branch);
appendIfNotEmpty(string, item.getLendingBranch(), R.string.accountdata_lent_lending_branch);
string.append("\n");
}
if (data.getLent().size() == 0) {
string.append(getResources().getString(R.string.lent_none));
}
string.append(getResources().getString(R.string.reservations_head));
string.append("\n\n");
for (ReservedItem item : data.getReservations()) {
appendIfNotEmpty(string, item.getTitle(), R.string.accountdata_title);
appendIfNotEmpty(string, item.getAuthor(), R.string.accountdata_author);
appendIfNotEmpty(string, item.getFormat(), R.string.accountdata_format);
appendIfNotEmpty(string, item.getStatus(), R.string.accountdata_status);
if (item.getReadyDate() != null) {
appendIfNotEmpty(string, fmt2.print(item.getReadyDate()), R.string.accountdata_reserved_ready_date);
}
if (item.getExpirationDate() != null) {
appendIfNotEmpty(string, fmt2.print(item.getExpirationDate()), R.string.accountdata_reserved_expiration_date);
}
appendIfNotEmpty(string, item.getBranch(), R.string.accountdata_reserved_branch);
string.append("\n");
}
if (data.getReservations().size() == 0) {
string.append(getResources().getString(R.string.reservations_none));
}
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, string.toString());
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.share_dialog_select)));
}
use of de.geeksfactory.opacclient.objects.ReservedItem 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