Search in sources :

Example 1 with FollowBody

use of org.edx.mobile.discussion.DiscussionService.FollowBody in project edx-app-android by edx.

the class CourseDiscussionResponsesAdapter method bindSocialView.

private void bindSocialView(DiscussionSocialLayoutViewHolder holder, DiscussionThread thread) {
    holder.setDiscussionThread(thread);
    holder.voteViewContainer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            discussionService.setThreadVoted(discussionThread.getIdentifier(), new VoteBody(!discussionThread.isVoted())).enqueue(new ErrorHandlingCallback<DiscussionThread>(context, null, new DialogErrorNotification(baseFragment)) {

                @Override
                protected void onResponse(@NonNull final DiscussionThread updatedDiscussionThread) {
                    discussionThread = discussionThread.patchObject(updatedDiscussionThread);
                    notifyItemChanged(0);
                    EventBus.getDefault().post(new DiscussionThreadUpdatedEvent(discussionThread));
                }
            });
        }
    });
    holder.threadFollowContainer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            discussionService.setThreadFollowed(discussionThread.getIdentifier(), new FollowBody(!discussionThread.isFollowing())).enqueue(new ErrorHandlingCallback<DiscussionThread>(context, null, new DialogErrorNotification(baseFragment)) {

                @Override
                protected void onResponse(@NonNull final DiscussionThread updatedDiscussionThread) {
                    discussionThread = discussionThread.patchObject(updatedDiscussionThread);
                    notifyItemChanged(0);
                    EventBus.getDefault().post(new DiscussionThreadUpdatedEvent(discussionThread));
                }
            });
        }
    });
}
Also used : ErrorHandlingCallback(org.edx.mobile.http.callback.ErrorHandlingCallback) FollowBody(org.edx.mobile.discussion.DiscussionService.FollowBody) VoteBody(org.edx.mobile.discussion.DiscussionService.VoteBody) NonNull(android.support.annotation.NonNull) DialogErrorNotification(org.edx.mobile.http.notifications.DialogErrorNotification) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) DiscussionThread(org.edx.mobile.discussion.DiscussionThread) DiscussionThreadUpdatedEvent(org.edx.mobile.discussion.DiscussionThreadUpdatedEvent)

Aggregations

NonNull (android.support.annotation.NonNull)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 FollowBody (org.edx.mobile.discussion.DiscussionService.FollowBody)1 VoteBody (org.edx.mobile.discussion.DiscussionService.VoteBody)1 DiscussionThread (org.edx.mobile.discussion.DiscussionThread)1 DiscussionThreadUpdatedEvent (org.edx.mobile.discussion.DiscussionThreadUpdatedEvent)1 ErrorHandlingCallback (org.edx.mobile.http.callback.ErrorHandlingCallback)1 DialogErrorNotification (org.edx.mobile.http.notifications.DialogErrorNotification)1