Allow batch deletion of media.

It is now possible to batch-delete media in the "media overview" screen.
You can long press to enter multi-select mode. Then a delete button
appears on the menu bar. After pressing delete, you will get a
confirmation, and if the user confirms, the items will delete while a
progres dialog shows.
This commit is contained in:
Greyson Parrelli
2018-03-15 11:17:40 -07:00
committed by Moxie Marlinspike
parent 0c768a24e4
commit 10e5b24cfd
8 changed files with 282 additions and 55 deletions

View File

@@ -6,10 +6,14 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
import android.text.TextUtils;
import android.util.Log;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.attachments.AttachmentId;
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import java.util.Collections;
import java.util.Set;
@@ -36,6 +40,27 @@ public class AttachmentUtil {
}
}
/**
* Deletes the specified attachment. If its the only attachment for its linked message, the entire
* message is deleted.
*/
@WorkerThread
public static void deleteAttachment(@NonNull Context context,
@NonNull DatabaseAttachment attachment)
{
AttachmentId attachmentId = attachment.getAttachmentId();
long mmsId = attachment.getMmsId();
int attachmentCount = DatabaseFactory.getAttachmentDatabase(context)
.getAttachmentsForMessage(mmsId)
.size();
if (attachmentCount <= 1) {
DatabaseFactory.getMmsDatabase(context).delete(mmsId);
} else {
DatabaseFactory.getAttachmentDatabase(context).deleteAttachment(attachmentId);
}
}
private static boolean isNonDocumentType(String contentType) {
return
MediaUtil.isImageType(contentType) ||