Search in sources :

Example 11 with AccountDataSource

use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.

the class OpacClient method getAccount.

public Account getAccount() {
    if (account != null) {
        if (sp.getLong(PREF_SELECTED_ACCOUNT, 0) == account.getId()) {
            return account;
        }
    }
    AccountDataSource data = new AccountDataSource(this);
    account = data.getAccount(sp.getLong(PREF_SELECTED_ACCOUNT, 0));
    return account;
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource)

Example 12 with AccountDataSource

use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.

the class ReminderBroadcastReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    this.context = context;
    this.intent = intent;
    this.prefs = PreferenceManager.getDefaultSharedPreferences(context);
    adata = new AccountDataSource(context);
    alarm = adata.getAlarm(intent.getLongExtra(EXTRA_ALARM_ID, -1));
    if (alarm == null) {
        return;
    }
    switch(intent.getAction()) {
        case ACTION_SHOW_NOTIFICATION:
            showNotification();
            break;
        case ACTION_NOTIFICATION_DELETED:
            notificationDeleted();
            break;
        case ACTION_NOTIFICATION_SNOOZE:
            notificationSnooze();
            break;
        case ACTION_NOTIFICATION_CLICK:
            notificationClick();
            break;
        case ACTION_NOTIFICATION_DONT_REMIND_AGAIN:
            notificationDontRemindAgain();
            break;
    }
    // reschedule alarms
    new ReminderHelper((OpacClient) context.getApplicationContext()).scheduleAlarms();
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) OpacClient(de.geeksfactory.opacclient.OpacClient)

Example 13 with AccountDataSource

use of de.geeksfactory.opacclient.storage.AccountDataSource 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 14 with AccountDataSource

use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.

the class SearchResultDetailFragment method bookingDo.

public void bookingDo() {
    MultiStepResultHelper<DetailedItem> msrhBooking = new MultiStepResultHelper<>(getActivity(), item, R.string.doing_booking);
    msrhBooking.setCallback(new Callback<DetailedItem>() {

        @Override
        public void onSuccess(MultiStepResult result) {
            if (getActivity() == null) {
                return;
            }
            AccountDataSource adata = new AccountDataSource(getActivity());
            adata.invalidateCachedAccountData(app.getAccount());
            Intent intent = new Intent(getActivity(), app.getMainActivity());
            intent.putExtra(MainActivity.EXTRA_FRAGMENT, "account");
            getActivity().startActivity(intent);
            getActivity().finish();
        }

        @Override
        public void onError(MultiStepResult result) {
            if (getActivity() == null) {
                return;
            }
            dialog_wrong_credentials(result.getMessage(), false);
        }

        @Override
        public void onUnhandledResult(MultiStepResult result) {
        }

        @Override
        public void onUserCancel() {
        }

        @Override
        public StepTask<?> newTask(MultiStepResultHelper helper, int useraction, String selection, DetailedItem item) {
            return new BookingTask(helper, useraction, selection, item);
        }
    });
    msrhBooking.start();
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) MultiStepResult(de.geeksfactory.opacclient.apis.OpacApi.MultiStepResult) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint) StepTask(de.geeksfactory.opacclient.frontend.MultiStepResultHelper.StepTask)

Example 15 with AccountDataSource

use of de.geeksfactory.opacclient.storage.AccountDataSource 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

AccountDataSource (de.geeksfactory.opacclient.storage.AccountDataSource)23 Intent (android.content.Intent)10 OpacClient (de.geeksfactory.opacclient.OpacClient)8 OnClickListener (android.view.View.OnClickListener)7 Account (de.geeksfactory.opacclient.objects.Account)7 View (android.view.View)6 ImageView (android.widget.ImageView)6 ListView (android.widget.ListView)6 TextView (android.widget.TextView)6 SuppressLint (android.annotation.SuppressLint)5 DialogInterface (android.content.DialogInterface)5 AlertDialog (android.support.v7.app.AlertDialog)5 RecyclerView (android.support.v7.widget.RecyclerView)4 ReminderHelper (de.geeksfactory.opacclient.reminder.ReminderHelper)4 SharedPreferences (android.content.SharedPreferences)3 LayoutInflater (android.view.LayoutInflater)3 AdapterView (android.widget.AdapterView)3 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)3 PendingIntent (android.app.PendingIntent)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2