use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.
the class SearchResultListFragment method performGoogleSearch.
private void performGoogleSearch(final String query) {
AccountDataSource data = new AccountDataSource(getActivity());
final List<Account> accounts = data.getAllAccounts();
if (accounts.size() == 0) {
Toast.makeText(getActivity(), R.string.welcome_select, Toast.LENGTH_LONG).show();
} else if (accounts.size() == 1) {
startGoogleSearch(accounts.get(0), query);
} else {
new AlertDialog.Builder(getActivity()).setTitle(R.string.account_select).setAdapter(new AccountListAdapter(getActivity(), accounts).setHighlightActiveAccount(false), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startGoogleSearch(accounts.get(which), query);
}
}).create().show();
}
}
use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.
the class AccountEditActivity method save.
private void save() {
AccountDataSource data = new AccountDataSource(AccountEditActivity.this);
data.update(account);
if (((OpacClient) getApplication()).getAccount().getId() == account.getId()) {
((OpacClient) getApplication()).resetCache();
}
}
use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.
the class AccountFragment method accountSelected.
@Override
public void accountSelected(Account account) {
swipeRefreshLayout.setVisibility(View.GONE);
unsupportedErrorView.setVisibility(View.GONE);
answerErrorView.setVisibility(View.GONE);
errorView.removeAllViews();
llLoading.setVisibility(View.VISIBLE);
setRefreshing(false);
supported = true;
this.account = app.getAccount();
OpacApi api;
try {
api = app.getApi();
} catch (NullPointerException e) {
e.printStackTrace();
return;
} catch (OpacClient.LibraryRemovedException e) {
show_connectivity_error(e);
return;
}
if (api != null && !app.getLibrary().isAccountSupported()) {
if (app.getLibrary().getReplacedBy() != null && !"".equals(app.getLibrary().getReplacedBy()) && app.promotePlusApps()) {
rlReplaced.setVisibility(View.VISIBLE);
tvErrBodyU.setVisibility(View.GONE);
ivReplacedStore.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(app.getLibrary().getReplacedBy().replace("https://play.google.com/store/apps/details?id=", "market://details?id=")));
startActivity(i);
} catch (ActivityNotFoundException e) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(app.getLibrary().getReplacedBy()));
startActivity(i);
}
}
});
} else {
rlReplaced.setVisibility(View.GONE);
tvErrBodyU.setVisibility(View.VISIBLE);
}
supported = false;
// Not supported with this api at all
llLoading.setVisibility(View.GONE);
unsupportedErrorView.setVisibility(View.VISIBLE);
tvErrBodyU.setText(R.string.account_unsupported_api);
} else if (account.getPassword() == null || account.getPassword().equals("null") || account.getPassword().equals("") || account.getName() == null || account.getName().equals("null") || account.getName().equals("")) {
// No credentials entered
llLoading.setVisibility(View.GONE);
answerErrorView.setVisibility(View.VISIBLE);
btPrefs.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), AccountEditActivity.class);
intent.putExtra(AccountEditActivity.EXTRA_ACCOUNT_ID, app.getAccount().getId());
startActivity(intent);
}
});
tvErrHeadA.setText("");
tvErrBodyA.setText(R.string.status_nouser);
} else {
// Supported
Context ctx = getActivity() != null ? getActivity() : OpacClient.getEmergencyContext();
AccountDataSource adatasource = new AccountDataSource(ctx);
refreshtime = adatasource.getCachedAccountDataTime(account);
if (refreshtime > 0) {
display(adatasource.getCachedAccountData(account), true);
if (System.currentTimeMillis() - refreshtime > MAX_CACHE_AGE) {
refresh();
}
} else {
refresh();
}
}
}
use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.
the class AccountFragment method show_connectivity_error.
public void show_connectivity_error(Exception e) {
if (e != null) {
e.printStackTrace();
}
if (getActivity() == null) {
return;
}
if (e instanceof OpacErrorException) {
AccountDataSource adatasource = new AccountDataSource(getActivity());
adatasource.invalidateCachedAccountData(account);
dialog_wrong_credentials(e.getMessage());
return;
}
if (getView() != null) {
final FrameLayout errorView = (FrameLayout) getView().findViewById(R.id.error_view);
errorView.removeAllViews();
View connError = getActivity().getLayoutInflater().inflate(R.layout.error_connectivity, errorView);
TextView tvErrBody = (TextView) connError.findViewById(R.id.tvErrBody);
Button btnRetry = (Button) connError.findViewById(R.id.btRetry);
btnRetry.setVisibility(View.VISIBLE);
if (e != null && e instanceof SSLSecurityException) {
tvErrBody.setText(R.string.connection_error_detail_security);
} else if (e != null && e instanceof NotReachableException) {
tvErrBody.setText(R.string.connection_error_detail_nre);
} else if (e != null && e instanceof OpacClient.LibraryRemovedException) {
tvErrBody.setText(R.string.library_removed_error);
btnRetry.setVisibility(View.GONE);
}
btnRetry.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
refresh();
}
});
llLoading.setVisibility(View.GONE);
swipeRefreshLayout.setVisibility(View.GONE);
connError.setVisibility(View.VISIBLE);
}
}
use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.
the class AccountFragment method invalidateData.
public void invalidateData() {
AccountDataSource adatasource = new AccountDataSource(getActivity());
adatasource.invalidateCachedAccountData(account);
swipeRefreshLayout.setVisibility(View.GONE);
accountSelected(account);
}
Aggregations