Search in sources :

Example 1 with StarDataSource

use of de.geeksfactory.opacclient.storage.StarDataSource 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);
        }
    }
}
Also used : OpacClient(de.geeksfactory.opacclient.OpacClient) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) EbookServiceApi(de.geeksfactory.opacclient.apis.EbookServiceApi) StarDataSource(de.geeksfactory.opacclient.storage.StarDataSource)

Example 2 with StarDataSource

use of de.geeksfactory.opacclient.storage.StarDataSource 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);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OpacClient(de.geeksfactory.opacclient.OpacClient) DialogInterface(android.content.DialogInterface) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Intent(android.content.Intent) LocalDate(org.joda.time.LocalDate) StarDataSource(de.geeksfactory.opacclient.storage.StarDataSource) Toast(android.widget.Toast) Copy(de.geeksfactory.opacclient.objects.Copy) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) OnClickListener(android.view.View.OnClickListener) Detail(de.geeksfactory.opacclient.objects.Detail)

Example 3 with StarDataSource

use of de.geeksfactory.opacclient.storage.StarDataSource in project opacclient by opacapp.

the class StarredFragment method remove.

public void remove(Starred item) {
    StarDataSource data = new StarDataSource(getActivity());
    sItem = item;
    showSnackBar();
    data.remove(item);
}
Also used : StarDataSource(de.geeksfactory.opacclient.storage.StarDataSource)

Example 4 with StarDataSource

use of de.geeksfactory.opacclient.storage.StarDataSource in project opacclient by opacapp.

the class StarredFragment method share.

protected void share() {
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.addFlags(CompatibilityUtils.getNewDocumentIntentFlag());
    StringBuilder text = new StringBuilder();
    StarDataSource data = new StarDataSource(getActivity());
    List<Starred> items = data.getAllItems(app.getLibrary().getIdent());
    for (Starred item : items) {
        text.append(item.getTitle());
        text.append("\n");
        String shareUrl;
        try {
            shareUrl = app.getApi().getShareUrl(item.getMNr(), item.getTitle());
        } catch (OpacClient.LibraryRemovedException e) {
            return;
        }
        if (shareUrl != null) {
            text.append(shareUrl);
            text.append("\n");
        }
        text.append("\n");
    }
    intent.putExtra(Intent.EXTRA_TEXT, text.toString().trim());
    startActivity(Intent.createChooser(intent, getResources().getString(R.string.share)));
}
Also used : OpacClient(de.geeksfactory.opacclient.OpacClient) Intent(android.content.Intent) Starred(de.geeksfactory.opacclient.objects.Starred) StarDataSource(de.geeksfactory.opacclient.storage.StarDataSource)

Example 5 with StarDataSource

use of de.geeksfactory.opacclient.storage.StarDataSource in project opacclient by opacapp.

the class StarredFragment method showSnackBar.

// Added code to show SnackBar when clicked on Remove button in Favorites screen
private void showSnackBar() {
    Snackbar snackbar = Snackbar.make(view, getString(R.string.starred_removed), Snackbar.LENGTH_LONG);
    snackbar.setAction(R.string.starred_removed_undo, new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            StarDataSource data = new StarDataSource(getActivity());
            String bib = app.getLibrary().getIdent();
            data.star(sItem.getMNr(), sItem.getTitle(), bib, sItem.getMediaType());
        }
    });
    snackbar.show();
}
Also used : OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) Snackbar(android.support.design.widget.Snackbar) StarDataSource(de.geeksfactory.opacclient.storage.StarDataSource)

Aggregations

StarDataSource (de.geeksfactory.opacclient.storage.StarDataSource)7 OpacClient (de.geeksfactory.opacclient.OpacClient)3 Intent (android.content.Intent)2 OnClickListener (android.view.View.OnClickListener)2 OpacApi (de.geeksfactory.opacclient.apis.OpacApi)2 Starred (de.geeksfactory.opacclient.objects.Starred)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 DialogInterface (android.content.DialogInterface)1 Uri (android.net.Uri)1 Snackbar (android.support.design.widget.Snackbar)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 EbookServiceApi (de.geeksfactory.opacclient.apis.EbookServiceApi)1