Added deleting attachments

This commit is contained in:
M66B
2023-06-26 11:35:26 +02:00
parent ba9c9f2165
commit b458d5f4e3
10 changed files with 397 additions and 20 deletions

View File

@@ -137,7 +137,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
lparam.setMarginStart(attachment.subsequence == null ? 0 : dp12);
view.setLayoutParams(lparam);
ibDelete.setVisibility(readonly && !BuildConfig.DEBUG ? View.GONE : View.VISIBLE);
ibDelete.setVisibility(readonly ? View.GONE : View.VISIBLE);
if (!readonly && attachment.isImage()) {
if (attachment.available) {
@@ -344,13 +344,11 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
private void onDelete(final EntityAttachment attachment) {
Bundle args = new Bundle();
args.putLong("id", attachment.id);
args.putBoolean("readonly", readonly);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
boolean readonly = args.getBoolean("readonly");
EntityAttachment attachment;
@@ -362,21 +360,14 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
if (attachment == null)
return null;
if (readonly) {
EntityMessage message = db.message().getMessage(attachment.message);
if (message == null)
return null;
EntityOperation.queue(context, message, EntityOperation.DETACH, attachment.id, true);
} else
db.attachment().deleteAttachment(attachment.id);
db.attachment().deleteAttachment(attachment.id);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
if (!readonly)
attachment.getFile(context).delete();
attachment.getFile(context).delete();
return null;
}