Layer’s UI Libraries

As part of Layer’s eXperience Development Kit (XDK), a library of UI widgets is provided to streamline building your applications. UI Libraries serve the following goals:

  • Provide commonly used high level UI Components such as the Conversation View and Conversation List
  • Provide a library of customizable lower level UI Components such as Avatars, Presence, Compose Bar, Typing Indicators, etc…
  • Enable application developers to focus on their business logic and customizations rather than focusing on providing, debugging and maintaining basic building blocks of a messaging application.
  • Provide a library of different types of messages that can be sent among users, and provide enhanced interactivity to your application.

Using the Android XDK UI Library

To simplify working with this library, dependencies used to create the components are managed one of two ways: using the supplied ServiceLocator or by using a Dagger Component. You must supply dependencies one of these two ways to work with this library.

Service Locator

The ServiceLocator provides a central object where dependencies are declared. It is recommended to make this object a singleton to avoid re-creating unnecessary dependencies. Two objects at a minimum are required to be set before interacting with XDK components: an application Context and a LayerClient. These should be set on the ServiceLocator as follows:

ServiceLocator serviceLocator = new ServiceLocator();
serviceLocator.setAppContext(context);
serviceLocator.setLayerClient(layerClient);

See here for how to create a LayerClient instance.

You can also set the following optional dependencies:

Default instances will be created and maintained by the ServiceLocator for those instances that are not set.

XDK components can then be created with the DefaultXdkUiComponent maintained in the ServiceLocator by calling getXdkUiComponent(). This object can create the following view models with the appropriate dependencies:

Use of these objects will be described in Core Components.

Dagger

If you are using Dagger in your application then you can bypass the ServiceLocator altogether. You will need to have a module that implements XdkUiModule. This module is where you can define the dependencies the XDK should use when creating components. For example:

@Module(includes = XdkUiInternalModule.class)
public class MyXdkUiModule implements XdkUiModule {
	@Provides
    @NonNull
    @Override
    public Context provideApplicationContext() {
        // Provide context
    }

    @Provides
    @NonNull
    @Override
    public LayerClient provideLayerClient() {
        // Provide LayerClient
    }

    @Provides
    @Singleton
    @NonNull
    @Override
    public ImageCacheWrapper provideImageCacheWrapper() {
        // Provide an ImageCacheWrapper (normally a singleton)
    }

    @Provides
    @Singleton
    @NonNull
    @Override
    public IdentityFormatter provideIdentityFormatter() {
        // Provide an IdentityFormatter (normally a singleton)
    }

    @Provides
    @Singleton
    @NonNull
    @Override
    public DateFormatter provideDateFormatter() {
        // Provide a DateFormatter (normally a singleton)
    }

    @Provides
    @Singleton
    @NonNull
    @Override
    public ConversationItemFormatter provideConversationItemFormatter() {
        // Provide a ConversationItemFormatter (normally a singleton)
    }
}

Note that this module includes XdkUiInternalModule, which provides dependencies to create models for ViewHolders used in RecyclerViews. This must be included in either your custom module or your custom component.

It is entirely possible that your required method signatures do not match what is in the XdkUiModule interface. In that case, use the XdkUiModule as a guide for what dependencies to provide and have the no-arg method no-op. For example, if my LayerClient provides method requires a Context:

@Module(includes = XdkUiInternalModule.class)
public class MyXdkUiModule implements XdkUiModule {
...
    @NonNull
    @Override
    public LayerClient provideLayerClient() {
        // Do nothing and don't annotate with @Provides
    }

    @Provides
    @NonNull
    public LayerClient provideLayerClient(Context context) {
        // Provide your LayerClient here (note @Override is omitted)
    }
...
}

Your component should either extend from XdkUiComponent or you should define a subcomponent that extends from XdkUiComponent. This component or subcomponent should include your custom XdkUiModule. For example:

@Singleton
@Component(modules = {MyXdkUiModule.class})
public interface MyXdkUiComponent extends XdkUiComponent {
}

Working With Android XDK UI Components

The XDK follows an MVVM architecture. RecyclerView.ViewHolders are also backed by models. The following components are included:

Privacy Core Components