Fix contact not added when composing

This commit is contained in:
Thomas 2022-12-12 18:13:06 +01:00
parent 2c32113476
commit bd8d3405b2
3 changed files with 25 additions and 12 deletions

View File

@ -402,8 +402,8 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
return true;
}
private void onRetrieveContact(PopupContactBinding binding, List<app.fedilab.android.client.entities.api.Account> accounts) {
binding.loader.setVisibility(View.GONE);
private void onRetrieveContact(PopupContactBinding popupContactBinding, List<app.fedilab.android.client.entities.api.Account> 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

View File

@ -34,7 +34,6 @@ public class AccountsReplyAdapter extends RecyclerView.Adapter<RecyclerView.View
private final boolean[] checked;
public ActionDone actionDone;
public AccountsReplyAdapter(List<Account> accounts, List<Boolean> checked) {
this.accounts = accounts;
this.checked = new boolean[checked.size()];

View File

@ -142,6 +142,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
private List<Emoji> emojisList = new ArrayList<>();
public promptDraftListener promptDraftListener;
private boolean unlisted_changed = false;
public static int currentCursorPosition;
public ComposeAdapter(List<Status> 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<RecyclerView.ViewHolder
} else {
holder.binding.content.requestFocus();
}
}
public void setStatusCount(int count) {
@ -852,19 +854,25 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
//It only targets last message in a thread
//Return content of last compose message
public String getLastComposeContent() {
return statusList.get(statusList.size() - 1).text != null ? statusList.get(statusList.size() - 1).text : "";
return statusList.get(currentCursorPosition).text != null ? statusList.get(currentCursorPosition).text : "";
}
//------- end contact ----->
//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<RecyclerView.ViewHolder
addAttachment(position, uris);
}
});
holder.binding.content.setOnFocusChangeListener((view, focused) -> {
if (focused) {
currentCursorPosition = position;
}
});
if (statusDraft.cursorPosition <= holder.binding.content.length()) {
holder.binding.content.setSelection(statusDraft.cursorPosition);
}