CheckLists

A checklist allows you to post a subject to a channel. Channel participants can choose from the items you specify, and the results can be viewed by everyone in the channel.

Here is a sample of what a complete checklist implementation can look like:

Create Checklist

The following example creates a checklist for a potluck.

List<String> options = Arrays.asList("Beer", "Juice", "Rum"); MMXChecklist.Builder builder = new MMXChecklist.Builder() .name("Drinks") .subject("What do you prefer to drink?") .items(options); MMXChecklist mmxChecklist = builder.build(); mmxChecklist.publish(mmxChannel, new MMX.OnFinishedListener<MMXMessage>() { @Override public void onSuccess(MMXMessage mmxMessage) { // Checklist created successfully } @Override public void onFailure(MMX.FailureCode failureCode, Throwable throwable) { // fail to create checklist, show error } });

Listen for Incoming Checklist Identifiers

Participants of the channel can listen for incoming checklist identifiers, which contain a checklistId we can use to get the checklist object from the server.

EventListener messageListener = new MMX.EventListener() { public boolean onMessageReceived(final MMXMessage messageReceived) { if (null != messageReceived.getContentType()) { if (messageReceived.getContentType().equals("object/ObjectIdentifier")) { ObjectIdentifier objectIdentifier = (ObjectIdentifier) messageReceived.getPayload(); if (objectIdentifier.getObjectType().endWith(MMXChecklist.TYPE)) { // get checklistID String checklistID = objectIdentifier.getObjectId(); } } else { // other message types } } return false; } ... } MMX.registerListener(messageListener);

Get the checklist object from the server using a checklistId (checklist identifier).

MMXChecklist.get("id", new MMX.OnFinishedListener<MMXChecklist>() { @Override public void onSuccess(MMXChecklist result) { // do somethings with checklist object } @Override public void onFailure(MMX.FailureCode code, Throwable ex) { // show error } });

The checklist object contains all the information needed to display a checklist in your user interface.

String name= myChecklist.getName(); // A user-friendly name of the checklist String question = myChecklist.getQuestion(); // The question of the checklist List<MMXChecklistItem> options = myChecklist.getOptions(); // A list of available checklist items Map<String, String> extras = myChecklist.getExtras(); // A user-defined object used to store arbitrary data will can accessed from a {MMXChecklist} instance

Checklist Items for Participants

Participants can choose one or more items.

MMXChecklistItem firstItem = myChecklist.getOptions().get(0); MMXChecklistItem secondItem = myChecklist.getOptions().get(1); List<MMXChecklistItem> selectedItems = Arrays.asList(firstItem, secondItem); myChecklist.select(selectedItems, new MMX.OnFinishedListener<MMXMessage>() { @Override public void onSuccess(MMXMessage mmxMessage) { //Items chosen } @Override public void onFailure(MMX.FailureCode failureCode, Throwable throwable) { //show error } });

Listen for Incoming CheckListSelections

Channel participants can listen for incoming CheckListSelection to display them in the user interface.

EventListener messageListener = new MMX.EventListener() { public boolean onMessageReceived(final MMXMessage messageReceived) { if (null != messageReceived.getContentType()) { if(messageReceived.getContentType().equals("object/" + MMXChecklist.MMXChecklistSelection.TYPE) { MMXChecklist.MMXChecklistSelection answer = (MMXChecklist.MMXChecklistSelection) messageReceived.getPayload(); String name = answer.getName(); // checklist name String checklistID = answer.getChecklistId(); //id of checklist String subject = answer.getSubject();//subject of checklist List<MMXChecklistItem> deselectedItems = answer.getDeselectedItems(); // the deselectedItems property is a list of CheckListItems deseleted by the sender List<MMXChecklistItem> selectedItems = answer.getSelectedItems(); // the selectedItems property is a list of CheckListItems seleted by the sender List<String> newItems = answer.getNewItems() // the newItems property is a list of CheckListItems the sender has added to the checklist User sender = messageReceived.getSender();//User object of sender } } return false; } ... }; MMX.registerListener(messageListener);

If the current user has voted in the checklist, the selected CheckListOption(s) can be obtained from the checklist object.

MMXChecklist myChecklist = … ; List<MMXChecklistItem> myChoices = myChecklist.getMySelections(); // a list of CheckListItems selected by the current user

Obtain Checklist Results

There are several ways to obtain checklist results.

  • Get the latest checklist object from the server using a checklistId:

    MMXChecklist.get("checklistId", new MMX.OnFinishedListener<MMXChecklist>() { @Override public void onSuccess(MMXChecklist result) { //do somethings with checklist object } @Override public void onFailure(MMX.FailureCode code, Throwable ex) { //show error } });

  • Use a listener to update existing checklist objects from the incoming checklistSelection. This method saves a round-trip to the server, updating the checklist results dynamically when a checklistSelection is received.

    MMXChecklist myChecklist = … ; myChecklist.refreshResults(new MMX.OnFinishedListener<Void>() { @Override public void onSuccess(Void result) { // myChecklist has been updated } @Override public void onFailure(MMX.FailureCode code, Throwable ex) { // show error } });