diff --git a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java index c9cedf5b8..f5244ea64 100644 --- a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java @@ -402,8 +402,8 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana return true; } - private void onRetrieveContact(PopupContactBinding binding, List accounts) { - binding.loader.setVisibility(View.GONE); + private void onRetrieveContact(PopupContactBinding popupContactBinding, List accounts) { + popupContactBinding.loader.setVisibility(View.GONE); if (accounts == null) { accounts = new ArrayList<>(); } @@ -413,8 +413,9 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana checkedValues.add(composeAdapter.getLastComposeContent().contains("@" + account.acct)); } AccountsReplyAdapter contactAdapter = new AccountsReplyAdapter(contacts, checkedValues); - binding.lvAccountsSearch.setAdapter(contactAdapter); - binding.lvAccountsSearch.setLayoutManager(new LinearLayoutManager(ComposeActivity.this)); + contactAdapter.actionDone = ComposeActivity.this; + popupContactBinding.lvAccountsSearch.setAdapter(contactAdapter); + popupContactBinding.lvAccountsSearch.setLayoutManager(new LinearLayoutManager(ComposeActivity.this)); } @Override diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/AccountsReplyAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/AccountsReplyAdapter.java index 2b23a0e5e..c0b378bf7 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/AccountsReplyAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/AccountsReplyAdapter.java @@ -34,7 +34,6 @@ public class AccountsReplyAdapter extends RecyclerView.Adapter accounts, List checked) { this.accounts = accounts; this.checked = new boolean[checked.size()]; diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java index b911b5231..b9fa08c55 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java @@ -142,6 +142,7 @@ public class ComposeAdapter extends RecyclerView.Adapter emojisList = new ArrayList<>(); public promptDraftListener promptDraftListener; private boolean unlisted_changed = false; + public static int currentCursorPosition; public ComposeAdapter(List statusList, int statusCount, BaseAccount account, app.fedilab.android.client.entities.api.Account mentionedAccount, String visibility, String editMessageId) { this.statusList = statusList; @@ -298,6 +299,7 @@ public class ComposeAdapter extends RecyclerView.Adapter //Used to write contact when composing public void updateContent(boolean checked, String acct) { - if (checked) { - if (!statusList.get(statusList.size() - 1).text.contains(acct)) - statusList.get(statusList.size() - 1).text = String.format("%s %s", acct, statusList.get(statusList.size() - 1).text); - } else { - statusList.get(statusList.size() - 1).text = statusList.get(statusList.size() - 1).text.replaceAll("\\s*" + acct, ""); + if (currentCursorPosition < statusList.size()) { + if (checked) { + if (statusList.get(currentCursorPosition).text == null) { + statusList.get(currentCursorPosition).text = ""; + } + if (!statusList.get(currentCursorPosition).text.contains(acct)) { + statusList.get(currentCursorPosition).text = String.format("@%s %s", acct, statusList.get(currentCursorPosition).text); + } + } else { + statusList.get(currentCursorPosition).text = statusList.get(currentCursorPosition).text.replaceAll("\\b@" + acct, ""); + } + notifyItemChanged(currentCursorPosition); } - notifyItemChanged(statusList.size() - 1); } //Put cursor to the end after changing contacts @@ -1316,6 +1324,11 @@ public class ComposeAdapter extends RecyclerView.Adapter { + if (focused) { + currentCursorPosition = position; + } + }); if (statusDraft.cursorPosition <= holder.binding.content.length()) { holder.binding.content.setSelection(statusDraft.cursorPosition); }