Search in sources :

Example 1 with CourseTopics

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

the class CourseDiscussionPostsThreadFragment method fetchDiscussionTopic.

private void fetchDiscussionTopic() {
    String topicId = getArguments().getString(Router.EXTRA_DISCUSSION_TOPIC_ID);
    final Activity activity = getActivity();
    discussionService.getSpecificCourseTopics(courseData.getCourse().getId(), Collections.singletonList(topicId)).enqueue(new ErrorHandlingCallback<CourseTopics>(activity, new ProgressViewController(loadingIndicator), errorNotification) {

        @Override
        protected void onResponse(@NonNull final CourseTopics courseTopics) {
            discussionTopic = courseTopics.getCoursewareTopics().get(0).getChildren().get(0);
            if (activity != null && !getArguments().getBoolean(ARG_DISCUSSION_HAS_TOPIC_NAME)) {
                // We only need to set the title here when coming from a deep link
                activity.setTitle(discussionTopic.getName());
            }
            if (getView() != null) {
                if (populatePostListRunnable != null) {
                    populatePostListRunnable.run();
                }
                // Now that we have the topic data, we can allow the user to add new posts.
                setCreateNewPostBtnVisibility(View.VISIBLE);
            }
        }
    });
}
Also used : ProgressViewController(org.edx.mobile.view.common.TaskProgressCallback.ProgressViewController) Activity(android.app.Activity) CourseTopics(org.edx.mobile.discussion.CourseTopics)

Example 2 with CourseTopics

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

the class DiscussionAddPostFragment method getTopicList.

protected void getTopicList() {
    if (getTopicListCall != null) {
        getTopicListCall.cancel();
    }
    getTopicListCall = discussionService.getCourseTopics(courseData.getCourse().getId());
    getTopicListCall.enqueue(new ErrorHandlingCallback<CourseTopics>(getActivity(), null, null, CallTrigger.LOADING_CACHED) {

        @Override
        protected void onResponse(@NonNull final CourseTopics courseTopics) {
            final ArrayList<DiscussionTopic> allTopics = new ArrayList<>();
            allTopics.addAll(courseTopics.getNonCoursewareTopics());
            allTopics.addAll(courseTopics.getCoursewareTopics());
            final TopicSpinnerAdapter adapter = new TopicSpinnerAdapter(container.getContext(), DiscussionTopicDepth.createFromDiscussionTopics(allTopics));
            topicsSpinner.setAdapter(adapter);
            {
                // Otherwise, leave the default option, which is the first non-courseware topic
                if (!discussionTopic.isAllType() && !discussionTopic.isFollowingType()) {
                    int selectedTopicIndex = -1;
                    if (discussionTopic.getIdentifier() == null) {
                        // In case of a parent topic, we need to select the first child topic
                        if (!discussionTopic.getChildren().isEmpty()) {
                            selectedTopicIndex = adapter.getPosition(discussionTopic.getChildren().get(0));
                        }
                    } else {
                        selectedTopicIndex = adapter.getPosition(discussionTopic);
                    }
                    if (selectedTopicIndex >= 0) {
                        topicsSpinner.setSelection(selectedTopicIndex);
                    }
                }
            }
            DiscussionTopic selectedTopic = ((DiscussionTopicDepth) topicsSpinner.getSelectedItem()).getDiscussionTopic();
            Map<String, String> values = new HashMap<>();
            values.put(Analytics.Keys.TOPIC_ID, selectedTopic.getIdentifier());
            analyticsRegistry.trackScreenView(Analytics.Screens.FORUM_CREATE_TOPIC_THREAD, courseData.getCourse().getId(), selectedTopic.getName(), values);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) CourseTopics(org.edx.mobile.discussion.CourseTopics) TopicSpinnerAdapter(org.edx.mobile.view.adapters.TopicSpinnerAdapter) HashMap(java.util.HashMap) Map(java.util.Map) DiscussionTopic(org.edx.mobile.discussion.DiscussionTopic)

Aggregations

CourseTopics (org.edx.mobile.discussion.CourseTopics)2 Activity (android.app.Activity)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DiscussionTopic (org.edx.mobile.discussion.DiscussionTopic)1 TopicSpinnerAdapter (org.edx.mobile.view.adapters.TopicSpinnerAdapter)1 ProgressViewController (org.edx.mobile.view.common.TaskProgressCallback.ProgressViewController)1