Search in sources :

Example 11 with Account

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");
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) Before(org.junit.Before)

Example 12 with Account

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);
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) OpacClient(de.geeksfactory.opacclient.OpacClient) SharedPreferences(android.content.SharedPreferences) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) Library(de.geeksfactory.opacclient.objects.Library) Before(org.junit.Before)

Example 13 with Account

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);
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) Test(org.junit.Test)

Example 14 with Account

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();
    }
}
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 15 with Account

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();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Account(de.geeksfactory.opacclient.objects.Account) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) DialogInterface(android.content.DialogInterface) 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) ListView(android.widget.ListView) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView)

Aggregations

Account (de.geeksfactory.opacclient.objects.Account)25 AccountDataSource (de.geeksfactory.opacclient.storage.AccountDataSource)8 View (android.view.View)6 TextView (android.widget.TextView)6 Cursor (android.database.Cursor)5 ImageView (android.widget.ImageView)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)4 AlertDialog (android.support.v7.app.AlertDialog)4 LayoutInflater (android.view.LayoutInflater)4 AdapterView (android.widget.AdapterView)4 ListView (android.widget.ListView)4 OpacClient (de.geeksfactory.opacclient.OpacClient)4 AccountData (de.geeksfactory.opacclient.objects.AccountData)4 JSONObject (org.json.JSONObject)4 SuppressLint (android.annotation.SuppressLint)3 SharedPreferences (android.content.SharedPreferences)3 RecyclerView (android.support.v7.widget.RecyclerView)3