Coder Social home page Coder Social logo

atoregozh / pubnub-android-lolli-chat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gleasonk/pubnub-android-lolli-chat

0.0 1.0 0.0 5.8 MB

An android chatting application that makes use of many PubNub features.

Home Page: http://kevingleason.me/pubnub-android-lolli-chat/

Java 100.00%

pubnub-android-lolli-chat's Introduction

Android PubNub Lolli-Chat

A simple chatting app that shows off the power of various PubNub features.

Overview

Download APK Here

This Android chatting app allows a user to create a login identity that is then stored in SharedPreferences until logout. The initial chat room is titled MainChat, but a user can change chat rooms at any time. An integer in the menu bar indicates how many users are in the current chat room. If you click that here now number, a modal with all users in the room is displayed. Clicking on a user in the here now modal will display the login time of the corresponding user. Clicking on a message in the chat room will send a poke to that user, notifying them that you are in the chat room.

PubNub's Role

Let's walk through the various roles PubNub is playing in this Chatting Application...

Publish/Subscribe

Publish and Subscribe are used to coordinate the basic chatting features of the app. When a user sends a message, the code creates a ChatMessage object that holds the username, message text, and timestamp for the given message. ChatMessages are then serialized into a JSONObject and published to all users on the current channel using PubNub.

Then, a message is received using PubNub's subscribe method. The JSONObject is deserialized back into a ChatMessage and added to a list of messages from the current chat room.

Presence

Presence is used to determine what users in the chatroom are online in realtime. If a user is online, a green dot is displayed next to their name. Join and Leave events are updated in real time as well so when a user logs off, you are notified immediately.

Here Now

Presence updates the number of users currently in a room, but when you want to see the users currently in the chat, hereNow is used. A modal opens and is populated with the users currently subscribed to the chat room. Clicking on a user will tell you their login time, and the modal can be dismissed by clicking done.

Storage & Playback

Storage & Playback is used when a user opens the app and is sent to MainChat, or when a user changes rooms. A call to PubNub's history function loads the last 100 messages from the current channel so you know what other users have been talking about when you join.

State API

The PubNub State API allows you to define state data on the current channel. You can attach an object to your UUID that is accessible to anyone on the channel. This chat app uses the state API to attach login time to all online users' UUIDs. When a user in the here now modal is clicked, their login time is read from the state of the channel and displayed in a Toast message.

Push Notifications

PubNub makes push notifications easy. Simple enable push notifications on a channel and attach your GCM device ID to that channel and you are all set to receive pushes. When you tap a user's message in a chat room, a PubNub push notification is sent through GCM protocols to notify the user that you are waiting for them.

Make it your own!

I encourage you to expand on this application! You could incorporate chat room features, perhaps using hereNow with an empty channel parameter to show users all active chat rooms and their occupancies. If you choose to do this, you will need your own Pub and Sub keys. To get these, sign up for a PubNub account, it's quick and easy! You can find your unique PubNub keys in the PubNub Developer Dashboard. Then, enable and customize the Presence, Storage & Playback, and Push Notification features. Once you have done this, simply replace the String values for PUBLISH_KEY and SUBSCRIBE_KEY in me.kevingleason.pubnubchat.Constants.

To enable Push Notifications, you will need to register your app for GCM. You will then receive an API Key which you can use to enable Push Notifications in the PubNub Developer Dashboard, as well as a Sender ID which you should use to replace the GCM_SENDER_ID in the me.kevingleason.pubnubchat.Constants file.

pubnub-android-lolli-chat's People

Contributors

atoregozh avatar gleasonk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.