Search in sources :

Example 1 with Tuple

use of net.iGap.libs.Tuple in project iGap-Android by KianIranian-STDG.

the class AbstractMessage method MessageBoldSetup.

private ArrayList<Tuple<Integer, Integer>> MessageBoldSetup(String text) {
    ArrayList<Tuple<Integer, Integer>> boldPlaces = getBoldPlaces(text);
    myText = new SpannableString(removeBoldMark(text, boldPlaces));
    updateBoldPlaces(boldPlaces);
    return boldPlaces;
}
Also used : SpannableString(android.text.SpannableString) Tuple(net.iGap.libs.Tuple)

Example 2 with Tuple

use of net.iGap.libs.Tuple in project iGap-Android by KianIranian-STDG.

the class AppUtils method replyTextMessage.

/**
 * fetch type of message for show in reply view
 *
 * @param messageObject for detect message type
 * @return final message text
 */
public static String replyTextMessage(MessageObject messageObject, Resources resources) {
    MessageObject message = RealmRoomMessage.getFinalMessage(messageObject);
    String messageText = "";
    if (message != null) {
        switch(message.messageType) {
            case TEXT_VALUE:
            case STORY_REPLY_VALUE:
                if (message.message != null) {
                    messageText = message.message;
                }
                break;
            case AUDIO_TEXT_VALUE:
            case AUDIO_VALUE:
                if (message.getAttachment() == null) {
                    return null;
                }
                messageText = resources.getString(R.string.audio_message);
                break;
            case CONTACT_VALUE:
                messageText = message.contact.firstName + "\n" + message.contact.phones.get(message.contact.phones.size() - 1);
                break;
            case FILE_TEXT_VALUE:
            case FILE_VALUE:
                if (message.getAttachment() == null) {
                    return null;
                }
                messageText = resources.getString(R.string.file_message);
                break;
            case STICKER_VALUE:
                messageText = resources.getString(R.string.sticker);
                break;
            case GIF_TEXT_VALUE:
            case GIF_VALUE:
                if (message.getAttachment() == null) {
                    return null;
                }
                messageText = resources.getString(R.string.gif_message);
                break;
            case IMAGE_TEXT_VALUE:
            case IMAGE_VALUE:
                if (message.getAttachment() == null) {
                    return null;
                }
                messageText = resources.getString(R.string.image_message);
                break;
            case LOCATION_VALUE:
                messageText = resources.getString(R.string.location_message);
                break;
            case VIDEO_TEXT_VALUE:
            case VIDEO_VALUE:
                if (message.getAttachment() == null) {
                    return null;
                }
                messageText = resources.getString(R.string.video_message);
                break;
            case VOICE_VALUE:
                if (message.getAttachment() == null) {
                    return null;
                }
                messageText = resources.getString(R.string.voice_message);
                break;
            default:
                messageText = "";
                break;
        }
    }
    ArrayList<Tuple<Integer, Integer>> places = AbstractMessage.getBoldPlaces(messageText);
    messageText = AbstractMessage.removeBoldMark(messageText, places);
    return messageText;
}
Also used : MessageObject(net.iGap.structs.MessageObject) Tuple(net.iGap.libs.Tuple)

Example 3 with Tuple

use of net.iGap.libs.Tuple in project iGap-Android by KianIranian-STDG.

the class AbstractMessage method updateMessageText.

public void updateMessageText() {
    if (!TextUtils.isEmpty(myText)) {
        ArrayList<Tuple<Integer, Integer>> results = MessageBoldSetup(myText.toString());
        if (messageObject.forwardedMessage != null) {
            if (messageObject.forwardedMessage.linkInfo != null) {
                messageObject.linkInfo = messageObject.forwardedMessage.linkInfo;
                messageObject.hasLink = messageObject.forwardedMessage.hasLink;
            }
        }
        if (messageObject.hasLink) {
            myText = SpannableString.valueOf(HelperUrl.getLinkText(G.currentActivity, myText.toString(), messageObject.linkInfo, messageObject.id + ""));
        }
        for (int i = 0; i < results.size(); i++) {
            Tuple<Integer, Integer> point = results.get(i);
            myText.setSpan(new StyleSpan(Typeface.BOLD), point.x, point.y, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
Also used : StyleSpan(android.text.style.StyleSpan) Tuple(net.iGap.libs.Tuple)

Example 4 with Tuple

use of net.iGap.libs.Tuple in project iGap-Android by KianIranian-STDG.

the class HelperUrl method getLinkInfo.

public static String getLinkInfo(String text) {
    StringBuilder linkInfo = new StringBuilder();
    if (text == null) {
        return linkInfo.toString();
    }
    if (text.trim().length() < 1) {
        return linkInfo.toString();
    }
    ArrayList<Tuple<Integer, Integer>> boldPlaces = AbstractMessage.getBoldPlaces(text);
    text = AbstractMessage.removeBoldMark(text, boldPlaces);
    String newText = text.toLowerCase();
    Matcher igapMatcher = Pattern.compile(// 2- igap deep link
    IGAP_DEEP_LINK_PATTERN + "|" + IGAP_LINK_PATTERN + // 1- igap link
    "|" + WEB_LINK + // 3- web link
    "|" + BOT_LINK + // 4- bot link
    "|" + IGAP_RESOLVE + // 5- igap resolve
    "|" + IGAP_DIGIT_LINK + // 6- igap digit link
    "|" + IGAP_AT_SIGN_PATTERN + // 7- igap atsign pattern
    "|" + // 8- igap hashTag pattern
    IGAP_HASH_TAG_PATTERN).matcher(newText);
    while (igapMatcher.find()) {
        if (igapMatcher.group(1) != null) {
            linkInfo.append(igapMatcher.start(1)).append("_").append(igapMatcher.end(1)).append("_").append(linkType.igapDeepLink.toString()).append("@");
        } else if (igapMatcher.group(2) != null) {
            linkInfo.append(igapMatcher.start(2)).append("_").append(igapMatcher.end(2)).append("_").append(linkType.igapLink.toString()).append("@");
        } else if (igapMatcher.group(3) != null) {
            linkInfo.append(igapMatcher.start(3)).append("_").append(igapMatcher.end(3)).append("_").append(linkType.webLink.toString()).append("@");
        } else if (igapMatcher.group(4) != null) {
            linkInfo.append(igapMatcher.start(4)).append("_").append(igapMatcher.end(4)).append("_").append(linkType.bot.toString()).append("@");
        } else if (igapMatcher.group(5) != null) {
            linkInfo.append(igapMatcher.start(5)).append("_").append(igapMatcher.end(5)).append("_").append(linkType.igapResolve.toString()).append("@");
        } else if (igapMatcher.group(6) != null) {
            linkInfo.append(igapMatcher.start(6)).append("_").append(igapMatcher.end(6)).append("_").append(linkType.digitLink.toString()).append("@");
        } else if (igapMatcher.group(7) != null) {
            linkInfo.append(igapMatcher.start(7)).append("_").append(igapMatcher.end(7)).append("_").append(linkType.atSighn.toString()).append("@");
        } else if (igapMatcher.group(8) != null) {
            linkInfo.append(igapMatcher.start(8)).append("_").append(igapMatcher.end(8)).append("_").append(linkType.hash.toString()).append("@");
        }
    }
    return linkInfo.toString();
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) Matcher(java.util.regex.Matcher) Tuple(net.iGap.libs.Tuple)

Aggregations

Tuple (net.iGap.libs.Tuple)4 SpannableString (android.text.SpannableString)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 StyleSpan (android.text.style.StyleSpan)1 Matcher (java.util.regex.Matcher)1 MessageObject (net.iGap.structs.MessageObject)1