use of org.edx.mobile.discussion.ThreadBody 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