Fix issue #79 - Delete & redraft for replies lose reference to initial message

This commit is contained in:
Thomas 2022-05-22 17:54:12 +02:00
parent 321021c9dd
commit 8a1e6240b7

View file

@ -174,16 +174,13 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
statusDraftList.add(status); statusDraftList.add(status);
if (statusReplyId != null && statusDraft != null) {//Delete and redraft if (statusReplyId != null && statusDraft != null) {//Delete and redraft
ArrayList<Status> statusDraftListDR = new ArrayList<>(); statusesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusReplyId)
statusDraftListDR.add(statusDraft.statusDraftList.get(0)); .observe(ComposeActivity.this, status1 -> {
statusList.addAll(statusDraftListDR); statusesVM.getContext(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusReplyId)
composeAdapter = new ComposeAdapter(statusList, 0, account, accountMention, visibility); .observe(ComposeActivity.this, statusContext -> {
composeAdapter.manageDrafts = this; initializeContextRedraftView(statusContext, status1);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); });
binding.recyclerView.setLayoutManager(mLayoutManager); });
binding.recyclerView.setAdapter(composeAdapter);
statusesVM.getContext(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusReplyId)
.observe(ComposeActivity.this, this::initializeContextView);
} else if (statusDraft != null) {//Restore a draft with all messages } else if (statusDraft != null) {//Restore a draft with all messages
new Thread(() -> { new Thread(() -> {
if (statusDraft.statusReplyList != null) { if (statusDraft.statusReplyList != null) {
@ -321,6 +318,32 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
} }
/**
* Intialize the common view for the context
*
* @param context {@link Context}
*/
private void initializeContextRedraftView(final Context context, Status initialStatus) {
if (context == null) {
return;
}
//Build the array of statuses
statusList.addAll(0, context.ancestors);
statusList.add(initialStatus);
statusList.add(statusDraft.statusDraftList.get(0));
composeAdapter = new ComposeAdapter(statusList, context.ancestors.size(), account, accountMention, visibility);
composeAdapter.manageDrafts = this;
LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this);
binding.recyclerView.setLayoutManager(mLayoutManager);
binding.recyclerView.setAdapter(composeAdapter);
composeAdapter.setStatusCount(context.ancestors.size() + 1);
binding.recyclerView.addItemDecoration(new DividerDecorationSimple(ComposeActivity.this, statusList));
binding.recyclerView.scrollToPosition(composeAdapter.getItemCount() - 1);
}
@Override @Override
public boolean onCreateOptionsMenu(@NonNull Menu menu) { public boolean onCreateOptionsMenu(@NonNull Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present. // Inflate the menu; this adds items to the action bar if it is present.