use of com.fsck.k9.view.RecipientSelectView.Recipient in project k-9 by k9mail.
the class RecipientSelectView method getAddresses.
public Address[] getAddresses() {
List<Recipient> recipients = getObjects();
Address[] address = new Address[recipients.size()];
for (int i = 0; i < address.length; i++) {
address[i] = recipients.get(i).address;
}
return address;
}
use of com.fsck.k9.view.RecipientSelectView.Recipient in project k-9 by k9mail.
the class RecipientAdapter method bindView.
public void bindView(View view, Recipient recipient) {
RecipientTokenHolder holder = (RecipientTokenHolder) view.getTag();
holder.name.setText(highlightText(recipient.getDisplayNameOrUnknown(context)));
String address = recipient.address.getAddress();
holder.email.setText(highlightText(address));
setContactPhotoOrPlaceholder(context, holder.photo, recipient);
Integer cryptoStatusRes = null, cryptoStatusColor = null;
RecipientCryptoStatus cryptoStatus = recipient.getCryptoStatus();
switch(cryptoStatus) {
case AVAILABLE_TRUSTED:
{
cryptoStatusRes = R.drawable.status_lock_dots_3;
cryptoStatusColor = ThemeUtils.getStyledColor(context, R.attr.openpgp_green);
break;
}
case AVAILABLE_UNTRUSTED:
{
cryptoStatusRes = R.drawable.status_lock_dots_2;
cryptoStatusColor = ThemeUtils.getStyledColor(context, R.attr.openpgp_orange);
break;
}
case UNAVAILABLE:
{
cryptoStatusRes = R.drawable.status_lock_disabled_dots_1;
cryptoStatusColor = ThemeUtils.getStyledColor(context, R.attr.openpgp_red);
break;
}
}
if (cryptoStatusRes != null) {
Drawable drawable = ContextCompat.getDrawable(context, cryptoStatusRes);
DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), cryptoStatusColor);
holder.cryptoStatusIcon.setImageDrawable(drawable);
holder.cryptoStatus.setVisibility(View.VISIBLE);
} else {
holder.cryptoStatus.setVisibility(View.GONE);
}
}
use of com.fsck.k9.view.RecipientSelectView.Recipient in project k-9 by k9mail.
the class RecipientAdapter method getView.
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
view = newView(parent);
}
Recipient recipient = getItem(position);
bindView(view, recipient);
return view;
}
use of com.fsck.k9.view.RecipientSelectView.Recipient in project k-9 by k9mail.
the class RecipientLoader method fillContactDataFromCursor.
private void fillContactDataFromCursor(Cursor cursor, List<Recipient> recipients, Map<String, Recipient> recipientMap) {
while (cursor.moveToNext()) {
String name = cursor.getString(INDEX_NAME);
String email = cursor.getString(INDEX_EMAIL);
long contactId = cursor.getLong(INDEX_CONTACT_ID);
String lookupKey = cursor.getString(INDEX_LOOKUP_KEY);
// already exists? just skip then
if (recipientMap.containsKey(email)) {
// TODO merge? do something else? what do we do?
continue;
}
int addressType = cursor.getInt(INDEX_EMAIL_TYPE);
String addressLabel = null;
switch(addressType) {
case ContactsContract.CommonDataKinds.Email.TYPE_HOME:
{
addressLabel = getContext().getString(R.string.address_type_home);
break;
}
case ContactsContract.CommonDataKinds.Email.TYPE_WORK:
{
addressLabel = getContext().getString(R.string.address_type_work);
break;
}
case ContactsContract.CommonDataKinds.Email.TYPE_OTHER:
{
addressLabel = getContext().getString(R.string.address_type_other);
break;
}
case ContactsContract.CommonDataKinds.Email.TYPE_MOBILE:
{
// mobile isn't listed as an option contacts app, but it has a constant so we better support it
addressLabel = getContext().getString(R.string.address_type_mobile);
break;
}
case ContactsContract.CommonDataKinds.Email.TYPE_CUSTOM:
{
addressLabel = cursor.getString(INDEX_EMAIL_CUSTOM_LABEL);
break;
}
}
Recipient recipient = new Recipient(name, email, addressLabel, contactId, lookupKey);
if (recipient.isValidEmailAddress()) {
Uri photoUri = cursor.isNull(INDEX_PHOTO_URI) ? null : Uri.parse(cursor.getString(INDEX_PHOTO_URI));
recipient.photoThumbnailUri = photoUri;
recipientMap.put(email, recipient);
recipients.add(recipient);
}
}
cursor.close();
}
use of com.fsck.k9.view.RecipientSelectView.Recipient in project k-9 by k9mail.
the class RecipientLoader method fillCryptoStatusData.
private void fillCryptoStatusData(Map<String, Recipient> recipientMap) {
List<String> recipientList = new ArrayList<>(recipientMap.keySet());
String[] recipientAddresses = recipientList.toArray(new String[recipientList.size()]);
Cursor cursor;
Uri queryUri = Uri.parse("content://" + cryptoProvider + ".provider.exported/email_status");
try {
cursor = getContext().getContentResolver().query(queryUri, PROJECTION_CRYPTO_STATUS, null, recipientAddresses, null);
} catch (SecurityException e) {
// TODO escalate error to crypto status?
return;
}
initializeCryptoStatusForAllRecipients(recipientMap);
if (cursor == null) {
return;
}
while (cursor.moveToNext()) {
String email = cursor.getString(INDEX_EMAIL_ADDRESS);
int status = cursor.getInt(INDEX_EMAIL_STATUS);
for (Address address : Address.parseUnencoded(email)) {
String emailAddress = address.getAddress();
if (recipientMap.containsKey(emailAddress)) {
Recipient recipient = recipientMap.get(emailAddress);
switch(status) {
case CRYPTO_PROVIDER_STATUS_UNTRUSTED:
{
if (recipient.getCryptoStatus() == RecipientCryptoStatus.UNAVAILABLE) {
recipient.setCryptoStatus(RecipientCryptoStatus.AVAILABLE_UNTRUSTED);
}
break;
}
case CRYPTO_PROVIDER_STATUS_TRUSTED:
{
if (recipient.getCryptoStatus() != RecipientCryptoStatus.AVAILABLE_TRUSTED) {
recipient.setCryptoStatus(RecipientCryptoStatus.AVAILABLE_TRUSTED);
}
break;
}
}
}
}
}
cursor.close();
if (observerKey != null) {
observerKey = new ForceLoadContentObserver();
getContext().getContentResolver().registerContentObserver(queryUri, false, observerKey);
}
}
Aggregations