Skip to content

Customizing chat bubbles

HentaiIsPower edited this page May 18, 2016 · 1 revision

MonkeyAdapter has methods that you can override to customize the views that are displayed in the RecyclerView.

Binding View Holders

The method bindCommonMonkeyHolder is called everytime a MonkeyItem is bound to a MonkeyHolder regardless of the type. The default implementation makes the view show the message's date and status. You can override this method to customize every MonkeyHolder. For specific types of messages you can override the following methods:

  • bindMonkeyTextHolder Binds a MonkeyHolder with a message of type text.
  • bindMonkeyPhotoHolder Binds a MonkeyHolder with a message of type photo.
  • bindMonkeyAudioHolder Binds a MonkeyHolder with a message of type audio.

Creating View Holders

Sometimes manipulating the ViewHolder at binding may not be enough for your customization needs. Maybe you want a completely different layout, or you want to use your own custom MonkeyHolder subclass. You can do all of that by overriding any of the following methods that create MonkeyHolder objects:

  • createMonkeyTextHolder Creates a new MonkeyHolder object for messages of type text.
  • createMonkeyAudioHolder Creates a new MonkeyHolder object for messages of type audio.
  • createMonkeyPhotoHolder Creates a new MonkeyHolder object for messages of type photo.

Everytime the RecyclerView needs a new ViewHolder it calls any of these methods depending on the type. The only constraint of overriding any of these is that you must return a ViewHolder that extends MonkeyHolder.

Extending MonkeyHolder

MonkeyAdapter calls a few MonkeyHolder methods to display data that is common to all types. By overriding the following methods you can create a custom MonkeyHolder subclass that displays data the way you want it:

  • updateReadStatus method called to show the user whether this message has been read or not.
  • updateSendingStatus method called to show the user whether this message still in route to server, or it has already been successfully delivered.
  • setSenderName method called to show the user the name of the sender of this message.
  • setMessageDate method called to show the user the date in which this message was sent.

By extending MonkeyHolder you can easily control the way the user percieves data about the messages that he/she receives.

Clone this wiki locally