Maximum 250 auto links

pull/162/head
M66B 5 years ago
parent 29ee1b163d
commit b31861e7e1

@ -78,7 +78,7 @@ import static androidx.core.text.HtmlCompat.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE;
public class HtmlHelper {
static final int PREVIEW_SIZE = 250; // characters
private static final int MAX_LINKS = 500;
private static final int MAX_AUTO_LINK = 250;
private static final int TRACKING_PIXEL_SURFACE = 25; // pixels
private static final List<String> heads = Collections.unmodifiableList(Arrays.asList(
@ -127,12 +127,6 @@ public class HtmlHelper {
}
}
int links = parsed.select("a").size();
if (links > MAX_LINKS) {
Log.i("Message links=" + links);
return "<strong>" + context.getString(R.string.title_hint_too_complex) + "</strong>";
}
Whitelist whitelist = Whitelist.relaxed()
.addTags("hr", "abbr")
.removeTags("col", "colgroup", "thead", "tbody")
@ -275,11 +269,11 @@ public class HtmlHelper {
PatternsCompat.AUTOLINK_WEB_URL.pattern());
NodeTraversor.traverse(new NodeVisitor() {
private int alinks = links;
private int links = 0;
@Override
public void head(Node node, int depth) {
if (alinks < MAX_LINKS && node instanceof TextNode) {
if (links < MAX_AUTO_LINK && node instanceof TextNode) {
TextNode tnode = (TextNode) node;
String text = tnode.text();
@ -303,7 +297,7 @@ public class HtmlHelper {
if (BuildConfig.DEBUG)
Log.i("Web url=" + matcher.group() +
" " + matcher.start() + "..." + matcher.end() + "/" + text.length() +
" linked=" + linked + " email=" + email);
" linked=" + linked + " email=" + email + " count=" + links);
if (linked)
span.appendText(text.substring(pos, matcher.end()));
@ -315,11 +309,11 @@ public class HtmlHelper {
a.text(matcher.group());
span.appendChild(a);
alinks++;
links++;
}
pos = matcher.end();
} while (alinks < MAX_LINKS && matcher.find());
} while (links < MAX_AUTO_LINK && matcher.find());
span.appendText(text.substring(pos));

@ -763,7 +763,6 @@
<string name="title_hint_message_selection">Long press a message to start selecting multiple messages</string>
<string name="title_hint_sync">Downloading messages can take some time, depending on the speed of the provider, internet connection and device and on the number of messages. While downloading messages the app might respond slower.</string>
<string name="title_hint_image_link">Image link</string>
<string name="title_hint_too_complex">Message too large or too complex to display</string>
<string name="title_hint_tracking_image">Tracking image %1$sx%2$s</string>
<string name="title_hint_contact_actions">Long press for options</string>

Loading…
Cancel
Save