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);
}
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;
}
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();
}
}
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);
}
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;
}
Aggregations