Remove Utility's dependency on ContactBadge

This commit is contained in:
cketti 2018-07-01 00:51:05 +02:00
parent 21220c41b5
commit b30c2f7811
4 changed files with 38 additions and 44 deletions

View file

@ -22,7 +22,6 @@ import com.fsck.k9.Account;
import com.fsck.k9.FontSizes;
import com.fsck.k9.K9;
import com.fsck.k9.core.R;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mailstore.DatabasePreviewType;
import com.fsck.k9.ui.ContactBadge;
@ -273,7 +272,7 @@ public class MessageListAdapter extends CursorAdapter {
private void updateContactBadge(MessageViewHolder holder, Address counterpartyAddress) {
if (counterpartyAddress != null) {
Utility.setContactForBadge(holder.contactBadge, counterpartyAddress);
holder.contactBadge.setContact(counterpartyAddress);
/*
* At least in Android 2.2 a different background + padding is used when no
* email address is available. ListView reuses the views but ContactBadge

View file

@ -1,31 +1,26 @@
package com.fsck.k9.helper;
import android.content.Context;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.provider.ContactsContract;
import android.text.Editable;
import android.text.TextUtils;
import timber.log.Timber;
import android.widget.EditText;
import android.widget.TextView;
import com.fsck.k9.ui.ContactBadge;
import com.fsck.k9.mail.Address;
import org.apache.james.mime4j.util.MimeUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.content.Context;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import android.os.Looper;
import android.text.Editable;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;
import org.apache.james.mime4j.util.MimeUtil;
import timber.log.Timber;
public class Utility {
// \u00A0 (non-breaking space) happens to be used by French MUA
@ -468,25 +463,4 @@ public class Utility {
}
return sMainThreadHandler;
}
/**
* Assign the contact to the badge.
*
* On 4.3, we pass the address name as extra info so that if the contact doesn't exist
* the name is auto-populated.
*
* @param contactBadge the badge to the set the contact for
* @param address the address to look for a contact for.
*/
public static void setContactForBadge(ContactBadge contactBadge,
Address address) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
Bundle extraContactInfo = new Bundle();
extraContactInfo.putString(ContactsContract.Intents.Insert.NAME, address.getPersonal());
contactBadge.assignContactFromEmail(address.getAddress(), true, extraContactInfo);
} else {
contactBadge.assignContactFromEmail(address.getAddress(), true);
}
}
}

View file

@ -9,7 +9,9 @@ import android.content.Intent;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Intents;
@ -24,6 +26,7 @@ import android.widget.ImageView;
import android.widget.Toast;
import com.fsck.k9.core.R;
import com.fsck.k9.mail.Address;
/**
@ -167,6 +170,25 @@ public class ContactBadge extends ImageView implements OnClickListener {
info.setClassName(ContactBadge.class.getName());
}
/**
* Assign the contact to the badge.
*
* On 4.3, we pass the address name as extra info so that if the contact doesn't exist
* the name is auto-populated.
*
* @param address the address to look for a contact for.
*/
public void setContact(Address address) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
Bundle extraContactInfo = new Bundle();
extraContactInfo.putString(ContactsContract.Intents.Insert.NAME, address.getPersonal());
assignContactFromEmail(address.getAddress(), true, extraContactInfo);
} else {
assignContactFromEmail(address.getAddress(), true);
}
}
private class QueryHandler extends AsyncQueryHandler {
QueryHandler(ContentResolver cr) {

View file

@ -37,7 +37,6 @@ import com.fsck.k9.helper.ClipboardManager;
import com.fsck.k9.helper.ContactPicture;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.helper.MessageHelper;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Message;
@ -316,7 +315,7 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo
if (K9.showContactPicture()) {
if (counterpartyAddress != null) {
Utility.setContactForBadge(mContactBadge, counterpartyAddress);
mContactBadge.setContact(counterpartyAddress);
mContactsPictureLoader.loadContactPicture(counterpartyAddress, mContactBadge);
} else {
mContactBadge.setImageResource(R.drawable.ic_contact_picture);