aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2015-12-16 00:53:04 +0100
committersteckbrief <steckbrief@chefmail.de>2015-12-16 00:53:04 +0100
commitc26335f3e366110366eb89025a42875bcb7840a9 (patch)
treef6ae254a0bf0a8ce2d9e43efd48a5eba6e454b4f /src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
parent556697c47e74766215c17fb5f721d71494a02643 (diff)
Implements FS#19, FS#84; Introduces ImageResizeException, MessageUtil and distinguishes between image resizing and compressing/saving
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java125
1 files changed, 23 insertions, 102 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
index 159fcf44..7472ad21 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java
@@ -53,10 +53,13 @@ import de.duenndns.ssl.MemorizingTrustManager;
import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.entities.DownloadableFile;
import de.thedevstack.conversationsplus.exceptions.FileCopyException;
+import de.thedevstack.conversationsplus.exceptions.UiException;
import de.thedevstack.conversationsplus.utils.AvatarUtil;
import de.thedevstack.conversationsplus.utils.FileHelper;
import de.thedevstack.conversationsplus.utils.ImageUtil;
+import de.thedevstack.conversationsplus.utils.MessageUtil;
import de.tzur.conversations.Settings;
import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
@@ -86,7 +89,6 @@ import de.thedevstack.conversationsplus.utils.ExceptionHelper;
import de.thedevstack.conversationsplus.utils.OnPhoneContactsLoadedListener;
import de.thedevstack.conversationsplus.utils.PRNGFixes;
import de.thedevstack.conversationsplus.utils.PhoneHelper;
-import de.thedevstack.conversationsplus.utils.SerialSingleThreadExecutor;
import de.thedevstack.conversationsplus.utils.Xmlns;
import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.OnBindListener;
@@ -130,9 +132,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
};
- private final SerialSingleThreadExecutor mFileAddingExecutor = new SerialSingleThreadExecutor();
- private final SerialSingleThreadExecutor mDatabaseExecutor = new SerialSingleThreadExecutor();
-
private final IBinder mBinder = new XmppConnectionBinder();
private final List<Conversation> conversations = new CopyOnWriteArrayList<>();
private final FileObserver fileObserver = new FileObserver(
@@ -375,110 +374,33 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_FILE);
String path = FileHelper.getRealPathFromUri(uri);
- if (path!=null) {
+ if (path != null) {
message.setRelativeFilePath(path);
- FileBackend.updateFileParams(message);
+ MessageUtil.updateFileParams(message);
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
getPgpEngine().encrypt(message, callback);
} else {
callback.success(message);
}
} else {
- mFileAddingExecutor.execute(new Runnable() {
- @Override
- public void run() {
- try {
- FileBackend.copyFileToPrivateStorage(message, uri);
- FileBackend.updateFileParams(message);
- if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
- getPgpEngine().encrypt(message, callback);
- } else {
- callback.success(message);
- }
- } catch (FileCopyException e) {
- callback.error(e.getResId(), message);
- }
- }
- });
- }
- }
-
- public void attachImageToConversationWithoutResizing(final Conversation conversation, final Uri uri, final UiCallback<Message> callback) {
- final Message message;
- final boolean forceEncryption = ConversationsPlusPreferences.forceEncryption();
- if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
- message = new Message(conversation, "",
- Message.ENCRYPTION_DECRYPTED);
- } else {
- message = new Message(conversation, "",
- conversation.getNextEncryption(forceEncryption));
- }
- message.setCounterpart(conversation.getNextCounterpart());
- message.setType(Message.TYPE_IMAGE);
- mFileAddingExecutor.execute(new Runnable() {
- @Override
- public void run() {
- InputStream is = null;
- try {
- is = ConversationsPlusApplication.getInstance().getContentResolver().openInputStream(uri);
- long imageSize = is.available();
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeStream(is, null, options);
- int imageHeight = options.outHeight;
- int imageWidth = options.outWidth;
- message.setRelativeFilePath(FileHelper.getRealPathFromUri(uri));
- message.setBody(Long.toString(imageSize) + '|' + imageWidth + '|' + imageHeight);
- callback.success(message);
- } catch (FileNotFoundException e) {
- Logging.e("pictureresize", "File not found to send not resized. " + e.getMessage());
- callback.error(R.string.error_file_not_found, message);
- } catch (IOException e) {
- Logging.e("pictureresize", "Error while sending not resized picture. " + e.getMessage());
- callback.error(R.string.error_io_exception, message);
- } finally {
- if (null != is) {
- try {
- is.close();
- } catch (IOException e) {
- Logging.w("pictureresize", "Error while closing stream for sending not resized picture. " + e.getMessage());
+ ConversationsPlusApplication.executeFileAdding(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ FileBackend.copyFileToPrivateStorage(message, uri);
+ MessageUtil.updateFileParams(message);
+ if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
+ getPgpEngine().encrypt(message, callback);
+ } else {
+ callback.success(message);
}
+ } catch (FileCopyException e) {
+ callback.error(e.getResId(), message);
}
}
- }
- });
- }
-
- public void attachImageToConversation(final Conversation conversation,
- final Uri uri, final UiCallback<Message> callback) {
- final Message message;
- final boolean forceEncryption = ConversationsPlusPreferences.forceEncryption();
- if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
- message = new Message(conversation, "",
- Message.ENCRYPTION_DECRYPTED);
- } else {
- message = new Message(conversation, "",
- conversation.getNextEncryption(forceEncryption));
- }
- message.setCounterpart(conversation.getNextCounterpart());
- message.setType(Message.TYPE_IMAGE);
- mFileAddingExecutor.execute(new Runnable() {
-
- @Override
- public void run() {
- try {
- FileBackend.copyImageToPrivateStorage(message, uri);
- if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
- getPgpEngine().encrypt(message, callback);
- } else {
- callback.success(message);
- }
- } catch (final FileCopyException e) {
- callback.error(e.getResId(), message);
- }
- }
- });
- }
+ });
+ }
+ }
public Conversation find(Bookmark bookmark) {
return find(bookmark.getAccount(), bookmark.getJid());
@@ -1019,7 +941,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
updateConversationUi();
}
};
- mDatabaseExecutor.execute(runnable);
+ ConversationsPlusApplication.executeDatabaseOperation(runnable);
}
}
@@ -1123,7 +1045,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
};
- mDatabaseExecutor.execute(runnable);
+ ConversationsPlusApplication.executeDatabaseOperation(runnable);
}
public List<Account> getAccounts() {
@@ -2390,8 +2312,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
databaseBackend.writeRoster(account.getRoster());
}
};
- mDatabaseExecutor.execute(runnable);
-
+ ConversationsPlusApplication.executeDatabaseOperation(runnable);
}
public List<String> getKnownHosts() {