Search in sources :

Example 1 with Contact

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;
}
Also used : PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) PhoneNumberMatch(com.google.i18n.phonenumbers.PhoneNumberMatch) Contact(com.moez.QKSMS.data.Contact)

Example 2 with Contact

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;
}
Also used : Contact(com.moez.QKSMS.data.Contact)

Example 3 with Contact

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);
    }
}
Also used : LayoutInflater(android.view.LayoutInflater) ImageView(android.widget.ImageView) View(android.view.View) Contact(com.moez.QKSMS.data.Contact)

Example 4 with Contact

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));
        });
    }
}
Also used : ConversationLegacy(com.moez.QKSMS.data.ConversationLegacy) Drawable(android.graphics.drawable.Drawable) Contact(com.moez.QKSMS.data.Contact)

Example 5 with Contact

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);
        }
    }
}
Also used : Contact(com.moez.QKSMS.data.Contact)

Aggregations

Contact (com.moez.QKSMS.data.Contact)5 Drawable (android.graphics.drawable.Drawable)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 PhoneNumberMatch (com.google.i18n.phonenumbers.PhoneNumberMatch)1 PhoneNumberUtil (com.google.i18n.phonenumbers.PhoneNumberUtil)1 ConversationLegacy (com.moez.QKSMS.data.ConversationLegacy)1