Git Product home page Git Product logo

mentions's Introduction

Mentions

Circle CI codecov.io Codacy Badge

This library provides a simple and customizable away to setup @ mentions on any EditText. Here's all it takes to get started.

Usage Examples

We provide a builder through which you can setup different options for @ mentions. Here is an example:

EditText commentField = findViewById(activity, R.id.my_edit_text);

Mentions mentions = new Mentions.Builder(activity, commentField)
    .highlightColor(R.color.blue)
    .maxCharacters(5)
    .queryListener(new QueryListener() {
        void onQueryReceived(final String query) {
           // Get and display results for query.
        }
    })
    .suggestionsListener(new SuggestionsListener() {
        void displaySuggestions(final boolean display) {
          // Hint that can be used to show or hide your list of @ mentions".
        }
    })
    .build();

The library allows you to display suggestions as you see fit. Here is an example in the sample app Display Suggestions. When the user chooses a suggestion to @ mention, show it in the EditText view by:

final Mention mention = new Mention();
mention.setMentionName(user.getFullName());
mentions.insertMention(mention);

Inserting the mention will highlight it in the EditText view and the library will keep track of its offset. As the user types more text in the view, the library will update the offset and maintain the highlighting for you.

If you need to get the mentions currently shown in your EditText view (to send to your API or do further processing):

final List<Mentionable> mentions = mentions.getInsertedMentions();
for (Mentionable mention : mentions) {
    println("Position of 1st Character in EditText " + mention.getMentionOffset());
    println("Text " + mention.getMentionName())
    println("Length " + mention.getMentionLength());
}

Builder methods

highlightColor(int color)

  • After a mention is chosen from a suggestions list, it is inserted into the EditText view and the mention is highlighted with a default color of orange. You may change the highlight color by providing a color resource id.

maxCharacters(int maxCharacters)

  • The user may type @ followed by some letters. You may want to set a threshold to only consider certain number of characters after the @ symbol as valid search queries. The default value 13 characters. You may configure to any number of characters.

suggestionsListener(SuggestionsListener suggestionsListener)

  • The SuggestionsListener interface has the method displaySuggestions(final boolean display). It will inform you on whether to show or hide a suggestions drop down.

queryListener(QueryListener queryListener)

  • The QueryListener interface has the method onQueryReceived(final String query). The library will provide you with a valid query that you could use to filter and search for mentions. For example, if the user types @Tes, the callback will receive "Tes" as the query.

Adding to your application

Simply add Mentions as a gradle dependency. Distribution is done through jitpack.io.

See https://jitpack.io/com/github/percolate/mentions/ for instructions

Running Tests

The library contains unit tests written in Kotlin with Mockito and Robolectric.

To run the tests and generate a coverage, please execute the command

gradlew clean coverage

License

Open source. Distributed under the BSD 3 license. See LICENSE.txt for details.

mentions's People

Contributors

augustmgodin avatar brentwatson avatar lra avatar msya avatar tabuchid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mentions's Issues

Show all user list when user press @ .

Hello
Thanks for sharing nice video.

Want to show all user list when user press @ and after select any user want to show user name with @UserName .

Please let me know solution for that.

Add custom pattern

Hi,

The pattern to trigger the mention is hardcoded '@'. But this does not totally fit my requirement. I will pull request a version where the pattern can be defined in the builder.

I need to analyse the side effect first.

Load mentions in edit text

Suppose a text I load in edit text has mentions. Is there a way to load the mentions in the edit text so that the users can edit the text and can remove or add more mentions.

Support for #Tags

It would be nice if this Library could support tags (#) in a similar fashion to @Mentions

how to insert Multiple Mention at a time

I have a list of 5 users I want to insert them into edit text but I am not able to insert them.

                    mention.setMentionName(user.getFIRSTNAME());
                    mention.setMentionId(user.getPERSON_ID());
                   mentions.insertMention(mention);

Detect mentions for the receiving client

Hi, how can we highlight mentions for client who is not sending a message. For ex. The sender can list mentions through edittext but receiving client do not have the same mechanism to extract mentions through Edittext. It will receive plain text, so any suggestions how could we detect mentions in text body to highlight mentions in chat for receivers. Thanks for the library.

Port to JavaFX

I've searched high and low for a mentions library for JavaFX, Java's UI library, but there isn't one.

How hard would it be to port this library to JavaFX?

Screen shots

The readme should include screenshots of what the library does in action.

Issue in getInsertedMentions() method

Hi, While using your library i encountered a flaw in this scenario

When user scrolls backwards and adds new mention in between of text, on send button when we get inserted mentions to process, you are giving mentions in the order of their insertions (the mention added in between later is coming at last) - that's not right for post-processing, you should give list of mentions in the order of their appearance in the edittext.

Why post-processing is important: because in it programmers may process insertions like for example constructing them in HTML format.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.