(bug fixing) When we share by an app : the text shared is not just an URL but a small text with the URL inside.
So we parse the text until find an url. Take the first one and send it to the parse
This commit is contained in:
parent
418fbd3b5c
commit
7cc06d3ad0
2 changed files with 25 additions and 6 deletions
|
@ -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<String> 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,10 +83,8 @@ public class ParserUtils {
|
|||
headerInfo.title = QUOTE + text.toUpperCase() + QUOTE;
|
||||
}
|
||||
if (!TextUtils.isEmpty(imageUrl)) {
|
||||
if (URLUtil.isValidUrl(imageUrl)) {
|
||||
headerInfo.image = (imageUrl);
|
||||
}
|
||||
}
|
||||
return headerInfo;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> extractUrl(String text) {
|
||||
List<String> links = new ArrayList<>();
|
||||
Matcher m = Patterns.WEB_URL.matcher(text);
|
||||
while (m.find()) {
|
||||
String url = m.group();
|
||||
links.add(url);
|
||||
}
|
||||
return links;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue