Date and Time
Table of contents
Overview
In the chat there are 2 main time related elements:
- The dates notifications in the chat - grouping elements of the same date messages
- The messages timestamp - usually appears arround the message bubble
Datestamp display
In order to change default datestamp display:
- Implement
DatesampFormatFactory
-
Pass that implementation to the ConversationSettings using
ConversationSettings.datestamp
method.class MyDatestampFactory : DatesampFormatFactory { override fun formatDate(datestamp:Long):String{ return ... } } val settings = ConversationSettings() .datestamp(true, myDatestampFactory) //... set more settings ChatController.Builder(context).apply{ //... do some initiations conversationSettings(settings) }
Datestamp display factories
The SDK provides 2 predefined factories:
- SimpleDatestampFormatFactory
Uses the pattern "EEE, d MMM, yyyy"
to display dates
- FriendlyDatestampFormatFactory default
Provides more common display, using today
, yesterday
phrases.
Disabling Datestamp display
The SDK enables to disable datestamp headers display altogther, as follows:
// deactivate datestamps
val settings = ConversationSettings()
.datestamp(false)
//... set more settings
ChatController.Builder(context).apply{
//... do some initiations
conversationSettings(settings)
}
Timestamp display
There are 2 ways of setting a new look to the timestamp display.
-
Configure by chat settings
Using
ConversationSettings.timestampConfig
method.val settings = ConversationSttongs() .timestampConfig(enable, TimestampStyle( time_pattern, text_size, text_color, font_typeface )) //... set more settings ChatController.Builder(context).apply{ //... do some initiations conversationSettings(setting) }
-
Overriding configure/customize
Overriding the configure and/or customize methods and set the desired look for the timestamp on
ChatUIProvider.chatElementsUIProvider.
incomingUIProvider and/orChatUIProvider.chatElementsUIProvider.
outgoingUIProvider.val chatUI = ChatUIProvider(context).apply { this.chatElementsUIProvider.incomingUIProvider.configure = { adapter -> this.setTimestampStyle(TimestampStyle(time_pattern, text_size, text_color)) } adapter } this.chatElementsUIProvider.outgoingUIProvider.configure = { adapter -> this.setTimestampStyle(TimestampStyle("hh:mm aa", 10, Color.parseColor("#aeaeae"))) } adapter } } ChatController.Builder(context).apply{ //... do some initiations chatUIProvider(chatUI) }