Fix crash when using GitHub issue form

This commit is contained in:
Eugene Cheung 2017-06-12 17:30:50 -04:00
commit 0b7d2591b4

View file

@ -72,15 +72,23 @@ public class BugReportActivity extends AbsThemeActivity {
@BindView(R.id.toolbar) @BindView(R.id.toolbar)
Toolbar toolbar; Toolbar toolbar;
@BindView(R.id.input_layout_title)
TextInputLayout inputLayoutTitle;
@BindView(R.id.input_title) @BindView(R.id.input_title)
TextInputEditText inputTitle; TextInputEditText inputTitle;
@BindView(R.id.input_layout_description)
TextInputLayout inputLayoutDescription;
@BindView(R.id.input_description) @BindView(R.id.input_description)
TextInputEditText inputDescription; TextInputEditText inputDescription;
@BindView(R.id.air_textDeviceInfo) @BindView(R.id.air_textDeviceInfo)
TextView textDeviceInfo; TextView textDeviceInfo;
@BindView(R.id.input_layout_username)
TextInputLayout inputLayoutUsername;
@BindView(R.id.input_username) @BindView(R.id.input_username)
TextInputEditText inputUsername; TextInputEditText inputUsername;
@BindView(R.id.input_layout_password)
TextInputLayout inputLayoutPassword;
@BindView(R.id.input_password) @BindView(R.id.input_password)
TextInputEditText inputPassword; TextInputEditText inputPassword;
@BindView(R.id.option_use_account) @BindView(R.id.option_use_account)
@ -223,45 +231,43 @@ public class BugReportActivity extends AbsThemeActivity {
if (optionUseAccount.isChecked()) { if (optionUseAccount.isChecked()) {
if (TextUtils.isEmpty(inputUsername.getText())) { if (TextUtils.isEmpty(inputUsername.getText())) {
setError(inputUsername, R.string.bug_report_no_username); setError(inputLayoutUsername, R.string.bug_report_no_username);
hasErrors = true; hasErrors = true;
} else { } else {
removeError(inputUsername); removeError(inputLayoutUsername);
} }
if (TextUtils.isEmpty(inputPassword.getText())) { if (TextUtils.isEmpty(inputPassword.getText())) {
setError(inputPassword, R.string.bug_report_no_password); setError(inputLayoutPassword, R.string.bug_report_no_password);
hasErrors = true; hasErrors = true;
} else { } else {
removeError(inputPassword); removeError(inputLayoutPassword);
} }
} }
if (TextUtils.isEmpty(inputTitle.getText())) { if (TextUtils.isEmpty(inputTitle.getText())) {
setError(inputTitle, R.string.bug_report_no_title); setError(inputLayoutTitle, R.string.bug_report_no_title);
hasErrors = true; hasErrors = true;
} else { } else {
removeError(inputTitle); removeError(inputLayoutTitle);
} }
if (TextUtils.isEmpty(inputDescription.getText())) { if (TextUtils.isEmpty(inputDescription.getText())) {
setError(inputDescription, R.string.bug_report_no_description); setError(inputLayoutDescription, R.string.bug_report_no_description);
hasErrors = true; hasErrors = true;
} else { } else {
removeError(inputDescription); removeError(inputLayoutDescription);
} }
return !hasErrors; return !hasErrors;
} }
private void setError(TextInputEditText editText, @StringRes int errorRes) { private void setError(TextInputLayout editTextLayout, @StringRes int errorRes) {
TextInputLayout layout = (TextInputLayout) editText.getParent(); editTextLayout.setError(getString(errorRes));
layout.setError(getString(errorRes));
} }
private void removeError(TextInputEditText editText) { private void removeError(TextInputLayout editTextLayout) {
TextInputLayout layout = (TextInputLayout) editText.getParent(); editTextLayout.setError(null);
layout.setError(null);
} }
private void sendBugReport(GithubLogin login) { private void sendBugReport(GithubLogin login) {