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 calls MesiboUI_onUpdateScreen, MesiboUI_onAction, MesiboUI_onGetCustomRow and MesiboUI_onUpdateRow for 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)ScreenClass
SCREEN_USERLIST / MESIBO_SCREEN_USERLISTThe chat list and contact pickersMesiboUserListScreen
SCREEN_MESSAGES / MESIBO_SCREEN_MESSAGESA chatMesiboMessageScreen
SCREEN_PROFILE / MESIBO_SCREEN_PROFILEThe profile of a user or groupMesiboProfileScreen
SCREEN_PROFILE_POPUP / MESIBO_SCREEN_PROFILE_POPUPThe profile popup of the chat listMesiboScreen
SCREEN_GENERIC / MESIBO_SCREEN_GENERICAny other screenMesiboScreen

Every screen object has these fields:

FieldWhat it isAndroidiOS
typeWhich screen, see the table aboveintint
parentThe activity or view controller of the screen. The app shows its own screens from it.ContextUIViewController
profileThe user profile or group profile of the screen, if any: the chat’s user or group, the profile shownMesiboProfileMesiboProfile
title, subtitleThe title and subtitle in the title barTextViewUILabel
titleAreaThe whole title area of the title bar, including the pictureViewUIView
menuThe items of the title bar, see belowMenuNSMutableArray<MesiboMenuItem *>
buttonsThe buttons of the navigation bar, see below-NSMutableArray<UIBarButtonItem *>
toolbarThe toolbar of the screenToolbar-
tableThe list of the screen: chats, messages or contactsRecyclerViewUITableView

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.menu is the Menu of 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.buttons are the buttons of the navigation bar (UIBarButtonItem), and screen.menu are the items of the navigation bar’s More button (⋯), as MesiboMenuItems: 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 a Menu; on iOS, a list of MesiboMenuItems.
  • 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) or SCREEN_USERLIST: button: true for a title bar button, false for the More menu.
  • MesiboUI.SCREEN_PROFILE: button: true for a button under the name, false for 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:

FeatureOption
The attach button and the attachment sheetattachments.enabled
One tile of the sheet (gallery, camera, video, document, audio, location)the tile’s enabled, attachments.getTile()
The camera buttonthe Camera tile’s enabled
Voice messages (the microphone)voiceMessages.enabled
Message optionsmessageOptions.enabled
Reply, forward, edit, copy, star, keep, message infomessages.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.