UI Listener - Message Rendering
mesibo shows every chat of the chat list, and every message of a chat, as a row of a list. An app can change how these rows look while mesibo keeps all their behavior: a different layout for incoming or outgoing messages, more information on a row, its own kinds of messages, or different chat list rows. The app can change a few views of mesibo’s rows, or show its own rows instead.
These lists are a RecyclerView on Android and a UITableView on iOS, so the row callbacks work
with view holders (Android) and cells (iOS).
Rows
The row callbacks get a MesiboRow: the data and the views of the row. The app casts it to the
class of the row, depending on the screen:
MesiboUserListRow: a row of the chat list (profile,message, and itsname,subtitle,timestampandimageviews).MesiboMessageRow: a row of a chat (message, and itsmessageText,title,subtitle,name,timestamp,image,statusandreplyViewviews).
if (MesiboUI.SCREEN_USERLIST == screen.type) {
MesiboUI.MesiboUserListRow userListRow = (MesiboUI.MesiboUserListRow) row;
} else if (MesiboUI.SCREEN_MESSAGES == screen.type) {
MesiboUI.MesiboMessageRow messageRow = (MesiboUI.MesiboMessageRow) row;
}
if (MesiboUI.SCREEN_USERLIST == screen.type) {
val userListRow = row as MesiboUI.MesiboUserListRow
} else if (MesiboUI.SCREEN_MESSAGES == screen.type) {
val messageRow = row as MesiboUI.MesiboMessageRow
}
if Int32(screen.type) == MESIBO_SCREEN_USERLIST, let userListRow = row as? MesiboUserListRow {
// ...
} else if Int32(screen.type) == MESIBO_SCREEN_MESSAGES, let messageRow = row as? MesiboMessageRow {
// ...
}
if (MESIBO_SCREEN_USERLIST == screen.type) {
MesiboUserListRow *userListRow = (MesiboUserListRow *)row;
} else if (MESIBO_SCREEN_MESSAGES == screen.type) {
MesiboMessageRow *messageRow = (MesiboMessageRow *)row;
}
A chat has three kinds of rows:
- Incoming messages, received from others, on the left by default.
- Outgoing messages, sent by the user, on the right by default, with their status.
- Information rows that are not messages: dates, missed calls and notices, in the center.
When the app shows its own rows, it handles each kind of row it replaces; not every row is a text or media message.
MesiboUI_onGetCustomRow
Called before a row is created. The app returns its own row, or null (nil) for mesibo’s row. On
Android, the row is a view holder derived from MesiboRecycleViewHolder; on iOS, a cell derived
from MesiboCell, which sizes itself with Auto Layout.
For example, the app’s own row for incoming text messages, with every other row left to mesibo:
public class IncomingTextHolder extends MesiboRecycleViewHolder {
TextView text;
public IncomingTextHolder(View v) {
super(v);
text = v.findViewById(R.id.my_message_text);
}
}
@Override
public MesiboRecycleViewHolder MesiboUI_onGetCustomRow(MesiboUI.MesiboScreen screen, MesiboUI.MesiboRow row) {
if (MesiboUI.SCREEN_MESSAGES != screen.type || null == row.message
|| !row.message.isIncoming() || row.message.hasFile())
return null; // the default row
View v = LayoutInflater.from(screen.parent).inflate(R.layout.my_incoming_text, row.viewGroup, false);
IncomingTextHolder holder = new IncomingTextHolder(v);
holder.text.setText(row.message.message);
return holder;
}
class IncomingTextHolder(v: View) : MesiboRecycleViewHolder(v) {
val text: TextView = v.findViewById(R.id.my_message_text)
}
override fun MesiboUI_onGetCustomRow(screen: MesiboUI.MesiboScreen, row: MesiboUI.MesiboRow): MesiboRecycleViewHolder? {
val message = row.message
if (MesiboUI.SCREEN_MESSAGES != screen.type || null == message
|| !message.isIncoming || message.hasFile())
return null // the default row
val v = LayoutInflater.from(screen.parent).inflate(R.layout.my_incoming_text, row.viewGroup, false)
val holder = IncomingTextHolder(v)
holder.text.text = message.message
return holder
}
class IncomingTextCell: MesiboCell {
let text = UILabel()
}
func MesiboUI_onGetCustomRow(screen: MesiboScreen, row: MesiboRow) -> MesiboCell? {
guard Int32(screen.type) == MESIBO_SCREEN_MESSAGES, let message = row.message,
message.isIncoming(), !message.hasFile() else {
return nil // the default row
}
let cell = IncomingTextCell(style: .default, reuseIdentifier: nil)
cell.text.numberOfLines = 0
cell.text.text = message.message
// add cell.text to cell.contentView with Auto Layout constraints
return cell
}
@interface IncomingTextCell : MesiboCell
@property (nonatomic, strong) UILabel *text;
@end
- (MesiboCell *)MesiboUI_onGetCustomRow:(MesiboScreen *)screen row:(MesiboRow *)row {
if (MESIBO_SCREEN_MESSAGES != screen.type || !row.message
|| ![row.message isIncoming] || [row.message hasFile])
return nil; // the default row
IncomingTextCell *cell = [[IncomingTextCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.text = [UILabel new];
cell.text.numberOfLines = 0;
cell.text.text = row.message.message;
// add cell.text to cell.contentView with Auto Layout constraints
return cell;
}
MesiboUI_onUpdateRow
The app does not need to replace a row to change how it looks. MesiboUI_onUpdateRow() is called
after mesibo fills one of its rows, and the app changes its views: text colors, backgrounds, fonts.
last is true for the last row of the list.
The message is row.message. It is a real message, or an information row (a date, a missed call, a
notice): the app checks with message.isMessage() or message.isDate() before changing the row.
@Override
public void MesiboUI_onUpdateRow(MesiboUI.MesiboScreen screen, MesiboUI.MesiboRow row, boolean last) {
if (MesiboUI.SCREEN_USERLIST == screen.type) {
MesiboUI.MesiboUserListRow r = (MesiboUI.MesiboUserListRow) row;
r.name.setTextColor(0xFF00868B);
}
}
override fun MesiboUI_onUpdateRow(screen: MesiboUI.MesiboScreen, row: MesiboUI.MesiboRow, last: Boolean) {
if (MesiboUI.SCREEN_USERLIST == screen.type) {
(row as MesiboUI.MesiboUserListRow).name?.setTextColor(0xFF00868B.toInt())
}
}
func MesiboUI_onUpdateRow(screen: MesiboScreen, row: MesiboRow, last: Bool) {
if Int32(screen.type) == MESIBO_SCREEN_USERLIST, let r = row as? MesiboUserListRow {
r.name?.textColor = UIColor(red: 0, green: 0.53, blue: 0.55, alpha: 1)
}
}
- (void)MesiboUI_onUpdateRow:(MesiboScreen *)screen row:(MesiboRow *)row last:(BOOL)last {
if (MESIBO_SCREEN_USERLIST == screen.type)
((MesiboUserListRow *)row).name.textColor = [UIColor colorWithRed:0 green:0.53 blue:0.55 alpha:1];
}
Which one to use
| Callback | For |
|---|---|
MesiboUI_onGetCustomRow | the app’s own row, with its own layout |
MesiboUI_onUpdateRow | changing a few views of mesibo’s row |
The app can use both: replace some rows, and change the look of the others.
Custom rows are not available in Flutter.