use of de.geeksfactory.opacclient.objects.Account in project opacclient by opacapp.
the class TouchPointTest method setUp.
@Before
public void setUp() {
touchPoint = spy(TouchPoint.class);
touchPoint.opac_url = "http://opac.example.com";
account = new Account();
account.setName("username");
account.setName("password");
}
use of de.geeksfactory.opacclient.objects.Account in project opacclient by opacapp.
the class SyncAccountJobTest method setUp.
@Before
public void setUp() throws Exception {
app = mock(OpacClient.class);
sp = mock(SharedPreferences.class);
data = mock(AccountDataSource.class);
helper = mock(ReminderHelper.class);
api1 = mock(OpacApi.class);
api2 = mock(OpacApi.class);
service = new SyncAccountJob();
when(sp.contains("update_151_clear_cache")).thenReturn(true);
accounts = new ArrayList<>();
account1 = new Account();
account1.setId(0);
account2 = new Account();
account2.setId(1);
accounts.add(account1);
accounts.add(account2);
library = new Library();
library.setAccountSupported(true);
}
use of de.geeksfactory.opacclient.objects.Account in project opacclient by opacapp.
the class LibraryApiTestCases method testWrongLogin.
/**
* Create an account with credentials that probably nobody has and try to login. This should
* normally give an {@link OpacErrorException}.
*/
@Test
public void testWrongLogin() throws IOException, JSONException {
if (!library.isAccountSupported()) {
return;
}
Account account = new Account();
account.setId(0);
account.setLabel("Test account");
account.setLibrary(library.getIdent());
account.setName("upvlgFLMNN2AyVsIzowcwzdypRXM2x");
account.setPassword("OTqbXhMJMKtjconhxX0LXMqWZsY2Ez");
OpacErrorException exception = null;
try {
api.checkAccountData(account);
} catch (OpacErrorException e) {
exception = e;
}
assertTrue(exception != null);
}
use of de.geeksfactory.opacclient.objects.Account 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.objects.Account in project opacclient by opacapp.
the class SearchResultDetailFragment method bookingStart.
protected void bookingStart() {
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) {
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 (app.getAccount().getId() != accounts.get(position).getId()) {
app.setAccount(accounts.get(position).getId());
}
bookingDo();
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 {
bookingDo();
}
}
Aggregations