Java Code Examples for android.text.TextUtils#replace()

The following examples show how to use android.text.TextUtils#replace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MarkDownUtil.java    From nextcloud-notes with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This is a compatibility-method that provides workarounds for several bugs in RxMarkdown
 * <p>
 * https://github.com/stefan-niedermann/nextcloud-notes/issues/772
 *
 * @param markdownProcessor RxMarkdown MarkdownProcessor instance
 * @param text              CharSequence that should be parsed
 * @return the processed text but with several workarounds for Bugs in RxMarkdown
 */
@NonNull
public static CharSequence parseCompat(@NonNull final MarkdownProcessor markdownProcessor, CharSequence text) {
    if (TextUtils.isEmpty(text)) {
        return "";
    }

    while (TextUtils.indexOf(text, MD_IMAGE_WITH_EMPTY_DESCRIPTION) >= 0) {
        text = TextUtils.replace(text, MD_IMAGE_WITH_EMPTY_DESCRIPTION_ARRAY, MD_IMAGE_WITH_SPACE_DESCRIPTION_ARRAY);
    }

    return markdownProcessor.parse(text);
}
 
Example 2
Source File: ChatAttachAlertPollLayout.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static CharSequence getFixedString(CharSequence text) {
    if (TextUtils.isEmpty(text)) {
        return text;
    }
    text = AndroidUtilities.getTrimmedString(text);
    while (TextUtils.indexOf(text, "\n\n\n") >= 0) {
        text = TextUtils.replace(text, new String[]{"\n\n\n"}, new CharSequence[]{"\n\n"});
    }
    while (TextUtils.indexOf(text, "\n\n\n") == 0) {
        text = TextUtils.replace(text, new String[]{"\n\n\n"}, new CharSequence[]{"\n\n"});
    }
    return text;
}
 
Example 3
Source File: ChatAttachAlertPollLayout.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static CharSequence getFixedString(CharSequence text) {
    if (TextUtils.isEmpty(text)) {
        return text;
    }
    text = AndroidUtilities.getTrimmedString(text);
    while (TextUtils.indexOf(text, "\n\n\n") >= 0) {
        text = TextUtils.replace(text, new String[]{"\n\n\n"}, new CharSequence[]{"\n\n"});
    }
    while (TextUtils.indexOf(text, "\n\n\n") == 0) {
        text = TextUtils.replace(text, new String[]{"\n\n\n"}, new CharSequence[]{"\n\n"});
    }
    return text;
}
 
Example 4
Source File: ChatAvatarContainer.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void updateSubtitle() {
    if (parentFragment == null) {
        return;
    }
    TLRPC.User user = parentFragment.getCurrentUser();
    if (UserObject.isUserSelf(user)) {
        if (subtitleTextView.getVisibility() != GONE) {
            subtitleTextView.setVisibility(GONE);
        }
        return;
    }
    TLRPC.Chat chat = parentFragment.getCurrentChat();
    CharSequence printString = MessagesController.getInstance(currentAccount).printingStrings.get(parentFragment.getDialogId());
    if (printString != null) {
        printString = TextUtils.replace(printString, new String[]{"..."}, new String[]{""});
    }
    CharSequence newSubtitle;
    if (printString == null || printString.length() == 0 || ChatObject.isChannel(chat) && !chat.megagroup) {
        setTypingAnimation(false);
        if (chat != null) {
            TLRPC.ChatFull info = parentFragment.getCurrentChatInfo();
            if (ChatObject.isChannel(chat)) {
                if (info != null && info.participants_count != 0) {
                    if (chat.megagroup && info.participants_count <= 200) {
                        if (onlineCount > 1 && info.participants_count != 0) {
                            newSubtitle = String.format("%s, %s", LocaleController.formatPluralString("Members", info.participants_count), LocaleController.formatPluralString("OnlineCount", onlineCount));
                        } else {
                            newSubtitle = LocaleController.formatPluralString("Members", info.participants_count);
                        }
                    } else {
                        int result[] = new int[1];
                        String shortNumber = LocaleController.formatShortNumber(info.participants_count, result);
                        if (chat.megagroup) {
                            newSubtitle = LocaleController.formatPluralString("Members", result[0]).replace(String.format("%d", result[0]), shortNumber);
                        } else {
                            newSubtitle = LocaleController.formatPluralString("Subscribers", result[0]).replace(String.format("%d", result[0]), shortNumber);
                        }
                    }
                } else {
                    if (chat.megagroup) {
                        newSubtitle = LocaleController.getString("Loading", R.string.Loading).toLowerCase();
                    } else {
                        if ((chat.flags & TLRPC.CHAT_FLAG_IS_PUBLIC) != 0) {
                            newSubtitle = LocaleController.getString("ChannelPublic", R.string.ChannelPublic).toLowerCase();
                        } else {
                            newSubtitle = LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate).toLowerCase();
                        }
                    }
                }
            } else {
                if (ChatObject.isKickedFromChat(chat)) {
                    newSubtitle = LocaleController.getString("YouWereKicked", R.string.YouWereKicked);
                } else if (ChatObject.isLeftFromChat(chat)) {
                    newSubtitle = LocaleController.getString("YouLeft", R.string.YouLeft);
                } else {
                    int count = chat.participants_count;
                    if (info != null && info.participants != null) {
                        count = info.participants.participants.size();
                    }
                    if (onlineCount > 1 && count != 0) {
                        newSubtitle = String.format("%s, %s", LocaleController.formatPluralString("Members", count), LocaleController.formatPluralString("OnlineCount", onlineCount));
                    } else {
                        newSubtitle = LocaleController.formatPluralString("Members", count);
                    }
                }
            }
        } else if (user != null) {
            TLRPC.User newUser = MessagesController.getInstance(currentAccount).getUser(user.id);
            if (newUser != null) {
                user = newUser;
            }
            String newStatus;
            if (user.id == UserConfig.getInstance(currentAccount).getClientUserId()) {
                newStatus = LocaleController.getString("ChatYourSelf", R.string.ChatYourSelf);
            } else if (user.id == 333000 || user.id == 777000) {
                newStatus = LocaleController.getString("ServiceNotifications", R.string.ServiceNotifications);
            } else if (user.bot) {
                newStatus = LocaleController.getString("Bot", R.string.Bot);
            } else {
                newStatus = LocaleController.formatUserStatus(currentAccount, user);
            }
            newSubtitle = newStatus;
        } else {
            newSubtitle = "";
        }
    } else {
        newSubtitle = printString;
        setTypingAnimation(true);
    }
    if (lastSubtitle == null) {
        subtitleTextView.setText(newSubtitle);
    } else {
        lastSubtitle = newSubtitle;
    }
}
 
Example 5
Source File: ChatAvatarContainer.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void updateSubtitle() {
    if (parentFragment == null) {
        return;
    }
    TLRPC.User user = parentFragment.getCurrentUser();
    if (UserObject.isUserSelf(user)) {
        if (subtitleTextView.getVisibility() != GONE) {
            subtitleTextView.setVisibility(GONE);
        }
        return;
    }
    TLRPC.Chat chat = parentFragment.getCurrentChat();
    CharSequence printString = MessagesController.getInstance(currentAccount).printingStrings.get(parentFragment.getDialogId());
    if (printString != null) {
        printString = TextUtils.replace(printString, new String[]{"..."}, new String[]{""});
    }
    CharSequence newSubtitle;
    if (printString == null || printString.length() == 0 || ChatObject.isChannel(chat) && !chat.megagroup) {
        setTypingAnimation(false);
        if (chat != null) {
            TLRPC.ChatFull info = parentFragment.getCurrentChatInfo();
            if (ChatObject.isChannel(chat)) {
                if (info != null && info.participants_count != 0) {
                    if (chat.megagroup && info.participants_count <= 200) {
                        if (onlineCount > 1 && info.participants_count != 0) {
                            newSubtitle = String.format("%s, %s", LocaleController.formatPluralString("Members", info.participants_count), LocaleController.formatPluralString("OnlineCount", onlineCount));
                        } else {
                            newSubtitle = LocaleController.formatPluralString("Members", info.participants_count);
                        }
                    } else {
                        int result[] = new int[1];
                        String shortNumber = LocaleController.formatShortNumber(info.participants_count, result);
                        if (chat.megagroup) {
                            newSubtitle = LocaleController.formatPluralString("Members", result[0]).replace(String.format("%d", result[0]), shortNumber);
                        } else {
                            newSubtitle = LocaleController.formatPluralString("Subscribers", result[0]).replace(String.format("%d", result[0]), shortNumber);
                        }
                    }
                } else {
                    if (chat.megagroup) {
                        newSubtitle = LocaleController.getString("Loading", R.string.Loading).toLowerCase();
                    } else {
                        if ((chat.flags & TLRPC.CHAT_FLAG_IS_PUBLIC) != 0) {
                            newSubtitle = LocaleController.getString("ChannelPublic", R.string.ChannelPublic).toLowerCase();
                        } else {
                            newSubtitle = LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate).toLowerCase();
                        }
                    }
                }
            } else {
                if (ChatObject.isKickedFromChat(chat)) {
                    newSubtitle = LocaleController.getString("YouWereKicked", R.string.YouWereKicked);
                } else if (ChatObject.isLeftFromChat(chat)) {
                    newSubtitle = LocaleController.getString("YouLeft", R.string.YouLeft);
                } else {
                    int count = chat.participants_count;
                    if (info != null && info.participants != null) {
                        count = info.participants.participants.size();
                    }
                    if (onlineCount > 1 && count != 0) {
                        newSubtitle = String.format("%s, %s", LocaleController.formatPluralString("Members", count), LocaleController.formatPluralString("OnlineCount", onlineCount));
                    } else {
                        newSubtitle = LocaleController.formatPluralString("Members", count);
                    }
                }
            }
        } else if (user != null) {
            TLRPC.User newUser = MessagesController.getInstance(currentAccount).getUser(user.id);
            if (newUser != null) {
                user = newUser;
            }
            String newStatus;
            if (user.id == UserConfig.getInstance(currentAccount).getClientUserId()) {
                newStatus = LocaleController.getString("ChatYourSelf", R.string.ChatYourSelf);
            } else if (user.id == 333000 || user.id == 777000) {
                newStatus = LocaleController.getString("ServiceNotifications", R.string.ServiceNotifications);
            } else if (user.bot) {
                newStatus = LocaleController.getString("Bot", R.string.Bot);
            } else {
                newStatus = LocaleController.formatUserStatus(currentAccount, user);
            }
            newSubtitle = newStatus;
        } else {
            newSubtitle = "";
        }
    } else {
        newSubtitle = printString;
        setTypingAnimation(true);
    }
    if (lastSubtitle == null) {
        subtitleTextView.setText(newSubtitle);
    } else {
        lastSubtitle = newSubtitle;
    }
}