allow to delete attachments. fixes #1539

This commit is contained in:
Daniel Gultsch 2016-03-23 19:23:22 +01:00
parent 281cb65046
commit a9b66e3ea5
8 changed files with 46 additions and 31 deletions

View file

@ -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:

View file

@ -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) {

View file

@ -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) {

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -33,5 +33,8 @@
android:id="@+id/cancel_transmission"
android:title="@string/cancel_transmission"
android:visible="false"/>
<item
android:id="@+id/delete_file"
android:title="@string/delete_x_file"
android:visible="false"/>
</menu>

View file

@ -385,6 +385,7 @@
<string name="choose_file">Choose file</string>
<string name="receiving_x_file">Receiving %1$s (%2$d%% completed)</string>
<string name="download_x_file">Download %s</string>
<string name="delete_x_file">Delete %s</string>
<string name="file">file</string>
<string name="open_x_file">Open %s</string>
<string name="sending_file">sending (%1$d%% completed)</string>