Especially for XDA notification ...
This commit is contained in:
M66B 2018-08-05 08:53:43 +00:00
parent a7188af295
commit b66ec74f98
1 changed files with 15 additions and 3 deletions

View File

@ -33,12 +33,15 @@ import org.jsoup.select.NodeVisitor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class HtmlHelper implements NodeVisitor { public class HtmlHelper implements NodeVisitor {
private Context context; private Context context;
private String newline; private String newline;
private List<String> refs = new ArrayList<>(); private List<String> refs = new ArrayList<>();
private StringBuilder sb = new StringBuilder(); private StringBuilder sb = new StringBuilder();
private Pattern pattern = Pattern.compile("([http|https]+://[\\w\\S(\\.|:|/)]+)");
private HtmlHelper(Context context, boolean reply) { private HtmlHelper(Context context, boolean reply) {
this.context = context; this.context = context;
@ -47,9 +50,18 @@ public class HtmlHelper implements NodeVisitor {
public void head(Node node, int depth) { public void head(Node node, int depth) {
String name = node.nodeName(); String name = node.nodeName();
if (node instanceof TextNode) if (node instanceof TextNode) {
sb.append(((TextNode) node).text()); String text = ((TextNode) node).text();
else if (name.equals("li")) Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
String ref = matcher.group();
if (!refs.contains(ref))
refs.add(ref);
String alt = context.getString(R.string.title_link);
text = text.replace(ref, String.format("<a href=\"%s\">%s [%d]</a>", ref, alt, refs.size()));
}
sb.append(text);
} else if (name.equals("li"))
sb.append(newline).append(" * "); sb.append(newline).append(" * ");
else if (name.equals("dt")) else if (name.equals("dt"))
sb.append(" "); sb.append(" ");