Search in sources :

Example 6 with AccountDataSource

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

Example 7 with AccountDataSource

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();
    }
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) OpacClient(de.geeksfactory.opacclient.OpacClient)

Example 8 with AccountDataSource

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();
        }
    }
}
Also used : Context(android.content.Context) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) OpacClient(de.geeksfactory.opacclient.OpacClient) ActivityNotFoundException(android.content.ActivityNotFoundException) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 9 with AccountDataSource

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);
    }
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) OpacClient(de.geeksfactory.opacclient.OpacClient) Button(android.widget.Button) NotReachableException(de.geeksfactory.opacclient.networking.NotReachableException) FrameLayout(android.widget.FrameLayout) SSLSecurityException(de.geeksfactory.opacclient.networking.SSLSecurityException) OnClickListener(android.view.View.OnClickListener) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 10 with AccountDataSource

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);
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource)

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