Skip to content

Built-in screens

The SDK on its own draws nothing: your app reads its state and draws every screen. If you’d rather not, add crm-android-ui, the SDK’s built-in screens. They open over your app the way a support messenger usually does: the messenger and its conversations in a sheet, and your in-app messages as banners, sheets and cards.

You can use them for everything, for some places only, or not at all.

  1. Add the second library next to the SDK. It needs Android 6.0 (API 23) or later, and brings Jetpack Compose with it.

    app/build.gradle.kts
    dependencies {
    implementation("com.github.MichalTDev:crm-android:v0.5.0")
    implementation("com.github.MichalTDev.crm-android:crm-android-ui:v0.5.0")
    }
  2. Install it once, in your Application, after you’ve made the Crm and started it:

    ShopApp.kt
    crm.start()
    val ui = CrmUi.install(crm)

That’s all. From now on, every way into PurrCRM‘s pages opens the built-in screen: crm.open(...), a tapped push, a link, and the setup check.

Call these from a button in your app:

ui.presentMessenger() // the messenger's first screen
ui.presentNewConversation() // a new conversation, ready to type in
ui.presentConversation(id) // one conversation
ui.presentHelpCenter() // the help center, with its search
ui.presentCollection(slug) // one collection of articles
ui.presentArticle(slug) // one article
ui.presentTickets() // the signed-in user's tickets
ui.presentTicket(id) // one ticket
ui.presentPreferences() // which messages they get, and how
ui.presentInbox() // the notices you sent them, newest first
ui.dismiss() // close them all, back to your app

The inbox has no link of its own, so open it from your app, from a bell for example. It needs someone signed in: presentInbox() returns false otherwise.

CrmUi.current gives you the installed screens from anywhere in your app.

What the screens do for you, as your team sets them up on PurrCRM:

  • Typing and Seen: a conversation shows the teammate’s face and three dots while they write a reply, and Seen under the user’s last message once your team has read it.
  • Files: where your team turns files on, the composer has Add a file beside Add a picture. It opens the system’s document picker, so your app adds no dependency. A file in a message opens in the phone’s browser or downloader, through your openExternal hook if you set one.
  • New tickets: where your team lets users open tickets themselves, the tickets page has a New ticket button, which opens the form.
  • Visitors: where your team lets people using your phone app write before they sign in, the messenger opens for someone who hasn’t (People who haven’t signed in).

If you draw the tickets page yourself with CrmTicketsScreen, pass onNewTicket to show the New ticket button, and open CrmNewTicketScreen from it.

To show one carousel, survey or post at a moment of your choosing (after a purchase, say), call it by its id. The id is on the message’s page on PurrCRM.

ui.presentCarousel(id) // a carousel your team made
ui.presentSurvey(id) // a survey
ui.presentPost(id) // a post
ui.presentMessage(id) // any in-app message, whatever its kind

The SDK asks PurrCRM for that message and shows it next, even if no check-in brought it. It still waits until you call crm.setReady(true), and nothing shows if the message isn’t meant for the signed-in user.

The message must be set to show Only when its link is opened on PurrCRM. A message that shows on its own when people check in can’t be called up by its id.

With the built-in screens installed, your in-app messages come in over your app as they arrive:

  • a banner slides in across the top, without moving your layout. A tap anywhere else still reaches your screen, and people swipe it away;
  • a post, a survey or a carousel opens as a sheet, a card or the whole screen, as your team chose on PurrCRM.

They still wait until you call crm.setReady(true), so they never cover your sign-in or onboarding steps. Everything people do with them is reported to PurrCRM as usual.

Pass CrmUiOptions to install:

CrmUi.install(
crm,
CrmUiOptions(
places = setOf(CrmPlace.Messenger, CrmPlace.Conversation, CrmPlace.NewConversation),
presentMessages = true,
theme = CrmUiTheme(accent = Color(0xFF0F766E)),
launcher = CrmLauncherChoice.Site,
),
)
  • places: the pages the SDK draws. A page you leave out goes to your own CrmHost.navigate, as it would without the built-in screens.
  • presentMessages: set it to false to draw your in-app messages yourself (see In-app messages) while the SDK draws the messenger.
  • theme: the accent colour, light or dark (darkMode), the fonts, the corners (corner), the buttons’ shape (buttonShape) and the animation (motion). Leave a part out and it comes from the look your team published (see below).
  • launcher: whether the launcher shows: Site (as your team chose, the default), Always or Never.
  • imageLoader: your own picture loader, if your app already has one.

Set crm.host before you install: a host you set afterwards replaces the built-in screens’ navigation.

Your team can style the built-in screens on PurrCRM, under Settings › your app › Messenger: the colours, the corners and buttons, light or dark, the messenger’s header and words, the launcher, and the animation (see Style the messenger and messages). The screens follow it the next time the app opens, with no new release.

Anything you set in code wins. Each part of the look comes from, in order:

  1. your theme, where you set that part;
  2. the look your team published on PurrCRM;
  3. the SDK’s own default.

So CrmUiTheme(accent = …) keeps your accent and takes everything else from PurrCRM. When the phone is set to remove animations, nothing animates, whatever the look or your theme says.

When your team turns the launcher on, a round button floats over your app’s screens. It opens the messenger and shows how many messages are unread. It puts itself away while the messenger, a message or the keyboard is up, and never shows over PurrCRM‘s own screens.

To keep it off one of your screens, a full-screen video say:

CrmUi.current?.hideLauncher(activity) // in onResume
CrmUi.current?.showLauncher(activity) // to bring it back

The messenger’s screens are public composables too:

CrmUiContent(crm) {
CrmMessengerScreen(onOpen = { where -> /* open it your way */ }, onClose = { /* go back */ })
}

The screens’ words are Android string resources, in English, named crm_…. You can say any of them in your own words, in any language, with a word table: strings of the same names in your app’s own resources. No code is needed.

  • To change the English, add the string to your app’s res/values/strings.xml.
  • For another language, add it to res/values-<language>/strings.xml, such as values-cy for Welsh. A phone set to a region of that language, such as cy-GB, uses it too.
  • Keep the library’s placeholders (%1$s, %1$d), and for a <plurals>, give the quantities your language has.
  • A table need not be whole: a string it leaves out is said in English.
<!-- res/values-cy/strings.xml in your app -->
<resources>
<string name="crm_help_still_stuck">Dal yn sownd?</string>
<string name="crm_conversation_typing">%1$s yn teipio</string>
<plurals name="crm_messenger_unread">
<item quantity="one">%1$d heb ei ddarllen</item>
<item quantity="other">%1$d heb eu darllen</item>
</plurals>
<!-- ...the rest stay English. -->
</resources>
<!-- res/values/strings.xml in your app: your own words in English too -->
<resources>
<string name="crm_ticket_new">Report a problem</string>
</resources>

The names follow the Flutter package’s strings, key for key, with crm_ in front and the key in snake case: ticketNew is crm_ticket_new. Android Lint checks your placeholders against the library’s. Dates and times are written in the phone’s own format for its language. The library ships English only.