Fixes composer not saving/restoring its text on configuration changes for some devices.

This commit is contained in:
Vavassor 2017-03-26 17:21:18 -04:00
parent b3e9b86b61
commit 5f2ddcfdc0

View file

@ -390,6 +390,7 @@ public class ComposeActivity extends BaseActivity {
Intent intent = getIntent(); Intent intent = getIntent();
String[] mentionedUsernames = null; String[] mentionedUsernames = null;
inReplyToId = null;
if (intent != null) { if (intent != null) {
inReplyToId = intent.getStringExtra("in_reply_to_id"); inReplyToId = intent.getStringExtra("in_reply_to_id");
String replyVisibility = intent.getStringExtra("reply_visibility"); String replyVisibility = intent.getStringExtra("reply_visibility");
@ -410,7 +411,7 @@ public class ComposeActivity extends BaseActivity {
textEditor = createEditText(null); // new String[] { "image/gif", "image/webp" } textEditor = createEditText(null); // new String[] { "image/gif", "image/webp" }
if (savedInstanceState != null) { if (savedInstanceState != null) {
textEditor.onRestoreInstanceState(savedInstanceState.getParcelable("textEditorState")); restoreTextEditorState(savedInstanceState.getParcelable("textEditorState"));
} }
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,
@ -541,7 +542,7 @@ public class ComposeActivity extends BaseActivity {
outState.putString("statusVisibility", statusVisibility); outState.putString("statusVisibility", statusVisibility);
outState.putBoolean("statusMarkSensitive", statusMarkSensitive); outState.putBoolean("statusMarkSensitive", statusMarkSensitive);
outState.putBoolean("statusHideText", statusHideText); outState.putBoolean("statusHideText", statusHideText);
outState.putParcelable("textEditorState", textEditor.onSaveInstanceState()); outState.putParcelable("textEditorState", saveTextEditorState());
if (currentInputContentInfo != null) { if (currentInputContentInfo != null) {
outState.putParcelable("commitContentInputContentInfo", outState.putParcelable("commitContentInputContentInfo",
(Parcelable) currentInputContentInfo.unwrap()); (Parcelable) currentInputContentInfo.unwrap());
@ -552,6 +553,28 @@ public class ComposeActivity extends BaseActivity {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
private Parcelable saveTextEditorState() {
Bundle bundle = new Bundle();
bundle.putString("text", HtmlUtils.toHtml(textEditor.getText()));
bundle.putInt("selectionStart", textEditor.getSelectionStart());
bundle.putInt("selectionEnd", textEditor.getSelectionEnd());
return bundle;
}
private void restoreTextEditorState(Parcelable state) {
Bundle bundle = (Bundle) state;
textEditor.setText(HtmlUtils.fromHtml(bundle.getString("text")));
int start = bundle.getInt("selectionStart");
int end = bundle.getInt("selectionEnd");
if (start != -1) {
if (end != -1) {
textEditor.setSelection(start, end);
} else {
textEditor.setSelection(start);
}
}
}
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();