Search in sources :

Example 1 with ForegroundColorSpanThemable

use of org.telegram.ui.Components.ForegroundColorSpanThemable in project Telegram-FOSS by Telegram-FOSS-Team.

the class AndroidUtilities method highlightText.

public static CharSequence highlightText(CharSequence str, String query, Theme.ResourcesProvider resourcesProvider) {
    if (TextUtils.isEmpty(query) || TextUtils.isEmpty(str)) {
        return null;
    }
    String s = str.toString().toLowerCase();
    SpannableStringBuilder spannableStringBuilder = SpannableStringBuilder.valueOf(str);
    int i = s.indexOf(query);
    while (i >= 0) {
        try {
            spannableStringBuilder.setSpan(new ForegroundColorSpanThemable(Theme.key_windowBackgroundWhiteBlueText4, resourcesProvider), i, Math.min(i + query.length(), str.length()), 0);
        } catch (Exception e) {
            FileLog.e(e);
        }
        i = s.indexOf(query, i + 1);
    }
    return spannableStringBuilder;
}
Also used : SpannedString(android.text.SpannedString) SpannableStringBuilder(android.text.SpannableStringBuilder) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) IOException(java.io.IOException) ForegroundColorSpanThemable(org.telegram.ui.Components.ForegroundColorSpanThemable)

Example 2 with ForegroundColorSpanThemable

use of org.telegram.ui.Components.ForegroundColorSpanThemable in project Telegram-FOSS by Telegram-FOSS-Team.

the class SearchAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    switch(holder.getItemViewType()) {
        case 0:
            {
                TLObject object = (TLObject) getItem(position);
                if (object != null) {
                    long id = 0;
                    String un = null;
                    boolean self = false;
                    if (object instanceof TLRPC.User) {
                        un = ((TLRPC.User) object).username;
                        id = ((TLRPC.User) object).id;
                        self = ((TLRPC.User) object).self;
                    } else if (object instanceof TLRPC.Chat) {
                        un = ((TLRPC.Chat) object).username;
                        id = ((TLRPC.Chat) object).id;
                    }
                    CharSequence username = null;
                    CharSequence name = null;
                    if (position < searchResult.size()) {
                        name = searchResultNames.get(position);
                        if (name != null && un != null && un.length() > 0) {
                            if (name.toString().startsWith("@" + un)) {
                                username = name;
                                name = null;
                            }
                        }
                    } else if (position > searchResult.size() && un != null) {
                        String foundUserName = searchAdapterHelper.getLastFoundUsername();
                        if (foundUserName != null && foundUserName.startsWith("@")) {
                            foundUserName = foundUserName.substring(1);
                        }
                        try {
                            int index;
                            SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
                            spannableStringBuilder.append("@");
                            spannableStringBuilder.append(un);
                            if (foundUserName != null && (index = AndroidUtilities.indexOfIgnoreCase(un, foundUserName)) != -1) {
                                int len = foundUserName.length();
                                if (index == 0) {
                                    len++;
                                } else {
                                    index++;
                                }
                                spannableStringBuilder.setSpan(new ForegroundColorSpanThemable(Theme.key_windowBackgroundWhiteBlueText4), index, index + len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            }
                            username = spannableStringBuilder;
                        } catch (Exception e) {
                            username = un;
                            FileLog.e(e);
                        }
                    }
                    if (useUserCell) {
                        UserCell userCell = (UserCell) holder.itemView;
                        userCell.setData(object, name, username, 0);
                        if (checkedMap != null) {
                            userCell.setChecked(checkedMap.indexOfKey(id) >= 0, false);
                        }
                    } else {
                        ProfileSearchCell profileSearchCell = (ProfileSearchCell) holder.itemView;
                        if (self) {
                            name = LocaleController.getString("SavedMessages", R.string.SavedMessages);
                        }
                        profileSearchCell.setData(object, null, name, username, false, self);
                        profileSearchCell.useSeparator = (position != getItemCount() - 1 && position != searchResult.size() - 1);
                    /*if (ignoreUsers != null) {
                            if (ignoreUsers.containsKey(id)) {
                                profileSearchCell.drawAlpha = 0.5f;
                            } else {
                                profileSearchCell.drawAlpha = 1.0f;
                            }
                        }*/
                    }
                }
                break;
            }
        case 1:
            {
                GraySectionCell cell = (GraySectionCell) holder.itemView;
                if (getItem(position) == null) {
                    cell.setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch));
                } else {
                    cell.setText(LocaleController.getString("PhoneNumberSearch", R.string.PhoneNumberSearch));
                }
                break;
            }
        case 2:
            {
                String str = (String) getItem(position);
                TextCell cell = (TextCell) holder.itemView;
                cell.setColors(null, Theme.key_windowBackgroundWhiteBlueText2);
                cell.setText(LocaleController.formatString("AddContactByPhone", R.string.AddContactByPhone, PhoneFormat.getInstance().format("+" + str)), false);
                break;
            }
    }
}
Also used : GraySectionCell(org.telegram.ui.Cells.GraySectionCell) TLRPC(org.telegram.tgnet.TLRPC) TextCell(org.telegram.ui.Cells.TextCell) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) TLObject(org.telegram.tgnet.TLObject) UserCell(org.telegram.ui.Cells.UserCell) SpannableStringBuilder(android.text.SpannableStringBuilder) ForegroundColorSpanThemable(org.telegram.ui.Components.ForegroundColorSpanThemable)

Example 3 with ForegroundColorSpanThemable

use of org.telegram.ui.Components.ForegroundColorSpanThemable in project Telegram-FOSS by Telegram-FOSS-Team.

the class AndroidUtilities method generateSearchName.

public static CharSequence generateSearchName(String name, String name2, String q) {
    if (name == null && name2 == null || TextUtils.isEmpty(q)) {
        return "";
    }
    SpannableStringBuilder builder = new SpannableStringBuilder();
    String wholeString = name;
    if (wholeString == null || wholeString.length() == 0) {
        wholeString = name2;
    } else if (name2 != null && name2.length() != 0) {
        wholeString += " " + name2;
    }
    wholeString = wholeString.trim();
    String lower = " " + wholeString.toLowerCase();
    int index;
    int lastIndex = 0;
    while ((index = lower.indexOf(" " + q, lastIndex)) != -1) {
        int idx = index - (index == 0 ? 0 : 1);
        int end = q.length() + (index == 0 ? 0 : 1) + idx;
        if (lastIndex != 0 && lastIndex != idx + 1) {
            builder.append(wholeString.substring(lastIndex, idx));
        } else if (lastIndex == 0 && idx != 0) {
            builder.append(wholeString.substring(0, idx));
        }
        String query = wholeString.substring(idx, Math.min(wholeString.length(), end));
        if (query.startsWith(" ")) {
            builder.append(" ");
        }
        query = query.trim();
        int start = builder.length();
        builder.append(query);
        builder.setSpan(new ForegroundColorSpanThemable(Theme.key_windowBackgroundWhiteBlueText4), start, start + query.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        lastIndex = end;
    }
    if (lastIndex != -1 && lastIndex < wholeString.length()) {
        builder.append(wholeString.substring(lastIndex));
    }
    return builder;
}
Also used : SpannedString(android.text.SpannedString) SpannableStringBuilder(android.text.SpannableStringBuilder) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) ForegroundColorSpanThemable(org.telegram.ui.Components.ForegroundColorSpanThemable)

Example 4 with ForegroundColorSpanThemable

use of org.telegram.ui.Components.ForegroundColorSpanThemable in project Telegram-FOSS by Telegram-FOSS-Team.

the class DialogsSearchAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    switch(holder.getItemViewType()) {
        case 0:
            {
                ProfileSearchCell cell = (ProfileSearchCell) holder.itemView;
                long oldDialogId = cell.getDialogId();
                TLRPC.User user = null;
                TLRPC.Chat chat = null;
                TLRPC.EncryptedChat encryptedChat = null;
                CharSequence username = null;
                CharSequence name = null;
                boolean isRecent = false;
                String un = null;
                Object obj = getItem(position);
                if (obj instanceof TLRPC.User) {
                    user = (TLRPC.User) obj;
                    un = user.username;
                } else if (obj instanceof TLRPC.Chat) {
                    chat = MessagesController.getInstance(currentAccount).getChat(((TLRPC.Chat) obj).id);
                    if (chat == null) {
                        chat = (TLRPC.Chat) obj;
                    }
                    un = chat.username;
                } else if (obj instanceof TLRPC.EncryptedChat) {
                    encryptedChat = MessagesController.getInstance(currentAccount).getEncryptedChat(((TLRPC.EncryptedChat) obj).id);
                    user = MessagesController.getInstance(currentAccount).getUser(encryptedChat.user_id);
                }
                if (isRecentSearchDisplayed()) {
                    isRecent = true;
                    cell.useSeparator = position != getItemCount() - 1;
                } else {
                    ArrayList<TLObject> globalSearch = searchAdapterHelper.getGlobalSearch();
                    ArrayList<Object> phoneSearch = searchAdapterHelper.getPhoneSearch();
                    int localCount = searchResult.size();
                    int localServerCount = searchAdapterHelper.getLocalServerSearch().size();
                    int phoneCount = phoneSearch.size();
                    if (phoneCount > 3 && phoneCollapsed) {
                        phoneCount = 3;
                    }
                    int phoneCount2 = phoneCount;
                    if (phoneCount > 0 && phoneSearch.get(phoneCount - 1) instanceof String) {
                        phoneCount2 -= 2;
                    }
                    int globalCount = globalSearch.isEmpty() ? 0 : globalSearch.size() + 1;
                    if (globalCount > 4 && globalSearchCollapsed) {
                        globalCount = 4;
                    }
                    cell.useSeparator = (position != getItemCount() - 1 && position != localCount + phoneCount2 + localServerCount - 1 && position != localCount + globalCount + phoneCount + localServerCount - 1);
                    if (position < searchResult.size()) {
                        name = searchResultNames.get(position);
                        if (name != null && user != null && user.username != null && user.username.length() > 0) {
                            if (name.toString().startsWith("@" + user.username)) {
                                username = name;
                                name = null;
                            }
                        }
                    } else {
                        String foundUserName = searchAdapterHelper.getLastFoundUsername();
                        if (!TextUtils.isEmpty(foundUserName)) {
                            String nameSearch = null;
                            int index;
                            if (user != null) {
                                nameSearch = ContactsController.formatName(user.first_name, user.last_name);
                            } else if (chat != null) {
                                nameSearch = chat.title;
                            }
                            if (nameSearch != null && (index = AndroidUtilities.indexOfIgnoreCase(nameSearch, foundUserName)) != -1) {
                                SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(nameSearch);
                                spannableStringBuilder.setSpan(new ForegroundColorSpanThemable(Theme.key_windowBackgroundWhiteBlueText4), index, index + foundUserName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                                name = spannableStringBuilder;
                            } else if (un != null) {
                                if (foundUserName.startsWith("@")) {
                                    foundUserName = foundUserName.substring(1);
                                }
                                try {
                                    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
                                    spannableStringBuilder.append("@");
                                    spannableStringBuilder.append(un);
                                    if ((index = AndroidUtilities.indexOfIgnoreCase(un, foundUserName)) != -1) {
                                        int len = foundUserName.length();
                                        if (index == 0) {
                                            len++;
                                        } else {
                                            index++;
                                        }
                                        spannableStringBuilder.setSpan(new ForegroundColorSpanThemable(Theme.key_windowBackgroundWhiteBlueText4), index, index + len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                                    }
                                    username = spannableStringBuilder;
                                } catch (Exception e) {
                                    username = un;
                                    FileLog.e(e);
                                }
                            }
                        }
                    }
                    cell.setChecked(false, false);
                }
                boolean savedMessages = false;
                if (user != null && user.id == selfUserId) {
                    name = LocaleController.getString("SavedMessages", R.string.SavedMessages);
                    username = null;
                    savedMessages = true;
                }
                if (chat != null && chat.participants_count != 0) {
                    String membersString;
                    if (ChatObject.isChannel(chat) && !chat.megagroup) {
                        membersString = LocaleController.formatPluralString("Subscribers", chat.participants_count);
                    } else {
                        membersString = LocaleController.formatPluralString("Members", chat.participants_count);
                    }
                    if (username instanceof SpannableStringBuilder) {
                        ((SpannableStringBuilder) username).append(", ").append(membersString);
                    } else if (!TextUtils.isEmpty(username)) {
                        username = TextUtils.concat(username, ", ", membersString);
                    } else {
                        username = membersString;
                    }
                }
                cell.setData(user != null ? user : chat, encryptedChat, name, username, isRecent, savedMessages);
                cell.setChecked(delegate.isSelected(cell.getDialogId()), oldDialogId == cell.getDialogId());
                break;
            }
        case 1:
            {
                GraySectionCell cell = (GraySectionCell) holder.itemView;
                if (isRecentSearchDisplayed()) {
                    int offset = (!MediaDataController.getInstance(currentAccount).hints.isEmpty() ? 1 : 0);
                    if (position < offset) {
                        cell.setText(LocaleController.getString("ChatHints", R.string.ChatHints));
                    } else {
                        cell.setText(LocaleController.getString("Recent", R.string.Recent), LocaleController.getString("ClearButton", R.string.ClearButton), v -> {
                            if (delegate != null) {
                                delegate.needClearList();
                            }
                        });
                    }
                } else if (!searchResultHashtags.isEmpty()) {
                    cell.setText(LocaleController.getString("Hashtags", R.string.Hashtags), LocaleController.getString("ClearButton", R.string.ClearButton), v -> {
                        if (delegate != null) {
                            delegate.needClearList();
                        }
                    });
                } else {
                    ArrayList<TLObject> globalSearch = searchAdapterHelper.getGlobalSearch();
                    int localCount = searchResult.size();
                    int localServerCount = searchAdapterHelper.getLocalServerSearch().size();
                    int phoneCount = searchAdapterHelper.getPhoneSearch().size();
                    if (phoneCount > 3 && phoneCollapsed) {
                        phoneCount = 3;
                    }
                    int globalCount = globalSearch.isEmpty() ? 0 : globalSearch.size() + 1;
                    if (globalCount > 4 && globalSearchCollapsed) {
                        globalCount = 4;
                    }
                    int messagesCount = searchResultMessages.isEmpty() ? 0 : searchResultMessages.size() + 1;
                    position -= localCount + localServerCount;
                    String title;
                    boolean showMore = false;
                    Runnable onClick = null;
                    if (position >= 0 && position < phoneCount) {
                        title = LocaleController.getString("PhoneNumberSearch", R.string.PhoneNumberSearch);
                        if (searchAdapterHelper.getPhoneSearch().size() > 3) {
                            showMore = phoneCollapsed;
                            onClick = () -> {
                                phoneCollapsed = !phoneCollapsed;
                                notifyDataSetChanged();
                            };
                        }
                    } else {
                        position -= phoneCount;
                        if (position >= 0 && position < globalCount) {
                            title = LocaleController.getString("GlobalSearch", R.string.GlobalSearch);
                            if (searchAdapterHelper.getGlobalSearch().size() > 3) {
                                showMore = globalSearchCollapsed;
                                onClick = () -> {
                                    globalSearchCollapsed = !globalSearchCollapsed;
                                    notifyDataSetChanged();
                                };
                            }
                        } else {
                            title = LocaleController.getString("SearchMessages", R.string.SearchMessages);
                        }
                    }
                    if (onClick == null) {
                        cell.setText(title);
                    } else {
                        final Runnable finalOnClick = onClick;
                        cell.setText(title, showMore ? LocaleController.getString("ShowMore", R.string.ShowMore) : LocaleController.getString("ShowLess", R.string.ShowLess), e -> finalOnClick.run());
                    }
                }
                break;
            }
        case 2:
            {
                DialogCell cell = (DialogCell) holder.itemView;
                cell.useSeparator = (position != getItemCount() - 1);
                MessageObject messageObject = (MessageObject) getItem(position);
                cell.setDialog(messageObject.getDialogId(), messageObject, messageObject.messageOwner.date, false);
                break;
            }
        case 4:
            {
                HashtagSearchCell cell = (HashtagSearchCell) holder.itemView;
                cell.setText(searchResultHashtags.get(position - 1));
                cell.setNeedDivider(position != searchResultHashtags.size());
                break;
            }
        case 5:
            {
                RecyclerListView recyclerListView = (RecyclerListView) holder.itemView;
                ((CategoryAdapterRecycler) recyclerListView.getAdapter()).setIndex(position / 2);
                break;
            }
        case 6:
            {
                String str = (String) getItem(position);
                TextCell cell = (TextCell) holder.itemView;
                cell.setColors(null, Theme.key_windowBackgroundWhiteBlueText2);
                cell.setText(LocaleController.formatString("AddContactByPhone", R.string.AddContactByPhone, PhoneFormat.getInstance().format("+" + str)), false);
                break;
            }
    }
}
Also used : Context(android.content.Context) ForegroundColorSpanThemable(org.telegram.ui.Components.ForegroundColorSpanThemable) Spanned(android.text.Spanned) Theme(org.telegram.ui.ActionBar.Theme) AndroidUtilities(org.telegram.messenger.AndroidUtilities) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) TextCell(org.telegram.ui.Cells.TextCell) MotionEvent(android.view.MotionEvent) TLRPC(org.telegram.tgnet.TLRPC) PhoneFormat(org.telegram.PhoneFormat.PhoneFormat) TLObject(org.telegram.tgnet.TLObject) HintDialogCell(org.telegram.ui.Cells.HintDialogCell) View(android.view.View) MessageObject(org.telegram.messenger.MessageObject) MediaDataController(org.telegram.messenger.MediaDataController) RecyclerView(androidx.recyclerview.widget.RecyclerView) DialogCell(org.telegram.ui.Cells.DialogCell) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) Utilities(org.telegram.messenger.Utilities) LongSparseArray(androidx.collection.LongSparseArray) DialogObject(org.telegram.messenger.DialogObject) FilteredSearchView(org.telegram.ui.FilteredSearchView) R(org.telegram.messenger.R) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TextUtils(android.text.TextUtils) SQLitePreparedStatement(org.telegram.SQLite.SQLitePreparedStatement) FileLog(org.telegram.messenger.FileLog) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) MessagesController(org.telegram.messenger.MessagesController) UserConfig(org.telegram.messenger.UserConfig) UserObject(org.telegram.messenger.UserObject) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) HashtagSearchCell(org.telegram.ui.Cells.HashtagSearchCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) ChatObject(org.telegram.messenger.ChatObject) Collections(java.util.Collections) RecyclerListView(org.telegram.ui.Components.RecyclerListView) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) ArrayList(java.util.ArrayList) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TLRPC(org.telegram.tgnet.TLRPC) TextCell(org.telegram.ui.Cells.TextCell) HintDialogCell(org.telegram.ui.Cells.HintDialogCell) DialogCell(org.telegram.ui.Cells.DialogCell) ForegroundColorSpanThemable(org.telegram.ui.Components.ForegroundColorSpanThemable) HashtagSearchCell(org.telegram.ui.Cells.HashtagSearchCell) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) TLObject(org.telegram.tgnet.TLObject) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) DialogObject(org.telegram.messenger.DialogObject) UserObject(org.telegram.messenger.UserObject) ChatObject(org.telegram.messenger.ChatObject) MessageObject(org.telegram.messenger.MessageObject) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 5 with ForegroundColorSpanThemable

use of org.telegram.ui.Components.ForegroundColorSpanThemable in project Telegram-FOSS by Telegram-FOSS-Team.

the class DialogCell method buildLayout.

public void buildLayout() {
    int thumbSize;
    if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
        Theme.dialogs_namePaint[1].setTextSize(AndroidUtilities.dp(16));
        Theme.dialogs_nameEncryptedPaint[1].setTextSize(AndroidUtilities.dp(16));
        Theme.dialogs_messagePaint[1].setTextSize(AndroidUtilities.dp(15));
        Theme.dialogs_messagePrintingPaint[1].setTextSize(AndroidUtilities.dp(15));
        Theme.dialogs_messagePaint[1].setColor(Theme.dialogs_messagePaint[1].linkColor = Theme.getColor(Theme.key_chats_message_threeLines, resourcesProvider));
        paintIndex = 1;
        thumbSize = 18;
    } else {
        Theme.dialogs_namePaint[0].setTextSize(AndroidUtilities.dp(17));
        Theme.dialogs_nameEncryptedPaint[0].setTextSize(AndroidUtilities.dp(17));
        Theme.dialogs_messagePaint[0].setTextSize(AndroidUtilities.dp(16));
        Theme.dialogs_messagePrintingPaint[0].setTextSize(AndroidUtilities.dp(16));
        Theme.dialogs_messagePaint[0].setColor(Theme.dialogs_messagePaint[0].linkColor = Theme.getColor(Theme.key_chats_message, resourcesProvider));
        paintIndex = 0;
        thumbSize = 19;
    }
    currentDialogFolderDialogsCount = 0;
    String nameString = "";
    String timeString = "";
    String countString = null;
    String mentionString = null;
    CharSequence messageString = "";
    CharSequence messageNameString = null;
    CharSequence printingString = null;
    if (isDialogCell) {
        printingString = MessagesController.getInstance(currentAccount).getPrintingString(currentDialogId, 0, true);
    }
    TextPaint currentMessagePaint = Theme.dialogs_messagePaint[paintIndex];
    boolean checkMessage = true;
    drawNameGroup = false;
    drawNameBroadcast = false;
    drawNameLock = false;
    drawNameBot = false;
    drawVerified = false;
    drawScam = 0;
    drawPinBackground = false;
    hasMessageThumb = false;
    int offsetName = 0;
    boolean showChecks = !UserObject.isUserSelf(user) && !useMeForMyMessages;
    boolean drawTime = true;
    printingStringType = -1;
    int printigStingReplaceIndex = -1;
    String messageFormat;
    boolean hasNameInMessage;
    if (Build.VERSION.SDK_INT >= 18) {
        if (!useForceThreeLines && !SharedConfig.useThreeLinesLayout || currentDialogFolderId != 0) {
            messageFormat = "%2$s: \u2068%1$s\u2069";
            hasNameInMessage = true;
        } else {
            messageFormat = "\u2068%s\u2069";
            hasNameInMessage = false;
        }
    } else {
        if (!useForceThreeLines && !SharedConfig.useThreeLinesLayout || currentDialogFolderId != 0) {
            messageFormat = "%2$s: %1$s";
            hasNameInMessage = true;
        } else {
            messageFormat = "%1$s";
            hasNameInMessage = false;
        }
    }
    CharSequence msgText = message != null ? message.messageText : null;
    if (msgText instanceof Spannable) {
        Spannable sp = new SpannableStringBuilder(msgText);
        for (Object span : sp.getSpans(0, sp.length(), URLSpanNoUnderlineBold.class)) sp.removeSpan(span);
        for (Object span : sp.getSpans(0, sp.length(), URLSpanNoUnderline.class)) sp.removeSpan(span);
        msgText = sp;
    }
    lastMessageString = msgText;
    if (customDialog != null) {
        if (customDialog.type == 2) {
            drawNameLock = true;
            if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
                nameLockTop = AndroidUtilities.dp(12.5f);
                if (!LocaleController.isRTL) {
                    nameLockLeft = AndroidUtilities.dp(72 + 6);
                    nameLeft = AndroidUtilities.dp(72 + 10) + Theme.dialogs_lockDrawable.getIntrinsicWidth();
                } else {
                    nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(72 + 6) - Theme.dialogs_lockDrawable.getIntrinsicWidth();
                    nameLeft = AndroidUtilities.dp(22);
                }
            } else {
                nameLockTop = AndroidUtilities.dp(16.5f);
                if (!LocaleController.isRTL) {
                    nameLockLeft = AndroidUtilities.dp(72 + 4);
                    nameLeft = AndroidUtilities.dp(72 + 8) + Theme.dialogs_lockDrawable.getIntrinsicWidth();
                } else {
                    nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(72 + 4) - Theme.dialogs_lockDrawable.getIntrinsicWidth();
                    nameLeft = AndroidUtilities.dp(18);
                }
            }
        } else {
            drawVerified = customDialog.verified;
            if (SharedConfig.drawDialogIcons && customDialog.type == 1) {
                drawNameGroup = true;
                if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
                    nameLockTop = AndroidUtilities.dp(13.5f);
                    if (!LocaleController.isRTL) {
                        nameLockLeft = AndroidUtilities.dp(72 + 6);
                        nameLeft = AndroidUtilities.dp(72 + 10) + (drawNameGroup ? Theme.dialogs_groupDrawable.getIntrinsicWidth() : Theme.dialogs_broadcastDrawable.getIntrinsicWidth());
                    } else {
                        nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(72 + 6) - (drawNameGroup ? Theme.dialogs_groupDrawable.getIntrinsicWidth() : Theme.dialogs_broadcastDrawable.getIntrinsicWidth());
                        nameLeft = AndroidUtilities.dp(22);
                    }
                } else {
                    if (!LocaleController.isRTL) {
                        nameLockTop = AndroidUtilities.dp(17.5f);
                        nameLockLeft = AndroidUtilities.dp(72 + 4);
                        nameLeft = AndroidUtilities.dp(72 + 8) + (drawNameGroup ? Theme.dialogs_groupDrawable.getIntrinsicWidth() : Theme.dialogs_broadcastDrawable.getIntrinsicWidth());
                    } else {
                        nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(72 + 4) - (drawNameGroup ? Theme.dialogs_groupDrawable.getIntrinsicWidth() : Theme.dialogs_broadcastDrawable.getIntrinsicWidth());
                        nameLeft = AndroidUtilities.dp(18);
                    }
                }
            } else {
                if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
                    if (!LocaleController.isRTL) {
                        nameLeft = AndroidUtilities.dp(72 + 6);
                    } else {
                        nameLeft = AndroidUtilities.dp(22);
                    }
                } else {
                    if (!LocaleController.isRTL) {
                        nameLeft = AndroidUtilities.dp(72 + 4);
                    } else {
                        nameLeft = AndroidUtilities.dp(18);
                    }
                }
            }
        }
        if (customDialog.type == 1) {
            messageNameString = LocaleController.getString("FromYou", R.string.FromYou);
            checkMessage = false;
            SpannableStringBuilder stringBuilder;
            if (customDialog.isMedia) {
                currentMessagePaint = Theme.dialogs_messagePrintingPaint[paintIndex];
                stringBuilder = SpannableStringBuilder.valueOf(String.format(messageFormat, message.messageText));
                stringBuilder.setSpan(new ForegroundColorSpanThemable(Theme.key_chats_attachMessage, resourcesProvider), 0, stringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else {
                String mess = customDialog.message;
                if (mess.length() > 150) {
                    mess = mess.substring(0, 150);
                }
                if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
                    stringBuilder = SpannableStringBuilder.valueOf(String.format(messageFormat, mess, messageNameString));
                } else {
                    stringBuilder = SpannableStringBuilder.valueOf(String.format(messageFormat, mess.replace('\n', ' '), messageNameString));
                }
            }
            messageString = Emoji.replaceEmoji(stringBuilder, Theme.dialogs_messagePaint[paintIndex].getFontMetricsInt(), AndroidUtilities.dp(20), false);
        } else {
            messageString = customDialog.message;
            if (customDialog.isMedia) {
                currentMessagePaint = Theme.dialogs_messagePrintingPaint[paintIndex];
            }
        }
        timeString = LocaleController.stringForMessageListDate(customDialog.date);
        if (customDialog.unread_count != 0) {
            drawCount = true;
            countString = String.format("%d", customDialog.unread_count);
        } else {
            drawCount = false;
        }
        if (customDialog.sent) {
            drawCheck1 = true;
            drawCheck2 = true;
        } else {
            drawCheck1 = false;
            drawCheck2 = false;
        }
        drawClock = false;
        drawError = false;
        nameString = customDialog.name;
    } else {
        if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
            if (!LocaleController.isRTL) {
                nameLeft = AndroidUtilities.dp(72 + 6);
            } else {
                nameLeft = AndroidUtilities.dp(22);
            }
        } else {
            if (!LocaleController.isRTL) {
                nameLeft = AndroidUtilities.dp(72 + 4);
            } else {
                nameLeft = AndroidUtilities.dp(18);
            }
        }
        if (encryptedChat != null) {
            if (currentDialogFolderId == 0) {
                drawNameLock = true;
                if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
                    nameLockTop = AndroidUtilities.dp(12.5f);
                    if (!LocaleController.isRTL) {
                        nameLockLeft = AndroidUtilities.dp(72 + 6);
                        nameLeft = AndroidUtilities.dp(72 + 10) + Theme.dialogs_lockDrawable.getIntrinsicWidth();
                    } else {
                        nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(72 + 6) - Theme.dialogs_lockDrawable.getIntrinsicWidth();
                        nameLeft = AndroidUtilities.dp(22);
                    }
                } else {
                    nameLockTop = AndroidUtilities.dp(16.5f);
                    if (!LocaleController.isRTL) {
                        nameLockLeft = AndroidUtilities.dp(72 + 4);
                        nameLeft = AndroidUtilities.dp(72 + 8) + Theme.dialogs_lockDrawable.getIntrinsicWidth();
                    } else {
                        nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(72 + 4) - Theme.dialogs_lockDrawable.getIntrinsicWidth();
                        nameLeft = AndroidUtilities.dp(18);
                    }
                }
            }
        } else {
            if (currentDialogFolderId == 0) {
                if (chat != null) {
                    if (chat.scam) {
                        drawScam = 1;
                        Theme.dialogs_scamDrawable.checkText();
                    } else if (chat.fake) {
                        drawScam = 2;
                        Theme.dialogs_fakeDrawable.checkText();
                    } else {
                        drawVerified = chat.verified;
                    }
                    if (SharedConfig.drawDialogIcons) {
                        if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
                            if (chat.id < 0 || ChatObject.isChannel(chat) && !chat.megagroup) {
                                drawNameBroadcast = true;
                                nameLockTop = AndroidUtilities.dp(12.5f);
                            } else {
                                drawNameGroup = true;
                                nameLockTop = AndroidUtilities.dp(13.5f);
                            }
                            if (!LocaleController.isRTL) {
                                nameLockLeft = AndroidUtilities.dp(72 + 6);
                                nameLeft = AndroidUtilities.dp(72 + 10) + (drawNameGroup ? Theme.dialogs_groupDrawable.getIntrinsicWidth() : Theme.dialogs_broadcastDrawable.getIntrinsicWidth());
                            } else {
                                nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(72 + 6) - (drawNameGroup ? Theme.dialogs_groupDrawable.getIntrinsicWidth() : Theme.dialogs_broadcastDrawable.getIntrinsicWidth());
                                nameLeft = AndroidUtilities.dp(22);
                            }
                        } else {
                            if (chat.id < 0 || ChatObject.isChannel(chat) && !chat.megagroup) {
                                drawNameBroadcast = true;
                                nameLockTop = AndroidUtilities.dp(16.5f);
                            } else {
                                drawNameGroup = true;
                                nameLockTop = AndroidUtilities.dp(17.5f);
                            }
                            if (!LocaleController.isRTL) {
                                nameLockLeft = AndroidUtilities.dp(72 + 4);
                                nameLeft = AndroidUtilities.dp(72 + 8) + (drawNameGroup ? Theme.dialogs_groupDrawable.getIntrinsicWidth() : Theme.dialogs_broadcastDrawable.getIntrinsicWidth());
                            } else {
                                nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(72 + 4) - (drawNameGroup ? Theme.dialogs_groupDrawable.getIntrinsicWidth() : Theme.dialogs_broadcastDrawable.getIntrinsicWidth());
                                nameLeft = AndroidUtilities.dp(18);
                            }
                        }
                    }
                } else if (user != null) {
                    if (user.scam) {
                        drawScam = 1;
                        Theme.dialogs_scamDrawable.checkText();
                    } else if (user.fake) {
                        drawScam = 2;
                        Theme.dialogs_fakeDrawable.checkText();
                    } else {
                        drawVerified = user.verified;
                    }
                    if (SharedConfig.drawDialogIcons && user.bot) {
                        drawNameBot = true;
                        if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
                            nameLockTop = AndroidUtilities.dp(12.5f);
                            if (!LocaleController.isRTL) {
                                nameLockLeft = AndroidUtilities.dp(72 + 6);
                                nameLeft = AndroidUtilities.dp(72 + 10) + Theme.dialogs_botDrawable.getIntrinsicWidth();
                            } else {
                                nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(72 + 6) - Theme.dialogs_botDrawable.getIntrinsicWidth();
                                nameLeft = AndroidUtilities.dp(22);
                            }
                        } else {
                            nameLockTop = AndroidUtilities.dp(16.5f);
                            if (!LocaleController.isRTL) {
                                nameLockLeft = AndroidUtilities.dp(72 + 4);
                                nameLeft = AndroidUtilities.dp(72 + 8) + Theme.dialogs_botDrawable.getIntrinsicWidth();
                            } else {
                                nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(72 + 4) - Theme.dialogs_botDrawable.getIntrinsicWidth();
                                nameLeft = AndroidUtilities.dp(18);
                            }
                        }
                    }
                }
            }
        }
        int lastDate = lastMessageDate;
        if (lastMessageDate == 0 && message != null) {
            lastDate = message.messageOwner.date;
        }
        if (isDialogCell) {
            draftMessage = MediaDataController.getInstance(currentAccount).getDraft(currentDialogId, 0);
            if (draftMessage != null && (TextUtils.isEmpty(draftMessage.message) && draftMessage.reply_to_msg_id == 0 || lastDate > draftMessage.date && unreadCount != 0) || ChatObject.isChannel(chat) && !chat.megagroup && !chat.creator && (chat.admin_rights == null || !chat.admin_rights.post_messages) || chat != null && (chat.left || chat.kicked)) {
                draftMessage = null;
            }
        } else {
            draftMessage = null;
        }
        if (printingString != null) {
            lastPrintString = printingString;
            printingStringType = MessagesController.getInstance(currentAccount).getPrintingStringType(currentDialogId, 0);
            StatusDrawable statusDrawable = Theme.getChatStatusDrawable(printingStringType);
            int startPadding = 0;
            if (statusDrawable != null) {
                startPadding = statusDrawable.getIntrinsicWidth() + AndroidUtilities.dp(3);
            }
            SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
            printingString = TextUtils.replace(printingString, new String[] { "..." }, new String[] { "" });
            if (printingStringType == 5) {
                printigStingReplaceIndex = printingString.toString().indexOf("**oo**");
            }
            if (printigStingReplaceIndex >= 0) {
                spannableStringBuilder.append(printingString).setSpan(new FixedWidthSpan(Theme.getChatStatusDrawable(printingStringType).getIntrinsicWidth()), printigStingReplaceIndex, printigStingReplaceIndex + 6, 0);
            } else {
                spannableStringBuilder.append(" ").append(printingString).setSpan(new FixedWidthSpan(startPadding), 0, 1, 0);
            }
            messageString = spannableStringBuilder;
            currentMessagePaint = Theme.dialogs_messagePrintingPaint[paintIndex];
            checkMessage = false;
        } else {
            lastPrintString = null;
            if (draftMessage != null) {
                checkMessage = false;
                messageNameString = LocaleController.getString("Draft", R.string.Draft);
                if (TextUtils.isEmpty(draftMessage.message)) {
                    if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
                        messageString = "";
                    } else {
                        SpannableStringBuilder stringBuilder = SpannableStringBuilder.valueOf(messageNameString);
                        stringBuilder.setSpan(new ForegroundColorSpanThemable(Theme.key_chats_draft, resourcesProvider), 0, messageNameString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        messageString = stringBuilder;
                    }
                } else {
                    String mess = draftMessage.message;
                    if (mess.length() > 150) {
                        mess = mess.substring(0, 150);
                    }
                    Spannable messSpan = new SpannableStringBuilder(mess);
                    MediaDataController.addTextStyleRuns(draftMessage, messSpan, TextStyleSpan.FLAG_STYLE_SPOILER);
                    SpannableStringBuilder stringBuilder = AndroidUtilities.formatSpannable(messageFormat, AndroidUtilities.replaceNewLines(messSpan), messageNameString);
                    if (!useForceThreeLines && !SharedConfig.useThreeLinesLayout) {
                        stringBuilder.setSpan(new ForegroundColorSpanThemable(Theme.key_chats_draft, resourcesProvider), 0, messageNameString.length() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    messageString = Emoji.replaceEmoji(stringBuilder, Theme.dialogs_messagePaint[paintIndex].getFontMetricsInt(), AndroidUtilities.dp(20), false);
                }
            } else {
                if (clearingDialog) {
                    currentMessagePaint = Theme.dialogs_messagePrintingPaint[paintIndex];
                    messageString = LocaleController.getString("HistoryCleared", R.string.HistoryCleared);
                } else if (message == null) {
                    if (encryptedChat != null) {
                        currentMessagePaint = Theme.dialogs_messagePrintingPaint[paintIndex];
                        if (encryptedChat instanceof TLRPC.TL_encryptedChatRequested) {
                            messageString = LocaleController.getString("EncryptionProcessing", R.string.EncryptionProcessing);
                        } else if (encryptedChat instanceof TLRPC.TL_encryptedChatWaiting) {
                            messageString = LocaleController.formatString("AwaitingEncryption", R.string.AwaitingEncryption, UserObject.getFirstName(user));
                        } else if (encryptedChat instanceof TLRPC.TL_encryptedChatDiscarded) {
                            messageString = LocaleController.getString("EncryptionRejected", R.string.EncryptionRejected);
                        } else if (encryptedChat instanceof TLRPC.TL_encryptedChat) {
                            if (encryptedChat.admin_id == UserConfig.getInstance(currentAccount).getClientUserId()) {
                                messageString = LocaleController.formatString("EncryptedChatStartedOutgoing", R.string.EncryptedChatStartedOutgoing, UserObject.getFirstName(user));
                            } else {
                                messageString = LocaleController.getString("EncryptedChatStartedIncoming", R.string.EncryptedChatStartedIncoming);
                            }
                        }
                    } else {
                        if (dialogsType == 3 && UserObject.isUserSelf(user)) {
                            messageString = LocaleController.getString("SavedMessagesInfo", R.string.SavedMessagesInfo);
                            showChecks = false;
                            drawTime = false;
                        } else {
                            messageString = "";
                        }
                    }
                } else {
                    String restrictionReason = MessagesController.getRestrictionReason(message.messageOwner.restriction_reason);
                    TLRPC.User fromUser = null;
                    TLRPC.Chat fromChat = null;
                    long fromId = message.getFromChatId();
                    if (DialogObject.isUserDialog(fromId)) {
                        fromUser = MessagesController.getInstance(currentAccount).getUser(fromId);
                    } else {
                        fromChat = MessagesController.getInstance(currentAccount).getChat(-fromId);
                    }
                    if (dialogsType == 3 && UserObject.isUserSelf(user)) {
                        messageString = LocaleController.getString("SavedMessagesInfo", R.string.SavedMessagesInfo);
                        showChecks = false;
                        drawTime = false;
                    } else if (!useForceThreeLines && !SharedConfig.useThreeLinesLayout && currentDialogFolderId != 0) {
                        checkMessage = false;
                        messageString = formatArchivedDialogNames();
                    } else if (message.messageOwner instanceof TLRPC.TL_messageService) {
                        if (ChatObject.isChannelAndNotMegaGroup(chat) && (message.messageOwner.action instanceof TLRPC.TL_messageActionHistoryClear || message.messageOwner.action instanceof TLRPC.TL_messageActionChannelMigrateFrom)) {
                            messageString = "";
                            showChecks = false;
                        } else {
                            messageString = msgText;
                        }
                        currentMessagePaint = Theme.dialogs_messagePrintingPaint[paintIndex];
                    } else {
                        boolean needEmoji = true;
                        if (TextUtils.isEmpty(restrictionReason) && currentDialogFolderId == 0 && encryptedChat == null && !message.needDrawBluredPreview() && (message.isPhoto() || message.isNewGif() || message.isVideo())) {
                            String type = message.isWebpage() ? message.messageOwner.media.webpage.type : null;
                            if (!("app".equals(type) || "profile".equals(type) || "article".equals(type) || type != null && type.startsWith("telegram_"))) {
                                TLRPC.PhotoSize smallThumb = FileLoader.getClosestPhotoSizeWithSize(message.photoThumbs, 40);
                                TLRPC.PhotoSize bigThumb = FileLoader.getClosestPhotoSizeWithSize(message.photoThumbs, AndroidUtilities.getPhotoSize());
                                if (smallThumb == bigThumb) {
                                    bigThumb = null;
                                }
                                if (smallThumb != null) {
                                    hasMessageThumb = true;
                                    drawPlay = message.isVideo();
                                    String fileName = FileLoader.getAttachFileName(bigThumb);
                                    if (message.mediaExists || DownloadController.getInstance(currentAccount).canDownloadMedia(message) || FileLoader.getInstance(currentAccount).isLoadingFile(fileName)) {
                                        int size;
                                        if (message.type == MessageObject.TYPE_PHOTO) {
                                            size = bigThumb != null ? bigThumb.size : 0;
                                        } else {
                                            size = 0;
                                        }
                                        thumbImage.setImage(ImageLocation.getForObject(bigThumb, message.photoThumbsObject), "20_20", ImageLocation.getForObject(smallThumb, message.photoThumbsObject), "20_20", size, null, message, 0);
                                    } else {
                                        thumbImage.setImage(null, null, ImageLocation.getForObject(smallThumb, message.photoThumbsObject), "20_20", (Drawable) null, message, 0);
                                    }
                                    needEmoji = false;
                                }
                            }
                        }
                        if (chat != null && chat.id > 0 && fromChat == null && (!ChatObject.isChannel(chat) || ChatObject.isMegagroup(chat))) {
                            if (message.isOutOwner()) {
                                messageNameString = LocaleController.getString("FromYou", R.string.FromYou);
                            } else if (message != null && message.messageOwner.fwd_from != null && message.messageOwner.fwd_from.from_name != null) {
                                messageNameString = message.messageOwner.fwd_from.from_name;
                            } else if (fromUser != null) {
                                if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
                                    if (UserObject.isDeleted(fromUser)) {
                                        messageNameString = LocaleController.getString("HiddenName", R.string.HiddenName);
                                    } else {
                                        messageNameString = ContactsController.formatName(fromUser.first_name, fromUser.last_name).replace("\n", "");
                                    }
                                } else {
                                    messageNameString = UserObject.getFirstName(fromUser).replace("\n", "");
                                }
                            } else {
                                messageNameString = "DELETED";
                            }
                            checkMessage = false;
                            SpannableStringBuilder stringBuilder;
                            if (!TextUtils.isEmpty(restrictionReason)) {
                                stringBuilder = SpannableStringBuilder.valueOf(String.format(messageFormat, restrictionReason, messageNameString));
                            } else if (message.caption != null) {
                                CharSequence mess = message.caption.toString();
                                if (mess.length() > 150) {
                                    mess = mess.subSequence(0, 150);
                                }
                                String emoji;
                                if (!needEmoji) {
                                    emoji = "";
                                } else if (message.isVideo()) {
                                    emoji = "\uD83D\uDCF9 ";
                                } else if (message.isVoice()) {
                                    emoji = "\uD83C\uDFA4 ";
                                } else if (message.isMusic()) {
                                    emoji = "\uD83C\uDFA7 ";
                                } else if (message.isPhoto()) {
                                    emoji = "\uD83D\uDDBC ";
                                } else {
                                    emoji = "\uD83D\uDCCE ";
                                }
                                SpannableStringBuilder msgBuilder = new SpannableStringBuilder(mess);
                                MediaDataController.addTextStyleRuns(message.messageOwner.entities, message.caption, msgBuilder, TextStyleSpan.FLAG_STYLE_SPOILER);
                                stringBuilder = AndroidUtilities.formatSpannable(messageFormat, new SpannableStringBuilder(emoji).append(AndroidUtilities.replaceNewLines(msgBuilder)), messageNameString);
                            } else if (message.messageOwner.media != null && !message.isMediaEmpty()) {
                                currentMessagePaint = Theme.dialogs_messagePrintingPaint[paintIndex];
                                String innerMessage;
                                if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPoll) {
                                    TLRPC.TL_messageMediaPoll mediaPoll = (TLRPC.TL_messageMediaPoll) message.messageOwner.media;
                                    if (Build.VERSION.SDK_INT >= 18) {
                                        innerMessage = String.format("\uD83D\uDCCA \u2068%s\u2069", mediaPoll.poll.question);
                                    } else {
                                        innerMessage = String.format("\uD83D\uDCCA %s", mediaPoll.poll.question);
                                    }
                                } else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
                                    if (Build.VERSION.SDK_INT >= 18) {
                                        innerMessage = String.format("\uD83C\uDFAE \u2068%s\u2069", message.messageOwner.media.game.title);
                                    } else {
                                        innerMessage = String.format("\uD83C\uDFAE %s", message.messageOwner.media.game.title);
                                    }
                                } else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) {
                                    innerMessage = message.messageOwner.media.title;
                                } else if (message.type == 14) {
                                    if (Build.VERSION.SDK_INT >= 18) {
                                        innerMessage = String.format("\uD83C\uDFA7 \u2068%s - %s\u2069", message.getMusicAuthor(), message.getMusicTitle());
                                    } else {
                                        innerMessage = String.format("\uD83C\uDFA7 %s - %s", message.getMusicAuthor(), message.getMusicTitle());
                                    }
                                } else {
                                    innerMessage = msgText.toString();
                                }
                                innerMessage = innerMessage.replace('\n', ' ');
                                stringBuilder = AndroidUtilities.formatSpannable(messageFormat, innerMessage, messageNameString);
                                try {
                                    stringBuilder.setSpan(new ForegroundColorSpanThemable(Theme.key_chats_attachMessage, resourcesProvider), hasNameInMessage ? messageNameString.length() + 2 : 0, stringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                                } catch (Exception e) {
                                    FileLog.e(e);
                                }
                            } else if (message.messageOwner.message != null) {
                                CharSequence mess = message.messageOwner.message;
                                if (message.hasHighlightedWords()) {
                                    if (message.messageTrimmedToHighlight != null) {
                                        mess = message.messageTrimmedToHighlight;
                                    }
                                    int w = getMeasuredWidth() - AndroidUtilities.dp(72 + 23 + 10);
                                    if (hasNameInMessage) {
                                        if (!TextUtils.isEmpty(messageNameString)) {
                                            w -= currentMessagePaint.measureText(messageNameString.toString());
                                        }
                                        w -= currentMessagePaint.measureText(": ");
                                    }
                                    if (w > 0) {
                                        mess = AndroidUtilities.ellipsizeCenterEnd(mess, message.highlightedWords.get(0), w, currentMessagePaint, 130).toString();
                                    }
                                } else {
                                    if (mess.length() > 150) {
                                        mess = mess.subSequence(0, 150);
                                    }
                                    mess = AndroidUtilities.replaceNewLines(mess);
                                }
                                mess = new SpannableStringBuilder(mess);
                                MediaDataController.addTextStyleRuns(message, (Spannable) mess, TextStyleSpan.FLAG_STYLE_SPOILER);
                                stringBuilder = AndroidUtilities.formatSpannable(messageFormat, mess, messageNameString);
                            } else {
                                stringBuilder = SpannableStringBuilder.valueOf("");
                            }
                            int thumbInsertIndex = 0;
                            if (!useForceThreeLines && !SharedConfig.useThreeLinesLayout || currentDialogFolderId != 0 && stringBuilder.length() > 0) {
                                try {
                                    stringBuilder.setSpan(new ForegroundColorSpanThemable(Theme.key_chats_nameMessage, resourcesProvider), 0, thumbInsertIndex = messageNameString.length() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                                    offsetName = thumbInsertIndex;
                                } catch (Exception e) {
                                    FileLog.e(e);
                                }
                            }
                            messageString = Emoji.replaceEmoji(stringBuilder, Theme.dialogs_messagePaint[paintIndex].getFontMetricsInt(), AndroidUtilities.dp(20), false);
                            if (message.hasHighlightedWords()) {
                                CharSequence messageH = AndroidUtilities.highlightText(messageString, message.highlightedWords, resourcesProvider);
                                if (messageH != null) {
                                    messageString = messageH;
                                }
                            }
                            if (hasMessageThumb) {
                                if (!(messageString instanceof SpannableStringBuilder)) {
                                    messageString = new SpannableStringBuilder(messageString);
                                }
                                checkMessage = false;
                                SpannableStringBuilder builder = (SpannableStringBuilder) messageString;
                                builder.insert(thumbInsertIndex, " ");
                                builder.setSpan(new FixedWidthSpan(AndroidUtilities.dp(thumbSize + 6)), thumbInsertIndex, thumbInsertIndex + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                            }
                        } else {
                            if (!TextUtils.isEmpty(restrictionReason)) {
                                messageString = restrictionReason;
                            } else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && message.messageOwner.media.photo instanceof TLRPC.TL_photoEmpty && message.messageOwner.media.ttl_seconds != 0) {
                                messageString = LocaleController.getString("AttachPhotoExpired", R.string.AttachPhotoExpired);
                            } else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaDocument && message.messageOwner.media.document instanceof TLRPC.TL_documentEmpty && message.messageOwner.media.ttl_seconds != 0) {
                                messageString = LocaleController.getString("AttachVideoExpired", R.string.AttachVideoExpired);
                            } else if (message.caption != null) {
                                String emoji;
                                if (!needEmoji) {
                                    emoji = "";
                                } else if (message.isVideo()) {
                                    emoji = "\uD83D\uDCF9 ";
                                } else if (message.isVoice()) {
                                    emoji = "\uD83C\uDFA4 ";
                                } else if (message.isMusic()) {
                                    emoji = "\uD83C\uDFA7 ";
                                } else if (message.isPhoto()) {
                                    emoji = "\uD83D\uDDBC ";
                                } else {
                                    emoji = "\uD83D\uDCCE ";
                                }
                                if (message.hasHighlightedWords() && !TextUtils.isEmpty(message.messageOwner.message)) {
                                    String str = message.messageTrimmedToHighlight;
                                    if (message.messageTrimmedToHighlight != null) {
                                        str = message.messageTrimmedToHighlight;
                                    }
                                    int w = getMeasuredWidth() - AndroidUtilities.dp(72 + 23 + 24);
                                    if (hasNameInMessage) {
                                        if (!TextUtils.isEmpty(messageNameString)) {
                                            w -= currentMessagePaint.measureText(messageNameString.toString());
                                        }
                                        w -= currentMessagePaint.measureText(": ");
                                    }
                                    if (w > 0) {
                                        str = AndroidUtilities.ellipsizeCenterEnd(str, message.highlightedWords.get(0), w, currentMessagePaint, 130).toString();
                                    }
                                    messageString = emoji + str;
                                } else {
                                    SpannableStringBuilder msgBuilder = new SpannableStringBuilder(message.caption);
                                    MediaDataController.addTextStyleRuns(message.messageOwner.entities, message.caption, msgBuilder, TextStyleSpan.FLAG_STYLE_SPOILER);
                                    messageString = new SpannableStringBuilder(emoji).append(msgBuilder);
                                }
                            } else {
                                if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPoll) {
                                    TLRPC.TL_messageMediaPoll mediaPoll = (TLRPC.TL_messageMediaPoll) message.messageOwner.media;
                                    messageString = "\uD83D\uDCCA " + mediaPoll.poll.question;
                                } else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
                                    messageString = "\uD83C\uDFAE " + message.messageOwner.media.game.title;
                                } else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) {
                                    messageString = message.messageOwner.media.title;
                                } else if (message.type == 14) {
                                    messageString = String.format("\uD83C\uDFA7 %s - %s", message.getMusicAuthor(), message.getMusicTitle());
                                } else {
                                    if (message.hasHighlightedWords() && !TextUtils.isEmpty(message.messageOwner.message)) {
                                        messageString = message.messageTrimmedToHighlight;
                                        if (message.messageTrimmedToHighlight != null) {
                                            messageString = message.messageTrimmedToHighlight;
                                        }
                                        int w = getMeasuredWidth() - AndroidUtilities.dp(72 + 23);
                                        messageString = AndroidUtilities.ellipsizeCenterEnd(messageString, message.highlightedWords.get(0), w, currentMessagePaint, 130).toString();
                                    } else {
                                        SpannableStringBuilder stringBuilder = new SpannableStringBuilder(msgText);
                                        MediaDataController.addTextStyleRuns(message, stringBuilder, TextStyleSpan.FLAG_STYLE_SPOILER);
                                        messageString = stringBuilder;
                                    }
                                    AndroidUtilities.highlightText(messageString, message.highlightedWords, resourcesProvider);
                                }
                                if (message.messageOwner.media != null && !message.isMediaEmpty()) {
                                    currentMessagePaint = Theme.dialogs_messagePrintingPaint[paintIndex];
                                }
                            }
                            if (hasMessageThumb) {
                                if (message.hasHighlightedWords() && !TextUtils.isEmpty(message.messageOwner.message)) {
                                    messageString = message.messageTrimmedToHighlight;
                                    if (message.messageTrimmedToHighlight != null) {
                                        messageString = message.messageTrimmedToHighlight;
                                    }
                                    int w = getMeasuredWidth() - AndroidUtilities.dp(72 + 23 + thumbSize + 6);
                                    messageString = AndroidUtilities.ellipsizeCenterEnd(messageString, message.highlightedWords.get(0), w, currentMessagePaint, 130).toString();
                                } else {
                                    if (messageString.length() > 150) {
                                        messageString = messageString.subSequence(0, 150);
                                    }
                                    messageString = AndroidUtilities.replaceNewLines(messageString);
                                }
                                if (!(messageString instanceof SpannableStringBuilder)) {
                                    messageString = new SpannableStringBuilder(messageString);
                                }
                                checkMessage = false;
                                SpannableStringBuilder builder = (SpannableStringBuilder) messageString;
                                builder.insert(0, " ");
                                builder.setSpan(new FixedWidthSpan(AndroidUtilities.dp(thumbSize + 6)), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                                Emoji.replaceEmoji(builder, Theme.dialogs_messagePaint[paintIndex].getFontMetricsInt(), AndroidUtilities.dp(17), false);
                                if (message.hasHighlightedWords()) {
                                    CharSequence s = AndroidUtilities.highlightText(builder, message.highlightedWords, resourcesProvider);
                                    if (s != null) {
                                        messageString = s;
                                    }
                                }
                            }
                        }
                    }
                    if (currentDialogFolderId != 0) {
                        messageNameString = formatArchivedDialogNames();
                    }
                }
            }
        }
        if (draftMessage != null) {
            timeString = LocaleController.stringForMessageListDate(draftMessage.date);
        } else if (lastMessageDate != 0) {
            timeString = LocaleController.stringForMessageListDate(lastMessageDate);
        } else if (message != null) {
            timeString = LocaleController.stringForMessageListDate(message.messageOwner.date);
        }
        if (message == null) {
            drawCheck1 = false;
            drawCheck2 = false;
            drawClock = false;
            drawCount = false;
            drawMention = false;
            drawReactionMention = false;
            drawError = false;
        } else {
            if (currentDialogFolderId != 0) {
                if (unreadCount + mentionCount > 0) {
                    if (unreadCount > mentionCount) {
                        drawCount = true;
                        drawMention = false;
                        countString = String.format("%d", unreadCount + mentionCount);
                    } else {
                        drawCount = false;
                        drawMention = true;
                        mentionString = String.format("%d", unreadCount + mentionCount);
                    }
                } else {
                    drawCount = false;
                    drawMention = false;
                }
                drawReactionMention = false;
            } else {
                if (clearingDialog) {
                    drawCount = false;
                    showChecks = false;
                } else if (unreadCount != 0 && (unreadCount != 1 || unreadCount != mentionCount || message == null || !message.messageOwner.mentioned)) {
                    drawCount = true;
                    countString = String.format("%d", unreadCount);
                } else if (markUnread) {
                    drawCount = true;
                    countString = "";
                } else {
                    drawCount = false;
                }
                if (mentionCount != 0) {
                    drawMention = true;
                    mentionString = "@";
                } else {
                    drawMention = false;
                }
                if (reactionMentionCount != 0) {
                    drawReactionMention = true;
                } else {
                    drawReactionMention = false;
                }
            }
            if (message.isOut() && draftMessage == null && showChecks && !(message.messageOwner.action instanceof TLRPC.TL_messageActionHistoryClear)) {
                if (message.isSending()) {
                    drawCheck1 = false;
                    drawCheck2 = false;
                    drawClock = true;
                    drawError = false;
                } else if (message.isSendError()) {
                    drawCheck1 = false;
                    drawCheck2 = false;
                    drawClock = false;
                    drawError = true;
                    drawCount = false;
                    drawMention = false;
                } else if (message.isSent()) {
                    drawCheck1 = !message.isUnread() || ChatObject.isChannel(chat) && !chat.megagroup;
                    drawCheck2 = true;
                    drawClock = false;
                    drawError = false;
                }
            } else {
                drawCheck1 = false;
                drawCheck2 = false;
                drawClock = false;
                drawError = false;
            }
        }
        promoDialog = false;
        MessagesController messagesController = MessagesController.getInstance(currentAccount);
        if (dialogsType == 0 && messagesController.isPromoDialog(currentDialogId, true)) {
            drawPinBackground = true;
            promoDialog = true;
            if (messagesController.promoDialogType == MessagesController.PROMO_TYPE_PROXY) {
                timeString = LocaleController.getString("UseProxySponsor", R.string.UseProxySponsor);
            } else if (messagesController.promoDialogType == MessagesController.PROMO_TYPE_PSA) {
                timeString = LocaleController.getString("PsaType_" + messagesController.promoPsaType);
                if (TextUtils.isEmpty(timeString)) {
                    timeString = LocaleController.getString("PsaTypeDefault", R.string.PsaTypeDefault);
                }
                if (!TextUtils.isEmpty(messagesController.promoPsaMessage)) {
                    messageString = messagesController.promoPsaMessage;
                    hasMessageThumb = false;
                }
            }
        }
        if (currentDialogFolderId != 0) {
            nameString = LocaleController.getString("ArchivedChats", R.string.ArchivedChats);
        } else {
            if (chat != null) {
                nameString = chat.title;
            } else if (user != null) {
                if (UserObject.isReplyUser(user)) {
                    nameString = LocaleController.getString("RepliesTitle", R.string.RepliesTitle);
                } else if (UserObject.isUserSelf(user)) {
                    if (useMeForMyMessages) {
                        nameString = LocaleController.getString("FromYou", R.string.FromYou);
                    } else {
                        if (dialogsType == 3) {
                            drawPinBackground = true;
                        }
                        nameString = LocaleController.getString("SavedMessages", R.string.SavedMessages);
                    }
                } else {
                    nameString = UserObject.getUserName(user);
                }
            }
            if (nameString.length() == 0) {
                nameString = LocaleController.getString("HiddenName", R.string.HiddenName);
            }
        }
    }
    int timeWidth;
    if (drawTime) {
        timeWidth = (int) Math.ceil(Theme.dialogs_timePaint.measureText(timeString));
        timeLayout = new StaticLayout(timeString, Theme.dialogs_timePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        if (!LocaleController.isRTL) {
            timeLeft = getMeasuredWidth() - AndroidUtilities.dp(15) - timeWidth;
        } else {
            timeLeft = AndroidUtilities.dp(15);
        }
    } else {
        timeWidth = 0;
        timeLayout = null;
        timeLeft = 0;
    }
    int nameWidth;
    if (!LocaleController.isRTL) {
        nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(14) - timeWidth;
    } else {
        nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(77) - timeWidth;
        nameLeft += timeWidth;
    }
    if (drawNameLock) {
        nameWidth -= AndroidUtilities.dp(4) + Theme.dialogs_lockDrawable.getIntrinsicWidth();
    } else if (drawNameGroup) {
        nameWidth -= AndroidUtilities.dp(4) + Theme.dialogs_groupDrawable.getIntrinsicWidth();
    } else if (drawNameBroadcast) {
        nameWidth -= AndroidUtilities.dp(4) + Theme.dialogs_broadcastDrawable.getIntrinsicWidth();
    } else if (drawNameBot) {
        nameWidth -= AndroidUtilities.dp(4) + Theme.dialogs_botDrawable.getIntrinsicWidth();
    }
    if (drawClock) {
        int w = Theme.dialogs_clockDrawable.getIntrinsicWidth() + AndroidUtilities.dp(5);
        nameWidth -= w;
        if (!LocaleController.isRTL) {
            clockDrawLeft = timeLeft - w;
        } else {
            clockDrawLeft = timeLeft + timeWidth + AndroidUtilities.dp(5);
            nameLeft += w;
        }
    } else if (drawCheck2) {
        int w = Theme.dialogs_checkDrawable.getIntrinsicWidth() + AndroidUtilities.dp(5);
        nameWidth -= w;
        if (drawCheck1) {
            nameWidth -= Theme.dialogs_halfCheckDrawable.getIntrinsicWidth() - AndroidUtilities.dp(8);
            if (!LocaleController.isRTL) {
                halfCheckDrawLeft = timeLeft - w;
                checkDrawLeft = halfCheckDrawLeft - AndroidUtilities.dp(5.5f);
            } else {
                checkDrawLeft = timeLeft + timeWidth + AndroidUtilities.dp(5);
                halfCheckDrawLeft = checkDrawLeft + AndroidUtilities.dp(5.5f);
                nameLeft += w + Theme.dialogs_halfCheckDrawable.getIntrinsicWidth() - AndroidUtilities.dp(8);
            }
        } else {
            if (!LocaleController.isRTL) {
                checkDrawLeft1 = timeLeft - w;
            } else {
                checkDrawLeft1 = timeLeft + timeWidth + AndroidUtilities.dp(5);
                nameLeft += w;
            }
        }
    }
    if (dialogMuted && !drawVerified && drawScam == 0) {
        int w = AndroidUtilities.dp(6) + Theme.dialogs_muteDrawable.getIntrinsicWidth();
        nameWidth -= w;
        if (LocaleController.isRTL) {
            nameLeft += w;
        }
    } else if (drawVerified) {
        int w = AndroidUtilities.dp(6) + Theme.dialogs_verifiedDrawable.getIntrinsicWidth();
        nameWidth -= w;
        if (LocaleController.isRTL) {
            nameLeft += w;
        }
    } else if (drawScam != 0) {
        int w = AndroidUtilities.dp(6) + (drawScam == 1 ? Theme.dialogs_scamDrawable : Theme.dialogs_fakeDrawable).getIntrinsicWidth();
        nameWidth -= w;
        if (LocaleController.isRTL) {
            nameLeft += w;
        }
    }
    nameWidth = Math.max(AndroidUtilities.dp(12), nameWidth);
    try {
        CharSequence nameStringFinal = TextUtils.ellipsize(nameString.replace('\n', ' '), Theme.dialogs_namePaint[paintIndex], nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END);
        if (message != null && message.hasHighlightedWords()) {
            CharSequence s = AndroidUtilities.highlightText(nameStringFinal, message.highlightedWords, resourcesProvider);
            if (s != null) {
                nameStringFinal = s;
            }
        }
        nameLayout = new StaticLayout(nameStringFinal, Theme.dialogs_namePaint[paintIndex], nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    } catch (Exception e) {
        FileLog.e(e);
    }
    int messageWidth;
    int avatarLeft;
    int avatarTop;
    int thumbLeft;
    if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
        avatarTop = AndroidUtilities.dp(11);
        messageNameTop = AndroidUtilities.dp(32);
        timeTop = AndroidUtilities.dp(13);
        errorTop = AndroidUtilities.dp(43);
        pinTop = AndroidUtilities.dp(43);
        countTop = AndroidUtilities.dp(43);
        checkDrawTop = AndroidUtilities.dp(13);
        messageWidth = getMeasuredWidth() - AndroidUtilities.dp(72 + 21);
        if (LocaleController.isRTL) {
            messageLeft = messageNameLeft = AndroidUtilities.dp(16);
            avatarLeft = getMeasuredWidth() - AndroidUtilities.dp(66);
            thumbLeft = avatarLeft - AndroidUtilities.dp(13 + 18);
        } else {
            messageLeft = messageNameLeft = AndroidUtilities.dp(72 + 6);
            avatarLeft = AndroidUtilities.dp(10);
            thumbLeft = avatarLeft + AndroidUtilities.dp(56 + 13);
        }
        avatarImage.setImageCoords(avatarLeft, avatarTop, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
        thumbImage.setImageCoords(thumbLeft, avatarTop + AndroidUtilities.dp(31), AndroidUtilities.dp(18), AndroidUtilities.dp(18));
    } else {
        avatarTop = AndroidUtilities.dp(9);
        messageNameTop = AndroidUtilities.dp(31);
        timeTop = AndroidUtilities.dp(16);
        errorTop = AndroidUtilities.dp(39);
        pinTop = AndroidUtilities.dp(39);
        countTop = AndroidUtilities.dp(39);
        checkDrawTop = AndroidUtilities.dp(17);
        messageWidth = getMeasuredWidth() - AndroidUtilities.dp(72 + 23);
        if (LocaleController.isRTL) {
            messageLeft = messageNameLeft = AndroidUtilities.dp(22);
            avatarLeft = getMeasuredWidth() - AndroidUtilities.dp(64);
            thumbLeft = avatarLeft - AndroidUtilities.dp(11 + thumbSize);
        } else {
            messageLeft = messageNameLeft = AndroidUtilities.dp(72 + 4);
            avatarLeft = AndroidUtilities.dp(10);
            thumbLeft = avatarLeft + AndroidUtilities.dp(56 + 11);
        }
        avatarImage.setImageCoords(avatarLeft, avatarTop, AndroidUtilities.dp(54), AndroidUtilities.dp(54));
        thumbImage.setImageCoords(thumbLeft, avatarTop + AndroidUtilities.dp(30), AndroidUtilities.dp(thumbSize), AndroidUtilities.dp(thumbSize));
    }
    if (drawPin) {
        if (!LocaleController.isRTL) {
            pinLeft = getMeasuredWidth() - Theme.dialogs_pinnedDrawable.getIntrinsicWidth() - AndroidUtilities.dp(14);
        } else {
            pinLeft = AndroidUtilities.dp(14);
        }
    }
    if (drawError) {
        int w = AndroidUtilities.dp(23 + 8);
        messageWidth -= w;
        if (!LocaleController.isRTL) {
            errorLeft = getMeasuredWidth() - AndroidUtilities.dp(23 + 11);
        } else {
            errorLeft = AndroidUtilities.dp(11);
            messageLeft += w;
            messageNameLeft += w;
        }
    } else if (countString != null || mentionString != null || drawReactionMention) {
        if (countString != null) {
            countWidth = Math.max(AndroidUtilities.dp(12), (int) Math.ceil(Theme.dialogs_countTextPaint.measureText(countString)));
            countLayout = new StaticLayout(countString, Theme.dialogs_countTextPaint, countWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
            int w = countWidth + AndroidUtilities.dp(18);
            messageWidth -= w;
            if (!LocaleController.isRTL) {
                countLeft = getMeasuredWidth() - countWidth - AndroidUtilities.dp(20);
            } else {
                countLeft = AndroidUtilities.dp(20);
                messageLeft += w;
                messageNameLeft += w;
            }
            drawCount = true;
        } else {
            countWidth = 0;
        }
        if (mentionString != null) {
            if (currentDialogFolderId != 0) {
                mentionWidth = Math.max(AndroidUtilities.dp(12), (int) Math.ceil(Theme.dialogs_countTextPaint.measureText(mentionString)));
                mentionLayout = new StaticLayout(mentionString, Theme.dialogs_countTextPaint, mentionWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
            } else {
                mentionWidth = AndroidUtilities.dp(12);
            }
            int w = mentionWidth + AndroidUtilities.dp(18);
            messageWidth -= w;
            if (!LocaleController.isRTL) {
                mentionLeft = getMeasuredWidth() - mentionWidth - AndroidUtilities.dp(20) - (countWidth != 0 ? countWidth + AndroidUtilities.dp(18) : 0);
            } else {
                mentionLeft = AndroidUtilities.dp(20) + (countWidth != 0 ? countWidth + AndroidUtilities.dp(18) : 0);
                messageLeft += w;
                messageNameLeft += w;
            }
            drawMention = true;
        }
        if (drawReactionMention) {
            int w = AndroidUtilities.dp(24);
            messageWidth -= w;
            if (!LocaleController.isRTL) {
                reactionMentionLeft = getMeasuredWidth() - AndroidUtilities.dp(32) - (mentionWidth != 0 ? (mentionWidth + AndroidUtilities.dp(18)) : 0) - (countWidth != 0 ? countWidth + AndroidUtilities.dp(18) : 0);
            } else {
                reactionMentionLeft = AndroidUtilities.dp(20) + (countWidth != 0 ? countWidth + AndroidUtilities.dp(18) : 0);
                messageLeft += w;
                messageNameLeft += w;
            }
        }
    } else {
        if (drawPin) {
            int w = Theme.dialogs_pinnedDrawable.getIntrinsicWidth() + AndroidUtilities.dp(8);
            messageWidth -= w;
            if (LocaleController.isRTL) {
                messageLeft += w;
                messageNameLeft += w;
            }
        }
        drawCount = false;
        drawMention = false;
    }
    if (checkMessage) {
        if (messageString == null) {
            messageString = "";
        }
        CharSequence mess = messageString;
        if (mess.length() > 150) {
            mess = mess.subSequence(0, 150);
        }
        if (!useForceThreeLines && !SharedConfig.useThreeLinesLayout || messageNameString != null) {
            mess = AndroidUtilities.replaceNewLines(mess);
        } else {
            mess = AndroidUtilities.replaceTwoNewLinesToOne(mess);
        }
        messageString = Emoji.replaceEmoji(mess, Theme.dialogs_messagePaint[paintIndex].getFontMetricsInt(), AndroidUtilities.dp(17), false);
        if (message != null) {
            CharSequence s = AndroidUtilities.highlightText(messageString, message.highlightedWords, resourcesProvider);
            if (s != null) {
                messageString = s;
            }
        }
    }
    messageWidth = Math.max(AndroidUtilities.dp(12), messageWidth);
    if ((useForceThreeLines || SharedConfig.useThreeLinesLayout) && messageNameString != null && (currentDialogFolderId == 0 || currentDialogFolderDialogsCount == 1)) {
        try {
            if (message != null && message.hasHighlightedWords()) {
                CharSequence s = AndroidUtilities.highlightText(messageNameString, message.highlightedWords, resourcesProvider);
                if (s != null) {
                    messageNameString = s;
                }
            }
            messageNameLayout = StaticLayoutEx.createStaticLayout(messageNameString, Theme.dialogs_messageNamePaint, messageWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0, false, TextUtils.TruncateAt.END, messageWidth, 1);
        } catch (Exception e) {
            FileLog.e(e);
        }
        messageTop = AndroidUtilities.dp(32 + 19);
        thumbImage.setImageY(avatarTop + AndroidUtilities.dp(40));
    } else {
        messageNameLayout = null;
        if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
            messageTop = AndroidUtilities.dp(32);
            thumbImage.setImageY(avatarTop + AndroidUtilities.dp(21));
        } else {
            messageTop = AndroidUtilities.dp(39);
        }
    }
    try {
        CharSequence messageStringFinal;
        if ((useForceThreeLines || SharedConfig.useThreeLinesLayout) && currentDialogFolderId != 0 && currentDialogFolderDialogsCount > 1) {
            messageStringFinal = messageNameString;
            messageNameString = null;
            currentMessagePaint = Theme.dialogs_messagePaint[paintIndex];
        } else if (!useForceThreeLines && !SharedConfig.useThreeLinesLayout || messageNameString != null) {
            messageStringFinal = TextUtils.ellipsize(messageString, currentMessagePaint, messageWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END);
        } else {
            messageStringFinal = messageString;
        }
        // Removing links and bold spans to get rid of underlining and boldness
        if (messageStringFinal instanceof Spannable) {
            Spannable messageStringSpannable = (Spannable) messageStringFinal;
            for (CharacterStyle span : messageStringSpannable.getSpans(0, messageStringSpannable.length(), CharacterStyle.class)) {
                if (span instanceof ClickableSpan || (span instanceof StyleSpan && ((StyleSpan) span).getStyle() == android.graphics.Typeface.BOLD)) {
                    messageStringSpannable.removeSpan(span);
                }
            }
        }
        if (useForceThreeLines || SharedConfig.useThreeLinesLayout) {
            if (hasMessageThumb && messageNameString != null) {
                messageWidth += AndroidUtilities.dp(6);
            }
            messageLayout = StaticLayoutEx.createStaticLayout(messageStringFinal, currentMessagePaint, messageWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false, TextUtils.TruncateAt.END, messageWidth, messageNameString != null ? 1 : 2);
        } else {
            if (hasMessageThumb) {
                messageWidth += thumbSize + AndroidUtilities.dp(6);
                if (LocaleController.isRTL) {
                    messageLeft -= thumbSize + AndroidUtilities.dp(6);
                }
            }
            messageLayout = new StaticLayout(messageStringFinal, currentMessagePaint, messageWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        }
        spoilersPool.addAll(spoilers);
        spoilers.clear();
        SpoilerEffect.addSpoilers(this, messageLayout, spoilersPool, spoilers);
    } catch (Exception e) {
        messageLayout = null;
        FileLog.e(e);
    }
    double widthpx;
    float left;
    if (LocaleController.isRTL) {
        if (nameLayout != null && nameLayout.getLineCount() > 0) {
            left = nameLayout.getLineLeft(0);
            widthpx = Math.ceil(nameLayout.getLineWidth(0));
            if (dialogMuted && !drawVerified && drawScam == 0) {
                nameMuteLeft = (int) (nameLeft + (nameWidth - widthpx) - AndroidUtilities.dp(6) - Theme.dialogs_muteDrawable.getIntrinsicWidth());
            } else if (drawVerified) {
                nameMuteLeft = (int) (nameLeft + (nameWidth - widthpx) - AndroidUtilities.dp(6) - Theme.dialogs_verifiedDrawable.getIntrinsicWidth());
            } else if (drawScam != 0) {
                nameMuteLeft = (int) (nameLeft + (nameWidth - widthpx) - AndroidUtilities.dp(6) - (drawScam == 1 ? Theme.dialogs_scamDrawable : Theme.dialogs_fakeDrawable).getIntrinsicWidth());
            }
            if (left == 0) {
                if (widthpx < nameWidth) {
                    nameLeft += (nameWidth - widthpx);
                }
            }
        }
        if (messageLayout != null) {
            int lineCount = messageLayout.getLineCount();
            if (lineCount > 0) {
                int w = Integer.MAX_VALUE;
                for (int a = 0; a < lineCount; a++) {
                    left = messageLayout.getLineLeft(a);
                    if (left == 0) {
                        widthpx = Math.ceil(messageLayout.getLineWidth(a));
                        w = Math.min(w, (int) (messageWidth - widthpx));
                    } else {
                        w = 0;
                        break;
                    }
                }
                if (w != Integer.MAX_VALUE) {
                    messageLeft += w;
                }
            }
        }
        if (messageNameLayout != null && messageNameLayout.getLineCount() > 0) {
            left = messageNameLayout.getLineLeft(0);
            if (left == 0) {
                widthpx = Math.ceil(messageNameLayout.getLineWidth(0));
                if (widthpx < messageWidth) {
                    messageNameLeft += (messageWidth - widthpx);
                }
            }
        }
    } else {
        if (nameLayout != null && nameLayout.getLineCount() > 0) {
            left = nameLayout.getLineRight(0);
            if (left == nameWidth) {
                widthpx = Math.ceil(nameLayout.getLineWidth(0));
                if (widthpx < nameWidth) {
                    nameLeft -= (nameWidth - widthpx);
                }
            }
            if (dialogMuted || drawVerified || drawScam != 0) {
                nameMuteLeft = (int) (nameLeft + left + AndroidUtilities.dp(6));
            }
        }
        if (messageLayout != null) {
            int lineCount = messageLayout.getLineCount();
            if (lineCount > 0) {
                left = Integer.MAX_VALUE;
                for (int a = 0; a < lineCount; a++) {
                    left = Math.min(left, messageLayout.getLineLeft(a));
                }
                messageLeft -= left;
            }
        }
        if (messageNameLayout != null && messageNameLayout.getLineCount() > 0) {
            messageNameLeft -= messageNameLayout.getLineLeft(0);
        }
    }
    if (messageLayout != null && hasMessageThumb) {
        try {
            int textLen = messageLayout.getText().length();
            if (offsetName >= textLen) {
                offsetName = textLen - 1;
            }
            float x1 = messageLayout.getPrimaryHorizontal(offsetName);
            float x2 = messageLayout.getPrimaryHorizontal(offsetName + 1);
            int offset = (int) Math.ceil(Math.min(x1, x2));
            if (offset != 0) {
                offset += AndroidUtilities.dp(3);
            }
            thumbImage.setImageX(messageLeft + offset);
        } catch (Exception e) {
            FileLog.e(e);
        }
    }
    if (messageLayout != null && printingStringType >= 0) {
        float x1, x2;
        if (printigStingReplaceIndex >= 0 && printigStingReplaceIndex + 1 < messageLayout.getText().length()) {
            x1 = messageLayout.getPrimaryHorizontal(printigStingReplaceIndex);
            x2 = messageLayout.getPrimaryHorizontal(printigStingReplaceIndex + 1);
        } else {
            x1 = messageLayout.getPrimaryHorizontal(0);
            x2 = messageLayout.getPrimaryHorizontal(1);
        }
        if (x1 < x2) {
            statusDrawableLeft = (int) (messageLeft + x1);
        } else {
            statusDrawableLeft = (int) (messageLeft + x2 + AndroidUtilities.dp(3));
        }
    }
}
Also used : MessagesController(org.telegram.messenger.MessagesController) StatusDrawable(org.telegram.ui.Components.StatusDrawable) TLRPC(org.telegram.tgnet.TLRPC) CharacterStyle(android.text.style.CharacterStyle) ForegroundColorSpanThemable(org.telegram.ui.Components.ForegroundColorSpanThemable) Drawable(android.graphics.drawable.Drawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) PullForegroundDrawable(org.telegram.ui.Components.PullForegroundDrawable) StatusDrawable(org.telegram.ui.Components.StatusDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) StaticLayout(android.text.StaticLayout) ClickableSpan(android.text.style.ClickableSpan) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) TextPaint(android.text.TextPaint) TextStyleSpan(org.telegram.ui.Components.TextStyleSpan) StyleSpan(android.text.style.StyleSpan) MessageObject(org.telegram.messenger.MessageObject) DialogObject(org.telegram.messenger.DialogObject) UserObject(org.telegram.messenger.UserObject) ChatObject(org.telegram.messenger.ChatObject) Spannable(android.text.Spannable) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

SpannableStringBuilder (android.text.SpannableStringBuilder)6 ForegroundColorSpanThemable (org.telegram.ui.Components.ForegroundColorSpanThemable)6 Paint (android.graphics.Paint)4 TLRPC (org.telegram.tgnet.TLRPC)4 SuppressLint (android.annotation.SuppressLint)3 TextPaint (android.text.TextPaint)3 Point (android.graphics.Point)2 SpannedString (android.text.SpannedString)2 ChatObject (org.telegram.messenger.ChatObject)2 DialogObject (org.telegram.messenger.DialogObject)2 MessageObject (org.telegram.messenger.MessageObject)2 MessagesController (org.telegram.messenger.MessagesController)2 UserObject (org.telegram.messenger.UserObject)2 AvatarDrawable (org.telegram.ui.Components.AvatarDrawable)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 BitmapShader (android.graphics.BitmapShader)1 Canvas (android.graphics.Canvas)1 RectF (android.graphics.RectF)1