{"action":"created","comment":{"url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls/comments/62257758","id":62257758,"diff_hunk":"@@ -0,0 +1,195 @@\n+package com.layer.sample.conversationlist;\n+\n+import android.content.Intent;\n+import android.support.v7.widget.RecyclerView;\n+import android.text.format.DateUtils;\n+import android.view.LayoutInflater;\n+import android.view.View;\n+import android.view.ViewGroup;\n+\n+import com.layer.sample.Participant;\n+import com.layer.sample.ParticipantProvider;\n+import com.layer.sample.PushNotificationReceiver;\n+import com.layer.sample.R;\n+import com.layer.sample.messagelist.MessagesListActivity;\n+import com.layer.sample.util.MessageUtils;\n+import com.layer.sdk.LayerClient;\n+import com.layer.sdk.messaging.Conversation;\n+import com.layer.sdk.messaging.Message;\n+import com.layer.sdk.query.Predicate;\n+import com.layer.sdk.query.Query;\n+import com.layer.sdk.query.RecyclerViewController;\n+import com.layer.sdk.query.SortDescriptor;\n+\n+import java.text.DateFormat;\n+import java.util.Date;\n+import java.util.List;\n+\n+public class ConversationRecyclerAdapter extends RecyclerView.Adapter<ConversationViewHolder> {\n+    private static final int SYNC_MESSAGE_COUNT = 20;\n+\n+    private ParticipantProvider mParticipantProvider;\n+    private RecyclerViewController<Conversation> mQueryController;\n+    private String mAuthenticatedUserId;\n+    private LayerClient mLayerClient;\n+\n+    public ConversationRecyclerAdapter(LayerClient layerClient, ParticipantProvider participantProvider) {\n+        mLayerClient = layerClient;\n+        mParticipantProvider = participantProvider;\n+        mAuthenticatedUserId = layerClient.getAuthenticatedUserId();\n+        setHasStableIds(false);\n+\n+        buildAndExecuteQuery(layerClient);\n+    }\n+\n+    @Override\n+    public ConversationViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {\n+        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.conversation_item, parent, false);\n+        return new ConversationViewHolder(v);\n+    }\n+\n+    @Override\n+    public void onBindViewHolder(ConversationViewHolder holder, int position) {\n+        mQueryController.updateBoundPosition(position);\n+        final Conversation conversation = mQueryController.getItem(position);\n+        holder.setOnClickListener(new ItemClickListener(conversation));\n+\n+        List<String> participantIds = conversation.getParticipants();\n+        setTitle(holder, participantIds);\n+\n+        Message lastMessage = conversation.getLastMessage();\n+        setMessage(holder, lastMessage);\n+        setMessageDate(holder, lastMessage);\n+    }\n+\n+    @Override\n+    public int getItemCount() {\n+        return mQueryController.getItemCount();\n+    }\n+\n+    private void buildAndExecuteQuery(LayerClient layerClient) {\n+        Query<Conversation> query = Query.builder(Conversation.class)\n+                /* Only show conversations we're still a member of */\n+                .predicate(new Predicate(Conversation.Property.PARTICIPANT_COUNT, Predicate.Operator.GREATER_THAN, 1))\n+\n+                /* Sort by the last Message's sentAt time */\n+                .sortDescriptor(new SortDescriptor(Conversation.Property.LAST_MESSAGE_SENT_AT, SortDescriptor.Order.DESCENDING))\n+                .build();\n+\n+        mQueryController = layerClient.newRecyclerViewController(query, null, new NotifyChangesCallback());\n+        mQueryController.execute();\n+    }\n+\n+    private void setTitle(ConversationViewHolder holder, List<String> participantIds) {\n+        StringBuilder sb = new StringBuilder();\n+        for (String participantId : participantIds) {\n+            if (mAuthenticatedUserId.equals(participantId)) {\n+                continue;\n+            }\n+            Participant participant = mParticipantProvider.getParticipant(participantId);\n+            if (sb.length() > 0) {\n+                sb.append(\", \");\n+            }\n+            sb.append(participant.getName());\n+        }\n+\n+        holder.setName(sb.toString());\n+    }\n+\n+    private void setMessage(ConversationViewHolder holder, Message lastMessage) {\n+        holder.setMessage(MessageUtils.getMessageText(lastMessage));\n+    }\n+\n+    private void setMessageDate(ConversationViewHolder holder, Message lastMessage) {\n+        Date sentDate = lastMessage.getSentAt();\n+        if (sentDate != null) {\n+            CharSequence formattedTime = DateUtils.formatSameDayTime(sentDate.getTime(), System.currentTimeMillis(), DateFormat.DEFAULT, DateFormat.SHORT);\n+            holder.setLastMessageTime(formattedTime);\n+        } else {\n+            holder.setLastMessageTime(null);\n+        }\n+    }\n+","path":"app/src/main/java/com/layer/sample/conversationlist/ConversationRecyclerAdapter.java","position":112,"original_position":112,"commit_id":"757fd2bfdc26dc81227b908a25f1935a725ccb10","original_commit_id":"757fd2bfdc26dc81227b908a25f1935a725ccb10","user":{"login":"sriamar","id":3992829,"avatar_url":"https://avatars.githubusercontent.com/u/3992829?v=3","gravatar_id":"","url":"https://api.github.com/users/sriamar","html_url":"https://github.com/sriamar","followers_url":"https://api.github.com/users/sriamar/followers","following_url":"https://api.github.com/users/sriamar/following{/other_user}","gists_url":"https://api.github.com/users/sriamar/gists{/gist_id}","starred_url":"https://api.github.com/users/sriamar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sriamar/subscriptions","organizations_url":"https://api.github.com/users/sriamar/orgs","repos_url":"https://api.github.com/users/sriamar/repos","events_url":"https://api.github.com/users/sriamar/events{/privacy}","received_events_url":"https://api.github.com/users/sriamar/received_events","type":"User","site_admin":false},"body":"Let's remove this method. If we initialize LayerClient with FROM_EARLIEST_UNREAD_MESSAGE, that should be a good default. It guarantees at least one message will be download for each conversation.","created_at":"2016-05-05T21:24:06Z","updated_at":"2016-05-05T21:24:06Z","html_url":"https://github.com/layerhq/Atlas-Android-Messenger/pull/20#discussion_r62257758","pull_request_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls/20","_links":{"self":{"href":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls/comments/62257758"},"html":{"href":"https://github.com/layerhq/Atlas-Android-Messenger/pull/20#discussion_r62257758"},"pull_request":{"href":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls/20"}}},"pull_request":{"url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls/20","id":68933508,"html_url":"https://github.com/layerhq/Atlas-Android-Messenger/pull/20","diff_url":"https://github.com/layerhq/Atlas-Android-Messenger/pull/20.diff","patch_url":"https://github.com/layerhq/Atlas-Android-Messenger/pull/20.patch","issue_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/issues/20","number":20,"state":"open","locked":false,"title":"Feature/apps 2001 improved sample app","user":{"login":"smpete","id":1000659,"avatar_url":"https://avatars.githubusercontent.com/u/1000659?v=3","gravatar_id":"","url":"https://api.github.com/users/smpete","html_url":"https://github.com/smpete","followers_url":"https://api.github.com/users/smpete/followers","following_url":"https://api.github.com/users/smpete/following{/other_user}","gists_url":"https://api.github.com/users/smpete/gists{/gist_id}","starred_url":"https://api.github.com/users/smpete/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smpete/subscriptions","organizations_url":"https://api.github.com/users/smpete/orgs","repos_url":"https://api.github.com/users/smpete/repos","events_url":"https://api.github.com/users/smpete/events{/privacy}","received_events_url":"https://api.github.com/users/smpete/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-05-04T21:17:26Z","updated_at":"2016-05-05T21:24:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"47bd7cc9b1dc097d19900aece371f327d8c26e9a","assignee":{"login":"sriamar","id":3992829,"avatar_url":"https://avatars.githubusercontent.com/u/3992829?v=3","gravatar_id":"","url":"https://api.github.com/users/sriamar","html_url":"https://github.com/sriamar","followers_url":"https://api.github.com/users/sriamar/followers","following_url":"https://api.github.com/users/sriamar/following{/other_user}","gists_url":"https://api.github.com/users/sriamar/gists{/gist_id}","starred_url":"https://api.github.com/users/sriamar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sriamar/subscriptions","organizations_url":"https://api.github.com/users/sriamar/orgs","repos_url":"https://api.github.com/users/sriamar/repos","events_url":"https://api.github.com/users/sriamar/events{/privacy}","received_events_url":"https://api.github.com/users/sriamar/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls/20/commits","review_comments_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls/20/comments","review_comment_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls/comments{/number}","comments_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/issues/20/comments","statuses_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/statuses/757fd2bfdc26dc81227b908a25f1935a725ccb10","head":{"label":"layerhq:feature/APPS-2001_improved_sample_app","ref":"feature/APPS-2001_improved_sample_app","sha":"757fd2bfdc26dc81227b908a25f1935a725ccb10","user":{"login":"layerhq","id":5497685,"avatar_url":"https://avatars.githubusercontent.com/u/5497685?v=3","gravatar_id":"","url":"https://api.github.com/users/layerhq","html_url":"https://github.com/layerhq","followers_url":"https://api.github.com/users/layerhq/followers","following_url":"https://api.github.com/users/layerhq/following{/other_user}","gists_url":"https://api.github.com/users/layerhq/gists{/gist_id}","starred_url":"https://api.github.com/users/layerhq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/layerhq/subscriptions","organizations_url":"https://api.github.com/users/layerhq/orgs","repos_url":"https://api.github.com/users/layerhq/repos","events_url":"https://api.github.com/users/layerhq/events{/privacy}","received_events_url":"https://api.github.com/users/layerhq/received_events","type":"Organization","site_admin":false},"repo":{"id":46327286,"name":"Atlas-Android-Messenger","full_name":"layerhq/Atlas-Android-Messenger","owner":{"login":"layerhq","id":5497685,"avatar_url":"https://avatars.githubusercontent.com/u/5497685?v=3","gravatar_id":"","url":"https://api.github.com/users/layerhq","html_url":"https://github.com/layerhq","followers_url":"https://api.github.com/users/layerhq/followers","following_url":"https://api.github.com/users/layerhq/following{/other_user}","gists_url":"https://api.github.com/users/layerhq/gists{/gist_id}","starred_url":"https://api.github.com/users/layerhq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/layerhq/subscriptions","organizations_url":"https://api.github.com/users/layerhq/orgs","repos_url":"https://api.github.com/users/layerhq/repos","events_url":"https://api.github.com/users/layerhq/events{/privacy}","received_events_url":"https://api.github.com/users/layerhq/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/layerhq/Atlas-Android-Messenger","description":"A fully-featured messaging app following Material Design guidelines, built on top of the Layer SDK, using the Atlas UI toolkit.","fork":false,"url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger","forks_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/forks","keys_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/keys{/key_id}","collaborators_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/teams","hooks_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/hooks","issue_events_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/issues/events{/number}","events_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/events","assignees_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/assignees{/user}","branches_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/branches{/branch}","tags_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/tags","blobs_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/git/refs{/sha}","trees_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/git/trees{/sha}","statuses_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/statuses/{sha}","languages_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/languages","stargazers_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/stargazers","contributors_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/contributors","subscribers_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/subscribers","subscription_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/subscription","commits_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/commits{/sha}","git_commits_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/git/commits{/sha}","comments_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/comments{/number}","issue_comment_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/issues/comments{/number}","contents_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/contents/{+path}","compare_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/compare/{base}...{head}","merges_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/merges","archive_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/downloads","issues_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/issues{/number}","pulls_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls{/number}","milestones_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/milestones{/number}","notifications_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/labels{/name}","releases_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/releases{/id}","deployments_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/deployments","created_at":"2015-11-17T06:19:03Z","updated_at":"2016-04-23T19:12:46Z","pushed_at":"2016-05-04T21:17:26Z","git_url":"git://github.com/layerhq/Atlas-Android-Messenger.git","ssh_url":"git@github.com:layerhq/Atlas-Android-Messenger.git","clone_url":"https://github.com/layerhq/Atlas-Android-Messenger.git","svn_url":"https://github.com/layerhq/Atlas-Android-Messenger","homepage":"https://layer.com","size":309,"stargazers_count":21,"watchers_count":21,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":7,"forks":18,"open_issues":7,"watchers":21,"default_branch":"master"}},"base":{"label":"layerhq:android_messenger","ref":"android_messenger","sha":"52375a609b54e1fb9a48edd5efd873412d130b0b","user":{"login":"layerhq","id":5497685,"avatar_url":"https://avatars.githubusercontent.com/u/5497685?v=3","gravatar_id":"","url":"https://api.github.com/users/layerhq","html_url":"https://github.com/layerhq","followers_url":"https://api.github.com/users/layerhq/followers","following_url":"https://api.github.com/users/layerhq/following{/other_user}","gists_url":"https://api.github.com/users/layerhq/gists{/gist_id}","starred_url":"https://api.github.com/users/layerhq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/layerhq/subscriptions","organizations_url":"https://api.github.com/users/layerhq/orgs","repos_url":"https://api.github.com/users/layerhq/repos","events_url":"https://api.github.com/users/layerhq/events{/privacy}","received_events_url":"https://api.github.com/users/layerhq/received_events","type":"Organization","site_admin":false},"repo":{"id":46327286,"name":"Atlas-Android-Messenger","full_name":"layerhq/Atlas-Android-Messenger","owner":{"login":"layerhq","id":5497685,"avatar_url":"https://avatars.githubusercontent.com/u/5497685?v=3","gravatar_id":"","url":"https://api.github.com/users/layerhq","html_url":"https://github.com/layerhq","followers_url":"https://api.github.com/users/layerhq/followers","following_url":"https://api.github.com/users/layerhq/following{/other_user}","gists_url":"https://api.github.com/users/layerhq/gists{/gist_id}","starred_url":"https://api.github.com/users/layerhq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/layerhq/subscriptions","organizations_url":"https://api.github.com/users/layerhq/orgs","repos_url":"https://api.github.com/users/layerhq/repos","events_url":"https://api.github.com/users/layerhq/events{/privacy}","received_events_url":"https://api.github.com/users/layerhq/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/layerhq/Atlas-Android-Messenger","description":"A fully-featured messaging app following Material Design guidelines, built on top of the Layer SDK, using the Atlas UI toolkit.","fork":false,"url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger","forks_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/forks","keys_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/keys{/key_id}","collaborators_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/teams","hooks_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/hooks","issue_events_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/issues/events{/number}","events_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/events","assignees_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/assignees{/user}","branches_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/branches{/branch}","tags_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/tags","blobs_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/git/refs{/sha}","trees_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/git/trees{/sha}","statuses_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/statuses/{sha}","languages_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/languages","stargazers_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/stargazers","contributors_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/contributors","subscribers_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/subscribers","subscription_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/subscription","commits_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/commits{/sha}","git_commits_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/git/commits{/sha}","comments_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/comments{/number}","issue_comment_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/issues/comments{/number}","contents_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/contents/{+path}","compare_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/compare/{base}...{head}","merges_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/merges","archive_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/downloads","issues_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/issues{/number}","pulls_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls{/number}","milestones_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/milestones{/number}","notifications_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/labels{/name}","releases_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/releases{/id}","deployments_url":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/deployments","created_at":"2015-11-17T06:19:03Z","updated_at":"2016-04-23T19:12:46Z","pushed_at":"2016-05-04T21:17:26Z","git_url":"git://github.com/layerhq/Atlas-Android-Messenger.git","ssh_url":"git@github.com:layerhq/Atlas-Android-Messenger.git","clone_url":"https://github.com/layerhq/Atlas-Android-Messenger.git","svn_url":"https://github.com/layerhq/Atlas-Android-Messenger","homepage":"https://layer.com","size":309,"stargazers_count":21,"watchers_count":21,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":7,"forks":18,"open_issues":7,"watchers":21,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls/20"},"html":{"href":"https://github.com/layerhq/Atlas-Android-Messenger/pull/20"},"issue":{"href":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/issues/20"},"comments":{"href":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/issues/20/comments"},"review_comments":{"href":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls/20/comments"},"review_comment":{"href":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/pulls/20/commits"},"statuses":{"href":"https://api.github.com/repos/layerhq/Atlas-Android-Messenger/statuses/757fd2bfdc26dc81227b908a25f1935a725ccb10"}}}}