Search in sources :

Example 6 with EmojiTextView

use of org.thoughtcrime.securesms.components.emoji.EmojiTextView in project Signal-Android by signalapp.

the class LongMessageFragment method initViewModel.

private void initViewModel(long messageId, boolean isMms) {
    viewModel = new ViewModelProvider(this, new LongMessageViewModel.Factory(requireActivity().getApplication(), new LongMessageRepository(), messageId, isMms)).get(LongMessageViewModel.class);
    viewModel.getMessage().observe(this, message -> {
        if (message == null)
            return;
        if (!message.isPresent()) {
            Toast.makeText(requireContext(), R.string.LongMessageActivity_unable_to_find_message, Toast.LENGTH_SHORT).show();
            dismissAllowingStateLoss();
            return;
        }
        if (message.get().getMessageRecord().isOutgoing()) {
            toolbar.setTitle(getString(R.string.LongMessageActivity_your_message));
        } else {
            Recipient recipient = message.get().getMessageRecord().getRecipient();
            String name = recipient.getDisplayName(requireContext());
            toolbar.setTitle(getString(R.string.LongMessageActivity_message_from_s, name));
        }
        ViewGroup bubble;
        if (message.get().getMessageRecord().isOutgoing()) {
            bubble = sentBubble.get();
            colorizerView.setVisibility(View.VISIBLE);
            colorizerView.setBackground(message.get().getMessageRecord().getRecipient().getChatColors().getChatBubbleMask());
            bubble.getBackground().setColorFilter(message.get().getMessageRecord().getRecipient().getChatColors().getChatBubbleColorFilter());
            bubble.addOnLayoutChangeListener(bubbleLayoutListener);
            bubbleLayoutListener.onLayoutChange(bubble, 0, 0, 0, 0, 0, 0, 0, 0);
        } else {
            bubble = receivedBubble.get();
            bubble.getBackground().setColorFilter(ContextCompat.getColor(requireContext(), R.color.signal_background_secondary), PorterDuff.Mode.MULTIPLY);
        }
        EmojiTextView text = bubble.findViewById(R.id.longmessage_text);
        ConversationItemFooter footer = bubble.findViewById(R.id.longmessage_footer);
        CharSequence trimmedBody = getTrimmedBody(message.get().getFullBody(requireContext()));
        SpannableString styledBody = linkifyMessageBody(new SpannableString(trimmedBody));
        bubble.setVisibility(View.VISIBLE);
        text.setText(styledBody);
        text.setMovementMethod(LinkMovementMethod.getInstance());
        text.setTextSize(TypedValue.COMPLEX_UNIT_SP, SignalStore.settings().getMessageFontSize());
        if (!message.get().getMessageRecord().isOutgoing()) {
            text.setMentionBackgroundTint(ContextCompat.getColor(requireContext(), ThemeUtil.isDarkTheme(requireActivity()) ? R.color.core_grey_60 : R.color.core_grey_20));
        } else {
            text.setMentionBackgroundTint(ContextCompat.getColor(requireContext(), R.color.transparent_black_40));
        }
        footer.setMessageRecord(message.get().getMessageRecord(), Locale.getDefault());
    });
}
Also used : SpannableString(android.text.SpannableString) ConversationItemFooter(org.thoughtcrime.securesms.components.ConversationItemFooter) ViewGroup(android.view.ViewGroup) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SpannableString(android.text.SpannableString) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

EmojiTextView (org.thoughtcrime.securesms.components.emoji.EmojiTextView)6 Context (android.content.Context)4 SpannableString (android.text.SpannableString)4 Nullable (androidx.annotation.Nullable)4 Resources (android.content.res.Resources)2 Bitmap (android.graphics.Bitmap)2 Typeface (android.graphics.Typeface)2 Drawable (android.graphics.drawable.Drawable)2 Spanned (android.text.Spanned)2 TextPaint (android.text.TextPaint)2 TextUtils (android.text.TextUtils)2 ClickableSpan (android.text.style.ClickableSpan)2 URLSpan (android.text.style.URLSpan)2 Linkify (android.text.util.Linkify)2 TransitionInflater (android.transition.TransitionInflater)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 ImageView (android.widget.ImageView)2 NonNull (androidx.annotation.NonNull)2 Toolbar (androidx.appcompat.widget.Toolbar)2