Search in sources :

Example 1 with ErrorHandlingCallback

use of org.edx.mobile.http.callback.ErrorHandlingCallback in project edx-app-android by edx.

the class CourseDiscussionResponsesAdapter method bindSocialView.

private void bindSocialView(DiscussionSocialLayoutViewHolder holder, final int position, final DiscussionComment response) {
    holder.setDiscussionResponse(response);
    holder.voteViewContainer.setOnClickListener(new View.OnClickListener() {

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

                @Override
                protected void onResponse(@NonNull final DiscussionComment comment) {
                    discussionResponses.get(position - 1).patchObject(comment);
                    discussionResponses.set(position - 1, comment);
                    notifyItemChanged(position);
                }
            });
        }
    });
}
Also used : ErrorHandlingCallback(org.edx.mobile.http.callback.ErrorHandlingCallback) VoteBody(org.edx.mobile.discussion.DiscussionService.VoteBody) NonNull(android.support.annotation.NonNull) DiscussionComment(org.edx.mobile.discussion.DiscussionComment) DialogErrorNotification(org.edx.mobile.http.notifications.DialogErrorNotification) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 2 with ErrorHandlingCallback

use of org.edx.mobile.http.callback.ErrorHandlingCallback in project edx-app-android by edx.

the class CourseDiscussionResponsesAdapter method bindViewHolderToResponseRow.

private void bindViewHolderToResponseRow(DiscussionResponseViewHolder holder, final int position) {
    // Subtract 1 for the discussion thread row at position 0
    final DiscussionComment comment = discussionResponses.get(position - 1);
    holder.authorLayoutViewHolder.populateViewHolder(config, comment, comment, initialTimeStampMs, new Runnable() {

        @Override
        public void run() {
            listener.onClickAuthor(comment.getAuthor());
        }
    });
    if (comment.isEndorsed()) {
        holder.authorLayoutViewHolder.answerTextView.setVisibility(View.VISIBLE);
        holder.responseAnswerAuthorTextView.setVisibility(View.VISIBLE);
        DiscussionThread.ThreadType threadType = discussionThread.getType();
        DiscussionTextUtils.AuthorAttributionLabel authorAttributionLabel;
        @StringRes int endorsementTypeStringRes;
        switch(threadType) {
            case QUESTION:
                authorAttributionLabel = DiscussionTextUtils.AuthorAttributionLabel.ANSWER;
                endorsementTypeStringRes = R.string.discussion_responses_answer;
                break;
            case DISCUSSION:
            default:
                authorAttributionLabel = DiscussionTextUtils.AuthorAttributionLabel.ENDORSEMENT;
                endorsementTypeStringRes = R.string.discussion_responses_endorsed;
                break;
        }
        holder.authorLayoutViewHolder.answerTextView.setText(endorsementTypeStringRes);
        DiscussionTextUtils.setAuthorAttributionText(holder.responseAnswerAuthorTextView, authorAttributionLabel, comment.getEndorserData(), initialTimeStampMs, new Runnable() {

            @Override
            public void run() {
                listener.onClickAuthor(comment.getEndorsedBy());
            }
        });
    } else {
        holder.authorLayoutViewHolder.answerTextView.setVisibility(View.GONE);
        holder.responseAnswerAuthorTextView.setVisibility(View.GONE);
    }
    DiscussionTextUtils.renderHtml(holder.responseCommentBodyTextView, comment.getRenderedBody());
    if (discussionThread.isClosed() && comment.getChildCount() == 0) {
        holder.addCommentLayout.setEnabled(false);
    } else if (courseData.isDiscussionBlackedOut() && comment.getChildCount() == 0) {
        holder.addCommentLayout.setEnabled(false);
    } else {
        holder.addCommentLayout.setEnabled(true);
        holder.addCommentLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (comment.getChildCount() > 0) {
                    listener.onClickViewComments(comment);
                } else {
                    listener.onClickAddComment(comment);
                }
            }
        });
    }
    bindNumberCommentsView(holder.numberResponsesViewHolder, comment);
    if (TextUtils.equals(loginPrefs.getUsername(), comment.getAuthor())) {
        holder.actionsBar.setVisibility(View.GONE);
    } else {
        holder.actionsBar.setVisibility(View.VISIBLE);
        bindSocialView(holder.socialLayoutViewHolder, position, comment);
        holder.discussionReportViewHolder.reportLayout.setOnClickListener(new View.OnClickListener() {

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

                    @Override
                    protected void onResponse(@NonNull final DiscussionComment comment) {
                        discussionResponses.get(position - 1).patchObject(comment);
                        discussionResponses.set(position - 1, comment);
                        notifyItemChanged(position);
                    }
                });
            }
        });
        holder.discussionReportViewHolder.setReported(comment.isAbuseFlagged());
        holder.socialLayoutViewHolder.threadFollowContainer.setVisibility(View.INVISIBLE);
    }
}
Also used : StringRes(android.support.annotation.StringRes) DiscussionComment(org.edx.mobile.discussion.DiscussionComment) DiscussionTextUtils(org.edx.mobile.discussion.DiscussionTextUtils) FlagBody(org.edx.mobile.discussion.DiscussionService.FlagBody) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) DiscussionThread(org.edx.mobile.discussion.DiscussionThread) ErrorHandlingCallback(org.edx.mobile.http.callback.ErrorHandlingCallback) NonNull(android.support.annotation.NonNull) DialogErrorNotification(org.edx.mobile.http.notifications.DialogErrorNotification)

Example 3 with ErrorHandlingCallback

use of org.edx.mobile.http.callback.ErrorHandlingCallback in project edx-app-android by edx.

the class NativeFindCoursesFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final Activity activity = getActivity();
    this.viewHolder = new ViewHolder(view);
    viewHolder.listView.setVisibility(View.GONE);
    viewHolder.loadingIndicator.setVisibility(View.VISIBLE);
    final FindCoursesListAdapter adapter = new FindCoursesListAdapter(activity, environment) {

        @Override
        public void onItemClicked(CourseDetail model) {
            environment.getRouter().showCourseDetail(activity, model);
        }
    };
    // Add empty views to cause a dividers to render at the top and bottom of the list
    viewHolder.listView.addHeaderView(new View(getContext()), null, false);
    viewHolder.listView.addFooterView(new View(getContext()), null, false);
    InfiniteScrollUtils.configureListViewWithInfiniteList(viewHolder.listView, adapter, new InfiniteScrollUtils.PageLoader<CourseDetail>() {

        @Override
        public void loadNextPage(@NonNull final InfiniteScrollUtils.PageLoadCallback<CourseDetail> callback) {
            if (null != call) {
                call.cancel();
            }
            call = courseAPI.getCourseList(nextPage);
            final TaskMessageCallback mCallback = activity instanceof TaskMessageCallback ? (TaskMessageCallback) activity : null;
            call.enqueue(new ErrorHandlingCallback<Page<CourseDetail>>(activity, null, mCallback, CallTrigger.LOADING_UNCACHED) {

                @Override
                protected void onResponse(@NonNull final Page<CourseDetail> coursesPage) {
                    callback.onPageLoaded(coursesPage);
                    ++nextPage;
                    if (null != viewHolder) {
                        viewHolder.listView.setVisibility(View.VISIBLE);
                        viewHolder.loadingIndicator.setVisibility(View.GONE);
                    }
                }

                @Override
                protected void onFailure(@NonNull final Throwable error) {
                    callback.onError();
                    nextPage = 1;
                    if (null != viewHolder) {
                        viewHolder.loadingIndicator.setVisibility(View.GONE);
                    }
                }
            });
        }
    });
    viewHolder.listView.setOnItemClickListener(adapter);
}
Also used : InfiniteScrollUtils(org.edx.mobile.view.adapters.InfiniteScrollUtils) Activity(android.app.Activity) Page(org.edx.mobile.model.Page) View(android.view.View) ListView(android.widget.ListView) TaskMessageCallback(org.edx.mobile.view.common.TaskMessageCallback) ErrorHandlingCallback(org.edx.mobile.http.callback.ErrorHandlingCallback) CourseDetail(org.edx.mobile.course.CourseDetail) NonNull(android.support.annotation.NonNull) FindCoursesListAdapter(org.edx.mobile.view.adapters.FindCoursesListAdapter)

Example 4 with ErrorHandlingCallback

use of org.edx.mobile.http.callback.ErrorHandlingCallback 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 5 with ErrorHandlingCallback

use of org.edx.mobile.http.callback.ErrorHandlingCallback 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)5 View (android.view.View)5 ErrorHandlingCallback (org.edx.mobile.http.callback.ErrorHandlingCallback)5 RecyclerView (android.support.v7.widget.RecyclerView)4 TextView (android.widget.TextView)4 DialogErrorNotification (org.edx.mobile.http.notifications.DialogErrorNotification)4 DiscussionThread (org.edx.mobile.discussion.DiscussionThread)3 DiscussionComment (org.edx.mobile.discussion.DiscussionComment)2 FlagBody (org.edx.mobile.discussion.DiscussionService.FlagBody)2 VoteBody (org.edx.mobile.discussion.DiscussionService.VoteBody)2 DiscussionThreadUpdatedEvent (org.edx.mobile.discussion.DiscussionThreadUpdatedEvent)2 Activity (android.app.Activity)1 StringRes (android.support.annotation.StringRes)1 ListView (android.widget.ListView)1 CourseDetail (org.edx.mobile.course.CourseDetail)1 FollowBody (org.edx.mobile.discussion.DiscussionService.FollowBody)1 DiscussionTextUtils (org.edx.mobile.discussion.DiscussionTextUtils)1 Page (org.edx.mobile.model.Page)1 FindCoursesListAdapter (org.edx.mobile.view.adapters.FindCoursesListAdapter)1 InfiniteScrollUtils (org.edx.mobile.view.adapters.InfiniteScrollUtils)1