Search in sources :

Example 1 with CourseDiscussionResponsesAdapter

use of org.edx.mobile.view.adapters.CourseDiscussionResponsesAdapter 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)

Aggregations

Activity (android.app.Activity)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 BaseFragmentActivity (org.edx.mobile.base.BaseFragmentActivity)1 ReadBody (org.edx.mobile.discussion.DiscussionService.ReadBody)1 DiscussionThread (org.edx.mobile.discussion.DiscussionThread)1 DiscussionThreadUpdatedEvent (org.edx.mobile.discussion.DiscussionThreadUpdatedEvent)1 CourseDiscussionResponsesAdapter (org.edx.mobile.view.adapters.CourseDiscussionResponsesAdapter)1 TaskMessageCallback (org.edx.mobile.view.common.TaskMessageCallback)1 InjectView (roboguice.inject.InjectView)1