Search in sources :

Example 21 with AccountDataSource

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

the class AccountEditActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getLayoutResource());
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ImageView image = (ImageView) findViewById(R.id.ivBarcode);
    image.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            BarcodeScanIntegrator integrator = new BarcodeScanIntegrator(AccountEditActivity.this);
            integrator.initiateScan();
        }
    });
    etLabel = (EditText) findViewById(R.id.etLabel);
    etName = (EditText) findViewById(R.id.etName);
    etPassword = (EditText) findViewById(R.id.etPassword);
    usernameContainer = findViewById(R.id.llBarcode);
    tilUsername = (TextInputLayout) findViewById(R.id.tilUsername);
    passwordContainer = findViewById(R.id.llPassword);
    tilPassword = (TextInputLayout) findViewById(R.id.tilPassword);
    rgType = (RadioGroup) findViewById(R.id.rgType);
    AccountDataSource data = new AccountDataSource(this);
    account = data.getAccount(getIntent().getLongExtra(EXTRA_ACCOUNT_ID, -1));
    if (account == null) {
        finish();
        return;
    }
    if (account.getLabel().equals(getString(R.string.default_account_name))) {
        etLabel.setText("");
    } else {
        etLabel.setText(account.getLabel());
    }
    etName.setText(account.getName());
    etPassword.setText(account.getPassword());
    etPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            saveAndCheck();
            return false;
        }
    });
    try {
        lib = ((OpacClient) getApplication()).getLibrary(account.getLibrary());
        if (findViewById(R.id.tvCity) != null) {
            TextView tvCity = (TextView) findViewById(R.id.tvCity);
            tvCity.setText(lib.getDisplayName());
        }
        if (lib.getReplacedBy() != null && !"".equals(lib.getReplacedBy()) && findViewById(R.id.rlReplaced) != null && ((OpacClient) getApplication()).promotePlusApps()) {
            findViewById(R.id.rlReplaced).setVisibility(View.VISIBLE);
            findViewById(R.id.ivReplacedStore).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    try {
                        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(lib.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(lib.getReplacedBy()));
                        startActivity(i);
                    }
                }
            });
        } else if (findViewById(R.id.rlReplaced) != null) {
            findViewById(R.id.rlReplaced).setVisibility(View.GONE);
        }
        refreshSslWarning();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        ErrorReporter.handleException(e);
        e.printStackTrace();
    }
    rgType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup radioGroup, int i) {
            if (i == R.id.rbAnonymous) {
                passwordContainer.setVisibility(View.GONE);
                usernameContainer.setVisibility(View.GONE);
            } else if (i == R.id.rbWithCredentials) {
                passwordContainer.setVisibility(View.VISIBLE);
                usernameContainer.setVisibility(View.VISIBLE);
            }
            refreshSslWarning();
        }
    });
    if ((account.getName() == null || account.getPassword() == null || account.getName().equals("") || account.getPassword().equals("")) && (getIntent().getBooleanExtra(EXTRA_EDITING, false) || !lib.isAccountSupported())) {
        ((RadioButton) findViewById(R.id.rbAnonymous)).setChecked(true);
    }
    if (account.getPassword() == null || account.getPassword().equals("")) {
        ((TextInputLayout) findViewById(R.id.tilPassword)).setPasswordVisibilityToggleEnabled(true);
    } else {
        ((TextInputLayout) findViewById(R.id.tilPassword)).setPasswordVisibilityToggleEnabled(false);
    }
}
Also used : BarcodeScanIntegrator(de.geeksfactory.opacclient.barcode.BarcodeScanIntegrator) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) RadioGroup(android.widget.RadioGroup) JSONException(org.json.JSONException) Intent(android.content.Intent) IOException(java.io.IOException) RadioButton(android.widget.RadioButton) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) ActivityNotFoundException(android.content.ActivityNotFoundException) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TextInputLayout(android.support.design.widget.TextInputLayout)

Example 22 with AccountDataSource

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

the class AccountFragment method export.

private void export() {
    if (refreshing) {
        Toast.makeText(getActivity(), R.string.account_no_concurrent, Toast.LENGTH_LONG).show();
        if (!refreshing) {
            refresh();
        }
        return;
    }
    Context ctx = getActivity() != null ? getActivity() : OpacClient.getEmergencyContext();
    AccountDataSource adatasource = new AccountDataSource(ctx);
    AccountData data = adatasource.getCachedAccountData(account);
    LocalDateTime dt = new LocalDateTime(adatasource.getCachedAccountDataTime(account));
    if (data == null)
        return;
    StringBuilder string = new StringBuilder();
    DateTimeFormatter fmt1 = DateTimeFormat.shortDateTime().withLocale(getResources().getConfiguration().locale);
    DateTimeFormatter fmt2 = DateTimeFormat.shortDate().withLocale(getResources().getConfiguration().locale);
    String dateStr = fmt1.print(dt);
    string.append(getResources().getString(R.string.accountdata_export_header, account.getLabel(), dateStr));
    string.append("\n\n");
    string.append(getResources().getString(R.string.lent_head));
    string.append("\n\n");
    for (LentItem item : data.getLent()) {
        appendIfNotEmpty(string, item.getTitle(), R.string.accountdata_title);
        appendIfNotEmpty(string, item.getAuthor(), R.string.accountdata_author);
        appendIfNotEmpty(string, item.getFormat(), R.string.accountdata_format);
        appendIfNotEmpty(string, item.getStatus(), R.string.accountdata_status);
        appendIfNotEmpty(string, item.getBarcode(), R.string.accountdata_lent_barcode);
        if (item.getDeadline() != null) {
            appendIfNotEmpty(string, fmt2.print(item.getDeadline()), R.string.accountdata_lent_deadline);
        }
        appendIfNotEmpty(string, item.getHomeBranch(), R.string.accountdata_lent_home_branch);
        appendIfNotEmpty(string, item.getLendingBranch(), R.string.accountdata_lent_lending_branch);
        string.append("\n");
    }
    if (data.getLent().size() == 0) {
        string.append(getResources().getString(R.string.lent_none));
    }
    string.append(getResources().getString(R.string.reservations_head));
    string.append("\n\n");
    for (ReservedItem item : data.getReservations()) {
        appendIfNotEmpty(string, item.getTitle(), R.string.accountdata_title);
        appendIfNotEmpty(string, item.getAuthor(), R.string.accountdata_author);
        appendIfNotEmpty(string, item.getFormat(), R.string.accountdata_format);
        appendIfNotEmpty(string, item.getStatus(), R.string.accountdata_status);
        if (item.getReadyDate() != null) {
            appendIfNotEmpty(string, fmt2.print(item.getReadyDate()), R.string.accountdata_reserved_ready_date);
        }
        if (item.getExpirationDate() != null) {
            appendIfNotEmpty(string, fmt2.print(item.getExpirationDate()), R.string.accountdata_reserved_expiration_date);
        }
        appendIfNotEmpty(string, item.getBranch(), R.string.accountdata_reserved_branch);
        string.append("\n");
    }
    if (data.getReservations().size() == 0) {
        string.append(getResources().getString(R.string.reservations_none));
    }
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, string.toString());
    sendIntent.setType("text/plain");
    startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.share_dialog_select)));
}
Also used : Context(android.content.Context) LocalDateTime(org.joda.time.LocalDateTime) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) AccountData(de.geeksfactory.opacclient.objects.AccountData) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) Intent(android.content.Intent) LentItem(de.geeksfactory.opacclient.objects.LentItem) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 23 with AccountDataSource

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

the class AccountListActivity method refreshLv.

public void refreshLv() {
    ListView lvAccounts = (ListView) findViewById(R.id.lvAccounts);
    AccountDataSource data = new AccountDataSource(this);
    accounts = data.getAllAccounts();
    AccountListAdapter adapter = new AccountListAdapter(this, accounts);
    lvAccounts.setAdapter(adapter);
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) ListView(android.widget.ListView)

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