aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu
diff options
context:
space:
mode:
authorChristian S <christian@pix-art.de>2016-03-26 11:17:48 +0100
committerChristian S <christian@pix-art.de>2016-03-26 11:17:48 +0100
commit927dde01a827a91a24495bd868575cefd981f8c2 (patch)
treef09ed178937f28b85d1499951cff3faa64988250 /src/main/java/eu
parent67eb44af3c5012cdc2da3af4ae94cf7fa51a3ef1 (diff)
parent46be514b4db1cb8c17037ac6cd307078e4794a12 (diff)
Merge branch 'siacs/master' into development
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/PgpEngine.java5
-rw-r--r--src/main/java/eu/siacs/conversations/generator/IqGenerator.java1
-rw-r--r--src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java12
-rw-r--r--src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java9
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java34
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java2
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java32
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java7
8 files changed, 63 insertions, 39 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java
index 0afcb9e10..7ca5bea07 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,9 +105,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().updateMediaScanner(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 15e27fc06..d8a0572b6 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 84a44715b..d23cb71a3 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,9 +123,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().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 c1bc897d7..df3740ff7 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;
@@ -200,9 +195,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().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 4bdf080cf..18c195f12 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;
@@ -26,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;
@@ -34,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;
@@ -50,6 +49,37 @@ 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 updateMediaScanner(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 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/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index dea0b1e3e..277f0667b 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -665,7 +665,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
private void resetAllAttemptCounts(boolean reallyAll) {
- Log.d(Config.LOGTAG, "resetting all attepmt counts");
+ Log.d(Config.LOGTAG, "resetting all attempt counts");
for (Account account : accounts) {
if (account.hasErrorStatus() || reallyAll) {
final XmppConnection connection = account.getXmppConnection();
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
index 3a889bacf..db34d1df3 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 dcb13c233..e3eec6471 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,9 +108,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().updateMediaScanner(file);
} else {
account.getPgpDecryptionService().add(message);
}