mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-01-07 00:20:08 +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.");
|
throw new DBException("db is null. Wrong initialization.");
|
||||||
}
|
}
|
||||||
try {
|
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);
|
return cursorToStatusDraftList(c);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -17,8 +17,6 @@ package app.fedilab.android.ui.drawer;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -101,12 +99,18 @@ public class StatusDraftAdapter extends RecyclerView.Adapter<StatusDraftAdapter.
|
||||||
unfollowConfirm.setMessage(context.getString(R.string.remove_draft));
|
unfollowConfirm.setMessage(context.getString(R.string.remove_draft));
|
||||||
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) -> {
|
||||||
|
statusDrafts.remove(holder.getAbsoluteAdapterPosition());
|
||||||
|
notifyItemRemoved(holder.getAbsoluteAdapterPosition());
|
||||||
|
if (statusDrafts.size() == 0) {
|
||||||
|
draftActions.onAllDeleted();
|
||||||
|
}
|
||||||
|
final StatusDraft statusDraftToDelete = statusDraft;
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
//Check if there are media in the drafts
|
//Check if there are media in the drafts
|
||||||
List<Attachment> attachments = new ArrayList<>();
|
List<Attachment> attachments = new ArrayList<>();
|
||||||
if (statusDraft.statusDraftList != null) {
|
if (statusDraftToDelete.statusDraftList != null) {
|
||||||
for (Status drafts : statusDraft.statusDraftList) {
|
for (Status drafts : statusDraftToDelete.statusDraftList) {
|
||||||
if (drafts.media_attachments != null && drafts.media_attachments.size() > 0) {
|
if (drafts.media_attachments != null && drafts.media_attachments.size() > 0) {
|
||||||
attachments.addAll(drafts.media_attachments);
|
attachments.addAll(drafts.media_attachments);
|
||||||
}
|
}
|
||||||
|
@ -125,16 +129,7 @@ public class StatusDraftAdapter extends RecyclerView.Adapter<StatusDraftAdapter.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Delete the draft
|
//Delete the draft
|
||||||
new StatusDraft(context).removeDraft(statusDraft);
|
new StatusDraft(context).removeDraft(statusDraftToDelete);
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
||||||
Runnable myRunnable = () -> {
|
|
||||||
statusDrafts.remove(statusDraft);
|
|
||||||
notifyItemRemoved(position);
|
|
||||||
if (statusDrafts.size() == 0) {
|
|
||||||
draftActions.onAllDeleted();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mainHandler.post(myRunnable);
|
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue