2

I want to refer to this question , on how to implement the mention feature, but for android.

I want to know how it goes in the database specifically .

Community
  • 1
  • 1
Ran
  • 145
  • 2
  • 11
  • Use the open source library by Linkedin if you don't want to dig how it works https://engineering.linkedin.com/android/open-sourcing-spyglass-flexible-library-implementing-mentions-android – Irfan Raza Jul 09 '18 at 09:33

2 Answers2

3

I guess the answer was already provided the old post,

Listen to the input. When the user types an @, followed by a character, make a call to an url on your server (/user/lookup/?username=joe for example) that routes to a view which looks up up users beginning with joe. Return it as json and display it in a dropdown.

To make is much simpler, you need to use @ as a keyword that is going to be used for understanding the beginning of a user name .

e.g. user types the following message

... was with @nour at NYC

in Java you can detect the @ using regular expression,

boolean foundMatch = false;
Pattern regex = Pattern.compile("\\b(?:@)\\b");
Matcher regexMatcher = regex.matcher(subjectString);
foundMatch = regexMatcher.find();

This will match if the input string has a @ keyword

Now once you get the @ keyword take all character after @ till you get a white space. In this example nour should be the result since its starts after @ and ends before a white space.

In the server part you can the the recognized name as a USER_NAME,

SELECT * FROM USERS WHERE USER_NAME = "nour";

Of-course the username needs to the unique.

Hope it helps.

Prokash Sarkar
  • 11,723
  • 1
  • 37
  • 50
  • Please can you take a look at this . https://zunostudios.com/blog/development/176-how-to-implment-hashtags-and-callouts-in-android , can you please tell me what to change to make it from database rather than simple array. shall I have the same classes provided or can I make it simpler – Ran Aug 09 '15 at 09:59
  • I ran their project and no this is not the thing I want to do .. :( still lost . any tutorials ? – Ran Aug 09 '15 at 10:14
  • I need your help like this .. http://stackoverflow.com/questions/25765364/parse-auto-suggestion-query-results-based-on-app-data I wanted to add a comment on his question, but I don't have enough reputation :( – Ran Aug 09 '15 at 10:45
1

It's mainly done by AutoCompleteTextView and handling the key events. I can't write such a code. I can give you simple main ideas. You listen to the user clicks on the keyboard by overrinding onKeyUp() method

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_AT:
        // @ is clicked
        // get the usernames
        return true;
    default:
        return super.onKeyUp(keyCode, event);
    }
}

now you should start getting usernames from the database, put them inside the AutoCompleteTextView adapter to be filtered according to the user entries and when the user selects a friend or someone to be mentioned "or many" you add them to an ArrayList and push a notification to them.

SaNtoRiaN
  • 2,212
  • 2
  • 15
  • 25