Search in sources :

Example 11 with OpacApi

use of de.geeksfactory.opacclient.apis.OpacApi in project opacclient by opacapp.

the class AccountFragment method prolong.

public void prolong(final String a) {
    long age = System.currentTimeMillis() - refreshtime;
    if (refreshing || age > MAX_CACHE_AGE) {
        Toast.makeText(getActivity(), R.string.account_no_concurrent, Toast.LENGTH_LONG).show();
        if (!refreshing) {
            refresh();
        }
        return;
    }
    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    OpacApi api;
    try {
        api = app.getApi();
    } catch (OpacClient.LibraryRemovedException e) {
        return;
    }
    if (sp.getBoolean("prolong_fee_warning_ignore", false) || app.getLibrary().isSuppressFeeWarnings() || (api.getSupportFlags() & OpacApi.SUPPORT_FLAG_WARN_PROLONG_FEES) > 0) {
        prolongPerform(a);
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        View content = getActivity().getLayoutInflater().inflate(R.layout.dialog_prolong_confirm, 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("prolong_fee_warning_ignore", true).apply();
                }
                prolongPerform(a);
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OpacClient(de.geeksfactory.opacclient.OpacClient) SharedPreferences(android.content.SharedPreferences) DialogInterface(android.content.DialogInterface) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) RecyclerView(android.support.v7.widget.RecyclerView) SuppressLint(android.annotation.SuppressLint) CheckBox(android.widget.CheckBox) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) OnClickListener(android.view.View.OnClickListener)

Example 12 with OpacApi

use of de.geeksfactory.opacclient.apis.OpacApi in project opacclient by opacapp.

the class AccountFragment method onCreateOptionsMenu.

@SuppressLint("NewApi")
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.activity_account, menu);
    OpacApi api;
    try {
        api = app.getApi();
    } catch (OpacClient.LibraryRemovedException e) {
        return;
    }
    if (app.getAccount() != null && (api.getSupportFlags() & OpacApi.SUPPORT_FLAG_ACCOUNT_PROLONG_ALL) != 0) {
        menu.findItem(R.id.action_prolong_all).setVisible(true);
    } else {
        menu.findItem(R.id.action_prolong_all).setVisible(false);
    }
    menu.findItem(R.id.action_refresh).setVisible(supported);
    super.onCreateOptionsMenu(menu, inflater);
}
Also used : OpacClient(de.geeksfactory.opacclient.OpacClient) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) SuppressLint(android.annotation.SuppressLint)

Example 13 with OpacApi

use of de.geeksfactory.opacclient.apis.OpacApi 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

OpacApi (de.geeksfactory.opacclient.apis.OpacApi)13 OpacClient (de.geeksfactory.opacclient.OpacClient)11 OnClickListener (android.view.View.OnClickListener)5 SuppressLint (android.annotation.SuppressLint)4 DialogInterface (android.content.DialogInterface)4 AlertDialog (android.support.v7.app.AlertDialog)4 RecyclerView (android.support.v7.widget.RecyclerView)4 View (android.view.View)4 ImageView (android.widget.ImageView)4 ListView (android.widget.ListView)4 TextView (android.widget.TextView)4 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)3 EbookServiceApi (de.geeksfactory.opacclient.apis.EbookServiceApi)3 WebView (android.webkit.WebView)2 AdapterView (android.widget.AdapterView)2 CheckBox (android.widget.CheckBox)2 ApacheBaseApi (de.geeksfactory.opacclient.apis.ApacheBaseApi)2 OpacErrorException (de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException)2 Account (de.geeksfactory.opacclient.objects.Account)2