Skip to main content
Version: v6

Formatting

You can customize how certain pieces of information are formatted by the SDK.

Formatting Dates

Overriding the DateFormatter allows you to change the way dates are formatted in the application:

ChatUI.dateFormatter = object: DateFormatter {
private val dateFormat: DateFormat = SimpleDateFormat("dd/MM/yyyy")
private val timeFormat: DateFormat = SimpleDateFormat("HH:mm")

override fun formatDate(date: Date?): String {
date ?: return ""
return dateFormat.format(date)
}

override fun formatTime(date: Date?): String {
date ?: return ""
return timeFormat.format(date)
}
}
ChatUI.setDateFormatter(new DateFormatter() {
private final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
private final DateFormat timeFormat = new SimpleDateFormat("HH:mm");

public String formatDate(Date date) {
// Provide a way to format Date
return dateFormat.format(date);
}

public String formatTime(Date date) {
// Provide a way to format Time
return timeFormat.format(date);
}
});

Formatting Channel Names

You can customize the way channel names are formatted by overriding the default ChannelNameFormatter:

ChatUI.channelNameFormatter = ChannelNameFormatter { channel, currentUser ->
channel.name
}
ChatUI.setChannelNameFormatter((channel, currentUser) -> channel.getName());

Markdown

The SDK provides a standalone Markdown module stream-chat-android-markdown-transformer that contains MarkdownTextTransformer which is an implementation of ChatMessageTextTransformer. It uses the Markwon library internally.

ChatUI.messageTextTransformer = MarkdownTextTransformer(context)
ChatUI.setMessageTextTransformer(new MarkdownTextTransformer(context));

If you use MarkdownTextTransformer, don't use android:autoLink attribute because it'll break the markdown Linkify implementation.

Then the SDK will parse Markdown automatically:

Markdown Input in the Message ComposerMessage with Markdown in the Message List
Markdown Input in the Message ComposerMarkdown Message in the Message List

Did you find this page helpful?