UI Listener - Screen Setup
Each screen of the messaging UI, the chat list, a chat or a profile, can be extended by the app with its own buttons and menu items, for example voice and video call buttons in a chat or a Settings item in the chat list. The app adds them when mesibo opens the screen, and can change them later while the screen is open.
Screen Initialization
Whenever mesibo opens a screen, it first calls MesiboUI_onInitScreen() with an object that
describes the screen, its screen object. Here the app adds its own buttons and menu items, and
changes the title bar.
The return value decides whether mesibo calls the other callbacks for this screen:
true(YES): mesibo callsMesiboUI_onUpdateScreen,MesiboUI_onAction,MesiboUI_onGetCustomRowandMesiboUI_onUpdateRowfor this screen.false(NO): mesibo calls none of them for this screen. The screen then works on its own, and saves a call for every row it shows.
The answer applies to this screen only. mesibo calls MesiboUI_onInitScreen() for every screen it
opens, each time it opens, so each screen can answer differently. When the app does not implement
MesiboUI_onInitScreen(), mesibo calls all the callbacks for every screen.
Screen types
screen.type tells which screen it is. The app casts the screen object to the class of that screen
to reach its own fields.
| Type (Android / iOS) | Screen | Class |
|---|---|---|
SCREEN_USERLIST / MESIBO_SCREEN_USERLIST | The chat list and contact pickers | MesiboUserListScreen |
SCREEN_MESSAGES / MESIBO_SCREEN_MESSAGES | A chat | MesiboMessageScreen |
SCREEN_PROFILE / MESIBO_SCREEN_PROFILE | The profile of a user or group | MesiboProfileScreen |
SCREEN_PROFILE_POPUP / MESIBO_SCREEN_PROFILE_POPUP | The profile popup of the chat list | MesiboScreen |
SCREEN_GENERIC / MESIBO_SCREEN_GENERIC | Any other screen | MesiboScreen |
Every screen object has these fields:
| Field | What it is | Android | iOS |
|---|---|---|---|
type | Which screen, see the table above | int | int |
parent | The activity or view controller of the screen. The app shows its own screens from it. | Context | UIViewController |
profile | The user profile or group profile of the screen, if any: the chat’s user or group, the profile shown | MesiboProfile | MesiboProfile |
title, subtitle | The title and subtitle in the title bar | TextView | UILabel |
titleArea | The whole title area of the title bar, including the picture | View | UIView |
menu | The items of the title bar, see below | Menu | NSMutableArray<MesiboMenuItem *> |
buttons | The buttons of the navigation bar, see below | - | NSMutableArray<UIBarButtonItem *> |
toolbar | The toolbar of the screen | Toolbar | - |
table | The list of the screen: chats, messages or contacts | RecyclerView | UITableView |
Adding buttons and menu items
The title bar of the chat list and of a chat has buttons, and a More button that opens a list of more actions. The app adds its own to both:
- Android:
screen.menuis theMenuof the screen’s toolbar, the standard Android toolbar menu. Each item the app adds shows as an icon in the toolbar when it has room and the item asks for it (setShowAsAction), otherwise in the toolbar’s overflow menu (the three dots). The app sets a click listener on each item. - iOS:
screen.buttonsare the buttons of the navigation bar (UIBarButtonItem), andscreen.menuare the items of the navigation bar’s More button (⋯), asMesiboMenuItems: a title, an image and the code to run when it is tapped.
For example, a Settings item in the More menu of the chat list:
@Override
public boolean MesiboUI_onInitScreen(MesiboUI.MesiboScreen screen) {
if (MesiboUI.SCREEN_USERLIST == screen.type) {
MenuItem settings = screen.menu.add(Menu.NONE, R.id.action_settings, 0, "Settings");
settings.setOnMenuItemClickListener(item -> {
openSettings(screen.parent);
return true;
});
}
return true;
}
override fun MesiboUI_onInitScreen(screen: MesiboUI.MesiboScreen): Boolean {
if (MesiboUI.SCREEN_USERLIST == screen.type) {
val settings = screen.menu.add(Menu.NONE, R.id.action_settings, 0, "Settings")
settings.setOnMenuItemClickListener {
openSettings(screen.parent)
true
}
}
return true
}
func MesiboUI_onInitScreen(screen: MesiboScreen) -> Bool {
if Int32(screen.type) == MESIBO_SCREEN_USERLIST {
let settings = MesiboMenuItem(title: "Settings", image: UIImage(systemName: "gearshape"),
identifier: "settings") { [weak screen] _ in
if let parent = screen?.parent {
self.openSettings(parent)
}
}
screen.menu.add(settings)
}
return true
}
- (BOOL)MesiboUI_onInitScreen:(MesiboScreen *)screen {
if (MESIBO_SCREEN_USERLIST == screen.type) {
__weak MesiboScreen *s = screen;
[screen.menu addObject:[MesiboMenuItem itemWithTitle:@"Settings" image:[UIImage systemImageNamed:@"gearshape"]
identifier:@"settings" handler:^(MesiboMenuItem *item) {
if (s.parent)
[self openSettings:s.parent];
}]];
}
return YES;
}
The profile screen and the profile popup
The profile screen (SCREEN_PROFILE) shows a user profile or a group profile. It has two places for
the app’s actions:
screen.actions: the round buttons under the name, after mesibo’s Message button, for example voice and video call buttons. On Android it is aMenu; on iOS, a list ofMesiboMenuItems.screen.menu: the items of the More button of the title bar, after mesibo’s Encryption item. Encryption shows only for a user profile, and only while end-to-end encryption is on; groups are not end-to-end encrypted.
The profile popup (SCREEN_PROFILE_POPUP) opens when the user taps a picture in the chat list. It
shows the picture with buttons under it. Each item of screen.menu is one of these buttons, between
mesibo’s Message and Info buttons. To hide those two, the app removes them by their
identifiers: MENU_POPUP_MESSAGE and MENU_POPUP_INFO on Android, MESIBO_MENU_POPUP_MESSAGE and
MESIBO_MENU_POPUP_INFO on iOS.
Flutter
In Flutter, the app gives its menu items to MesiboUI().setMenu(), with a listener for their taps.
The screen of an item says on which screen it shows; button says whether it is a button or an
item of the More menu:
MesiboUI.SCREEN_MESSAGES(the default) orSCREEN_USERLIST:button: truefor a title bar button,falsefor the More menu.MesiboUI.SCREEN_PROFILE:button: truefor a button under the name,falsefor the More menu.MesiboUI.SCREEN_PROFILE_POPUP: a button of the popup.
The built-in MENU_VOICECALL and MENU_VIDEOCALL items start a call, or return to the call in
progress:
List<MesiboUIMenuItem> menu = MesiboUI.defaultMenu(); // call buttons in chats
for (int screen in [MesiboUI.SCREEN_PROFILE, MesiboUI.SCREEN_PROFILE_POPUP]) {
menu.add(MesiboUIMenuItem(id: MesiboUI.MENU_VOICECALL, title: "Voice", screen: screen));
menu.add(MesiboUIMenuItem(id: MesiboUI.MENU_VIDEOCALL, title: "Video", screen: screen));
}
menu.add(MesiboUIMenuItem(id: "settings", title: "Settings", screen: MesiboUI.SCREEN_USERLIST, button: false));
MesiboUI().setMenu(menu, this); // this implements MesiboUIMenuListener: MesiboUI_onMenuItem
Message Screen Controls
The screen object of a chat (MesiboMessageScreen) has controls, the views of the message input
at the bottom of the chat: the text field (editText), the attach button (attachButton), the
camera button (cameraButton) and the send button (sendButton). The app can restyle these views.
To turn features of the chat on or off, the app uses the configuration instead, for example:
| Feature | Option |
|---|---|
| The attach button and the attachment sheet | attachments.enabled |
| One tile of the sheet (gallery, camera, video, document, audio, location) | the tile’s enabled, attachments.getTile() |
| The camera button | the Camera tile’s enabled |
| Voice messages (the microphone) | voiceMessages.enabled |
| Message options | messageOptions.enabled |
| Reply, forward, edit, copy, star, keep, message info | messages.enableReply, enableForward, enableEdit, enableCopy, enableStar, enableKeep, messageInfo.enabled |
See UI Configuration for all of them.
Updating Screens
Sometimes the app needs to change a screen after it was created. For example, when a call starts, the voice and video buttons of the open chats should become a Call in progress button that brings the call back.
The app calls MesiboUI.updateScreens(). mesibo then calls MesiboUI_onUpdateScreen() for every
open chat list and chat, with the same screen object as MesiboUI_onInitScreen(), and the app
changes the buttons and menu items it added. The app needs this callback only if it calls
updateScreens().
The calls module tells the app when a call starts or ends, the moment to update the screens:
MesiboCall.getInstance().addCallMonitorListener(new MesiboCall.CallMonitorListener() {
@Override
public void MesiboCall_onCallStarted(MesiboProfile profile, boolean incoming, boolean video) {
MesiboUI.updateScreens();
}
@Override
public void MesiboCall_onCallEnded(MesiboProfile profile, boolean incoming, boolean video) {
MesiboUI.updateScreens();
}
});
MesiboCall.getInstance().addCallMonitorListener(object : MesiboCall.CallMonitorListener {
override fun MesiboCall_onCallStarted(profile: MesiboProfile, incoming: Boolean, video: Boolean) {
MesiboUI.updateScreens()
}
override fun MesiboCall_onCallEnded(profile: MesiboProfile, incoming: Boolean, video: Boolean) {
MesiboUI.updateScreens()
}
})
// self implements MesiboCallMonitorListener
MesiboCall.getInstance().addCallMonitorListener(self)
func MesiboCall_onCallStarted(profile: MesiboProfile, incoming: Bool, video: Bool) {
MesiboUI.updateScreens()
}
func MesiboCall_onCallEnded(profile: MesiboProfile, incoming: Bool, video: Bool) {
MesiboUI.updateScreens()
}
// self implements MesiboCallMonitorListener
[MesiboCallInstance addCallMonitorListener:self];
- (void)MesiboCall_onCallStarted:(MesiboProfile *)profile incoming:(BOOL)incoming video:(BOOL)video {
[MesiboUI updateScreens];
}
- (void)MesiboCall_onCallEnded:(MesiboProfile *)profile incoming:(BOOL)incoming video:(BOOL)video {
[MesiboUI updateScreens];
}
Then, in MesiboUI_onUpdateScreen(), the app shows or hides its call buttons. The sample Messenger
apps do exactly this.