Search in sources :

Example 1 with DiscussionThreadUpdatedEvent

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

the class CourseDiscussionResponsesFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final Activity activity = getActivity();
    responsesLoader = new ResponsesLoader(activity, discussionThread.getIdentifier(), discussionThread.getType() == DiscussionThread.ThreadType.QUESTION);
    courseDiscussionResponsesAdapter = new CourseDiscussionResponsesAdapter(activity, this, this, discussionThread, courseData);
    controller = InfiniteScrollUtils.configureRecyclerViewWithInfiniteList(discussionResponsesRecyclerView, courseDiscussionResponsesAdapter, responsesLoader);
    discussionResponsesRecyclerView.setAdapter(courseDiscussionResponsesAdapter);
    responsesLoader.freeze();
    if (getAndReadThreadCall != null) {
        getAndReadThreadCall.cancel();
    }
    final TaskMessageCallback mCallback = activity instanceof TaskMessageCallback ? (TaskMessageCallback) activity : null;
    getAndReadThreadCall = discussionService.setThreadRead(discussionThread.getIdentifier(), new ReadBody(true));
    // Setting a thread's "read" state gives us back the updated Thread object.
    getAndReadThreadCall.enqueue(new ErrorHandlingCallback<DiscussionThread>(activity, null, mCallback, CallTrigger.LOADING_UNCACHED) {

        @Override
        protected void onResponse(@NonNull final DiscussionThread discussionThread) {
            courseDiscussionResponsesAdapter.updateDiscussionThread(discussionThread);
            responsesLoader.unfreeze();
            EventBus.getDefault().post(new DiscussionThreadUpdatedEvent(discussionThread));
        }
    });
    DiscussionUtils.setStateOnTopicClosed(discussionThread.isClosed(), addResponseTextView, R.string.discussion_responses_add_response_button, R.string.discussion_add_response_disabled_title, addResponseLayout, new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            router.showCourseDiscussionAddResponse(activity, discussionThread);
        }
    });
    addResponseLayout.setEnabled(!courseData.isDiscussionBlackedOut());
}
Also used : ReadBody(org.edx.mobile.discussion.DiscussionService.ReadBody) CourseDiscussionResponsesAdapter(org.edx.mobile.view.adapters.CourseDiscussionResponsesAdapter) BaseFragmentActivity(org.edx.mobile.base.BaseFragmentActivity) Activity(android.app.Activity) View(android.view.View) InjectView(roboguice.inject.InjectView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) DiscussionThread(org.edx.mobile.discussion.DiscussionThread) DiscussionThreadUpdatedEvent(org.edx.mobile.discussion.DiscussionThreadUpdatedEvent) TaskMessageCallback(org.edx.mobile.view.common.TaskMessageCallback)

Example 2 with DiscussionThreadUpdatedEvent

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

the class CourseDiscussionResponsesAdapter method bindViewHolderToThreadRow.

private void bindViewHolderToThreadRow(DiscussionThreadViewHolder holder) {
    holder.authorLayoutViewHolder.populateViewHolder(config, discussionThread, discussionThread, initialTimeStampMs, new Runnable() {

        @Override
        public void run() {
            listener.onClickAuthor(discussionThread.getAuthor());
        }
    });
    holder.threadTitleTextView.setText(discussionThread.getTitle());
    DiscussionTextUtils.renderHtml(holder.threadBodyTextView, discussionThread.getRenderedBody());
    String groupName = discussionThread.getGroupName();
    if (groupName == null) {
        holder.threadVisibilityTextView.setText(R.string.discussion_post_visibility_everyone);
    } else {
        holder.threadVisibilityTextView.setText(ResourceUtil.getFormattedString(context.getResources(), R.string.discussion_post_visibility_cohort, "cohort", groupName));
    }
    bindNumberResponsesView(holder.numberResponsesViewHolder);
    if (TextUtils.equals(loginPrefs.getUsername(), discussionThread.getAuthor())) {
        holder.actionsBar.setVisibility(View.GONE);
    } else {
        holder.actionsBar.setVisibility(View.VISIBLE);
        bindSocialView(holder.socialLayoutViewHolder, discussionThread);
        holder.discussionReportViewHolder.reportLayout.setOnClickListener(new View.OnClickListener() {

            public void onClick(final View v) {
                discussionService.setThreadFlagged(discussionThread.getIdentifier(), new FlagBody(!discussionThread.isAbuseFlagged())).enqueue(new ErrorHandlingCallback<DiscussionThread>(context, null, new DialogErrorNotification(baseFragment)) {

                    @Override
                    protected void onResponse(@NonNull final DiscussionThread topicThread) {
                        discussionThread = discussionThread.patchObject(topicThread);
                        notifyItemChanged(0);
                        EventBus.getDefault().post(new DiscussionThreadUpdatedEvent(discussionThread));
                    }
                });
            }
        });
        holder.discussionReportViewHolder.setReported(discussionThread.isAbuseFlagged());
    }
}
Also used : ErrorHandlingCallback(org.edx.mobile.http.callback.ErrorHandlingCallback) NonNull(android.support.annotation.NonNull) FlagBody(org.edx.mobile.discussion.DiscussionService.FlagBody) 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)

Example 3 with DiscussionThreadUpdatedEvent

use of org.edx.mobile.discussion.DiscussionThreadUpdatedEvent 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

RecyclerView (android.support.v7.widget.RecyclerView)3 View (android.view.View)3 TextView (android.widget.TextView)3 DiscussionThread (org.edx.mobile.discussion.DiscussionThread)3 DiscussionThreadUpdatedEvent (org.edx.mobile.discussion.DiscussionThreadUpdatedEvent)3 NonNull (android.support.annotation.NonNull)2 ErrorHandlingCallback (org.edx.mobile.http.callback.ErrorHandlingCallback)2 DialogErrorNotification (org.edx.mobile.http.notifications.DialogErrorNotification)2 Activity (android.app.Activity)1 BaseFragmentActivity (org.edx.mobile.base.BaseFragmentActivity)1 FlagBody (org.edx.mobile.discussion.DiscussionService.FlagBody)1 FollowBody (org.edx.mobile.discussion.DiscussionService.FollowBody)1 ReadBody (org.edx.mobile.discussion.DiscussionService.ReadBody)1 VoteBody (org.edx.mobile.discussion.DiscussionService.VoteBody)1 CourseDiscussionResponsesAdapter (org.edx.mobile.view.adapters.CourseDiscussionResponsesAdapter)1 TaskMessageCallback (org.edx.mobile.view.common.TaskMessageCallback)1 InjectView (roboguice.inject.InjectView)1