Do not show :query completion for possible time entries.
This commit is contained in:
parent
eac9f78dfa
commit
9f5b822e33
1 changed files with 31 additions and 1 deletions
|
@ -46,6 +46,8 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.thoughtcrime.securesms.database.MentionUtil.MENTION_STARTER;
|
||||
|
||||
|
@ -54,6 +56,8 @@ public class ComposeText extends EmojiEditText {
|
|||
private static final char EMOJI_STARTER = ':';
|
||||
private static final long EMOJI_KEYWORD_DELAY = 1500;
|
||||
|
||||
private static final Pattern TIME_PATTERN = Pattern.compile("^[0-9]{1,2}:[0-9]{1,2}$");
|
||||
|
||||
private CharSequence hint;
|
||||
private SpannableString subHint;
|
||||
private MentionRendererDelegate mentionRendererDelegate;
|
||||
|
@ -427,11 +431,37 @@ public class ComposeText extends EmojiEditText {
|
|||
}
|
||||
|
||||
if (delimiterSearchIndex >= 0 && text.charAt(delimiterSearchIndex) == starter) {
|
||||
return delimiterSearchIndex + 1;
|
||||
if (couldBeTimeEntry(text, delimiterSearchIndex)) {
|
||||
return -1;
|
||||
} else {
|
||||
return delimiterSearchIndex + 1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if we think the user may be inputting a time.
|
||||
*/
|
||||
private static boolean couldBeTimeEntry(@NonNull CharSequence text, int startIndex) {
|
||||
if (startIndex <= 0 || startIndex + 1 >= text.length()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int startOfToken = startIndex;
|
||||
while (startOfToken > 0 && !Character.isWhitespace(text.charAt(startOfToken))) {
|
||||
startOfToken--;
|
||||
}
|
||||
startOfToken++;
|
||||
|
||||
int endOfToken = startIndex;
|
||||
while (endOfToken < text.length() && !Character.isWhitespace(text.charAt(endOfToken))) {
|
||||
endOfToken++;
|
||||
}
|
||||
|
||||
return TIME_PATTERN.matcher(text.subSequence(startOfToken, endOfToken)).find();
|
||||
}
|
||||
|
||||
private static class CommitContentListener implements InputConnectionCompat.OnCommitContentListener {
|
||||
|
||||
private static final String TAG = Log.tag(CommitContentListener.class);
|
||||
|
|
Loading…
Add table
Reference in a new issue