Search in sources :

Example 1 with TimePeriod

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

the class CourseDiscussionPostsThreadFragment method checkIfDiscussionsBlackedOut.

/**
 * Query server to check if discussions on this course are blacked out.
 */
private void checkIfDiscussionsBlackedOut() {
    setCreateNewPostBtnVisibility(View.GONE);
    discussionService.getCourseDiscussionInfo(courseData.getCourse().getId()).enqueue(new ErrorHandlingCallback<CourseDiscussionInfo>(getContext(), (TaskProgressCallback) null) {

        @Override
        public void onFailure(@NonNull Call<CourseDiscussionInfo> call, @NonNull Throwable t) {
            markAsBlackedOut(false);
        }

        @Override
        protected void onResponse(@NonNull CourseDiscussionInfo discussionInfo) {
            final Date today = new Date();
            final List<TimePeriod> blackoutTimesList = discussionInfo.getBlackoutList();
            for (TimePeriod timePeriod : blackoutTimesList) {
                if (today.after(timePeriod.getStart()) && today.before(timePeriod.getEnd())) {
                    markAsBlackedOut(true);
                    return;
                }
            }
            markAsBlackedOut(false);
        }

        private void markAsBlackedOut(boolean isBlackedOut) {
            courseData.setDiscussionBlackedOut(isBlackedOut);
            createNewPostLayout.setEnabled(!isBlackedOut);
            setCreateNewPostBtnVisibility(View.VISIBLE);
        }
    });
}
Also used : TaskProgressCallback(org.edx.mobile.view.common.TaskProgressCallback) TimePeriod(org.edx.mobile.discussion.TimePeriod) CourseDiscussionInfo(org.edx.mobile.discussion.CourseDiscussionInfo) List(java.util.List) ArrayList(java.util.ArrayList) Date(java.util.Date)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 CourseDiscussionInfo (org.edx.mobile.discussion.CourseDiscussionInfo)1 TimePeriod (org.edx.mobile.discussion.TimePeriod)1 TaskProgressCallback (org.edx.mobile.view.common.TaskProgressCallback)1