use of org.edx.mobile.view.adapters.TopicSpinnerAdapter 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);
}
});
}
Aggregations