aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-03-23 12:20:09 +0100
committerDaniel Gultsch <daniel@gultsch.de>2016-03-23 12:20:09 +0100
commit281cb6504683ae2b8b957e18ff3f7f7f94941777 (patch)
tree0a3dd67f1193419b5a09de2f9b87362449cc775d /src/main/java/eu
parent564113669e214bab604bb760aa4105e280845b33 (diff)
only add image files to media scanner
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/PgpEngine.java4
-rw-r--r--src/main/java/eu/siacs/conversations/generator/IqGenerator.java1
-rw-r--r--src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java4
-rw-r--r--src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java4
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java22
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java4
6 files changed, 26 insertions, 13 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java
index 0afcb9e1..c05cf2ee 100644
--- a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java
+++ b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java
@@ -106,9 +106,7 @@ public class PgpEngine {
PgpEngine.this.mXmppConnectionService
.updateMessage(message);
inputFile.delete();
- Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
- intent.setData(Uri.fromFile(outputFile));
- mXmppConnectionService.sendBroadcast(intent);
+ mXmppConnectionService.getFileBackend().addImageFileToMedia(outputFile);
callback.success(message);
return;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
index a3b0f650..b7911ef7 100644
--- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
@@ -25,7 +25,6 @@ import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.Xmlns;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.forms.Data;
-import eu.siacs.conversations.xmpp.forms.Field;
import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.pep.Avatar;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
index 84a44715..161a73f6 100644
--- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
+++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
@@ -129,9 +129,7 @@ public class HttpDownloadConnection implements Transferable {
}
private void finish() {
- Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
- intent.setData(Uri.fromFile(file));
- mXmppConnectionService.sendBroadcast(intent);
+ mXmppConnectionService.getFileBackend().addImageFileToMedia(file);
message.setTransferable(null);
mHttpConnectionManager.finishConnection(this);
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
diff --git a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java
index 1e4b9102..4d880ffc 100644
--- a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java
+++ b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java
@@ -196,9 +196,7 @@ public class HttpUploadConnection implements Transferable {
mGetUrl = new URL(mGetUrl.toString() + "#" + CryptoHelper.bytesToHex(key));
}
mXmppConnectionService.getFileBackend().updateFileParams(message, mGetUrl);
- Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
- intent.setData(Uri.fromFile(file));
- mXmppConnectionService.sendBroadcast(intent);
+ mXmppConnectionService.getFileBackend().addImageFileToMedia(file);
message.setTransferable(null);
message.setCounterpart(message.getConversation().getJid().toBareJid());
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
index 4bdf080c..8aa4f064 100644
--- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
@@ -1,5 +1,6 @@
package eu.siacs.conversations.persistance;
+import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
@@ -50,6 +51,27 @@ public class FileBackend {
this.mXmppConnectionService = service;
}
+ private void createNoMedia() {
+ final File nomedia = new File(getConversationsFileDirectory()+".nomedia");
+ if (!nomedia.exists()) {
+ try {
+ nomedia.createNewFile();
+ } catch (Exception e) {
+ Log.d(Config.LOGTAG, "could not create nomedia file");
+ }
+ }
+ }
+
+ public void addImageFileToMedia(File file) {
+ if (file.getAbsolutePath().startsWith(getConversationsImageDirectory())) {
+ Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+ intent.setData(Uri.fromFile(file));
+ mXmppConnectionService.sendBroadcast(intent);
+ } else {
+ createNoMedia();
+ }
+ }
+
public DownloadableFile getFile(Message message) {
return getFile(message, true);
}
diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
index dcb13c23..2f8b9841 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
@@ -111,9 +111,7 @@ public class JingleConnection implements Transferable {
}
Log.d(Config.LOGTAG,"successfully transmitted file:" + file.getAbsolutePath()+" ("+file.getSha1Sum()+")");
if (message.getEncryption() != Message.ENCRYPTION_PGP) {
- Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
- intent.setData(Uri.fromFile(file));
- mXmppConnectionService.sendBroadcast(intent);
+ mXmppConnectionService.getFileBackend().addImageFileToMedia(file);
} else {
account.getPgpDecryptionService().add(message);
}