Search in sources :

Example 1 with DiscussionTopicDepth

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

the class TopicSpinnerAdapter method getView.

@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    final TextView view;
    if (convertView == null) {
        view = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.edx_spinner_item, parent, false);
    } else {
        view = (TextView) convertView;
    }
    final DiscussionTopicDepth topic = getItem(position);
    view.setText(ResourceUtil.getFormattedString(getContext().getResources(), R.string.discussion_add_post_topic_selection, "topic", topic.getDiscussionTopic().getName()));
    return view;
}
Also used : TextView(android.widget.TextView) DiscussionTopicDepth(org.edx.mobile.discussion.DiscussionTopicDepth)

Example 2 with DiscussionTopicDepth

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

the class TopicSpinnerAdapter method getDropDownView.

@Override
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    final TextView view;
    if (convertView == null) {
        view = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.edx_spinner_dropdown_item, parent, false);
    } else {
        view = (TextView) convertView;
    }
    final DiscussionTopicDepth topic = getItem(position);
    final int extraLeftPadding = topic.getDepth() * extraPaddingPerLevel;
    ViewCompat.setPaddingRelative(view, basePadding + extraLeftPadding, view.getPaddingTop(), basePadding, view.getPaddingBottom());
    view.setText(topic.getDiscussionTopic().getName());
    view.setEnabled(isEnabled(position));
    return view;
}
Also used : TextView(android.widget.TextView) DiscussionTopicDepth(org.edx.mobile.discussion.DiscussionTopicDepth)

Example 3 with DiscussionTopicDepth

use of org.edx.mobile.discussion.DiscussionTopicDepth 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 4 with DiscussionTopicDepth

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

the class DiscussionAddPostFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    discussionQuestionSegmentedGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            @StringRes final int bodyHint;
            @StringRes final int submitLabel;
            @StringRes final int submitDescription;
            if (discussionQuestionSegmentedGroup.getCheckedRadioButtonId() == R.id.discussion_radio_button) {
                bodyHint = R.string.discussion_body_hint_discussion;
                submitLabel = R.string.discussion_add_post_button_label;
                submitDescription = R.string.discussion_add_post_button_description;
            } else {
                bodyHint = R.string.discussion_body_hint_question;
                submitLabel = R.string.discussion_add_question_button_label;
                submitDescription = R.string.discussion_add_question_button_description;
            }
            bodyEditText.setHint(bodyHint);
            addPostButtonText.setText(submitLabel);
            addPostButton.setContentDescription(getText(submitDescription));
        }
    });
    discussionQuestionSegmentedGroup.check(R.id.discussion_radio_button);
    getTopicList();
    topicsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // Even though we disabled topics that aren't supposed to be selected, Android still allows you to select them using keyboard or finger-dragging
            // So, we have to revert the user's selection if they select a topic that cannot be posted to
            final DiscussionTopicDepth item = (DiscussionTopicDepth) parent.getItemAtPosition(position);
            if (null == item || item.isPostable()) {
                selectedTopicIndex = position;
            } else {
                // Revert selection
                parent.setSelection(selectedTopicIndex);
            }
            setPostButtonEnabledState();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            setPostButtonEnabledState();
        }
    });
    ViewCompat.setBackgroundTintList(topicsSpinner, getResources().getColorStateList(R.color.edx_brand_gray_base));
    addPostButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            Activity activity = getActivity();
            if (activity != null) {
                SoftKeyboardUtil.hide(activity);
            }
            final String title = titleEditText.getText().toString();
            final String body = bodyEditText.getText().toString();
            final DiscussionThread.ThreadType discussionQuestion;
            if (discussionQuestionSegmentedGroup.getCheckedRadioButtonId() == R.id.discussion_radio_button) {
                discussionQuestion = DiscussionThread.ThreadType.DISCUSSION;
            } else {
                discussionQuestion = DiscussionThread.ThreadType.QUESTION;
            }
            ThreadBody threadBody = new ThreadBody();
            threadBody.setCourseId(courseData.getCourse().getId());
            threadBody.setTitle(title);
            threadBody.setRawBody(body);
            threadBody.setTopicId(((DiscussionTopicDepth) topicsSpinner.getSelectedItem()).getDiscussionTopic().getIdentifier());
            threadBody.setType(discussionQuestion);
            addPostButton.setEnabled(false);
            createThread(threadBody);
        }
    });
    addPostButton.setEnabled(false);
    final TextWatcher textWatcher = new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            setPostButtonEnabledState();
        }
    };
    titleEditText.addTextChangedListener(textWatcher);
    bodyEditText.addTextChangedListener(textWatcher);
}
Also used : RadioGroup(android.widget.RadioGroup) ThreadBody(org.edx.mobile.discussion.ThreadBody) Activity(android.app.Activity) View(android.view.View) AdapterView(android.widget.AdapterView) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) DiscussionTopicDepth(org.edx.mobile.discussion.DiscussionTopicDepth) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AdapterView(android.widget.AdapterView)

Aggregations

TextView (android.widget.TextView)4 DiscussionTopicDepth (org.edx.mobile.discussion.DiscussionTopicDepth)4 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 InjectView (roboguice.inject.InjectView)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 LayoutInflater (android.view.LayoutInflater)1 ListView (android.widget.ListView)1 RadioGroup (android.widget.RadioGroup)1 SearchView (android.widget.SearchView)1 IconDrawable (com.joanzapata.iconify.IconDrawable)1 DiscussionTopic (org.edx.mobile.discussion.DiscussionTopic)1 ThreadBody (org.edx.mobile.discussion.ThreadBody)1 FullScreenErrorNotification (org.edx.mobile.http.notifications.FullScreenErrorNotification)1