aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator
diff options
context:
space:
mode:
authorscria1000 <91804886+scria1000@users.noreply.github.com>2021-11-25 16:22:32 +0000
committerscria1000 <91804886+scria1000@users.noreply.github.com>2021-11-25 16:22:32 +0000
commite481980480bc5666edd671a06a71078525824bac (patch)
treeb6f889410d7a922717129b2df8941935525de81f /app/src/main/java/ml/docilealligator
parentd1096f1f7648b3e09d4bf3437121c37c96d966e4 (diff)
downloadinfinity-for-reddit-e481980480bc5666edd671a06a71078525824bac.tar
infinity-for-reddit-e481980480bc5666edd671a06a71078525824bac.tar.gz
infinity-for-reddit-e481980480bc5666edd671a06a71078525824bac.tar.bz2
infinity-for-reddit-e481980480bc5666edd671a06a71078525824bac.tar.lz
infinity-for-reddit-e481980480bc5666edd671a06a71078525824bac.tar.xz
infinity-for-reddit-e481980480bc5666edd671a06a71078525824bac.tar.zst
infinity-for-reddit-e481980480bc5666edd671a06a71078525824bac.zip
Check if spoiler was found before setting markdown
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java10
1 files changed, 6 insertions, 4 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java
index 2fd243ac..a83df76a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java
@@ -14,6 +14,7 @@ import org.commonmark.node.HtmlInline;
import org.commonmark.parser.Parser;
import java.util.LinkedHashMap;
+import java.util.Map;
import java.util.Set;
import java.util.Stack;
@@ -55,7 +56,7 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin {
LinkedHashMap<Integer, Integer> spoilers = parse(markdownStringBuilder);
int offset = 2;
- for (var entry : spoilers.entrySet()) {
+ for (Map.Entry<Integer, Integer> entry : spoilers.entrySet()) {
int spoilerStart = entry.getKey() - offset;
int spoilerEnd = entry.getValue() - offset;
@@ -69,7 +70,7 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin {
markdownStringBuilder.setSpan(spoilerSpan, spoilerStart, spoilerEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
offset += 4;
}
-
+
for (CodeSpan codeSpan : codeSpans) {
int spanBeginning = markdownStringBuilder.getSpanStart(codeSpan);
int spanEnd = markdownStringBuilder.getSpanEnd(codeSpan);
@@ -98,8 +99,9 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin {
}
}
}
-
- textView.setText(markdownStringBuilder);
+ if(offset > 2) {
+ textView.setText(markdownStringBuilder);
+ }
}
// Very naive implementation, needs to be improved for efficiency and edge cases