diff --git a/app/src/main/java/com/keylesspalace/tusky/util/ParserUtils.java b/app/src/main/java/com/keylesspalace/tusky/util/ParserUtils.java index 9c1eed33..80a932f6 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/ParserUtils.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/ParserUtils.java @@ -13,6 +13,8 @@ import org.jsoup.helper.HttpConnection; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; +import java.util.List; + import static com.keylesspalace.tusky.util.StringUtils.QUOTE; /** @@ -35,9 +37,13 @@ public class ParserUtils { ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); pasteData = item.getText().toString(); - // we have to find an url for start it - if (URLUtil.isValidUrl(pasteData)) { - new ThreadHeaderInfo().execute(pasteData); + // If we share with an app, it's not only an url + List strings = StringUtils.extractUrl(pasteData); + String url = strings.get(0); // we assume that the first url is the good one + if (strings.size() > 0) { + if (URLUtil.isValidUrl(url)) { + new ThreadHeaderInfo().execute(url); + } } } return null; @@ -77,9 +83,7 @@ public class ParserUtils { headerInfo.title = QUOTE + text.toUpperCase() + QUOTE; } if (!TextUtils.isEmpty(imageUrl)) { - if (URLUtil.isValidUrl(imageUrl)) { - headerInfo.image = (imageUrl); - } + headerInfo.image = (imageUrl); } return headerInfo; } diff --git a/app/src/main/java/com/keylesspalace/tusky/util/StringUtils.java b/app/src/main/java/com/keylesspalace/tusky/util/StringUtils.java index ff050f2c..1d909751 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/StringUtils.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/StringUtils.java @@ -1,6 +1,11 @@ package com.keylesspalace.tusky.util; +import android.util.Patterns; + +import java.util.ArrayList; +import java.util.List; import java.util.Random; +import java.util.regex.Matcher; public class StringUtils { @@ -16,4 +21,14 @@ public class StringUtils { } return new String(chars); } + + static List extractUrl(String text) { + List links = new ArrayList<>(); + Matcher m = Patterns.WEB_URL.matcher(text); + while (m.find()) { + String url = m.group(); + links.add(url); + } + return links; + } }