Search in sources :

Example 1 with EbookServiceApi

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);
        }
    }
}
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 EbookServiceApi

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();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Account(de.geeksfactory.opacclient.objects.Account) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) OpacClient(de.geeksfactory.opacclient.OpacClient) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) SharedPreferences(android.content.SharedPreferences) DialogInterface(android.content.DialogInterface) EbookServiceApi(de.geeksfactory.opacclient.apis.EbookServiceApi) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) WebView(android.webkit.WebView) TextView(android.widget.TextView) ListView(android.widget.ListView) RecyclerView(android.support.v7.widget.RecyclerView) SuppressLint(android.annotation.SuppressLint) ListView(android.widget.ListView) LayoutInflater(android.view.LayoutInflater) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView)

Example 3 with EbookServiceApi

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;
}
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

OpacClient (de.geeksfactory.opacclient.OpacClient)3 EbookServiceApi (de.geeksfactory.opacclient.apis.EbookServiceApi)3 OpacApi (de.geeksfactory.opacclient.apis.OpacApi)3 SuppressLint (android.annotation.SuppressLint)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 AlertDialog (android.support.v7.app.AlertDialog)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LayoutInflater (android.view.LayoutInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 WebView (android.webkit.WebView)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 Account (de.geeksfactory.opacclient.objects.Account)1