Search in sources :

Example 6 with Account

use of de.geeksfactory.opacclient.objects.Account in project opacclient by opacapp.

the class DrawerAccountsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof AccountViewHolder) {
        Account account = accountsWithoutCurrent.get(position);
        ((AccountViewHolder) holder).setData(account, expiring.get(account));
    } else if (holder instanceof FooterViewHolder) {
        FooterViewHolder footer = (FooterViewHolder) holder;
        if (position == accountsWithoutCurrent.size() + (accountsWithoutCurrent.size() > 0 ? 1 : 0)) {
            footer.setTitle(R.string.account_add);
            footer.setIcon(R.drawable.ic_add_24dp);
            footer.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    if (listener != null)
                        listener.onAddAccountClicked();
                }
            });
        } else if (position == accountsWithoutCurrent.size() + (accountsWithoutCurrent.size() > 0 ? 2 : 1)) {
            footer.setTitle(R.string.accounts);
            footer.setIcon(R.drawable.ic_settings_24dp);
            footer.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    if (listener != null)
                        listener.onManageAccountsClicked();
                }
            });
        }
    }
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 7 with Account

use of de.geeksfactory.opacclient.objects.Account in project opacclient by opacapp.

the class AccountListAdapter method getView.

@SuppressWarnings("deprecation")
@Override
public View getView(int position, View contentView, ViewGroup viewGroup) {
    View view;
    // position always 0-7
    if (objects.get(position) == null) {
        LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.listitem_account, viewGroup, false);
        return view;
    }
    Account item = objects.get(position);
    if (contentView == null) {
        LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.listitem_account, viewGroup, false);
    } else {
        view = contentView;
    }
    if (((OpacClient) ((Activity) context).getApplication()).getAccount().getId() == item.getId() && highlight) {
        view.findViewById(R.id.rlItem).setBackgroundColor(context.getResources().getColor(R.color.accent_red));
    } else {
        // should be replaced by setBackground which is not available before API level 16
        view.findViewById(R.id.rlItem).setBackgroundDrawable(null);
    }
    Library lib;
    try {
        lib = ((OpacClient) ((Activity) context).getApplication()).getLibrary(item.getLibrary());
        TextView tvCity = (TextView) view.findViewById(R.id.tvCity);
        if (lib.getTitle() != null && !lib.getTitle().equals("null")) {
            tvCity.setText(lib.getCity() + "\n" + lib.getTitle());
        } else {
            tvCity.setText(lib.getCity());
        }
    } catch (IOException | JSONException e) {
        e.printStackTrace();
    }
    TextView tvName = (TextView) view.findViewById(R.id.tvName);
    if (item.getName() != null) {
        tvName.setText(item.getName());
    }
    TextView tvLabel = (TextView) view.findViewById(R.id.tvLabel);
    if (item.getLabel() != null) {
        tvLabel.setText(item.getLabel());
    }
    return view;
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) LayoutInflater(android.view.LayoutInflater) Activity(android.app.Activity) JSONException(org.json.JSONException) TextView(android.widget.TextView) Library(de.geeksfactory.opacclient.objects.Library) IOException(java.io.IOException) TextView(android.widget.TextView) View(android.view.View)

Example 8 with Account

use of de.geeksfactory.opacclient.objects.Account in project opacclient by opacapp.

the class AccountDataSource method getAccount.

public Account getAccount(long id) {
    String[] selA = { "" + id };
    Cursor cursor = database.query("accounts", allColumns, "id = ?", selA, null, null, null);
    Account acc = null;
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {
        acc = cursorToAccount(cursor);
        cursor.moveToNext();
    }
    // Make sure to close the cursor
    cursor.close();
    return acc;
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) Cursor(android.database.Cursor)

Example 9 with Account

use of de.geeksfactory.opacclient.objects.Account in project opacclient by opacapp.

the class AccountDataSource method getAccountsWithPassword.

public List<Account> getAccountsWithPassword() {
    List<Account> accs = new ArrayList<>();
    Cursor cursor = database.query("accounts", allColumns, "name is not null AND name != '' AND password is not null", null, null, null, null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        Account acc = cursorToAccount(cursor);
        accs.add(acc);
        cursor.moveToNext();
    }
    // Make sure to close the cursor
    cursor.close();
    return accs;
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 10 with Account

use of de.geeksfactory.opacclient.objects.Account in project opacclient by opacapp.

the class AccountDataSource method cursorToAccount.

private Account cursorToAccount(Cursor cursor) {
    Account acc = new Account();
    acc.setId(cursor.getLong(0));
    acc.setLibrary(cursor.getString(1));
    acc.setLabel(cursor.getString(2));
    acc.setName(cursor.getString(3));
    acc.setPassword(cursor.getString(4));
    acc.setCached(cursor.getLong(5));
    acc.setPasswordKnownValid(cursor.getLong(9) > 0);
    return acc;
}
Also used : Account(de.geeksfactory.opacclient.objects.Account)

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