linkedin / Spyglass

A library for mentions on Android
Apache License 2.0
387 stars 128 forks source link

change the displayed text with ID before saving it #122

Closed jalalkun closed 3 years ago

jalalkun commented 3 years ago

hello I have my own object with data
Person( id, firstname, lastname )

I want to save it like this: "thanks to @[id] and @[id]"

I'm trying this comment 28

but I don't know that'd ID come from how to convert that id to my own id thanks

nhibner commented 3 years ago

Not sure I understand your question. The ID is just an example of a field that you have in your data. It could be anything you want, the library doesn't care about how your mention data is stored. This is why the library has you implement the Mentionable interface.

So at a high-level, to convert your data to a string that gets displayed:

  1. Create a span class that stores your data and implements the Mentionable interface.
  2. Use Android's spannable text APIs to add your spans to the correct pieces of text.

To convert the string back to your data:

  1. Loop through the mentionable spans in the string, extracting the data.