Search in sources :

Example 11 with Recipient

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;
}
Also used : Address(com.fsck.k9.mail.Address) Recipient(com.fsck.k9.view.RecipientSelectView.Recipient) SuppressLint(android.annotation.SuppressLint)

Example 12 with Recipient

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);
    }
}
Also used : RecipientCryptoStatus(com.fsck.k9.view.RecipientSelectView.RecipientCryptoStatus) Drawable(android.graphics.drawable.Drawable)

Example 13 with Recipient

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;
}
Also used : Recipient(com.fsck.k9.view.RecipientSelectView.Recipient)

Example 14 with Recipient

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();
}
Also used : Recipient(com.fsck.k9.view.RecipientSelectView.Recipient) Uri(android.net.Uri)

Example 15 with Recipient

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);
    }
}
Also used : Address(com.fsck.k9.mail.Address) ArrayList(java.util.ArrayList) Recipient(com.fsck.k9.view.RecipientSelectView.Recipient) Cursor(android.database.Cursor) Uri(android.net.Uri)

Aggregations

Recipient (com.fsck.k9.view.RecipientSelectView.Recipient)11 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 Test (org.junit.Test)6 Callback (com.fsck.k9.message.MessageBuilder.Callback)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStream (java.io.OutputStream)5 OpenPgpDataSource (org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource)5 ComposeCryptoStatus (com.fsck.k9.activity.compose.ComposeCryptoStatus)4 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)4 Address (com.fsck.k9.mail.Address)3 SuppressLint (android.annotation.SuppressLint)2 Uri (android.net.Uri)2 MessagingException (com.fsck.k9.mail.MessagingException)2 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)2 Cursor (android.database.Cursor)1 Drawable (android.graphics.drawable.Drawable)1 NonNull (android.support.annotation.NonNull)1 View (android.view.View)1 ImageView (android.widget.ImageView)1