Fixes a crash when changing orientation in the composer.

This commit is contained in:
Vavassor 2017-04-04 16:02:08 -04:00
parent e311a67a8f
commit eef0f82e96
1 changed files with 4 additions and 3 deletions

View File

@ -416,8 +416,10 @@ public class ComposeActivity extends BaseActivity {
setStatusVisibility(startingVisibility); setStatusVisibility(startingVisibility);
textEditor = createEditText(null); // new String[] { "image/gif", "image/webp" } textEditor = createEditText(null); // new String[] { "image/gif", "image/webp" }
final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color);
if (savedInstanceState != null) { if (savedInstanceState != null) {
restoreTextEditorState(savedInstanceState.getParcelable("textEditorState")); restoreTextEditorState(savedInstanceState.getParcelable("textEditorState"));
highlightSpans(textEditor.getText(), mentionColour);
} }
RelativeLayout editArea = (RelativeLayout) findViewById(R.id.compose_edit_area); RelativeLayout editArea = (RelativeLayout) findViewById(R.id.compose_edit_area);
/* Adding this at index zero because it implicitly gives it the lowest input priority. So, /* Adding this at index zero because it implicitly gives it the lowest input priority. So,
@ -426,7 +428,6 @@ public class ComposeActivity extends BaseActivity {
editArea.addView(textEditor, 0); editArea.addView(textEditor, 0);
contentWarningEditor = (EditText) findViewById(R.id.field_content_warning); contentWarningEditor = (EditText) findViewById(R.id.field_content_warning);
final TextView charactersLeft = (TextView) findViewById(R.id.characters_left); final TextView charactersLeft = (TextView) findViewById(R.id.characters_left);
final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color);
textEditor.addTextChangedListener(new TextWatcher() { textEditor.addTextChangedListener(new TextWatcher() {
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
@ -589,7 +590,7 @@ public class ComposeActivity extends BaseActivity {
private Parcelable saveTextEditorState() { private Parcelable saveTextEditorState() {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("text", HtmlUtils.toHtml(textEditor.getText())); bundle.putString("text", textEditor.getText().toString());
bundle.putInt("selectionStart", textEditor.getSelectionStart()); bundle.putInt("selectionStart", textEditor.getSelectionStart());
bundle.putInt("selectionEnd", textEditor.getSelectionEnd()); bundle.putInt("selectionEnd", textEditor.getSelectionEnd());
return bundle; return bundle;
@ -597,7 +598,7 @@ public class ComposeActivity extends BaseActivity {
private void restoreTextEditorState(Parcelable state) { private void restoreTextEditorState(Parcelable state) {
Bundle bundle = (Bundle) state; Bundle bundle = (Bundle) state;
textEditor.setText(HtmlUtils.fromHtml(bundle.getString("text"))); textEditor.setText(bundle.getString("text"));
int start = bundle.getInt("selectionStart"); int start = bundle.getInt("selectionStart");
int end = bundle.getInt("selectionEnd"); int end = bundle.getInt("selectionEnd");
if (start != -1) { if (start != -1) {