(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
main
torrentcome 8 years ago
parent 5b07e9c26a
commit dd707ee7da
  1. 16
      app/src/main/java/com/keylesspalace/tusky/util/ParserUtils.java
  2. 15
      app/src/main/java/com/keylesspalace/tusky/util/StringUtils.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<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,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;
}

@ -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…
Cancel
Save