Search in sources :

Example 1 with URLSpanNoUnderlineBold

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

the class MessageObject method replaceWithLink.

public static CharSequence replaceWithLink(CharSequence source, String param, TLObject object) {
    int start = TextUtils.indexOf(source, param);
    if (start >= 0) {
        String name;
        String id;
        TLObject spanObject = null;
        if (object instanceof TLRPC.User) {
            name = UserObject.getUserName((TLRPC.User) object);
            id = "" + ((TLRPC.User) object).id;
        } else if (object instanceof TLRPC.Chat) {
            name = ((TLRPC.Chat) object).title;
            id = "" + -((TLRPC.Chat) object).id;
        } else if (object instanceof TLRPC.TL_game) {
            TLRPC.TL_game game = (TLRPC.TL_game) object;
            name = game.title;
            id = "game";
        } else if (object instanceof TLRPC.TL_chatInviteExported) {
            TLRPC.TL_chatInviteExported invite = (TLRPC.TL_chatInviteExported) object;
            name = invite.link;
            id = "invite";
            spanObject = invite;
        } else {
            name = "";
            id = "0";
        }
        name = name.replace('\n', ' ');
        SpannableStringBuilder builder = new SpannableStringBuilder(TextUtils.replace(source, new String[] { param }, new String[] { name }));
        URLSpanNoUnderlineBold span = new URLSpanNoUnderlineBold("" + id);
        span.setObject(spanObject);
        builder.setSpan(span, start, start + name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return builder;
    }
    return source;
}
Also used : SpannableString(android.text.SpannableString) TextPaint(android.text.TextPaint) TLRPC(org.telegram.tgnet.TLRPC) TLObject(org.telegram.tgnet.TLObject) URLSpanNoUnderlineBold(org.telegram.ui.Components.URLSpanNoUnderlineBold) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 2 with URLSpanNoUnderlineBold

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

the class MessageObject method updateMessageText.

private void updateMessageText(AbstractMap<Long, TLRPC.User> users, AbstractMap<Long, TLRPC.Chat> chats, LongSparseArray<TLRPC.User> sUsers, LongSparseArray<TLRPC.Chat> sChats) {
    TLRPC.User fromUser = null;
    TLRPC.Chat fromChat = null;
    if (messageOwner.from_id instanceof TLRPC.TL_peerUser) {
        fromUser = getUser(users, sUsers, messageOwner.from_id.user_id);
    } else if (messageOwner.from_id instanceof TLRPC.TL_peerChannel) {
        fromChat = getChat(chats, sChats, messageOwner.from_id.channel_id);
    }
    TLObject fromObject = fromUser != null ? fromUser : fromChat;
    if (messageOwner instanceof TLRPC.TL_messageService) {
        if (messageOwner.action != null) {
            if (messageOwner.action instanceof TLRPC.TL_messageActionGroupCallScheduled) {
                TLRPC.TL_messageActionGroupCallScheduled action = (TLRPC.TL_messageActionGroupCallScheduled) messageOwner.action;
                if (messageOwner.peer_id instanceof TLRPC.TL_peerChat || isSupergroup()) {
                    messageText = LocaleController.formatString("ActionGroupCallScheduled", R.string.ActionGroupCallScheduled, LocaleController.formatStartsTime(action.schedule_date, 3, false));
                } else {
                    messageText = LocaleController.formatString("ActionChannelCallScheduled", R.string.ActionChannelCallScheduled, LocaleController.formatStartsTime(action.schedule_date, 3, false));
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionGroupCall) {
                if (messageOwner.action.duration != 0) {
                    String time;
                    int days = messageOwner.action.duration / (3600 * 24);
                    if (days > 0) {
                        time = LocaleController.formatPluralString("Days", days);
                    } else {
                        int hours = messageOwner.action.duration / 3600;
                        if (hours > 0) {
                            time = LocaleController.formatPluralString("Hours", hours);
                        } else {
                            int minutes = messageOwner.action.duration / 60;
                            if (minutes > 0) {
                                time = LocaleController.formatPluralString("Minutes", minutes);
                            } else {
                                time = LocaleController.formatPluralString("Seconds", messageOwner.action.duration);
                            }
                        }
                    }
                    if (messageOwner.peer_id instanceof TLRPC.TL_peerChat || isSupergroup()) {
                        if (isOut()) {
                            messageText = LocaleController.formatString("ActionGroupCallEndedByYou", R.string.ActionGroupCallEndedByYou, time);
                        } else {
                            messageText = replaceWithLink(LocaleController.formatString("ActionGroupCallEndedBy", R.string.ActionGroupCallEndedBy, time), "un1", fromObject);
                        }
                    } else {
                        messageText = LocaleController.formatString("ActionChannelCallEnded", R.string.ActionChannelCallEnded, time);
                    }
                } else {
                    if (messageOwner.peer_id instanceof TLRPC.TL_peerChat || isSupergroup()) {
                        if (isOut()) {
                            messageText = LocaleController.getString("ActionGroupCallStartedByYou", R.string.ActionGroupCallStartedByYou);
                        } else {
                            messageText = replaceWithLink(LocaleController.getString("ActionGroupCallStarted", R.string.ActionGroupCallStarted), "un1", fromObject);
                        }
                    } else {
                        messageText = LocaleController.getString("ActionChannelCallJustStarted", R.string.ActionChannelCallJustStarted);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionInviteToGroupCall) {
                long singleUserId = messageOwner.action.user_id;
                if (singleUserId == 0 && messageOwner.action.users.size() == 1) {
                    singleUserId = messageOwner.action.users.get(0);
                }
                if (singleUserId != 0) {
                    TLRPC.User whoUser = getUser(users, sUsers, singleUserId);
                    if (isOut()) {
                        messageText = replaceWithLink(LocaleController.getString("ActionGroupCallYouInvited", R.string.ActionGroupCallYouInvited), "un2", whoUser);
                    } else if (singleUserId == UserConfig.getInstance(currentAccount).getClientUserId()) {
                        messageText = replaceWithLink(LocaleController.getString("ActionGroupCallInvitedYou", R.string.ActionGroupCallInvitedYou), "un1", fromObject);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionGroupCallInvited", R.string.ActionGroupCallInvited), "un2", whoUser);
                        messageText = replaceWithLink(messageText, "un1", fromObject);
                    }
                } else {
                    if (isOut()) {
                        messageText = replaceWithLink(LocaleController.getString("ActionGroupCallYouInvited", R.string.ActionGroupCallYouInvited), "un2", messageOwner.action.users, users, sUsers);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionGroupCallInvited", R.string.ActionGroupCallInvited), "un2", messageOwner.action.users, users, sUsers);
                        messageText = replaceWithLink(messageText, "un1", fromObject);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionGeoProximityReached) {
                TLRPC.TL_messageActionGeoProximityReached action = (TLRPC.TL_messageActionGeoProximityReached) messageOwner.action;
                long fromId = getPeerId(action.from_id);
                TLObject from;
                if (fromId > 0) {
                    from = getUser(users, sUsers, fromId);
                } else {
                    from = getChat(chats, sChats, -fromId);
                }
                long toId = getPeerId(action.to_id);
                long selfUserId = UserConfig.getInstance(currentAccount).getClientUserId();
                if (toId == selfUserId) {
                    messageText = replaceWithLink(LocaleController.formatString("ActionUserWithinRadius", R.string.ActionUserWithinRadius, LocaleController.formatDistance(action.distance, 2)), "un1", from);
                } else {
                    TLObject to;
                    if (toId > 0) {
                        to = getUser(users, sUsers, toId);
                    } else {
                        to = getChat(chats, sChats, -toId);
                    }
                    if (fromId == selfUserId) {
                        messageText = replaceWithLink(LocaleController.formatString("ActionUserWithinYouRadius", R.string.ActionUserWithinYouRadius, LocaleController.formatDistance(action.distance, 2)), "un1", to);
                    } else {
                        messageText = replaceWithLink(LocaleController.formatString("ActionUserWithinOtherRadius", R.string.ActionUserWithinOtherRadius, LocaleController.formatDistance(action.distance, 2)), "un2", to);
                        messageText = replaceWithLink(messageText, "un1", from);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionCustomAction) {
                messageText = messageOwner.action.message;
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatCreate) {
                if (isOut()) {
                    messageText = LocaleController.getString("ActionYouCreateGroup", R.string.ActionYouCreateGroup);
                } else {
                    messageText = replaceWithLink(LocaleController.getString("ActionCreateGroup", R.string.ActionCreateGroup), "un1", fromObject);
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
                if (isFromUser() && messageOwner.action.user_id == messageOwner.from_id.user_id) {
                    if (isOut()) {
                        messageText = LocaleController.getString("ActionYouLeftUser", R.string.ActionYouLeftUser);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionLeftUser", R.string.ActionLeftUser), "un1", fromObject);
                    }
                } else {
                    TLRPC.User whoUser = getUser(users, sUsers, messageOwner.action.user_id);
                    if (isOut()) {
                        messageText = replaceWithLink(LocaleController.getString("ActionYouKickUser", R.string.ActionYouKickUser), "un2", whoUser);
                    } else if (messageOwner.action.user_id == UserConfig.getInstance(currentAccount).getClientUserId()) {
                        messageText = replaceWithLink(LocaleController.getString("ActionKickUserYou", R.string.ActionKickUserYou), "un1", fromObject);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionKickUser", R.string.ActionKickUser), "un2", whoUser);
                        messageText = replaceWithLink(messageText, "un1", fromObject);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
                long singleUserId = messageOwner.action.user_id;
                if (singleUserId == 0 && messageOwner.action.users.size() == 1) {
                    singleUserId = messageOwner.action.users.get(0);
                }
                if (singleUserId != 0) {
                    TLRPC.User whoUser = getUser(users, sUsers, singleUserId);
                    TLRPC.Chat chat = null;
                    if (messageOwner.peer_id.channel_id != 0) {
                        chat = getChat(chats, sChats, messageOwner.peer_id.channel_id);
                    }
                    if (messageOwner.from_id != null && singleUserId == messageOwner.from_id.user_id) {
                        if (ChatObject.isChannel(chat) && !chat.megagroup) {
                            messageText = LocaleController.getString("ChannelJoined", R.string.ChannelJoined);
                        } else {
                            if (messageOwner.peer_id.channel_id != 0) {
                                if (singleUserId == UserConfig.getInstance(currentAccount).getClientUserId()) {
                                    messageText = LocaleController.getString("ChannelMegaJoined", R.string.ChannelMegaJoined);
                                } else {
                                    messageText = replaceWithLink(LocaleController.getString("ActionAddUserSelfMega", R.string.ActionAddUserSelfMega), "un1", fromObject);
                                }
                            } else if (isOut()) {
                                messageText = LocaleController.getString("ActionAddUserSelfYou", R.string.ActionAddUserSelfYou);
                            } else {
                                messageText = replaceWithLink(LocaleController.getString("ActionAddUserSelf", R.string.ActionAddUserSelf), "un1", fromObject);
                            }
                        }
                    } else {
                        if (isOut()) {
                            messageText = replaceWithLink(LocaleController.getString("ActionYouAddUser", R.string.ActionYouAddUser), "un2", whoUser);
                        } else if (singleUserId == UserConfig.getInstance(currentAccount).getClientUserId()) {
                            if (messageOwner.peer_id.channel_id != 0) {
                                if (chat != null && chat.megagroup) {
                                    messageText = replaceWithLink(LocaleController.getString("MegaAddedBy", R.string.MegaAddedBy), "un1", fromObject);
                                } else {
                                    messageText = replaceWithLink(LocaleController.getString("ChannelAddedBy", R.string.ChannelAddedBy), "un1", fromObject);
                                }
                            } else {
                                messageText = replaceWithLink(LocaleController.getString("ActionAddUserYou", R.string.ActionAddUserYou), "un1", fromObject);
                            }
                        } else {
                            messageText = replaceWithLink(LocaleController.getString("ActionAddUser", R.string.ActionAddUser), "un2", whoUser);
                            messageText = replaceWithLink(messageText, "un1", fromObject);
                        }
                    }
                } else {
                    if (isOut()) {
                        messageText = replaceWithLink(LocaleController.getString("ActionYouAddUser", R.string.ActionYouAddUser), "un2", messageOwner.action.users, users, sUsers);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionAddUser", R.string.ActionAddUser), "un2", messageOwner.action.users, users, sUsers);
                        messageText = replaceWithLink(messageText, "un1", fromObject);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByLink) {
                if (isOut()) {
                    messageText = LocaleController.getString("ActionInviteYou", R.string.ActionInviteYou);
                } else {
                    messageText = replaceWithLink(LocaleController.getString("ActionInviteUser", R.string.ActionInviteUser), "un1", fromObject);
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto) {
                TLRPC.Chat chat = messageOwner.peer_id != null && messageOwner.peer_id.channel_id != 0 ? getChat(chats, sChats, messageOwner.peer_id.channel_id) : null;
                if (ChatObject.isChannel(chat) && !chat.megagroup) {
                    if (isVideoAvatar()) {
                        messageText = LocaleController.getString("ActionChannelChangedVideo", R.string.ActionChannelChangedVideo);
                    } else {
                        messageText = LocaleController.getString("ActionChannelChangedPhoto", R.string.ActionChannelChangedPhoto);
                    }
                } else {
                    if (isOut()) {
                        if (isVideoAvatar()) {
                            messageText = LocaleController.getString("ActionYouChangedVideo", R.string.ActionYouChangedVideo);
                        } else {
                            messageText = LocaleController.getString("ActionYouChangedPhoto", R.string.ActionYouChangedPhoto);
                        }
                    } else {
                        if (isVideoAvatar()) {
                            messageText = replaceWithLink(LocaleController.getString("ActionChangedVideo", R.string.ActionChangedVideo), "un1", fromObject);
                        } else {
                            messageText = replaceWithLink(LocaleController.getString("ActionChangedPhoto", R.string.ActionChangedPhoto), "un1", fromObject);
                        }
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatEditTitle) {
                TLRPC.Chat chat = messageOwner.peer_id != null && messageOwner.peer_id.channel_id != 0 ? getChat(chats, sChats, messageOwner.peer_id.channel_id) : null;
                if (ChatObject.isChannel(chat) && !chat.megagroup) {
                    messageText = LocaleController.getString("ActionChannelChangedTitle", R.string.ActionChannelChangedTitle).replace("un2", messageOwner.action.title);
                } else {
                    if (isOut()) {
                        messageText = LocaleController.getString("ActionYouChangedTitle", R.string.ActionYouChangedTitle).replace("un2", messageOwner.action.title);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionChangedTitle", R.string.ActionChangedTitle).replace("un2", messageOwner.action.title), "un1", fromObject);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
                TLRPC.Chat chat = messageOwner.peer_id != null && messageOwner.peer_id.channel_id != 0 ? getChat(chats, sChats, messageOwner.peer_id.channel_id) : null;
                if (ChatObject.isChannel(chat) && !chat.megagroup) {
                    messageText = LocaleController.getString("ActionChannelRemovedPhoto", R.string.ActionChannelRemovedPhoto);
                } else {
                    if (isOut()) {
                        messageText = LocaleController.getString("ActionYouRemovedPhoto", R.string.ActionYouRemovedPhoto);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionRemovedPhoto", R.string.ActionRemovedPhoto), "un1", fromObject);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionTTLChange) {
                if (messageOwner.action.ttl != 0) {
                    if (isOut()) {
                        messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, LocaleController.formatTTLString(messageOwner.action.ttl));
                    } else {
                        messageText = LocaleController.formatString("MessageLifetimeChanged", R.string.MessageLifetimeChanged, UserObject.getFirstName(fromUser), LocaleController.formatTTLString(messageOwner.action.ttl));
                    }
                } else {
                    if (isOut()) {
                        messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
                    } else {
                        messageText = LocaleController.formatString("MessageLifetimeRemoved", R.string.MessageLifetimeRemoved, UserObject.getFirstName(fromUser));
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionSetMessagesTTL) {
                TLRPC.TL_messageActionSetMessagesTTL action = (TLRPC.TL_messageActionSetMessagesTTL) messageOwner.action;
                TLRPC.Chat chat = messageOwner.peer_id != null && messageOwner.peer_id.channel_id != 0 ? getChat(chats, sChats, messageOwner.peer_id.channel_id) : null;
                if (chat != null && !chat.megagroup) {
                    if (action.period != 0) {
                        messageText = LocaleController.formatString("ActionTTLChannelChanged", R.string.ActionTTLChannelChanged, LocaleController.formatTTLString(action.period));
                    } else {
                        messageText = LocaleController.getString("ActionTTLChannelDisabled", R.string.ActionTTLChannelDisabled);
                    }
                } else if (action.period != 0) {
                    if (isOut()) {
                        messageText = LocaleController.formatString("ActionTTLYouChanged", R.string.ActionTTLYouChanged, LocaleController.formatTTLString(action.period));
                    } else {
                        messageText = replaceWithLink(LocaleController.formatString("ActionTTLChanged", R.string.ActionTTLChanged, LocaleController.formatTTLString(action.period)), "un1", fromObject);
                    }
                } else {
                    if (isOut()) {
                        messageText = LocaleController.getString("ActionTTLYouDisabled", R.string.ActionTTLYouDisabled);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionTTLDisabled", R.string.ActionTTLDisabled), "un1", fromObject);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
                String date;
                long time = ((long) messageOwner.date) * 1000;
                if (LocaleController.getInstance().formatterDay != null && LocaleController.getInstance().formatterYear != null) {
                    date = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(time), LocaleController.getInstance().formatterDay.format(time));
                } else {
                    date = "" + messageOwner.date;
                }
                TLRPC.User to_user = UserConfig.getInstance(currentAccount).getCurrentUser();
                if (to_user == null) {
                    to_user = getUser(users, sUsers, messageOwner.peer_id.user_id);
                }
                String name = to_user != null ? UserObject.getFirstName(to_user) : "";
                messageText = LocaleController.formatString("NotificationUnrecognizedDevice", R.string.NotificationUnrecognizedDevice, name, date, messageOwner.action.title, messageOwner.action.address);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionUserJoined || messageOwner.action instanceof TLRPC.TL_messageActionContactSignUp) {
                messageText = LocaleController.formatString("NotificationContactJoined", R.string.NotificationContactJoined, UserObject.getUserName(fromUser));
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
                messageText = LocaleController.formatString("NotificationContactNewPhoto", R.string.NotificationContactNewPhoto, UserObject.getUserName(fromUser));
            } else if (messageOwner.action instanceof TLRPC.TL_messageEncryptedAction) {
                if (messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages) {
                    if (isOut()) {
                        messageText = LocaleController.formatString("ActionTakeScreenshootYou", R.string.ActionTakeScreenshootYou);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionTakeScreenshoot", R.string.ActionTakeScreenshoot), "un1", fromObject);
                    }
                } else if (messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
                    TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL) messageOwner.action.encryptedAction;
                    if (action.ttl_seconds != 0) {
                        if (isOut()) {
                            messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, LocaleController.formatTTLString(action.ttl_seconds));
                        } else {
                            messageText = LocaleController.formatString("MessageLifetimeChanged", R.string.MessageLifetimeChanged, UserObject.getFirstName(fromUser), LocaleController.formatTTLString(action.ttl_seconds));
                        }
                    } else {
                        if (isOut()) {
                            messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
                        } else {
                            messageText = LocaleController.formatString("MessageLifetimeRemoved", R.string.MessageLifetimeRemoved, UserObject.getFirstName(fromUser));
                        }
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionScreenshotTaken) {
                if (isOut()) {
                    messageText = LocaleController.formatString("ActionTakeScreenshootYou", R.string.ActionTakeScreenshootYou);
                } else {
                    messageText = replaceWithLink(LocaleController.getString("ActionTakeScreenshoot", R.string.ActionTakeScreenshoot), "un1", fromObject);
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionCreatedBroadcastList) {
                messageText = LocaleController.formatString("YouCreatedBroadcastList", R.string.YouCreatedBroadcastList);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChannelCreate) {
                TLRPC.Chat chat = messageOwner.peer_id != null && messageOwner.peer_id.channel_id != 0 ? getChat(chats, sChats, messageOwner.peer_id.channel_id) : null;
                if (ChatObject.isChannel(chat) && chat.megagroup) {
                    messageText = LocaleController.getString("ActionCreateMega", R.string.ActionCreateMega);
                } else {
                    messageText = LocaleController.getString("ActionCreateChannel", R.string.ActionCreateChannel);
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
                messageText = LocaleController.getString("ActionMigrateFromGroup", R.string.ActionMigrateFromGroup);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChannelMigrateFrom) {
                messageText = LocaleController.getString("ActionMigrateFromGroup", R.string.ActionMigrateFromGroup);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
                TLRPC.Chat chat;
                if (fromUser == null) {
                    chat = getChat(chats, sChats, messageOwner.peer_id.channel_id);
                } else {
                    chat = null;
                }
                generatePinMessageText(fromUser, chat);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionHistoryClear) {
                messageText = LocaleController.getString("HistoryCleared", R.string.HistoryCleared);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionGameScore) {
                generateGameMessageText(fromUser);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall) {
                TLRPC.TL_messageActionPhoneCall call = (TLRPC.TL_messageActionPhoneCall) messageOwner.action;
                boolean isMissed = call.reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed;
                if (isFromUser() && messageOwner.from_id.user_id == UserConfig.getInstance(currentAccount).getClientUserId()) {
                    if (isMissed) {
                        if (call.video) {
                            messageText = LocaleController.getString("CallMessageVideoOutgoingMissed", R.string.CallMessageVideoOutgoingMissed);
                        } else {
                            messageText = LocaleController.getString("CallMessageOutgoingMissed", R.string.CallMessageOutgoingMissed);
                        }
                    } else {
                        if (call.video) {
                            messageText = LocaleController.getString("CallMessageVideoOutgoing", R.string.CallMessageVideoOutgoing);
                        } else {
                            messageText = LocaleController.getString("CallMessageOutgoing", R.string.CallMessageOutgoing);
                        }
                    }
                } else {
                    if (isMissed) {
                        if (call.video) {
                            messageText = LocaleController.getString("CallMessageVideoIncomingMissed", R.string.CallMessageVideoIncomingMissed);
                        } else {
                            messageText = LocaleController.getString("CallMessageIncomingMissed", R.string.CallMessageIncomingMissed);
                        }
                    } else if (call.reason instanceof TLRPC.TL_phoneCallDiscardReasonBusy) {
                        if (call.video) {
                            messageText = LocaleController.getString("CallMessageVideoIncomingDeclined", R.string.CallMessageVideoIncomingDeclined);
                        } else {
                            messageText = LocaleController.getString("CallMessageIncomingDeclined", R.string.CallMessageIncomingDeclined);
                        }
                    } else {
                        if (call.video) {
                            messageText = LocaleController.getString("CallMessageVideoIncoming", R.string.CallMessageVideoIncoming);
                        } else {
                            messageText = LocaleController.getString("CallMessageIncoming", R.string.CallMessageIncoming);
                        }
                    }
                }
                if (call.duration > 0) {
                    String duration = LocaleController.formatCallDuration(call.duration);
                    messageText = LocaleController.formatString("CallMessageWithDuration", R.string.CallMessageWithDuration, messageText, duration);
                    String _messageText = messageText.toString();
                    int start = _messageText.indexOf(duration);
                    if (start != -1) {
                        SpannableString sp = new SpannableString(messageText);
                        int end = start + duration.length();
                        if (start > 0 && _messageText.charAt(start - 1) == '(') {
                            start--;
                        }
                        if (end < _messageText.length() && _messageText.charAt(end) == ')') {
                            end++;
                        }
                        sp.setSpan(new TypefaceSpan(Typeface.DEFAULT), start, end, 0);
                        messageText = sp;
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionPaymentSent) {
                TLRPC.User user = getUser(users, sUsers, getDialogId());
                generatePaymentSentMessageText(user);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionBotAllowed) {
                String domain = ((TLRPC.TL_messageActionBotAllowed) messageOwner.action).domain;
                String text = LocaleController.getString("ActionBotAllowed", R.string.ActionBotAllowed);
                int start = text.indexOf("%1$s");
                SpannableString str = new SpannableString(String.format(text, domain));
                if (start >= 0) {
                    str.setSpan(new URLSpanNoUnderlineBold("http://" + domain), start, start + domain.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
                messageText = str;
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionSecureValuesSent) {
                TLRPC.TL_messageActionSecureValuesSent valuesSent = (TLRPC.TL_messageActionSecureValuesSent) messageOwner.action;
                StringBuilder str = new StringBuilder();
                for (int a = 0, size = valuesSent.types.size(); a < size; a++) {
                    TLRPC.SecureValueType type = valuesSent.types.get(a);
                    if (str.length() > 0) {
                        str.append(", ");
                    }
                    if (type instanceof TLRPC.TL_secureValueTypePhone) {
                        str.append(LocaleController.getString("ActionBotDocumentPhone", R.string.ActionBotDocumentPhone));
                    } else if (type instanceof TLRPC.TL_secureValueTypeEmail) {
                        str.append(LocaleController.getString("ActionBotDocumentEmail", R.string.ActionBotDocumentEmail));
                    } else if (type instanceof TLRPC.TL_secureValueTypeAddress) {
                        str.append(LocaleController.getString("ActionBotDocumentAddress", R.string.ActionBotDocumentAddress));
                    } else if (type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
                        str.append(LocaleController.getString("ActionBotDocumentIdentity", R.string.ActionBotDocumentIdentity));
                    } else if (type instanceof TLRPC.TL_secureValueTypePassport) {
                        str.append(LocaleController.getString("ActionBotDocumentPassport", R.string.ActionBotDocumentPassport));
                    } else if (type instanceof TLRPC.TL_secureValueTypeDriverLicense) {
                        str.append(LocaleController.getString("ActionBotDocumentDriverLicence", R.string.ActionBotDocumentDriverLicence));
                    } else if (type instanceof TLRPC.TL_secureValueTypeIdentityCard) {
                        str.append(LocaleController.getString("ActionBotDocumentIdentityCard", R.string.ActionBotDocumentIdentityCard));
                    } else if (type instanceof TLRPC.TL_secureValueTypeUtilityBill) {
                        str.append(LocaleController.getString("ActionBotDocumentUtilityBill", R.string.ActionBotDocumentUtilityBill));
                    } else if (type instanceof TLRPC.TL_secureValueTypeBankStatement) {
                        str.append(LocaleController.getString("ActionBotDocumentBankStatement", R.string.ActionBotDocumentBankStatement));
                    } else if (type instanceof TLRPC.TL_secureValueTypeRentalAgreement) {
                        str.append(LocaleController.getString("ActionBotDocumentRentalAgreement", R.string.ActionBotDocumentRentalAgreement));
                    } else if (type instanceof TLRPC.TL_secureValueTypeInternalPassport) {
                        str.append(LocaleController.getString("ActionBotDocumentInternalPassport", R.string.ActionBotDocumentInternalPassport));
                    } else if (type instanceof TLRPC.TL_secureValueTypePassportRegistration) {
                        str.append(LocaleController.getString("ActionBotDocumentPassportRegistration", R.string.ActionBotDocumentPassportRegistration));
                    } else if (type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) {
                        str.append(LocaleController.getString("ActionBotDocumentTemporaryRegistration", R.string.ActionBotDocumentTemporaryRegistration));
                    }
                }
                TLRPC.User user = null;
                if (messageOwner.peer_id != null) {
                    user = getUser(users, sUsers, messageOwner.peer_id.user_id);
                }
                messageText = LocaleController.formatString("ActionBotDocuments", R.string.ActionBotDocuments, UserObject.getFirstName(user), str.toString());
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionSetChatTheme) {
                String emoticon = ((TLRPC.TL_messageActionSetChatTheme) messageOwner.action).emoticon;
                String userName = UserObject.getFirstName(fromUser);
                boolean isUserSelf = UserObject.isUserSelf(fromUser);
                if (TextUtils.isEmpty(emoticon)) {
                    messageText = isUserSelf ? LocaleController.formatString("ChatThemeDisabledYou", R.string.ChatThemeDisabledYou) : LocaleController.formatString("ChatThemeDisabled", R.string.ChatThemeDisabled, userName, emoticon);
                } else {
                    messageText = isUserSelf ? LocaleController.formatString("ChatThemeChangedYou", R.string.ChatThemeChangedYou, emoticon) : LocaleController.formatString("ChatThemeChangedTo", R.string.ChatThemeChangedTo, userName, emoticon);
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByRequest) {
                if (UserObject.isUserSelf(fromUser)) {
                    boolean isChannel = ChatObject.isChannelAndNotMegaGroup(messageOwner.peer_id.channel_id, currentAccount);
                    messageText = isChannel ? LocaleController.getString("RequestToJoinChannelApproved", R.string.RequestToJoinChannelApproved) : LocaleController.getString("RequestToJoinGroupApproved", R.string.RequestToJoinGroupApproved);
                } else {
                    messageText = replaceWithLink(LocaleController.getString("UserAcceptedToGroupAction", R.string.UserAcceptedToGroupAction), "un1", fromObject);
                }
            }
        }
    } else {
        isRestrictedMessage = false;
        String restrictionReason = MessagesController.getRestrictionReason(messageOwner.restriction_reason);
        if (!TextUtils.isEmpty(restrictionReason)) {
            messageText = restrictionReason;
            isRestrictedMessage = true;
        } else if (!isMediaEmpty()) {
            if (messageOwner.media instanceof TLRPC.TL_messageMediaDice) {
                messageText = getDiceEmoji();
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaPoll) {
                if (((TLRPC.TL_messageMediaPoll) messageOwner.media).poll.quiz) {
                    messageText = LocaleController.getString("QuizPoll", R.string.QuizPoll);
                } else {
                    messageText = LocaleController.getString("Poll", R.string.Poll);
                }
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                if (messageOwner.media.ttl_seconds != 0 && !(messageOwner instanceof TLRPC.TL_message_secret)) {
                    messageText = LocaleController.getString("AttachDestructingPhoto", R.string.AttachDestructingPhoto);
                } else {
                    messageText = LocaleController.getString("AttachPhoto", R.string.AttachPhoto);
                }
            } else if (isVideo() || messageOwner.media instanceof TLRPC.TL_messageMediaDocument && getDocument() instanceof TLRPC.TL_documentEmpty && messageOwner.media.ttl_seconds != 0) {
                if (messageOwner.media.ttl_seconds != 0 && !(messageOwner instanceof TLRPC.TL_message_secret)) {
                    messageText = LocaleController.getString("AttachDestructingVideo", R.string.AttachDestructingVideo);
                } else {
                    messageText = LocaleController.getString("AttachVideo", R.string.AttachVideo);
                }
            } else if (isVoice()) {
                messageText = LocaleController.getString("AttachAudio", R.string.AttachAudio);
            } else if (isRoundVideo()) {
                messageText = LocaleController.getString("AttachRound", R.string.AttachRound);
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaGeo || messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                messageText = LocaleController.getString("AttachLocation", R.string.AttachLocation);
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) {
                messageText = LocaleController.getString("AttachLiveLocation", R.string.AttachLiveLocation);
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                messageText = LocaleController.getString("AttachContact", R.string.AttachContact);
                if (!TextUtils.isEmpty(messageOwner.media.vcard)) {
                    vCardData = VCardData.parse(messageOwner.media.vcard);
                }
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
                messageText = messageOwner.message;
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) {
                messageText = messageOwner.media.description;
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaUnsupported) {
                messageText = LocaleController.getString("UnsupportedMedia", R.string.UnsupportedMedia).replace("https://telegram.org/update", "https://github.com/Telegram-FOSS-Team/Telegram-FOSS/blob/master/Update.md");
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                if (isSticker() || isAnimatedStickerDocument(getDocument(), true)) {
                    String sch = getStickerChar();
                    if (sch != null && sch.length() > 0) {
                        messageText = String.format("%s %s", sch, LocaleController.getString("AttachSticker", R.string.AttachSticker));
                    } else {
                        messageText = LocaleController.getString("AttachSticker", R.string.AttachSticker);
                    }
                } else if (isMusic()) {
                    messageText = LocaleController.getString("AttachMusic", R.string.AttachMusic);
                } else if (isGif()) {
                    messageText = LocaleController.getString("AttachGif", R.string.AttachGif);
                } else {
                    String name = FileLoader.getDocumentFileName(getDocument());
                    if (!TextUtils.isEmpty(name)) {
                        messageText = name;
                    } else {
                        messageText = LocaleController.getString("AttachDocument", R.string.AttachDocument);
                    }
                }
            }
        } else {
            if (messageOwner.message != null) {
                try {
                    if (messageOwner.message.length() > 200) {
                        messageText = AndroidUtilities.BAD_CHARS_MESSAGE_LONG_PATTERN.matcher(messageOwner.message).replaceAll("\u200C");
                    } else {
                        messageText = AndroidUtilities.BAD_CHARS_MESSAGE_PATTERN.matcher(messageOwner.message).replaceAll("\u200C");
                    }
                } catch (Throwable e) {
                    messageText = messageOwner.message;
                }
            } else {
                messageText = messageOwner.message;
            }
        }
    }
    if (messageText == null) {
        messageText = "";
    }
}
Also used : SpannableString(android.text.SpannableString) TLRPC(org.telegram.tgnet.TLRPC) SpannableString(android.text.SpannableString) URLSpanNoUnderlineBold(org.telegram.ui.Components.URLSpanNoUnderlineBold) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) TextPaint(android.text.TextPaint) TLObject(org.telegram.tgnet.TLObject)

Example 3 with URLSpanNoUnderlineBold

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

the class MessageObject method replaceWithLink.

public CharSequence replaceWithLink(CharSequence source, String param, ArrayList<Long> uids, AbstractMap<Long, TLRPC.User> usersDict, LongSparseArray<TLRPC.User> sUsersDict) {
    int start = TextUtils.indexOf(source, param);
    if (start >= 0) {
        SpannableStringBuilder names = new SpannableStringBuilder("");
        for (int a = 0; a < uids.size(); a++) {
            TLRPC.User user = null;
            if (usersDict != null) {
                user = usersDict.get(uids.get(a));
            } else if (sUsersDict != null) {
                user = sUsersDict.get(uids.get(a));
            }
            if (user == null) {
                user = MessagesController.getInstance(currentAccount).getUser(uids.get(a));
            }
            if (user != null) {
                String name = UserObject.getUserName(user);
                start = names.length();
                if (names.length() != 0) {
                    names.append(", ");
                }
                names.append(name);
                names.setSpan(new URLSpanNoUnderlineBold("" + user.id), start, start + name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        return TextUtils.replace(source, new String[] { param }, new CharSequence[] { names });
    }
    return source;
}
Also used : URLSpanNoUnderlineBold(org.telegram.ui.Components.URLSpanNoUnderlineBold) SpannableString(android.text.SpannableString) TextPaint(android.text.TextPaint) SpannableStringBuilder(android.text.SpannableStringBuilder) TLRPC(org.telegram.tgnet.TLRPC)

Aggregations

SpannableString (android.text.SpannableString)3 SpannableStringBuilder (android.text.SpannableStringBuilder)3 TextPaint (android.text.TextPaint)3 TLRPC (org.telegram.tgnet.TLRPC)3 URLSpanNoUnderlineBold (org.telegram.ui.Components.URLSpanNoUnderlineBold)3 TLObject (org.telegram.tgnet.TLObject)2 TypefaceSpan (org.telegram.ui.Components.TypefaceSpan)1