aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/persistance/FileBackend.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/persistance/FileBackend.java')
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java51
1 files changed, 12 insertions, 39 deletions
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java
index 35aa9042..72c620a7 100644
--- a/src/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/eu/siacs/conversations/persistance/FileBackend.java
@@ -34,7 +34,6 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.entities.Message;
-import eu.siacs.conversations.services.ImageProvider;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.pep.Avatar;
@@ -66,34 +65,11 @@ public class FileBackend {
return thumbnailCache;
}
- public DownloadableFile getJingleFileLegacy(Message message) {
- return getJingleFileLegacy(message, true);
+ public DownloadableFile getFile(Message message) {
+ return getFile(message, true);
}
- public DownloadableFile getJingleFileLegacy(Message message,
- boolean decrypted) {
- Conversation conversation = message.getConversation();
- String prefix = context.getFilesDir().getAbsolutePath();
- String path = prefix + "/" + conversation.getAccount().getJid() + "/"
- + conversation.getContactJid();
- String filename;
- if ((decrypted) || (message.getEncryption() == Message.ENCRYPTION_NONE)) {
- filename = message.getUuid() + ".webp";
- } else {
- if (message.getEncryption() == Message.ENCRYPTION_OTR) {
- filename = message.getUuid() + ".webp";
- } else {
- filename = message.getUuid() + ".webp.pgp";
- }
- }
- return new DownloadableFile(path + "/" + filename);
- }
-
- public DownloadableFile getJingleFile(Message message) {
- return getConversationsFile(message, true);
- }
-
- public DownloadableFile getConversationsFile(Message message,
+ public DownloadableFile getFile(Message message,
boolean decrypted) {
StringBuilder filename = new StringBuilder();
filename.append(Environment.getExternalStoragePublicDirectory(
@@ -151,7 +127,7 @@ public class FileBackend {
try {
InputStream is = context.getContentResolver()
.openInputStream(image);
- DownloadableFile file = getJingleFile(message);
+ DownloadableFile file = getFile(message);
file.getParentFile().mkdirs();
file.createNewFile();
Bitmap originalBitmap;
@@ -240,7 +216,7 @@ public class FileBackend {
}
public Bitmap getImageFromMessage(Message message) {
- return BitmapFactory.decodeFile(getJingleFile(message)
+ return BitmapFactory.decodeFile(getFile(message)
.getAbsolutePath());
}
@@ -248,10 +224,7 @@ public class FileBackend {
throws FileNotFoundException {
Bitmap thumbnail = thumbnailCache.get(message.getUuid());
if ((thumbnail == null) && (!cacheOnly)) {
- File file = getJingleFile(message);
- if (!file.exists()) {
- file = getJingleFileLegacy(message);
- }
+ File file = getFile(message);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = calcSampleSize(file, size);
Bitmap fullsize = BitmapFactory.decodeFile(file.getAbsolutePath(),
@@ -447,12 +420,8 @@ public class FileBackend {
}
public Uri getJingleFileUri(Message message) {
- File file = getJingleFile(message);
- if (file.exists()) {
- return Uri.parse("file://" + file.getAbsolutePath());
- } else {
- return ImageProvider.getProviderUri(message);
- }
+ File file = getFile(message);
+ return Uri.parse("file://" + file.getAbsolutePath());
}
public class ImageCopyException extends Exception {
@@ -476,4 +445,8 @@ public class FileBackend {
}
return cropCenterSquare(bm, UIHelper.getRealPx(size, context));
}
+
+ public boolean isFileAvailable(Message message) {
+ return getFile(message).exists();
+ }
}