Search in sources :

Example 1 with PhoneNumberFormatter

use of org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter in project Signal-Android by WhisperSystems.

the class ConversationFragment method presentMessageRequestProfileView.

private void presentMessageRequestProfileView(@NonNull Context context, @NonNull MessageRequestViewModel.RecipientInfo recipientInfo, @Nullable ConversationBannerView conversationBanner) {
    if (conversationBanner == null) {
        return;
    }
    Recipient recipient = recipientInfo.getRecipient();
    boolean isSelf = Recipient.self().equals(recipient);
    int memberCount = recipientInfo.getGroupMemberCount();
    int pendingMemberCount = recipientInfo.getGroupPendingMemberCount();
    List<String> groups = recipientInfo.getSharedGroups();
    conversationBanner.setBadge(recipient);
    if (recipient != null) {
        conversationBanner.setAvatar(GlideApp.with(context), recipient);
        conversationBanner.showBackgroundBubble(recipient.hasWallpaper());
        String title = conversationBanner.setTitle(recipient);
        conversationBanner.setAbout(recipient);
        if (recipient.isGroup()) {
            if (pendingMemberCount > 0) {
                conversationBanner.setSubtitle(context.getResources().getQuantityString(R.plurals.MessageRequestProfileView_members_and_invited, memberCount, memberCount, pendingMemberCount));
            } else if (memberCount > 0) {
                conversationBanner.setSubtitle(context.getResources().getQuantityString(R.plurals.MessageRequestProfileView_members, memberCount, memberCount));
            } else {
                conversationBanner.setSubtitle(null);
            }
        } else if (isSelf) {
            conversationBanner.setSubtitle(context.getString(R.string.ConversationFragment__you_can_add_notes_for_yourself_in_this_conversation));
        } else {
            String subtitle = recipient.getE164().transform(PhoneNumberFormatter::prettyPrint).orNull();
            if (subtitle == null || subtitle.equals(title)) {
                conversationBanner.hideSubtitle();
            } else {
                conversationBanner.setSubtitle(subtitle);
            }
        }
    }
    if (groups.isEmpty() || isSelf) {
        if (TextUtils.isEmpty(recipientInfo.getGroupDescription())) {
            conversationBanner.setLinkifyDescription(false);
            conversationBanner.hideDescription();
        } else {
            conversationBanner.setLinkifyDescription(true);
            boolean linkifyWebLinks = recipientInfo.getMessageRequestState() == MessageRequestState.NONE;
            conversationBanner.showDescription();
            GroupDescriptionUtil.setText(context, conversationBanner.getDescription(), recipientInfo.getGroupDescription(), linkifyWebLinks, () -> GroupDescriptionDialog.show(getChildFragmentManager(), recipient.getDisplayName(context), recipientInfo.getGroupDescription(), linkifyWebLinks));
        }
    } else {
        final String description;
        switch(groups.size()) {
            case 1:
                description = context.getString(R.string.MessageRequestProfileView_member_of_one_group, HtmlUtil.bold(groups.get(0)));
                break;
            case 2:
                description = context.getString(R.string.MessageRequestProfileView_member_of_two_groups, HtmlUtil.bold(groups.get(0)), HtmlUtil.bold(groups.get(1)));
                break;
            case 3:
                description = context.getString(R.string.MessageRequestProfileView_member_of_many_groups, HtmlUtil.bold(groups.get(0)), HtmlUtil.bold(groups.get(1)), HtmlUtil.bold(groups.get(2)));
                break;
            default:
                int others = groups.size() - 2;
                description = context.getString(R.string.MessageRequestProfileView_member_of_many_groups, HtmlUtil.bold(groups.get(0)), HtmlUtil.bold(groups.get(1)), context.getResources().getQuantityString(R.plurals.MessageRequestProfileView_member_of_d_additional_groups, others, others));
        }
        conversationBanner.setDescription(HtmlCompat.fromHtml(description, 0));
        conversationBanner.showDescription();
    }
}
Also used : PhoneNumberFormatter(org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 PhoneNumberFormatter (org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter)1 LiveRecipient (org.thoughtcrime.securesms.recipients.LiveRecipient)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1