use of com.moez.QKSMS.data.Contact in project qksms by moezbhatti.
the class NumberToContactFormatter method format.
@Override
public String format(String text) {
PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
Iterable<PhoneNumberMatch> matches = phoneNumberUtil.findNumbers(text, getCurrentCountryIso());
for (PhoneNumberMatch match : matches) {
Contact contact = Contact.get(match.rawString(), true);
if (contact.isNamed()) {
String nameAndNumber = phoneNumberUtil.format(match.number(), PhoneNumberFormat.NATIONAL) + " (" + contact.getName() + ")";
text = text.replace(match.rawString(), nameAndNumber);
}
// If the contact doesn't exist yet, leave the number as-is
}
return text;
}
use of com.moez.QKSMS.data.Contact in project qksms by moezbhatti.
the class ConversationDetailsContactListAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = View.inflate(getContext(), R.layout.list_item_recipient, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Contact contact = mContacts.get(position);
holder.name.setText(contact.getName());
holder.address.setText(contact.getNumber());
holder.avatar.setImageDrawable(contact.getAvatar(getContext(), null));
holder.avatar.setContactName(contact.getName());
if (contact.existsInDatabase()) {
holder.avatar.assignContactUri(contact.getUri());
} else {
holder.avatar.assignContactFromPhone(contact.getNumber(), true);
}
return convertView;
}
use of com.moez.QKSMS.data.Contact in project qksms by moezbhatti.
the class StarredContactsView method onLoadFinished.
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
mCursor = data;
mFavorites.removeAllViews();
LayoutInflater inflater = LayoutInflater.from(mContext);
if (data.moveToFirst()) {
do {
// only add them to the favorites list if they have a phone number
if (mCursor.getInt(ContactHelper.Favorites.HAS_PHONE_NUMBER) > 0) {
final String photoUri = mCursor.getString(ContactHelper.Favorites.PHOTO_THUMBNAIL_URI);
final Contact contact = Contact.get(ContactHelper.getPhoneNumber(mContext, mCursor.getString(ContactHelper.Favorites.ID)), true);
final View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
collapse();
mRecipients.submitItem(contact.getName(), contact.getNumber(), photoUri == null ? null : Uri.parse(photoUri));
mComposeView.requestReplyTextFocus();
}
};
View view = inflater.inflate(R.layout.view_favorite_contact, null);
view.setOnClickListener(onClickListener);
AvatarView avatar = (AvatarView) view.findViewById(R.id.avatar);
avatar.setOnClickListener(onClickListener);
avatar.setImageDrawable(contact.getAvatar(mContext, null));
avatar.setContactName(contact.getName());
QKTextView name = (QKTextView) view.findViewById(R.id.name);
name.setOnClickListener(onClickListener);
name.setText(contact.getName());
mFavorites.addView(view);
}
} while (data.moveToNext());
}
if (mFavorites.getChildCount() > 0) {
mFavoritesBackground.setVisibility(View.VISIBLE);
}
}
use of com.moez.QKSMS.data.Contact in project qksms by moezbhatti.
the class ConversationListViewHolder method onUpdate.
@Override
public void onUpdate(final Contact updated) {
boolean shouldUpdate = true;
final Drawable drawable;
final String name;
if (mData.getRecipients().size() == 1) {
Contact contact = mData.getRecipients().get(0);
if (contact.getNumber().equals(updated.getNumber())) {
drawable = contact.getAvatar(mContext, null);
name = contact.getName();
if (contact.existsInDatabase()) {
mAvatarView.assignContactUri(contact.getUri());
} else {
mAvatarView.assignContactFromPhone(contact.getNumber(), true);
}
} else {
// onUpdate was called because *some* contact was loaded, but it wasn't the contact for this
// conversation, and thus we shouldn't update the UI because we won't be able to set the correct data
drawable = null;
name = "";
shouldUpdate = false;
}
} else if (mData.getRecipients().size() > 1) {
drawable = null;
name = "" + mData.getRecipients().size();
mAvatarView.assignContactUri(null);
} else {
drawable = null;
name = "#";
mAvatarView.assignContactUri(null);
}
final ConversationLegacy conversationLegacy = new ConversationLegacy(mContext, mData.getThreadId());
if (shouldUpdate) {
mContext.runOnUiThread(() -> {
mAvatarView.setImageDrawable(drawable);
mAvatarView.setContactName(name);
fromView.setText(formatMessage(mData, conversationLegacy));
});
}
}
use of com.moez.QKSMS.data.Contact in project qksms by moezbhatti.
the class MessageListAdapter method bindAvatar.
private void bindAvatar(MessageListViewHolder holder, MessageItem messageItem) {
if (!messageItem.isMe()) {
Contact contact = Contact.get(messageItem.mAddress, true);
holder.mAvatarView.setImageDrawable(contact.getAvatar(mContext, null));
holder.mAvatarView.setContactName(contact.getName());
if (contact.existsInDatabase()) {
holder.mAvatarView.assignContactUri(contact.getUri());
} else {
holder.mAvatarView.assignContactFromPhone(contact.getNumber(), true);
}
}
}
Aggregations