Skip to content

Library of native Android chat and messaging UI components, built to work with Layer

License

Notifications You must be signed in to change notification settings

xircleag/Android-XDK

 
 

Repository files navigation

Android XDK

Overview

The Android XDK is an open source framework of customizable UI components built on top of Layer SDK to get messaging tested and integrated quickly. This repository contains the Android XDK library. For a fully-featured messaging app, see the open source Android XDK Messenger project, which uses this Android XDK library and the Layer SDK.

Requirements

The Android XDK requires Android API Level >= 14 (OS v4.0). The Layer SDK version requirements for each release are tightly coupled. See the release notes for details about specifics.

Key Concepts

With the XDK UI, Messages have types. One type might be rich text, and another might be a map location or photo. Anything that can be packaged into a set of MIME Types and data can be represented the XDK.

Under the hood, MessageSenders send individual Message types, and CellFactories render them. Additional Message types can be added to your app by extending these classes. For a list of default types, see the messagetypes subpackage.

API Quickstart

The XDK UI library is located in the ui directory. The table below details the most important classes in the XDK UI and is hyperlinked directly to the current java file.

Views
ConversationItemsListView A list of Conversations
MessageItemsListView A list of Messages within a Conversation
ComposeBar A View used to compose and send Messages
TypingIndicatorLayout Displays TypingIndicator information for a Conversation
Factories and Senders
MessageSender Sends Messages
TypingIndicatorLayout. TypingIndicatorFactory Renders typing indicators

Installation

Add the following to the build.gradle:

repositories {
    maven { url "https://raw.githubusercontent.com/layerhq/releases-android/master/releases/" }
    maven { url "https://raw.githubusercontent.com/layerhq/Android-XDK/master/releases/" }
}

dependencies {
    compile 'com.layer.xdk:xdk:4.0.0'
}

Libraries

The XDK UI uses Picasso for image caching, resizing, and processing, and Subsampling Scale Image View for image its in-app lightbox. Other dependencies include the Android recyclerview, appcompat, and design libraries.

Component Details

The XDK UI is divided into five basic View components, typically presented on a screen with a user's conversations, a screen with messages within a conversation, and a component that lets the user select participants.

Conversations

ConversationItemsListView

The ConversationItemsListView is a list of Conversations.

XML

It uses databinding which takes an object of ConversationItemsListViewModel as a ViewModel. The ConversationItemsListViewModel creates an object of ConversationItemsAdapter which is passed as the Adapter in the xml.

    mConversationItemsAdapter = new ConversationItemsAdapter(context, layerClient, query,
<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

        <import type="com.layer.xdk.ui.conversation.ConversationItemsListViewModel"/>

        <variable
            name="viewModel"
            type="ConversationItemsListViewModel"/>
    </data>

    <com.layer.xdk.ui.conversation.ConversationItemsListView
        app:adapter="@{viewModel.conversationItemsAdapter}"
        ... />
</layout>
Java

Create an Object of ConversationItemsListViewModel and bind it to the ConversationView.

        ConversationItemsListViewModel conversationItemsListViewModel = new ConversationItemsListViewModel(this, App.getLayerClient(), Util.getConversationItemFormatter(), Util.getImageCacheWrapper(),new IdentityFormatterImpl());
        binding.setViewModel(conversationItemsListViewModel);

An item click listener can be set via ConversationItemsListViewModel#setItemClickListener

Messages

MessageItemsListView

The MessageItemsListView is list of Messages. MessageItemsListView is used in ConversationView

XML
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

        <import type="com.layer.xdk.ui.message.MessageItemsListViewModel"/>

        <variable
            name="viewModel"
            type="MessageItemsListViewModel"/>
    </data>

    <merge
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.layer.xdk.ui.message.MessageItemsListView
            app:adapter="@{viewModel.adapter}"
             ... />

    </merge>
</layout>

ComposeBar

The ComposeBar is a text entry area for composing messages and a menu of AttachmentSenders.

ConversationView

The ConversationView is comprised of a MessageItemsListView and a ComposeBar.

    <layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

        <variable
            name="viewModel"
            type="com.layer.xdk.ui.conversation.ConversationViewModel"/>
    </data>

    <LinearLayout ...>

        <com.layer.xdk.ui.conversation.ConversationView
            app:conversation="@{viewModel.conversation}"
            app:layerClient="@{viewModel.layerClient}"
            app:messageItemsListViewModel="@{viewModel.messageItemsListViewModel}"/>
    </LinearLayout>
</layout>
Java
    ConversationView conversationView = activityMessagesListBinding.conversation;
    messageItemsListViewModel = new MessageItemsListViewModel(this, App.getLayerClient(),
                Util.getImageCacheWrapper(), Util.getDateFormatter(this));

    conversationViewModel = new ConversationViewModel(...);
    activityMessagesListBinding.setViewModel(conversationViewModel);
    setConversation(conversation, conversation != null);
    activityMessagesListBinding.executePendingBindings();

Listeners

ItemClickListener and ItemSwipeListener can be set on the ViewModel. ConversationItemsListViewModel has setItemClickListener and setItemSwipeListener methods.

Java
    conversationItemsListViewModel.setItemClickListener(new OnItemClickListener<Conversation>() {
        @Override
        public void onItemClick(Conversation item) {
            ...
        }

        @Override
        public boolean onItemLongClick(Conversation item) {
            return false;
        }
    });

    conversationItemsListViewModel.setItemSwipeListener(new SwipeableItem.OnItemSwipeListener<Conversation>() {
        @Override
        public void onSwipe(final Conversation conversation, int direction) {
            ...
    });

TypingIndicator

The TypingIndicator presents the user with active typists.

XML
<com.layer.xdk.ui.typingindicator.TypingIndicatorLayout
    android:id="@+id/typing_indicator"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
Java
    typingIndicator = new TypingIndicatorLayout(context);
        typingIndicator.setTypingIndicatorFactory(new BubbleTypingIndicatorFactory());
        typingIndicator.setTypingActivityListener(new TypingIndicatorLayout.TypingActivityListener() {
            @Override
            public void onTypingActivityChange(TypingIndicatorLayout typingIndicator, boolean active, Set<Identity> users) {
                messageItemListView.setTypingIndicatorLayout(active ? typingIndicator : null, users);
            }
        });

Message Types

By default, the XDK UI supports the following types of messages.

Type Description
Generic Default handler for unknown message types. Displays the mimetype and the content size
Text Handler for text/plain content.
Location Handler for location/coordinate content. Given lat/lon information, displays the location image (from Google maps), with a hyperlink that launches Maps application
ThreePartImage Handler for 3 part JPEG image, with preview & dimensions. By default, displays the preview image. On tap, downloads and renders the full resolution image
SinglePartImage Handler for any mime type that starts with image tag

We expect to add support for other handlers in future. If you would like to build a handler, please check doc on message handlers.

Identity

An application server can directly upload user information to Layer server. This user information is called Identity.AvatarView is a control that is used to render the Identity information.

AvatarView

AvatarViewcan be used to show information about one user, or a cluster of users. AvatarView uses ImageCacheWrapper to abstract any image caching & loading library you wish to use. An implementation of ImageCacheWrapper is available in layer-ui that uses Picasso.

PicassoImageCacheWrapper

XML
         <com.layer.xdk.ui.avatar.AvatarView
            android:id="@+id/avatar"
            android:layout_width="@dimen/xdk_ui_avatar_width"
            android:layout_height="@dimen/xdk_ui_avatar_height" />
Java
	    // To create an avatar
        //get Avatar object from layout
        avatar.init(new AvatarViewModelImpl(imageCachWrapper), new IdentityFormatterImpl());

	    // To set identites meant for the avatar cluster
	    //get ViewHolder Object from the RecyclerView.ViewHolder
	    HashSet<Identity> participants = new HashSet<>(conversation.getParticipants());
	    viewHolder.avatar.setParticipants(participants);

Contributing

The Android XDK is an Open Source project maintained by Layer. Feedback and contributions are always welcome and the maintainers try to process patches as quickly as possible. Feel free to open up a Pull Request or Issue on Github.

License

The Android XDK is licensed under the terms of the Apache License, version 2.0. Please see the LICENSE file for full details.

Contact

The Android XDK was developed in San Francisco by the Layer team. If you have any technical questions or concerns about this project feel free to reach out to Layer Support.

Credits

About

Library of native Android chat and messaging UI components, built to work with Layer

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%