|
|
|
@ -16,6 +16,7 @@
|
|
|
|
|
*/
|
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
@ -46,6 +47,7 @@ import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.view.Window;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import com.codewaves.stickyheadergrid.StickyHeaderGridLayoutManager;
|
|
|
|
|
|
|
|
|
@ -56,16 +58,20 @@ import org.thoughtcrime.securesms.database.loaders.BucketedThreadMediaLoader;
|
|
|
|
|
import org.thoughtcrime.securesms.database.loaders.BucketedThreadMediaLoader.BucketedThreadMedia;
|
|
|
|
|
import org.thoughtcrime.securesms.database.loaders.ThreadMediaLoader;
|
|
|
|
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
|
|
|
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
|
import org.thoughtcrime.securesms.util.AttachmentUtil;
|
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
|
|
|
|
import org.thoughtcrime.securesms.util.SaveAttachmentTask;
|
|
|
|
|
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
|
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
|
|
|
import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask;
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -317,6 +323,50 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("CodeBlock2Expr")
|
|
|
|
|
@SuppressLint({"InlinedApi","StaticFieldLeak"})
|
|
|
|
|
private void handleSaveMedia(@NonNull Collection<MediaDatabase.MediaRecord> mediaRecords) {
|
|
|
|
|
final Context context = getContext();
|
|
|
|
|
SaveAttachmentTask.showWarningDialog(context, (dialogInterface, which) -> {
|
|
|
|
|
Permissions.with(this)
|
|
|
|
|
.request(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE)
|
|
|
|
|
.ifNecessary()
|
|
|
|
|
.withPermanentDenialDialog(getString(R.string.MediaPreviewActivity_signal_needs_the_storage_permission_in_order_to_write_to_external_storage_but_it_has_been_permanently_denied))
|
|
|
|
|
.onAnyDenied(() -> Toast.makeText(getContext(), R.string.MediaPreviewActivity_unable_to_write_to_external_storage_without_permission, Toast.LENGTH_LONG).show())
|
|
|
|
|
.onAllGranted(() -> {
|
|
|
|
|
new ProgressDialogAsyncTask<Void, Void, List<SaveAttachmentTask.Attachment>>(context,
|
|
|
|
|
R.string.MediaOverviewActivity_collecting_attachments,
|
|
|
|
|
R.string.please_wait) {
|
|
|
|
|
@Override
|
|
|
|
|
protected List<SaveAttachmentTask.Attachment> doInBackground(Void... params) {
|
|
|
|
|
List<SaveAttachmentTask.Attachment> attachments = new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
for (MediaDatabase.MediaRecord mediaRecord : mediaRecords) {
|
|
|
|
|
if (mediaRecord.getAttachment().getDataUri() != null) {
|
|
|
|
|
attachments.add(new SaveAttachmentTask.Attachment(mediaRecord.getAttachment().getDataUri(),
|
|
|
|
|
mediaRecord.getContentType(),
|
|
|
|
|
mediaRecord.getDate(),
|
|
|
|
|
mediaRecord.getAttachment().getFileName()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return attachments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPostExecute(List<SaveAttachmentTask.Attachment> attachments) {
|
|
|
|
|
super.onPostExecute(attachments);
|
|
|
|
|
SaveAttachmentTask saveTask = new SaveAttachmentTask(context,
|
|
|
|
|
attachments.size());
|
|
|
|
|
saveTask.executeOnExecutor(THREAD_POOL_EXECUTOR,
|
|
|
|
|
attachments.toArray(new SaveAttachmentTask.Attachment[attachments.size()]));
|
|
|
|
|
}
|
|
|
|
|
}.execute();
|
|
|
|
|
})
|
|
|
|
|
.execute();
|
|
|
|
|
}, mediaRecords.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressLint("StaticFieldLeak")
|
|
|
|
|
private void handleDeleteMedia(@NonNull Collection<MediaDatabase.MediaRecord> mediaRecords) {
|
|
|
|
|
int recordCount = mediaRecords.size();
|
|
|
|
@ -402,6 +452,9 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem menuItem) {
|
|
|
|
|
switch (menuItem.getItemId()) {
|
|
|
|
|
case R.id.save:
|
|
|
|
|
handleSaveMedia(getListAdapter().getSelectedMedia());
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.delete:
|
|
|
|
|
handleDeleteMedia(getListAdapter().getSelectedMedia());
|
|
|
|
|
exitMultiSelect();
|
|
|
|
|