mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-07-14 07:30:29 +03:00
#1237 - Wrong messages deleted for scheduled (messages and boosts)
This commit is contained in:
parent
e6a8a45e03
commit
477b2bfc3b
1 changed files with 33 additions and 47 deletions
|
@ -62,9 +62,6 @@ public class StatusScheduledAdapter extends RecyclerView.Adapter<StatusScheduled
|
||||||
private final List<ScheduledBoost> scheduledBoosts;
|
private final List<ScheduledBoost> scheduledBoosts;
|
||||||
public ScheduledActions scheduledActions;
|
public ScheduledActions scheduledActions;
|
||||||
private Context context;
|
private Context context;
|
||||||
private ScheduledStatus scheduledStatus;
|
|
||||||
private StatusDraft statusDraft;
|
|
||||||
private ScheduledBoost scheduledBoost;
|
|
||||||
|
|
||||||
public StatusScheduledAdapter(List<ScheduledStatus> scheduledStatuses, List<StatusDraft> statusDraftList, List<ScheduledBoost> scheduledBoosts) {
|
public StatusScheduledAdapter(List<ScheduledStatus> scheduledStatuses, List<StatusDraft> statusDraftList, List<ScheduledBoost> scheduledBoosts) {
|
||||||
this.scheduledStatuses = scheduledStatuses;
|
this.scheduledStatuses = scheduledStatuses;
|
||||||
|
@ -83,32 +80,27 @@ public class StatusScheduledAdapter extends RecyclerView.Adapter<StatusScheduled
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull StatusScheduledHolder holder, int position) {
|
public void onBindViewHolder(@NonNull StatusScheduledHolder holder, int position) {
|
||||||
|
|
||||||
scheduledStatus = null;
|
|
||||||
statusDraft = null;
|
|
||||||
String scheduledDate = null;
|
String scheduledDate = null;
|
||||||
String statusContent = null;
|
String statusContent = null;
|
||||||
if (scheduledStatuses != null) {
|
if (scheduledStatuses != null && scheduledStatuses.size() > position) {
|
||||||
scheduledStatus = scheduledStatuses.get(position);
|
scheduledDate = Helper.dateToString(scheduledStatuses.get(position).scheduled_at);
|
||||||
scheduledDate = Helper.dateToString(scheduledStatus.scheduled_at);
|
statusContent = scheduledStatuses.get(position).params.text;
|
||||||
statusContent = scheduledStatus.params.text;
|
if (scheduledStatuses.get(position).params.in_reply_to_id != null) {
|
||||||
if (scheduledStatus.params.in_reply_to_id != null) {
|
|
||||||
holder.binding.reply.setVisibility(View.VISIBLE);
|
holder.binding.reply.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
holder.binding.reply.setVisibility(View.GONE);
|
holder.binding.reply.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
} else if (statusDraftList != null) {
|
} else if (statusDraftList != null && statusDraftList.size() > position) {
|
||||||
statusDraft = statusDraftList.get(position);
|
scheduledDate = Helper.dateToString(statusDraftList.get(position).scheduled_at);
|
||||||
scheduledDate = Helper.dateToString(statusDraft.scheduled_at);
|
statusContent = statusDraftList.get(position).statusDraftList.get(0).text;
|
||||||
statusContent = statusDraft.statusDraftList.get(0).text;
|
if (statusDraftList.get(position).statusDraftList.get(0).in_reply_to_id != null) {
|
||||||
if (statusDraft.statusDraftList.get(0).in_reply_to_id != null) {
|
|
||||||
holder.binding.reply.setVisibility(View.VISIBLE);
|
holder.binding.reply.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
holder.binding.reply.setVisibility(View.GONE);
|
holder.binding.reply.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
} else if (scheduledBoosts != null) {
|
} else if (scheduledBoosts != null && scheduledBoosts.size() > position) {
|
||||||
scheduledBoost = scheduledBoosts.get(position);
|
scheduledDate = Helper.dateToString(scheduledBoosts.get(position).scheduledAt);
|
||||||
scheduledDate = Helper.dateToString(scheduledBoost.scheduledAt);
|
if (scheduledBoosts.get(position).status.in_reply_to_id != null) {
|
||||||
if (scheduledBoost.status.in_reply_to_id != null) {
|
|
||||||
holder.binding.reply.setVisibility(View.VISIBLE);
|
holder.binding.reply.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
holder.binding.reply.setVisibility(View.GONE);
|
holder.binding.reply.setVisibility(View.GONE);
|
||||||
|
@ -117,10 +109,10 @@ public class StatusScheduledAdapter extends RecyclerView.Adapter<StatusScheduled
|
||||||
|
|
||||||
holder.binding.date.setText(scheduledDate);
|
holder.binding.date.setText(scheduledDate);
|
||||||
|
|
||||||
if (scheduledBoost != null) {
|
if (scheduledBoosts != null && scheduledBoosts.size() > position) {
|
||||||
SpannableString statusContentSpan;
|
SpannableString statusContentSpan;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||||
statusContentSpan = new SpannableString(Html.fromHtml(scheduledBoost.status.content, FROM_HTML_MODE_LEGACY));
|
statusContentSpan = new SpannableString(Html.fromHtml(scheduledBoosts.get(position).status.content, FROM_HTML_MODE_LEGACY));
|
||||||
else
|
else
|
||||||
statusContentSpan = new SpannableString(Html.fromHtml(statusContent));
|
statusContentSpan = new SpannableString(Html.fromHtml(statusContent));
|
||||||
holder.binding.statusContent.setText(statusContentSpan, TextView.BufferType.SPANNABLE);
|
holder.binding.statusContent.setText(statusContentSpan, TextView.BufferType.SPANNABLE);
|
||||||
|
@ -161,43 +153,37 @@ public class StatusScheduledAdapter extends RecyclerView.Adapter<StatusScheduled
|
||||||
unfollowConfirm.setMessage(context.getString(R.string.remove_scheduled));
|
unfollowConfirm.setMessage(context.getString(R.string.remove_scheduled));
|
||||||
unfollowConfirm.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
unfollowConfirm.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||||
unfollowConfirm.setPositiveButton(R.string.delete, (dialog, which) -> {
|
unfollowConfirm.setPositiveButton(R.string.delete, (dialog, which) -> {
|
||||||
if (scheduledStatus != null) {
|
if (scheduledStatuses != null && scheduledStatuses.size() > position) {
|
||||||
StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class);
|
StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class);
|
||||||
statusesVM.deleteScheduledStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, scheduledStatus.id)
|
statusesVM.deleteScheduledStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, scheduledStatuses.get(position).id)
|
||||||
.observe((LifecycleOwner) context, unused -> {
|
.observe((LifecycleOwner) context, unused -> {
|
||||||
if (scheduledStatuses != null) {
|
scheduledStatuses.remove(scheduledStatuses.get(position));
|
||||||
scheduledStatuses.remove(scheduledStatus);
|
if (scheduledStatuses.isEmpty()) {
|
||||||
if (scheduledStatuses.isEmpty()) {
|
scheduledActions.onAllDeleted();
|
||||||
scheduledActions.onAllDeleted();
|
|
||||||
}
|
|
||||||
notifyItemRemoved(position);
|
|
||||||
}
|
}
|
||||||
|
notifyItemRemoved(position);
|
||||||
});
|
});
|
||||||
} else if (statusDraft != null) {
|
} else if (statusDraftList != null && statusDraftList.size() > position) {
|
||||||
try {
|
try {
|
||||||
new StatusDraft(context).removeScheduled(statusDraft);
|
new StatusDraft(context).removeScheduled(statusDraftList.get(position));
|
||||||
WorkManager.getInstance(context).cancelWorkById(statusDraft.workerUuid);
|
WorkManager.getInstance(context).cancelWorkById(statusDraftList.get(position).workerUuid);
|
||||||
if (statusDraftList != null) {
|
statusDraftList.remove(statusDraftList.get(position));
|
||||||
statusDraftList.remove(statusDraft);
|
if (statusDraftList.isEmpty()) {
|
||||||
if (statusDraftList.isEmpty()) {
|
scheduledActions.onAllDeleted();
|
||||||
scheduledActions.onAllDeleted();
|
|
||||||
}
|
|
||||||
notifyItemRemoved(position);
|
|
||||||
}
|
}
|
||||||
|
notifyItemRemoved(position);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else if (scheduledBoost != null) {
|
} else if (scheduledBoosts != null && position < scheduledBoosts.size()) {
|
||||||
try {
|
try {
|
||||||
new ScheduledBoost(context).removeScheduled(scheduledBoost);
|
new ScheduledBoost(context).removeScheduled(scheduledBoosts.get(position));
|
||||||
WorkManager.getInstance(context).cancelWorkById(scheduledBoost.workerUuid);
|
WorkManager.getInstance(context).cancelWorkById(scheduledBoosts.get(position).workerUuid);
|
||||||
if (scheduledBoosts != null) {
|
scheduledBoosts.remove(scheduledBoosts.get(position));
|
||||||
scheduledBoosts.remove(scheduledBoost);
|
if (scheduledBoosts.isEmpty()) {
|
||||||
if (scheduledBoosts.isEmpty()) {
|
scheduledActions.onAllDeleted();
|
||||||
scheduledActions.onAllDeleted();
|
|
||||||
}
|
|
||||||
notifyItemRemoved(position);
|
|
||||||
}
|
}
|
||||||
|
notifyItemRemoved(position);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue