Skip to content

Commit

Permalink
add rudimentary emote autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
still-flow authored and samfundev committed May 28, 2023
1 parent 43d155b commit db32f41
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/src/main/java/com/perflyst/twire/fragments/ChatFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ private void setupChatInput() {
});

final Pattern mentionPattern = Pattern.compile("@(\\w+)$");
final Pattern emotePattern = Pattern.compile(":(\\w+)$");
mSendText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
Expand All @@ -697,6 +698,29 @@ public void afterTextChanged(Editable editable) {
} else {
setMentionSuggestions(new ArrayList<>());
}


mInputMatcher = emotePattern.matcher(getSendText());

String emoteName = null;
while (mInputMatcher.find()) {
emoteName = mInputMatcher.group(1);
}

if (emoteName != null && !emoteName.isEmpty() && customEmotes != null) {
List<String> result = new ArrayList<>();

for (Emote emote : customEmotes) {
if (emote.getKeyword().toLowerCase().matches("\\w*" + emoteName.toLowerCase() + "\\w*") && !result.contains(emote.getKeyword())) {
result.add(emote.getKeyword());
}
}

Collections.sort(result);
setMentionSuggestions(result);
} else {
setMentionSuggestions(new ArrayList<>());
}
}
});

Expand Down

0 comments on commit db32f41

Please sign in to comment.