From 9c3d0e77ac5bc4e87d75d24ebbbea3734f29f746 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Mon, 1 Sep 2014 23:53:11 +0200 Subject: avoid superfluous empty space in trackable goal --- main/src/cgeo/geocaching/utils/HtmlUtils.java | 28 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'main/src/cgeo/geocaching/utils/HtmlUtils.java') diff --git a/main/src/cgeo/geocaching/utils/HtmlUtils.java b/main/src/cgeo/geocaching/utils/HtmlUtils.java index 51c4d6e..e90b70d 100644 --- a/main/src/cgeo/geocaching/utils/HtmlUtils.java +++ b/main/src/cgeo/geocaching/utils/HtmlUtils.java @@ -24,7 +24,7 @@ public final class HtmlUtils { * @param html * @return */ - public static String extractText(CharSequence html) { + public static String extractText(final CharSequence html) { if (StringUtils.isBlank(html)) { return StringUtils.EMPTY; } @@ -32,13 +32,13 @@ public final class HtmlUtils { // recognize images in textview HTML contents if (html instanceof Spanned) { - Spanned text = (Spanned) html; - Object[] styles = text.getSpans(0, text.length(), Object.class); - ArrayList> removals = new ArrayList<>(); - for (Object style : styles) { + final Spanned text = (Spanned) html; + final Object[] styles = text.getSpans(0, text.length(), Object.class); + final ArrayList> removals = new ArrayList<>(); + for (final Object style : styles) { if (style instanceof ImageSpan) { - int start = text.getSpanStart(style); - int end = text.getSpanEnd(style); + final int start = text.getSpanStart(style); + final int end = text.getSpanEnd(style); removals.add(Pair.of(start, end)); } } @@ -47,12 +47,12 @@ public final class HtmlUtils { Collections.sort(removals, new Comparator>() { @Override - public int compare(Pair lhs, Pair rhs) { + public int compare(final Pair lhs, final Pair rhs) { return rhs.getRight().compareTo(lhs.getRight()); } }); result = text.toString(); - for (Pair removal : removals) { + for (final Pair removal : removals) { result = result.substring(0, removal.getLeft()) + result.substring(removal.getRight()); } } @@ -60,4 +60,14 @@ public final class HtmlUtils { // now that images are gone, do a normal html to text conversion return Html.fromHtml(result).toString().trim(); } + + public static String removeExtraParagraph(final String html) { + if (StringUtils.startsWith(html, "

") && StringUtils.endsWith(html, "

")) { + final String paragraph = StringUtils.substring(html, "

".length(), html.length() - "

".length()).trim(); + if (extractText(paragraph).equals(paragraph)) { + return paragraph; + } + } + return html; + } } -- cgit v1.1