diff options
Diffstat (limited to '')
16 files changed, 88 insertions, 39 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java index f5f4c057..d2eb77b7 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java +++ b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java @@ -7,6 +7,7 @@ import android.preference.PreferenceManager; import java.io.File; +import de.thedevstack.conversationsplus.persistance.FileBackend; import de.thedevstack.conversationsplus.utils.ImageUtil; import de.thedevstack.conversationsplus.R; import de.thedevstack.conversationsplus.utils.SerialSingleThreadExecutor; @@ -31,6 +32,7 @@ public class ConversationsPlusApplication extends Application { ConversationsPlusApplication.instance = this; ConversationsPlusPreferences.init(PreferenceManager.getDefaultSharedPreferences(getAppContext())); ImageUtil.initBitmapCache(); + FileBackend.createNoMedia(); } /** diff --git a/src/main/java/de/thedevstack/conversationsplus/crypto/PgpEngine.java b/src/main/java/de/thedevstack/conversationsplus/crypto/PgpEngine.java index d01dc867..3f6f8ce7 100644 --- a/src/main/java/de/thedevstack/conversationsplus/crypto/PgpEngine.java +++ b/src/main/java/de/thedevstack/conversationsplus/crypto/PgpEngine.java @@ -2,7 +2,6 @@ package de.thedevstack.conversationsplus.crypto; import android.app.PendingIntent; import android.content.Intent; -import android.net.Uri; import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.util.OpenPgpApi; @@ -108,9 +107,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); + FileBackend.updateMediaScanner(outputFile, mXmppConnectionService); callback.success(message); return; case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: diff --git a/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java b/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java index 1517e5d1..424dc96a 100644 --- a/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java @@ -1,7 +1,5 @@ package de.thedevstack.conversationsplus.http; -import android.content.Intent; -import android.net.Uri; import android.os.PowerManager; import android.util.Log; @@ -130,9 +128,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); + FileBackend.updateMediaScanner(file, mXmppConnectionService); message.setTransferable(null); mHttpConnectionManager.finishConnection(this); if (message.getEncryption() == Message.ENCRYPTION_PGP) { diff --git a/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java b/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java index 5eab0a6b..4cf7e282 100644 --- a/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java @@ -1,8 +1,6 @@ package de.thedevstack.conversationsplus.http; import android.app.PendingIntent; -import android.content.Intent; -import android.net.Uri; import android.os.PowerManager; import android.util.Pair; @@ -191,9 +189,7 @@ public class HttpUploadConnection implements Transferable { mGetUrl = new URL(mGetUrl.toString() + "#" + CryptoHelper.bytesToHex(key)); } MessageUtil.updateFileParams(message, mGetUrl); - Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); - intent.setData(Uri.fromFile(file)); - mXmppConnectionService.sendBroadcast(intent); + FileBackend.updateMediaScanner(file, mXmppConnectionService); message.setTransferable(null); message.setCounterpart(message.getConversation().getJid().toBareJid()); if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { diff --git a/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java b/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java index 07537fe3..45510661 100644 --- a/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java +++ b/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java @@ -1,5 +1,6 @@ package de.thedevstack.conversationsplus.persistance; +import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; import android.os.Environment; @@ -25,10 +26,40 @@ import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.R; import de.thedevstack.conversationsplus.entities.DownloadableFile; import de.thedevstack.conversationsplus.entities.Message; +import de.thedevstack.conversationsplus.services.XmppConnectionService; public class FileBackend { private static final SimpleDateFormat imageDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.US); + public static 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 static void updateMediaScanner(File file, XmppConnectionService xmppConnectionService) { + if (file.getAbsolutePath().startsWith(getConversationsImageDirectory())) { + Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); + intent.setData(Uri.fromFile(file)); + xmppConnectionService.sendBroadcast(intent); + } + } + + public static boolean deleteFile(Message message, XmppConnectionService xmppConnectionService) { + File file = getFile(message); + if (file.delete()) { + updateMediaScanner(file, xmppConnectionService); + return true; + } else { + return false; + } + } + public static DownloadableFile getFile(Message message) { return getFile(message, true); } diff --git a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java index 943c8dff..b8fd5894 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java @@ -618,7 +618,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } private void resetAllAttemptCounts(boolean reallyAll) { - Logging.d(Config.LOGTAG, "resetting all attepmt counts"); + Logging.d(Config.LOGTAG, "resetting all attempt counts"); for (Account account : accounts) { if (account.hasErrorStatus() || reallyAll) { final XmppConnection connection = account.getXmppConnection(); @@ -2353,6 +2353,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } Thread thread = new Thread(connection); connection.setInteractive(interactive); + connection.prepareNewConnection(); thread.start(); scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode()); } else { diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java index a18fd848..3ca9fce7 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java @@ -457,7 +457,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd private void onOmemoKeyClicked(Account account, String fingerprint) { final XmppAxolotlSession.Trust trust = account.getAxolotlService().getFingerprintTrust(fingerprint); - if (trust != null && trust == XmppAxolotlSession.Trust.TRUSTED_X509) { + if (Config.X509_VERIFICATION && trust != null && trust == XmppAxolotlSession.Trust.TRUSTED_X509) { X509Certificate x509Certificate = account.getAxolotlService().getFingerprintCertificate(fingerprint); if (x509Certificate != null) { showCertificateInformationDialog(CryptoHelper.extractCertificateInformation(x509Certificate)); diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java index 1bf95910..5a8bd3db 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java @@ -527,6 +527,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa final Message m = this.selectedMessage; final Transferable t = m.getTransferable(); 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); @@ -536,8 +539,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); @@ -545,11 +548,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) { retryDecryption.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) { @@ -571,6 +570,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))); + } } } @@ -601,6 +604,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); } @@ -638,12 +644,20 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } } + private void deleteFile(Message message) { + if (FileBackend.deleteFile(message, activity.xmppConnectionService)) { + message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED)); + activity.xmppConnectionService.updateConversationUi(); + } + } + private void resendMessage(Message message) { if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) { DownloadableFile file = FileBackend.getFile(message); if (!file.exists()) { Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show(); message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED)); + activity.xmppConnectionService.updateConversationUi(); return; } } diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java index ff7e11d1..35816cff 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java @@ -30,6 +30,8 @@ import de.thedevstack.conversationsplus.services.ExportLogsService; import de.tzur.conversations.Settings; import de.thedevstack.conversationsplus.R; import de.thedevstack.conversationsplus.entities.Account; +import de.thedevstack.conversationsplus.persistance.FileBackend; +import de.thedevstack.conversationsplus.services.ExportLogsService; import de.thedevstack.conversationsplus.xmpp.XmppConnection; import github.ankushsachdeva.emojicon.EmojiconHandler; @@ -184,7 +186,9 @@ public class SettingsActivity extends XmppActivity implements reconnectAccounts(); } else if ("parse_emoticons".equals(name)) { EmojiconHandler.setParseEmoticons(Settings.PARSE_EMOTICONS); - } + } else if ("file_transfer_folder".equals(name)) { + FileBackend.createNoMedia(); + } } diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java index 8cb71308..3446bfbd 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java @@ -191,7 +191,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer if (Intent.ACTION_SEND.equals(action)) { final String text = intent.getStringExtra(Intent.EXTRA_TEXT); final Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); - if (type != null && uri != null && text == null) { + if (type != null && uri != null && (text == null || !type.equals("text/plain"))) { this.share.uris.clear(); this.share.uris.add(uri); this.share.image = type.startsWith("image/") || isImage(uri); diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java index e467b5da..fb8aedef 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java @@ -738,14 +738,15 @@ public abstract class XmppActivity extends Activity { view.setOnLongClickListener(purge); key.setOnLongClickListener(purge); keyType.setOnLongClickListener(purge); - boolean x509 = trust == XmppAxolotlSession.Trust.TRUSTED_X509 || trust == XmppAxolotlSession.Trust.INACTIVE_TRUSTED_X509; + boolean x509 = Config.X509_VERIFICATION + && (trust == XmppAxolotlSession.Trust.TRUSTED_X509 || trust == XmppAxolotlSession.Trust.INACTIVE_TRUSTED_X509); switch (trust) { case UNTRUSTED: case TRUSTED: case TRUSTED_X509: trustToggle.setChecked(trust.trusted()); - trustToggle.setEnabled(trust != XmppAxolotlSession.Trust.TRUSTED_X509); - if (trust == XmppAxolotlSession.Trust.TRUSTED_X509) { + trustToggle.setEnabled(!Config.X509_VERIFICATION || trust != XmppAxolotlSession.Trust.TRUSTED_X509); + if (Config.X509_VERIFICATION && trust == XmppAxolotlSession.Trust.TRUSTED_X509) { trustToggle.setOnClickListener(null); } key.setTextColor(getPrimaryTextColor()); diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/UIHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/UIHelper.java index 2c43e86f..1c142dad 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/UIHelper.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/UIHelper.java @@ -220,9 +220,10 @@ public class UIHelper { } public static String getMessageDisplayName(final Message message) { + final Conversation conversation = message.getConversation(); if (message.getStatus() == Message.STATUS_RECEIVED) { final Contact contact = message.getContact(); - if (message.getConversation().getMode() == Conversation.MODE_MULTI) { + if (conversation.getMode() == Conversation.MODE_MULTI) { if (contact != null) { return contact.getDisplayName(); } else { @@ -232,10 +233,10 @@ public class UIHelper { return contact != null ? contact.getDisplayName() : ""; } } else { - if (message.getConversation().getMode() == Conversation.MODE_MULTI) { - return getDisplayedMucCounterpart(message.getConversation().getJid()); + if (conversation.getMode() == Conversation.MODE_MULTI) { + return conversation.getMucOptions().getSelf().getName(); } else { - final Jid jid = message.getConversation().getAccount().getJid(); + final Jid jid = conversation.getAccount().getJid(); return jid.hasLocalpart() ? jid.getLocalpart() : jid.toDomainJid().toString(); } } diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java index f5a4add8..9036bf8d 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java @@ -218,12 +218,16 @@ public class XmppConnection implements Runnable { } } + public void prepareNewConnection() { + this.lastConnect = SystemClock.elapsedRealtime(); + this.lastPingSent = SystemClock.elapsedRealtime(); + this.lastDiscoStarted = Long.MAX_VALUE; + this.changeStatus(Account.State.CONNECTING); + } + protected void connect() { Logging.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": connecting"); features.encryptionEnabled = false; - lastConnect = SystemClock.elapsedRealtime(); - lastPingSent = SystemClock.elapsedRealtime(); - lastDiscoStarted = Long.MAX_VALUE; this.attempt++; switch (account.getJid().getDomainpart()) { case "chat.facebook.com": diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java index eff9a947..618d75ee 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java @@ -115,9 +115,7 @@ public class JingleConnection implements Transferable { } Logging.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); + FileBackend.updateMediaScanner(file, mXmppConnectionService); } else { account.getPgpDecryptionService().add(message); } diff --git a/src/main/res/menu/message_context.xml b/src/main/res/menu/message_context.xml index 292a4938..0c7d8eef 100644 --- a/src/main/res/menu/message_context.xml +++ b/src/main/res/menu/message_context.xml @@ -32,5 +32,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>
\ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 8005e432..59bf0b9c 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -399,6 +399,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> |