aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/PgpEngine.java3
-rw-r--r--src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java10
-rw-r--r--src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java7
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java14
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java32
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java5
6 files changed, 41 insertions, 30 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java
index c05cf2ee..7ca5bea0 100644
--- a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java
+++ b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java
@@ -2,7 +2,6 @@ package eu.siacs.conversations.crypto;
import android.app.PendingIntent;
import android.content.Intent;
-import android.net.Uri;
import org.openintents.openpgp.OpenPgpSignatureResult;
import org.openintents.openpgp.util.OpenPgpApi;
@@ -106,7 +105,7 @@ public class PgpEngine {
PgpEngine.this.mXmppConnectionService
.updateMessage(message);
inputFile.delete();
- mXmppConnectionService.getFileBackend().addImageFileToMedia(outputFile);
+ mXmppConnectionService.getFileBackend().updateMediaScanner(outputFile);
callback.success(message);
return;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
index 161a73f6..d23cb71a 100644
--- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
+++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java
@@ -1,7 +1,5 @@
package eu.siacs.conversations.http;
-import android.content.Intent;
-import android.net.Uri;
import android.os.PowerManager;
import android.util.Log;
@@ -10,12 +8,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
import java.net.MalformedURLException;
-import java.net.Proxy;
import java.net.URL;
-import java.util.Arrays;
import java.util.concurrent.CancellationException;
import javax.net.ssl.HttpsURLConnection;
@@ -94,7 +88,7 @@ public class HttpDownloadConnection implements Transferable {
} else {
extension = lastPart;
}
- message.setRelativeFilePath(message.getUuid()+"."+extension);
+ message.setRelativeFilePath(message.getUuid() + "." + extension);
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
String reference = mUrl.getRef();
if (reference != null && reference.length() == 96) {
@@ -129,7 +123,7 @@ public class HttpDownloadConnection implements Transferable {
}
private void finish() {
- mXmppConnectionService.getFileBackend().addImageFileToMedia(file);
+ mXmppConnectionService.getFileBackend().updateMediaScanner(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 4d880ffc..e337509b 100644
--- a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java
+++ b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java
@@ -1,8 +1,6 @@
package eu.siacs.conversations.http;
import android.app.PendingIntent;
-import android.content.Intent;
-import android.net.Uri;
import android.os.PowerManager;
import android.util.Log;
import android.util.Pair;
@@ -12,10 +10,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
import java.net.MalformedURLException;
-import java.net.Proxy;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
@@ -196,7 +191,7 @@ public class HttpUploadConnection implements Transferable {
mGetUrl = new URL(mGetUrl.toString() + "#" + CryptoHelper.bytesToHex(key));
}
mXmppConnectionService.getFileBackend().updateFileParams(message, mGetUrl);
- mXmppConnectionService.getFileBackend().addImageFileToMedia(file);
+ mXmppConnectionService.getFileBackend().updateMediaScanner(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 8aa4f064..18c195f1 100644
--- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
@@ -27,7 +27,6 @@ import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
-import java.util.Arrays;
import java.util.Date;
import java.util.Locale;
@@ -35,7 +34,6 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.entities.Message;
-import eu.siacs.conversations.entities.Transferable;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.ExifHelper;
@@ -62,7 +60,7 @@ public class FileBackend {
}
}
- public void addImageFileToMedia(File file) {
+ public void updateMediaScanner(File file) {
if (file.getAbsolutePath().startsWith(getConversationsImageDirectory())) {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
@@ -72,6 +70,16 @@ public class FileBackend {
}
}
+ public boolean deleteFile(Message message) {
+ File file = getFile(message);
+ if (file.delete()) {
+ updateMediaScanner(file);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
public DownloadableFile getFile(Message message) {
return getFile(message, true);
}
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
index 1665090c..679e2a03 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
@@ -527,6 +527,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
relevantForCorrection = relevantForCorrection.next();
}
if (m.getType() != Message.TYPE_STATUS) {
+ final boolean treatAsFile = m.getType() != Message.TYPE_TEXT
+ && m.getType() != Message.TYPE_PRIVATE
+ && t == null;
activity.getMenuInflater().inflate(R.menu.message_context, menu);
menu.setHeaderTitle(R.string.message_options);
MenuItem copyText = menu.findItem(R.id.copy_text);
@@ -537,8 +540,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
MenuItem copyUrl = menu.findItem(R.id.copy_url);
MenuItem downloadFile = menu.findItem(R.id.download_file);
MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
- if ((m.getType() == Message.TYPE_TEXT || m.getType() == Message.TYPE_PRIVATE)
- && t == null
+ MenuItem deleteFile = menu.findItem(R.id.delete_file);
+ if (!treatAsFile
&& !GeoHelper.isGeoUri(m.getBody())
&& m.treatAsDownloadable() != Message.Decision.MUST) {
copyText.setVisible(true);
@@ -550,10 +553,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
&& relevantForCorrection.isLastCorrectableMessage()) {
correctMessage.setVisible(true);
}
- if ((m.getType() != Message.TYPE_TEXT
- && m.getType() != Message.TYPE_PRIVATE
- && t == null)
- || (GeoHelper.isGeoUri(m.getBody()))) {
+ if (treatAsFile || (GeoHelper.isGeoUri(m.getBody()))) {
shareWith.setVisible(true);
}
if (m.getStatus() == Message.STATUS_SEND_FAILED) {
@@ -575,6 +575,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|| m.getStatus() == Message.STATUS_OFFERED))) {
cancelTransmission.setVisible(true);
}
+ if (treatAsFile) {
+ deleteFile.setVisible(true);
+ deleteFile.setTitle(activity.getString(R.string.delete_x_file,UIHelper.getFileDescriptionString(activity, m)));
+ }
}
}
@@ -605,6 +609,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
case R.id.retry_decryption:
retryDecryption(selectedMessage);
return true;
+ case R.id.delete_file:
+ deleteFile(selectedMessage);
+ return true;
default:
return super.onContextItemSelected(item);
}
@@ -643,12 +650,22 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
}
+ private void deleteFile(Message message) {
+ if (activity.xmppConnectionService.getFileBackend().deleteFile(message)) {
+ message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
+ activity.updateConversationList();
+ updateMessages();
+ }
+ }
+
private void resendMessage(Message message) {
if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) {
DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
if (!file.exists()) {
Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show();
message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
+ activity.updateConversationList();
+ updateMessages();
return;
}
}
@@ -690,7 +707,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
private void retryDecryption(Message message) {
message.setEncryption(Message.ENCRYPTION_PGP);
- activity.xmppConnectionService.updateConversationUi();
+ activity.updateConversationList();
+ updateMessages();
conversation.getAccount().getPgpDecryptionService().add(message);
}
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 2f8b9841..e3eec647 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
@@ -1,7 +1,5 @@
package eu.siacs.conversations.xmpp.jingle;
-import android.content.Intent;
-import android.net.Uri;
import android.util.Log;
import android.util.Pair;
@@ -9,7 +7,6 @@ import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -111,7 +108,7 @@ public class JingleConnection implements Transferable {
}
Log.d(Config.LOGTAG,"successfully transmitted file:" + file.getAbsolutePath()+" ("+file.getSha1Sum()+")");
if (message.getEncryption() != Message.ENCRYPTION_PGP) {
- mXmppConnectionService.getFileBackend().addImageFileToMedia(file);
+ mXmppConnectionService.getFileBackend().updateMediaScanner(file);
} else {
account.getPgpDecryptionService().add(message);
}