Search in sources :

Example 21 with ReservedItem

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;
}
Also used : AccountData(de.geeksfactory.opacclient.objects.AccountData) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 22 with ReservedItem

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;
}
Also used : Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem)

Example 23 with ReservedItem

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);
}
Also used : SharedPreferences(android.content.SharedPreferences) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem) NoHttpResponseException(org.apache.http.NoHttpResponseException) JSONException(org.json.JSONException) SSLSecurityException(de.geeksfactory.opacclient.networking.SSLSecurityException) ActivityNotFoundException(android.content.ActivityNotFoundException) NotReachableException(de.geeksfactory.opacclient.networking.NotReachableException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) IOException(java.io.IOException)

Example 24 with ReservedItem

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)));
}
Also used : Context(android.content.Context) LocalDateTime(org.joda.time.LocalDateTime) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) AccountData(de.geeksfactory.opacclient.objects.AccountData) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) Intent(android.content.Intent) LentItem(de.geeksfactory.opacclient.objects.LentItem) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 25 with ReservedItem

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;
}
Also used : OpacClient(de.geeksfactory.opacclient.OpacClient) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) EbookServiceApi(de.geeksfactory.opacclient.apis.EbookServiceApi) MenuItem(android.view.MenuItem) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem)

Aggregations

ReservedItem (de.geeksfactory.opacclient.objects.ReservedItem)34 ArrayList (java.util.ArrayList)20 Element (org.jsoup.nodes.Element)17 LentItem (de.geeksfactory.opacclient.objects.LentItem)16 AccountData (de.geeksfactory.opacclient.objects.AccountData)13 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)8 Document (org.jsoup.nodes.Document)8 Elements (org.jsoup.select.Elements)8 JSONObject (org.json.JSONObject)7 Test (org.junit.Test)7 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)6 DummyStringProvider (de.geeksfactory.opacclient.i18n.DummyStringProvider)4 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 Pattern (java.util.regex.Pattern)3 JSONException (org.json.JSONException)3 Intent (android.content.Intent)2 Account (de.geeksfactory.opacclient.objects.Account)2 Report (de.geeksfactory.opacclient.reporting.Report)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2