From 2ed979d7fdab001f1e234812f4316738a1006e99 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Tue, 25 Jul 2017 19:23:37 -0400 Subject: [PATCH] Fixes a crash and errors associated with a URL pasted into the composer being edited before its metadata is loaded. --- .../keylesspalace/tusky/ComposeActivity.java | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 2a021dc8b..2b1a5ea8f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -1472,10 +1472,12 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm @Override public void onReceiveHeaderInfo(ParserUtils.HeaderInfo headerInfo) { if (!TextUtils.isEmpty(headerInfo.title)) { - cleanBaseUrl(headerInfo); - textEditor.append(headerInfo.title); - textEditor.append(StringUtils.carriageReturn); - textEditor.append(headerInfo.baseUrl); + Editable text = textEditor.getText(); + int index = text.toString().indexOf(headerInfo.baseUrl); + if (index < 0) { + index = 0; + } + text.insert(index, headerInfo.title + StringUtils.carriageReturn); } if (!TextUtils.isEmpty(headerInfo.image)) { 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 public void onErrorHeaderInfo() { displayTransientError(R.string.error_generic);