mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 17:59:39 +02:00
File deduplication, Android part (#3513)
This commit is contained in:
parent
bfda7ab2c3
commit
c6b89055d8
8 changed files with 32 additions and 25 deletions
|
@ -1632,6 +1632,18 @@ JNIEXPORT void Java_com_b44t_messenger_DcMsg_setFile(JNIEnv *env, jobject obj, j
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JNIEXPORT void Java_com_b44t_messenger_DcMsg_setFileAndDeduplicate(JNIEnv *env, jobject obj, jstring file, jstring name, jstring filemime)
|
||||||
|
{
|
||||||
|
CHAR_REF(file);
|
||||||
|
CHAR_REF(name);
|
||||||
|
CHAR_REF(filemime);
|
||||||
|
dc_msg_set_file_and_deduplicate(get_dc_msg(env, obj), filePtr, namePtr, filemimePtr);
|
||||||
|
CHAR_UNREF(filemime);
|
||||||
|
CHAR_UNREF(name);
|
||||||
|
CHAR_UNREF(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT void Java_com_b44t_messenger_DcMsg_setDimension(JNIEnv *env, jobject obj, int width, int height)
|
JNIEXPORT void Java_com_b44t_messenger_DcMsg_setDimension(JNIEnv *env, jobject obj, int width, int height)
|
||||||
{
|
{
|
||||||
dc_msg_set_dimension(get_dc_msg(env, obj), width, height);
|
dc_msg_set_dimension(get_dc_msg(env, obj), width, height);
|
||||||
|
|
|
@ -157,6 +157,7 @@ public class DcMsg {
|
||||||
public native int getVideochatType ();
|
public native int getVideochatType ();
|
||||||
public native void setText (String text);
|
public native void setText (String text);
|
||||||
public native void setFile (String file, String filemime);
|
public native void setFile (String file, String filemime);
|
||||||
|
public native void setFileAndDeduplicate(String file, String name, String filemime);
|
||||||
public native void setDimension (int width, int height);
|
public native void setDimension (int width, int height);
|
||||||
public native void setDuration (int duration);
|
public native void setDuration (int duration);
|
||||||
public native void setLocation (float latitude, float longitude);
|
public native void setLocation (float latitude, float longitude);
|
||||||
|
|
|
@ -1039,7 +1039,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
msg = new DcMsg(dcContext, DcMsg.DC_MSG_FILE);
|
msg = new DcMsg(dcContext, DcMsg.DC_MSG_FILE);
|
||||||
}
|
}
|
||||||
String path = attachment.getRealPath(this);
|
String path = attachment.getRealPath(this);
|
||||||
msg.setFile(path, null);
|
msg.setFileAndDeduplicate(path, attachment.getFileName(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
msg.setText(body);
|
msg.setText(body);
|
||||||
|
@ -1329,7 +1329,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
if (quote.isPresent()) {
|
if (quote.isPresent()) {
|
||||||
msg.setQuote(quote.get().getQuotedMsg());
|
msg.setQuote(quote.get().getQuotedMsg());
|
||||||
}
|
}
|
||||||
msg.setFile(path, null);
|
msg.setFileAndDeduplicate(path, null, null);
|
||||||
dcContext.sendMsg(chatId, msg);
|
dcContext.sendMsg(chatId, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,8 @@ package org.thoughtcrime.securesms.components;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
|
|
|
@ -367,6 +367,13 @@ public class DcHelper {
|
||||||
return mimeType;
|
return mimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the path of a not-yet-existing file in the blobdir with roughly the given filename
|
||||||
|
* and the given extension.
|
||||||
|
* In many cases, since we're using setFileAndDeduplicate now, this wouldn't be necessary anymore
|
||||||
|
* and we could just create a file with a random filename,
|
||||||
|
* but there are a few usages that still need the current behavior (like `openMaps()`).
|
||||||
|
*/
|
||||||
public static String getBlobdirFile(DcContext dcContext, String filename, String ext) {
|
public static String getBlobdirFile(DcContext dcContext, String filename, String ext) {
|
||||||
filename = FileUtils.sanitizeFilename(filename);
|
filename = FileUtils.sanitizeFilename(filename);
|
||||||
ext = FileUtils.sanitizeFilename(ext);
|
ext = FileUtils.sanitizeFilename(ext);
|
||||||
|
|
|
@ -23,7 +23,6 @@ import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
@ -68,7 +67,6 @@ import org.thoughtcrime.securesms.permissions.Permissions;
|
||||||
import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
|
import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
|
||||||
import org.thoughtcrime.securesms.scribbles.ScribbleActivity;
|
import org.thoughtcrime.securesms.scribbles.ScribbleActivity;
|
||||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
|
||||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
import org.thoughtcrime.securesms.util.guava.Optional;
|
import org.thoughtcrime.securesms.util.guava.Optional;
|
||||||
import org.thoughtcrime.securesms.util.views.Stub;
|
import org.thoughtcrime.securesms.util.views.Stub;
|
||||||
|
@ -693,7 +691,7 @@ public class AttachmentManager {
|
||||||
DcMsg msg = new DcMsg(dcContext, DcMsg.DC_MSG_WEBXDC);
|
DcMsg msg = new DcMsg(dcContext, DcMsg.DC_MSG_WEBXDC);
|
||||||
Attachment attachment = new UriAttachment(uri, null, MediaUtil.WEBXDC, AttachmentDatabase.TRANSFER_PROGRESS_STARTED, 0, 0, 0, fileName, null, false);
|
Attachment attachment = new UriAttachment(uri, null, MediaUtil.WEBXDC, AttachmentDatabase.TRANSFER_PROGRESS_STARTED, 0, 0, 0, fileName, null, false);
|
||||||
String path = attachment.getRealPath(context);
|
String path = attachment.getRealPath(context);
|
||||||
msg.setFile(path, MediaUtil.WEBXDC);
|
msg.setFileAndDeduplicate(path, fileName, MediaUtil.WEBXDC);
|
||||||
dcContext.setDraft(chatId, msg);
|
dcContext.setDraft(chatId, msg);
|
||||||
return new DocumentSlide(context, msg);
|
return new DocumentSlide(context, msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class SendRelayedMessageUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
message.setFile(getRealPathFromUri(context, uri), mimeType);
|
setFileFromUri(context, uri, message, mimeType);
|
||||||
}
|
}
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
message.setText(text);
|
message.setText(text);
|
||||||
|
@ -113,11 +113,12 @@ public class SendRelayedMessageUtil {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getRealPathFromUri(Context context, Uri uri) throws NullPointerException {
|
private static void setFileFromUri(Context context, Uri uri, DcMsg message, String mimeType) {
|
||||||
|
String path;
|
||||||
DcContext dcContext = DcHelper.getContext(context);
|
DcContext dcContext = DcHelper.getContext(context);
|
||||||
|
String filename = "cannot-resolve.jpg"; // best guess, this still leads to most images being workable if OS does weird things
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String filename = "cannot-resolve.jpg"; // best guess, this still leads to most images being workable if OS does weird things
|
|
||||||
if (PartAuthority.isLocalUri(uri)) {
|
if (PartAuthority.isLocalUri(uri)) {
|
||||||
filename = uri.getPathSegments().get(PersistentBlobProvider.FILENAME_PATH_SEGMENT);
|
filename = uri.getPathSegments().get(PersistentBlobProvider.FILENAME_PATH_SEGMENT);
|
||||||
} else if (uri.getScheme().equals("content")) {
|
} else if (uri.getScheme().equals("content")) {
|
||||||
|
@ -135,14 +136,7 @@ public class SendRelayedMessageUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String ext = "";
|
path = DcHelper.getBlobdirFile(dcContext, filename, "temp");
|
||||||
int i = filename.lastIndexOf(".");
|
|
||||||
if (i >= 0) {
|
|
||||||
ext = filename.substring(i);
|
|
||||||
filename = filename.substring(0, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
String path = DcHelper.getBlobdirFile(dcContext, filename, ext);
|
|
||||||
|
|
||||||
// copy content to this file
|
// copy content to this file
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
|
@ -150,11 +144,11 @@ public class SendRelayedMessageUtil {
|
||||||
OutputStream outputStream = new FileOutputStream(path);
|
OutputStream outputStream = new FileOutputStream(path);
|
||||||
Util.copy(inputStream, outputStream);
|
Util.copy(inputStream, outputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
path = null;
|
||||||
}
|
}
|
||||||
|
message.setFileAndDeduplicate(path, filename, mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -640,10 +640,7 @@ public class VideoRecoder {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Util.moveFile(tempPath, inPath)) {
|
msg.setFileAndDeduplicate(tempPath, msg.getFilename(), msg.getFilemime());
|
||||||
alert(context, String.format("Recoding failed for %s: cannot move temporary file %s", inPath, tempPath));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.i(TAG, String.format("recoding for %s done", inPath));
|
Log.i(TAG, String.format("recoding for %s done", inPath));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue