diff --git a/app/src/main/java/com/nextcloud/talk/callbacks/MentionAutocompleteCallback.java b/app/src/main/java/com/nextcloud/talk/callbacks/MentionAutocompleteCallback.java index 4c4ea0413..2d1283301 100644 --- a/app/src/main/java/com/nextcloud/talk/callbacks/MentionAutocompleteCallback.java +++ b/app/src/main/java/com/nextcloud/talk/callbacks/MentionAutocompleteCallback.java @@ -60,12 +60,10 @@ public class MentionAutocompleteCallback implements AutocompleteCallback 1) { - // Do absolutely nothing + if (span == null || span.length == 0) { + return null; + } else { + QuerySpan sp = span[0]; + return new TextSpan(text.getSpanStart(sp), text.getSpanEnd(sp)); } - QuerySpan sp = span[0]; - return new int[]{text.getSpanStart(sp), text.getSpanEnd(sp)}; } - private int[] checkText(Spannable text, int cursorPos) { + private TextSpan checkText(Spannable text, int cursorPos) { if (text.length() == 0) { return null; } - int[] span = new int[2]; Pattern pattern = Pattern.compile("@+\\S*", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); Matcher matcher = pattern.matcher(text); while (matcher.find()) { if (cursorPos >= matcher.start() && cursorPos <= matcher.end()) { - span[0] = matcher.start(); - span[1] = matcher.end(); if (text.subSequence(matcher.start(), matcher.end()).charAt(0) == character) { - return span; + return new TextSpan(matcher.start(), matcher.end()); } } } @@ -69,11 +66,29 @@ public class MagicCharPolicy implements AutocompletePolicy { return null; } + public static class TextSpan { + int start; + int end; + + public TextSpan(int start, int end) { + this.start = start; + this.end = end; + } + + public int getStart() { + return start; + } + + public int getEnd() { + return end; + } + } + @Override public boolean shouldShowPopup(Spannable text, int cursorPos) { - int[] show = checkText(text, cursorPos); + TextSpan show = checkText(text, cursorPos); if (show != null) { - text.setSpan(new QuerySpan(), show[0], show[1], Spanned.SPAN_INCLUSIVE_INCLUSIVE); + text.setSpan(new QuerySpan(), show.getStart(), show.getEnd(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); return true; } return false;