use of org.edx.mobile.discussion.DiscussionTopic in project edx-app-android by edx.
the class CourseDiscussionTopicsFragment method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
errorNotification = new FullScreenErrorNotification((View) discussionTopicsListView.getParent());
final LayoutInflater inflater = LayoutInflater.from(getActivity());
// Add "All posts" item
{
final TextView header = (TextView) inflater.inflate(R.layout.row_discussion_topic, discussionTopicsListView, false);
header.setText(R.string.discussion_posts_filter_all_posts);
final DiscussionTopic discussionTopic = new DiscussionTopic();
discussionTopic.setIdentifier(DiscussionTopic.ALL_TOPICS_ID);
discussionTopic.setName(getString(R.string.discussion_posts_filter_all_posts));
discussionTopicsListView.addHeaderView(header, new DiscussionTopicDepth(discussionTopic, 0, true), true);
}
// Add "Posts I'm following" item
{
final TextView header = (TextView) inflater.inflate(R.layout.row_discussion_topic, discussionTopicsListView, false);
header.setText(R.string.forum_post_i_am_following);
Context context = getActivity();
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(header, new IconDrawable(context, FontAwesomeIcons.fa_star).colorRes(context, R.color.edx_brand_gray_base).sizeRes(context, R.dimen.edx_base), null, null, null);
final DiscussionTopic discussionTopic = new DiscussionTopic();
discussionTopic.setIdentifier(DiscussionTopic.FOLLOWING_TOPICS_ID);
discussionTopic.setName(getString(R.string.forum_post_i_am_following));
discussionTopicsListView.addHeaderView(header, new DiscussionTopicDepth(discussionTopic, 0, true), true);
}
discussionTopicsListView.setAdapter(discussionTopicsAdapter);
discussionTopicsSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (query == null || query.trim().isEmpty())
return false;
router.showCourseDiscussionPostsForSearchQuery(getActivity(), query, courseData);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
discussionTopicsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
router.showCourseDiscussionPostsForDiscussionTopic(getActivity(), ((DiscussionTopicDepth) parent.getItemAtPosition(position)).getDiscussionTopic(), courseData);
}
});
getTopicList();
}
use of org.edx.mobile.discussion.DiscussionTopic 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