From e787a270050386142122f7ed804efb2b1c82e079 Mon Sep 17 00:00:00 2001 From: stom79 Date: Tue, 26 Dec 2017 12:33:11 +0100 Subject: [PATCH] Fixes issue #201 - Mentions in replies & cursor position --- .../mastodon/activities/TootActivity.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index aedd715a5..f8884cd3b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -1857,27 +1857,31 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount } //Retrieves mentioned accounts + OP and adds them at the beginin of the toot ArrayList mentionedAccountsAdded = new ArrayList<>(); + int cursorReply = 0; if( tootReply.getAccount() != null && tootReply.getAccount().getAcct() != null && !tootReply.getAccount().getId().equals(userId)) { - toot_content.setText(String.format("@%s ", tootReply.getAccount().getAcct())); + toot_content.setText(String.format("@%s", tootReply.getAccount().getAcct())); mentionedAccountsAdded.add(tootReply.getAccount().getAcct()); + //Evaluate the cursor position => mention length + 1 char for carriage return + cursorReply = toot_content.getText().toString().length() + 1; } if( tootReply.getMentions() != null ){ + //Put other accounts mentioned at the bottom + toot_content.setText(String.format("%s", (toot_content.getText().toString() + "\n\n"))); for(Mention mention : tootReply.getMentions()){ if( mention.getAcct() != null && !mention.getId().equals(userId) && !mentionedAccountsAdded.contains(mention.getAcct())) { mentionedAccountsAdded.add(mention.getAcct()); String tootTemp = String.format("@%s ", mention.getAcct()); - toot_content.setText(String.format("%s ", (toot_content.getText().toString() + " " + tootTemp))); + toot_content.setText(String.format("%s ", (toot_content.getText().toString() + tootTemp.trim()))); } } } - toot_content.setText(toot_content.getText().toString().trim()); - if (toot_content.getText().toString().startsWith("@")) { - toot_content.append("\n"); - } toot_space_left.setText(String.valueOf(toot_content.length())); toot_content.requestFocus(); - toot_content.setSelection(toot_content.getText().length()); //Put cursor at the end + if( cursorReply > 0 ) + toot_content.setSelection(cursorReply); + else + toot_content.setSelection(toot_content.getText().length()); //Put cursor at the end } initialContent = toot_content.getText().toString(); }