|
|
@ -4,14 +4,14 @@ import android.content.Context;
|
|
|
|
import android.content.DialogInterface.OnClickListener;
|
|
|
|
import android.content.DialogInterface.OnClickListener;
|
|
|
|
import android.media.MediaScannerConnection;
|
|
|
|
import android.media.MediaScannerConnection;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
import android.webkit.MimeTypeMap;
|
|
|
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
import android.webkit.MimeTypeMap;
|
|
|
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import network.loki.messenger.R;
|
|
|
|
import org.thoughtcrime.securesms.database.NoExternalStorageException;
|
|
|
|
import org.thoughtcrime.securesms.database.NoExternalStorageException;
|
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
|
|
|
import org.thoughtcrime.securesms.mms.PartAuthority;
|
|
|
|
import org.thoughtcrime.securesms.mms.PartAuthority;
|
|
|
@ -26,8 +26,6 @@ import java.io.OutputStream;
|
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
|
|
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class SaveAttachmentTask extends ProgressDialogAsyncTask<SaveAttachmentTask.Attachment, Void, Pair<Integer, String>> {
|
|
|
|
public class SaveAttachmentTask extends ProgressDialogAsyncTask<SaveAttachmentTask.Attachment, Void, Pair<Integer, String>> {
|
|
|
|
private static final String TAG = SaveAttachmentTask.class.getSimpleName();
|
|
|
|
private static final String TAG = SaveAttachmentTask.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
|
@ -61,7 +59,7 @@ public class SaveAttachmentTask extends ProgressDialogAsyncTask<SaveAttachmentTa
|
|
|
|
Context context = contextReference.get();
|
|
|
|
Context context = contextReference.get();
|
|
|
|
String directory = null;
|
|
|
|
String directory = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (!StorageUtil.canWriteInSessionStorageDir(context)) {
|
|
|
|
if (!StorageUtil.canWriteInSessionStorageDir()) {
|
|
|
|
return new Pair<>(WRITE_ACCESS_FAILURE, null);
|
|
|
|
return new Pair<>(WRITE_ACCESS_FAILURE, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -113,17 +111,16 @@ public class SaveAttachmentTask extends ProgressDialogAsyncTask<SaveAttachmentTa
|
|
|
|
private File createOutputDirectoryFromContentType(@NonNull String contentType)
|
|
|
|
private File createOutputDirectoryFromContentType(@NonNull String contentType)
|
|
|
|
throws NoExternalStorageException
|
|
|
|
throws NoExternalStorageException
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Context context = contextReference.get();
|
|
|
|
|
|
|
|
File outputDirectory;
|
|
|
|
File outputDirectory;
|
|
|
|
|
|
|
|
|
|
|
|
if (contentType.startsWith("video/")) {
|
|
|
|
if (contentType.startsWith("video/")) {
|
|
|
|
outputDirectory = StorageUtil.getVideoDir(context);
|
|
|
|
outputDirectory = StorageUtil.getVideoDir();
|
|
|
|
} else if (contentType.startsWith("audio/")) {
|
|
|
|
} else if (contentType.startsWith("audio/")) {
|
|
|
|
outputDirectory = StorageUtil.getAudioDir(context);
|
|
|
|
outputDirectory = StorageUtil.getAudioDir();
|
|
|
|
} else if (contentType.startsWith("image/")) {
|
|
|
|
} else if (contentType.startsWith("image/")) {
|
|
|
|
outputDirectory = StorageUtil.getImageDir(context);
|
|
|
|
outputDirectory = StorageUtil.getImageDir();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
outputDirectory = StorageUtil.getDownloadDir(context);
|
|
|
|
outputDirectory = StorageUtil.getDownloadDir();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!outputDirectory.mkdirs()) Log.w(TAG, "mkdirs() returned false, attempting to continue");
|
|
|
|
if (!outputDirectory.mkdirs()) Log.w(TAG, "mkdirs() returned false, attempting to continue");
|
|
|
|