Search in sources :

Example 1 with DiscussionTopic

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();
}
Also used : Context(android.content.Context) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(android.widget.SearchView) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) ListView(android.widget.ListView) DiscussionTopic(org.edx.mobile.discussion.DiscussionTopic) DiscussionTopicDepth(org.edx.mobile.discussion.DiscussionTopicDepth) FullScreenErrorNotification(org.edx.mobile.http.notifications.FullScreenErrorNotification) SearchView(android.widget.SearchView) LayoutInflater(android.view.LayoutInflater) IconDrawable(com.joanzapata.iconify.IconDrawable) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView)

Example 2 with DiscussionTopic

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);
        }
    });
}
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

DiscussionTopic (org.edx.mobile.discussion.DiscussionTopic)2 Context (android.content.Context)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 SearchView (android.widget.SearchView)1 TextView (android.widget.TextView)1 IconDrawable (com.joanzapata.iconify.IconDrawable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CourseTopics (org.edx.mobile.discussion.CourseTopics)1 DiscussionTopicDepth (org.edx.mobile.discussion.DiscussionTopicDepth)1 FullScreenErrorNotification (org.edx.mobile.http.notifications.FullScreenErrorNotification)1 TopicSpinnerAdapter (org.edx.mobile.view.adapters.TopicSpinnerAdapter)1 InjectView (roboguice.inject.InjectView)1