linkedin / Spyglass

A library for mentions on Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Only allow mentions to be added from recycler view.

ianmiddelkamp opened this issue · comments

Hello, I am using the Mentions Edit Text with an outside Recycler View configuration.

An employee name is 'George'. The mentionable interface for the employee class returns 'george'.

As the user types '@george' the adapter for the recycler will gradually filter results. If the user selects george from the recycler, a mention is added (with text color change) and the MentionWatcher onMentionAdded function fires.

This is perfect.

However, if no item in the recyclerview is selected, and the user types space, or ",' then the MentionsEditText will translate '@george' to '@george' (with capital G, github is not showing this capital lol) but the onMentionAdded function does not fire, and the text color does not change.

The first problem is that it capitalizes the first character and the second problem is that the watcher does not fire.

I need help to fix this either one of two ways.

  1. disable the functionality of capitalizing the first character so that the user does not think a mention is added. This will force the user to use the recycler view only to add mentions

or 2) do not capitalize first character, add a mention, fire the onMentionAdded function and change the text color

Any help would be greatly appreciated.

Code below

Here is my Tokenizer config:


  private static final WordTokenizerConfig tokenizerConfig = new WordTokenizerConfig
            .Builder()
            //.setWordBreakChars(",. ")
            .setExplicitChars("@")
            .setThreshold(2)
            .build();

Here is my editor set up:

        chatViewMessage = (MentionsEditText) rootView.findViewById(R.id.edittext_chatbox);
        chatViewMessage.setTokenizer(new WordTokenizer(tokenizerConfig));
        chatViewMessage.setQueryTokenReceiver(this);
        chatViewMessage.setSuggestionsVisibilityManager(this);
        chatViewMessage.addMentionWatcher(mentionWatcher);


Here is the tokenizer getSuggestions function call


    public List<Employee> getSuggestions(QueryToken queryToken) {


        if(queryToken.isExplicit()){

            String prefix = queryToken.getKeywords().toLowerCase();
            List<Employee> suggestions = new ArrayList<>();
            if (Mentionable != null) {
                for (Employee suggestion : Mentionable) {
                    String name = suggestion.getSuggestiblePrimaryText().toLowerCase();


                    if (name.startsWith(prefix)) {
                        suggestions.add(suggestion);
                    }
                }
            }
            return suggestions;
        }else{
            return null;
        }

    }


And finally here is the Mentionable interface for employee class


  @NonNull
    @Override
    public String getTextForDisplayMode(MentionDisplayMode mode) {
        return "@" + FirstName.toLowerCase();
    }

    @NonNull
    @Override
    public MentionDeleteStyle getDeleteStyle() {
        return MentionDeleteStyle.FULL_DELETE;
    }

    @Override
    public int getSuggestibleId() {
        
        return EmployeeId;
    }

    @Override
    public String getSuggestiblePrimaryText() {
        
        return FirstName.toLowerCase();
    }

What is the input type for your EditText? Note that different flags can result in various behaviors (for example, there is a flag that capitalizes the first letter of every word). See: https://developer.android.com/reference/android/text/InputType#TYPE_TEXT_FLAG_CAP_WORDS

Using the sample app included with the library, it does not appear that the library is capitalizing words. It is worth noting, however, that the behavior may differ between keyboards (Google's keyboard is capitalizing the first word that I enter, while AOSP keyboard is not).