hanggrian / socialview

Android TextView and EditText with hashtag, mention, and hyperlink support
http://hanggrian.com/socialview/
Apache License 2.0
333 stars 81 forks source link

Only colorize valid mentions #52

Open vanyasem opened 5 years ago

vanyasem commented 5 years ago

Some mentions can be invalid. For example, Telegram only highlights mentions that are in fact valid and existing users.

A simple solution for that would be to have an option to disable auto-coloring, so that I can check for mention validity in a text-watcher and only call colorize() if that mention is in fact valid

vanyasem commented 5 years ago

I've settled with a hack that calls setMentionColor() with the default text color upon creation, and calls setMentionColor() with the accent color once again (overriding the first value) upon detecting a valid mention

(This works for me because in my case only one mention can be used at a time, see #51)

hanggrian commented 5 years ago

I've seen issues with similar request. While it is absolutely possible to limit the mention colorization, I can't find a solution that we universally can agree is the best one to achieve it.

For example, an extremely easy solution is to keep a list of Mentionable in SocialView, only mentions that are registered in that list will then be colorized. It's not a perfect solution, since app with large user base will suffer.

Another solution is to provide (String) -> Boolean everytime a mention is being detected, only mentions that return true are being colorized. But in my opinion it poses another issue: what about those app that performs this check asynchronously?

Until we can agree for the best solution, this library keeps it as simple as colorizing all mentions. I would hope that there is some kind of error handling if the mentions interacted by users are indeed non-existent.

vanyasem commented 5 years ago

In the mean time, please-please-please, make an option .setAutoColorize(false), so that i can handle mentions colorization myself when i need it by calling .colorize(). It will partially fix the issue for me

v1pu2 commented 5 years ago

Really, I also need to set the color of mention only when it comes in start of word. No need of color while typing email id or any else word, which contains @ in between. Please fix this issue.

mathan1987 commented 3 years ago

@hendraanggrian Any updates or any solution for this issue.