Fixes a crash and errors associated with a URL pasted into the composer being edited before its metadata is loaded.

This commit is contained in:
Vavassor 2017-07-25 19:23:37 -04:00
parent e5deac0fa9
commit 2ed979d7fd
1 changed files with 6 additions and 14 deletions

View File

@ -1472,10 +1472,12 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
@Override @Override
public void onReceiveHeaderInfo(ParserUtils.HeaderInfo headerInfo) { public void onReceiveHeaderInfo(ParserUtils.HeaderInfo headerInfo) {
if (!TextUtils.isEmpty(headerInfo.title)) { if (!TextUtils.isEmpty(headerInfo.title)) {
cleanBaseUrl(headerInfo); Editable text = textEditor.getText();
textEditor.append(headerInfo.title); int index = text.toString().indexOf(headerInfo.baseUrl);
textEditor.append(StringUtils.carriageReturn); if (index < 0) {
textEditor.append(headerInfo.baseUrl); index = 0;
}
text.insert(index, headerInfo.title + StringUtils.carriageReturn);
} }
if (!TextUtils.isEmpty(headerInfo.image)) { if (!TextUtils.isEmpty(headerInfo.image)) {
Picasso.Builder builder = new Picasso.Builder(getApplicationContext()); Picasso.Builder builder = new Picasso.Builder(getApplicationContext());
@ -1505,16 +1507,6 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
} }
} }
// remove the precedent paste from the edit text
private void cleanBaseUrl(ParserUtils.HeaderInfo headerInfo) {
int lengthBaseUrl = headerInfo.baseUrl.length();
int total = textEditor.getText().length();
int indexSubString = total - lengthBaseUrl;
String text = textEditor.getText().toString();
text = text.substring(0, indexSubString);
textEditor.setText(text);
}
@Override @Override
public void onErrorHeaderInfo() { public void onErrorHeaderInfo() {
displayTransientError(R.string.error_generic); displayTransientError(R.string.error_generic);