Search in sources :

Example 6 with OpacApi

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

the class CoverDownloadTask method getImage.

protected byte[] getImage() throws IOException {
    try {
        OpacApi api = ((OpacClient) context.getApplicationContext()).getApi();
        if (api instanceof ApacheBaseApi) {
            return getImageApacheClient(((ApacheBaseApi) api).http_client);
        } else if (api instanceof OkHttpBaseApi) {
            return getImageOkHttpClient(((OkHttpBaseApi) api).http_client);
        }
    } catch (OpacClient.LibraryRemovedException e) {
    }
    HttpClient httpClient;
    httpClient = new AndroidHttpClientFactory().getNewApacheHttpClient(false, true, false, false);
    return getImageApacheClient(httpClient);
}
Also used : OpacClient(de.geeksfactory.opacclient.OpacClient) OkHttpBaseApi(de.geeksfactory.opacclient.apis.OkHttpBaseApi) AndroidHttpClient(android.net.http.AndroidHttpClient) OkHttpClient(okhttp3.OkHttpClient) HttpClient(org.apache.http.client.HttpClient) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) ApacheBaseApi(de.geeksfactory.opacclient.apis.ApacheBaseApi)

Example 7 with OpacApi

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

the class OpacApiFactory method create.

/**
 * Creates an {@link OpacApi} instance for accessing the given {@link Library}
 *
 * @param lib  the {@link Library} you want to connect to
 * @param sp   the {@link StringProvider} to use
 * @param hcf  the {@link HttpClientFactory} to use
 * @param lang the preferred language as a ISO-639-1 code, see {@link OpacApi#setLanguage(String)}
 * @return a new {@link OpacApi} instance
 */
public static OpacApi create(Library lib, StringProvider sp, HttpClientFactory hcf, String lang, ReportHandler reportHandler) {
    OpacApi newApiInstance;
    if (lib.getApi().equals("bibliotheca")) {
        newApiInstance = new Bibliotheca();
    } else if (lib.getApi().equals("sisis")) {
        newApiInstance = new SISIS();
    } else if (lib.getApi().equals("zones")) {
        newApiInstance = new Zones();
    } else if (lib.getApi().equals("biber1992")) {
        newApiInstance = new BiBer1992();
    } else if (lib.getApi().equals("pica")) {
        switch(lib.getData().optString("account_system", "")) {
            case "lbs":
                newApiInstance = new PicaLBS();
                break;
            case "default":
                newApiInstance = new PicaOld();
                break;
            default:
                newApiInstance = new PicaOld();
                break;
        }
    } else if (lib.getApi().equals("iopac")) {
        newApiInstance = new IOpac();
    } else if (lib.getApi().equals("adis")) {
        newApiInstance = new Adis();
    } else if (lib.getApi().equals("sru")) {
        newApiInstance = new SRU();
    } else if (lib.getApi().equals("primo")) {
        newApiInstance = new Primo();
    } else if (lib.getApi().equals("vufind")) {
        newApiInstance = new VuFind();
    } else if (lib.getApi().equals("webopac.net")) {
        newApiInstance = new WebOpacNet();
    } else if (lib.getApi().equals("web-opac.at") || lib.getApi().equals("littera")) {
        newApiInstance = new Littera();
    } else if (lib.getApi().equals("winbiap")) {
        newApiInstance = new WinBiap();
    } else if (lib.getApi().equals("heidi")) {
        newApiInstance = new Heidi();
    } else if (lib.getApi().equals("touchpoint")) {
        newApiInstance = new TouchPoint();
    } else if (lib.getApi().equals("open")) {
        newApiInstance = new Open();
    } else if (lib.getApi().equals("test")) {
        newApiInstance = new TestApi();
    } else {
        return null;
    }
    newApiInstance.init(lib, hcf);
    newApiInstance.setStringProvider(sp);
    newApiInstance.setReportHandler(reportHandler);
    if (lang != null)
        newApiInstance.setLanguage(lang);
    return newApiInstance;
}
Also used : IOpac(de.geeksfactory.opacclient.apis.IOpac) TestApi(de.geeksfactory.opacclient.apis.TestApi) Littera(de.geeksfactory.opacclient.apis.Littera) Bibliotheca(de.geeksfactory.opacclient.apis.Bibliotheca) VuFind(de.geeksfactory.opacclient.apis.VuFind) WinBiap(de.geeksfactory.opacclient.apis.WinBiap) Zones(de.geeksfactory.opacclient.apis.Zones) PicaOld(de.geeksfactory.opacclient.apis.PicaOld) Open(de.geeksfactory.opacclient.apis.Open) Adis(de.geeksfactory.opacclient.apis.Adis) SISIS(de.geeksfactory.opacclient.apis.SISIS) Primo(de.geeksfactory.opacclient.apis.Primo) SRU(de.geeksfactory.opacclient.apis.SRU) Heidi(de.geeksfactory.opacclient.apis.Heidi) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) PicaLBS(de.geeksfactory.opacclient.apis.PicaLBS) TouchPoint(de.geeksfactory.opacclient.apis.TouchPoint) BiBer1992(de.geeksfactory.opacclient.apis.BiBer1992) WebOpacNet(de.geeksfactory.opacclient.apis.WebOpacNet)

Example 8 with OpacApi

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

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

the class SearchResultListFragment method setSearchResult.

public void setSearchResult(final SearchRequestResult searchresult) {
    for (SearchResult result : searchresult.getResults()) {
        result.setPage(searchresult.getPage_index());
    }
    if (searchresult.getTotal_result_count() >= 0) {
        ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(getResources().getQuantityString(R.plurals.result_number, searchresult.getTotal_result_count(), searchresult.getTotal_result_count()));
    }
    if (searchresult.getResults().size() == 0 && searchresult.getTotal_result_count() <= 0) {
        setEmptyText(getString(R.string.no_results));
    }
    this.searchresult = searchresult;
    OpacApi api = null;
    try {
        api = app.getApi();
    } catch (OpacClient.LibraryRemovedException ignored) {
    }
    adapter = new ResultsAdapterEndless(getActivity(), searchresult, new OnLoadMoreListener() {

        @Override
        public SearchRequestResult onLoadMore(int page) throws Exception {
            SearchRequestResult res = app.getApi().searchGetPage(page);
            setLastLoadedPage(page);
            return res;
        }

        @Override
        public void onError(Exception e) {
            if (getActivity() != null) {
                if (e instanceof OpacErrorException) {
                    showConnectivityError(e.getMessage());
                } else if (e instanceof SSLSecurityException) {
                    showConnectivityError(getResources().getString(R.string.connection_error_detail_security));
                } else if (e instanceof NotReachableException) {
                    showConnectivityError(getResources().getString(R.string.connection_error_detail_nre));
                } else {
                    e.printStackTrace();
                    showConnectivityError();
                }
            }
        }

        @Override
        public void updateResultCount(int resultCount) {
            /*
                         * When IOpac finds more than 200 results, the real
						 * result count is not known until the second page is
						 * loaded
						 */
            if (resultCount >= 0 && getActivity() != null) {
                ((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(getResources().getQuantityString(R.plurals.result_number, resultCount, resultCount));
            }
        }
    }, api);
    setListAdapter(adapter);
    getListView().setTextFilterEnabled(true);
    setListShown(true);
}
Also used : OnLoadMoreListener(de.geeksfactory.opacclient.frontend.ResultsAdapterEndless.OnLoadMoreListener) OpacClient(de.geeksfactory.opacclient.OpacClient) SearchRequestResult(de.geeksfactory.opacclient.objects.SearchRequestResult) NotReachableException(de.geeksfactory.opacclient.networking.NotReachableException) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) SSLSecurityException(de.geeksfactory.opacclient.networking.SSLSecurityException) SearchResult(de.geeksfactory.opacclient.objects.SearchResult) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) JSONException(org.json.JSONException) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) IOException(java.io.IOException) SSLSecurityException(de.geeksfactory.opacclient.networking.SSLSecurityException) NotReachableException(de.geeksfactory.opacclient.networking.NotReachableException)

Example 10 with OpacApi

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

the class SyncAccountJob method syncAccounts.

boolean syncAccounts(OpacClient app, AccountDataSource data, SharedPreferences sp, ReminderHelper helper) {
    boolean failed = false;
    List<Account> accounts = data.getAccountsWithPassword();
    if (!sp.contains("update_151_clear_cache")) {
        data.invalidateCachedData();
        sp.edit().putBoolean("update_151_clear_cache", true).apply();
    }
    for (Account account : accounts) {
        if (BuildConfig.DEBUG) {
            Log.i(TAG, "Loading data for Account " + account.toString());
        }
        AccountData res;
        try {
            Library library = app.getLibrary(account.getLibrary());
            if (!library.isAccountSupported()) {
                data.deleteAccountData(account);
                continue;
            }
            OpacApi api = app.getNewApi(library);
            res = api.account(account);
            if (res == null) {
                failed = true;
                continue;
            }
        } catch (JSONException | IOException | OpacApi.OpacErrorException e) {
            e.printStackTrace();
            failed = true;
            continue;
        } catch (OpacClient.LibraryRemovedException e) {
            continue;
        }
        account.setPasswordKnownValid(true);
        try {
            data.update(account);
            data.storeCachedAccountData(account, res);
        } finally {
            helper.generateAlarms();
        }
    }
    return failed;
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) OpacClient(de.geeksfactory.opacclient.OpacClient) AccountData(de.geeksfactory.opacclient.objects.AccountData) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) JSONException(org.json.JSONException) Library(de.geeksfactory.opacclient.objects.Library) IOException(java.io.IOException)

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