mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-23 01:00:04 +02:00
Fix issue #113 - Bad behavior when removing drafts
This commit is contained in:
parent
4792c4971c
commit
2f716b9b11
2 changed files with 10 additions and 15 deletions
|
@ -283,7 +283,7 @@ public class StatusDraft implements Serializable {
|
|||
throw new DBException("db is null. Wrong initialization.");
|
||||
}
|
||||
try {
|
||||
Cursor c = db.query(Sqlite.TABLE_STATUS_DRAFT, null, Sqlite.COL_INSTANCE + " = '" + account.instance + "' AND " + Sqlite.COL_USER_ID + " = '" + account.user_id + "'", null, null, null, Sqlite.COL_UPDATED_AT + " ASC", null);
|
||||
Cursor c = db.query(Sqlite.TABLE_STATUS_DRAFT, null, Sqlite.COL_INSTANCE + " = '" + account.instance + "' AND " + Sqlite.COL_USER_ID + " = '" + account.user_id + "'", null, null, null, Sqlite.COL_UPDATED_AT + " DESC", null);
|
||||
return cursorToStatusDraftList(c);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
|
|
|
@ -17,8 +17,6 @@ package app.fedilab.android.ui.drawer;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
@ -101,12 +99,18 @@ public class StatusDraftAdapter extends RecyclerView.Adapter<StatusDraftAdapter.
|
|||
unfollowConfirm.setMessage(context.getString(R.string.remove_draft));
|
||||
unfollowConfirm.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||
unfollowConfirm.setPositiveButton(R.string.delete, (dialog, which) -> {
|
||||
statusDrafts.remove(holder.getAbsoluteAdapterPosition());
|
||||
notifyItemRemoved(holder.getAbsoluteAdapterPosition());
|
||||
if (statusDrafts.size() == 0) {
|
||||
draftActions.onAllDeleted();
|
||||
}
|
||||
final StatusDraft statusDraftToDelete = statusDraft;
|
||||
new Thread(() -> {
|
||||
try {
|
||||
//Check if there are media in the drafts
|
||||
List<Attachment> attachments = new ArrayList<>();
|
||||
if (statusDraft.statusDraftList != null) {
|
||||
for (Status drafts : statusDraft.statusDraftList) {
|
||||
if (statusDraftToDelete.statusDraftList != null) {
|
||||
for (Status drafts : statusDraftToDelete.statusDraftList) {
|
||||
if (drafts.media_attachments != null && drafts.media_attachments.size() > 0) {
|
||||
attachments.addAll(drafts.media_attachments);
|
||||
}
|
||||
|
@ -125,16 +129,7 @@ public class StatusDraftAdapter extends RecyclerView.Adapter<StatusDraftAdapter.
|
|||
}
|
||||
}
|
||||
//Delete the draft
|
||||
new StatusDraft(context).removeDraft(statusDraft);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
statusDrafts.remove(statusDraft);
|
||||
notifyItemRemoved(position);
|
||||
if (statusDrafts.size() == 0) {
|
||||
draftActions.onAllDeleted();
|
||||
}
|
||||
};
|
||||
mainHandler.post(myRunnable);
|
||||
new StatusDraft(context).removeDraft(statusDraftToDelete);
|
||||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue