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();
}
});
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations