Search in sources :

Example 1 with CallContact

use of cx.ring.model.CallContact in project ring-client-android by savoirfairelinux.

the class ConversationAdapter method configureForTextMessage.

/**
 * Configures the viewholder to display a classic text message, ie. not a call info text message
 *
 * @param convViewHolder The conversation viewHolder
 * @param convElement    The conversation element to display
 * @param position       The position of the viewHolder
 */
private void configureForTextMessage(final ConversationViewHolder convViewHolder, final IConversationElement convElement, int position) {
    if (convViewHolder == null || convElement == null) {
        return;
    }
    TextMessage textMessage = (TextMessage) convElement;
    CallContact contact = textMessage.getContact();
    if (contact == null) {
        Log.e(TAG, "Invalid contact, not able to display message correctly");
        return;
    }
    convViewHolder.mCid = textMessage.getContact().getId();
    String message = textMessage.getMessage().trim();
    if (StringUtils.isOnlyEmoji(message)) {
        convViewHolder.mMsgTxt.getBackground().setAlpha(0);
        convViewHolder.mMsgTxt.setTextSize(24.f);
        convViewHolder.mMsgTxt.setPadding(hPadding, vPaddingEmoticon, hPadding, vPaddingEmoticon);
    } else {
        convViewHolder.mMsgTxt.getBackground().setAlpha(255);
        convViewHolder.mMsgTxt.setTextSize(16.f);
        convViewHolder.mMsgTxt.setPadding(hPadding, vPadding, hPadding, vPadding);
    }
    convViewHolder.mMsgTxt.setText(message);
    if (convViewHolder.mPhoto != null) {
        convViewHolder.mPhoto.setImageBitmap(null);
    }
    boolean shouldSeparateByDetails = this.shouldSeparateByDetails(textMessage, position);
    boolean isConfigSameAsPreviousMsg = this.isMessageConfigSameAsPrevious(textMessage, position);
    if (textMessage.isIncoming() && !isConfigSameAsPreviousMsg) {
        Drawable contactPicture = AvatarFactory.getAvatar(convViewHolder.itemView.getContext(), mPhoto, contact.getUsername(), textMessage.getNumberUri().getHost());
        Glide.with(convViewHolder.itemView.getContext()).load(contactPicture).apply(AvatarFactory.getGlideOptions(true, true)).into(convViewHolder.mPhoto);
    }
    if (textMessage.getStatus() == TextMessage.Status.SENDING) {
        convViewHolder.mMsgDetailTxt.setVisibility(View.VISIBLE);
        convViewHolder.mMsgDetailTxt.setText(R.string.message_sending);
    } else if (shouldSeparateByDetails) {
        convViewHolder.mMsgDetailTxt.setVisibility(View.VISIBLE);
        String timeSeparationString = computeTimeSeparationStringFromMsgTimeStamp(convViewHolder.itemView.getContext(), textMessage.getDate());
        convViewHolder.mMsgDetailTxt.setText(timeSeparationString);
    } else {
        convViewHolder.mMsgDetailTxt.setVisibility(View.GONE);
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) TextMessage(cx.ring.model.TextMessage) CallContact(cx.ring.model.CallContact)

Example 2 with CallContact

use of cx.ring.model.CallContact in project ring-client-android by savoirfairelinux.

the class BlackListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(BlackListViewHolder holder, int position) {
    final CallContact contact = mBlacklisted.get(position);
    holder.bind(mListener, contact);
}
Also used : CallContact(cx.ring.model.CallContact)

Example 3 with CallContact

use of cx.ring.model.CallContact in project ring-client-android by savoirfairelinux.

the class ContactServiceImpl method findContactBySipNumberFromSystem.

public CallContact findContactBySipNumberFromSystem(String number) {
    CallContact contact = null;
    ContentResolver contentResolver = mContext.getContentResolver();
    try {
        Cursor result = contentResolver.query(ContactsContract.Data.CONTENT_URI, DATA_PROJECTION, ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + "=?" + " AND (" + ContactsContract.Data.MIMETYPE + "=? OR " + ContactsContract.Data.MIMETYPE + "=?)", new String[] { number, ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE }, null);
        if (result == null) {
            Log.d(TAG, "findContactBySipNumberFromSystem: " + number + " can't find contact.");
            return CallContact.buildUnknown(number);
        }
        int indexId = result.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID);
        int indexKey = result.getColumnIndex(ContactsContract.Data.LOOKUP_KEY);
        int indexName = result.getColumnIndex(ContactsContract.Data.DISPLAY_NAME);
        int indexPhoto = result.getColumnIndex(ContactsContract.Data.PHOTO_ID);
        int indexStared = result.getColumnIndex(ContactsContract.Contacts.STARRED);
        if (result.moveToFirst()) {
            long contactId = result.getLong(indexId);
            contact = new CallContact(contactId, result.getString(indexKey), result.getString(indexName), result.getLong(indexPhoto));
            if (result.getInt(indexStared) != 0) {
                contact.setStared();
            }
            fillContactDetails(contact);
        }
        result.close();
        if (contact == null || contact.getPhones() == null || contact.getPhones().isEmpty()) {
            return null;
        }
    } catch (Exception e) {
        Log.d(TAG, "findContactBySipNumberFromSystem: Error while searching for contact number=" + number, e);
    }
    return contact;
}
Also used : Cursor(android.database.Cursor) CallContact(cx.ring.model.CallContact) IOException(java.io.IOException) ContentResolver(android.content.ContentResolver)

Example 4 with CallContact

use of cx.ring.model.CallContact in project ring-client-android by savoirfairelinux.

the class ContactServiceImpl method findContactByNumberFromSystem.

public CallContact findContactByNumberFromSystem(String number) {
    CallContact callContact = null;
    ContentResolver contentResolver = mContext.getContentResolver();
    try {
        android.net.Uri uri = android.net.Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, android.net.Uri.encode(number));
        Cursor result = contentResolver.query(uri, PHONELOOKUP_PROJECTION, null, null, null);
        if (result == null) {
            Log.d(TAG, "findContactByNumberFromSystem: " + number + " can't find contact.");
            return findContactBySipNumberFromSystem(number);
        }
        if (result.moveToFirst()) {
            int indexId = result.getColumnIndex(ContactsContract.Contacts._ID);
            int indexKey = result.getColumnIndex(ContactsContract.Data.LOOKUP_KEY);
            int indexName = result.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
            int indexPhoto = result.getColumnIndex(ContactsContract.Contacts.PHOTO_ID);
            callContact = new CallContact(result.getLong(indexId), result.getString(indexKey), result.getString(indexName), result.getLong(indexPhoto));
            fillContactDetails(callContact);
            Log.d(TAG, "findContactByNumberFromSystem: " + number + " found " + callContact.getDisplayName());
        }
        result.close();
    } catch (Exception e) {
        Log.d(TAG, "findContactByNumber: Error while searching for contact number=" + number, e);
    }
    if (callContact == null) {
        Log.d(TAG, "findContactByNumberFromSystem: " + number + " can't find contact.");
        callContact = findContactBySipNumberFromSystem(number);
    }
    return callContact;
}
Also used : Cursor(android.database.Cursor) CallContact(cx.ring.model.CallContact) IOException(java.io.IOException) ContentResolver(android.content.ContentResolver)

Example 5 with CallContact

use of cx.ring.model.CallContact in project ring-client-android by savoirfairelinux.

the class ContactCardPresenter method onBindViewHolder.

@Override
public void onBindViewHolder(Card card, ImageCardView cardView) {
    ContactCard contact = (ContactCard) card;
    CallContact model = contact.getModel().getCallContact();
    String username = model.getUsername();
    if (username == null) {
        username = model.getIds().get(0);
    }
    if (username != null && (username.isEmpty() || model.getDisplayName().equals(username))) {
        cardView.setTitleText(username);
        cardView.setContentText("");
    } else {
        cardView.setTitleText(model.getDisplayName());
        cardView.setContentText(username);
    }
    cardView.setBackgroundColor(cardView.getResources().getColor(R.color.color_primary_dark));
    cardView.setMainImage(getCardImage(contact));
}
Also used : CallContact(cx.ring.model.CallContact)

Aggregations

CallContact (cx.ring.model.CallContact)38 Conversation (cx.ring.model.Conversation)9 Uri (cx.ring.model.Uri)8 Account (cx.ring.model.Account)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)5 ContentResolver (android.content.ContentResolver)4 Cursor (android.database.Cursor)4 SipCall (cx.ring.model.SipCall)4 ServiceEvent (cx.ring.model.ServiceEvent)3 Settings (cx.ring.model.Settings)3 TextMessage (cx.ring.model.TextMessage)3 IOException (java.io.IOException)3 Map (java.util.Map)3 Intent (android.content.Intent)2 StringMap (cx.ring.daemon.StringMap)2 TrustRequest (cx.ring.model.TrustRequest)2 TVListViewModel (cx.ring.tv.model.TVListViewModel)2 List (java.util.List)2 PendingIntent (android.app.PendingIntent)1