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