aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ui')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java11
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java14
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java120
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java3
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java151
5 files changed, 83 insertions, 216 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
index bca0851a..ce1eb439 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
@@ -44,6 +44,7 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import de.thedevstack.android.logcat.Logging;
+import de.thedevstack.conversationsplus.services.filetransfer.FileTransferManager;
import de.thedevstack.conversationsplus.utils.AccountUtil;
import de.timroes.android.listview.EnhancedListView;
@@ -59,8 +60,6 @@ import de.thedevstack.conversationsplus.entities.Contact;
import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.entities.Transferable;
-import de.thedevstack.conversationsplus.http.HttpConnectionManager;
-import de.thedevstack.conversationsplus.http.HttpDownloadConnection;
import de.thedevstack.conversationsplus.persistance.FileBackend;
import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.services.XmppConnectionService.OnAccountUpdate;
@@ -624,8 +623,12 @@ public class ConversationActivity extends XmppActivity
Toast.makeText(this, R.string.not_connected_try_again, Toast.LENGTH_SHORT).show();
}
} else if (message.treatAsDownloadable() != Message.Decision.NEVER) {
- HttpDownloadConnection downloadConnection = HttpConnectionManager.createNewDownloadConnection(message, true);
- if (null == downloadConnection) {
+ FileTransferManager ftm = FileTransferManager.getInstance();
+ boolean created = false;
+ if (ftm.accept(message)) {
+ created = ftm.transferFile(message);
+ }
+ if (!created) {
Toast.makeText(this, R.string.file_not_on_remote_host, Toast.LENGTH_LONG).show();
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
index 157e6dc3..0f32e762 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
@@ -43,8 +43,7 @@ import java.util.Collections;
import java.util.List;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
-import de.thedevstack.conversationsplus.http.HttpConnectionManager;
-import de.thedevstack.conversationsplus.http.HttpDownloadConnection;
+import de.thedevstack.conversationsplus.services.filetransfer.FileTransferManager;
import de.thedevstack.conversationsplus.services.filetransfer.http.delete.DeleteRemoteFileService;
import de.thedevstack.conversationsplus.ui.dialogs.SimpleConfirmDialog;
import de.thedevstack.conversationsplus.ui.dialogs.MessageDetailsDialog;
@@ -559,8 +558,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
if (m.hasFileOnRemoteHost()
|| GeoHelper.isGeoUri(m.getBody())
- || m.treatAsDownloadable() == Message.Decision.MUST
- || (t != null && t instanceof HttpDownloadConnection)) {
+ || m.treatAsDownloadable() == Message.Decision.MUST) {
copyUrl.setVisible(true);
}
if ((m.getType() == Message.TYPE_TEXT && t == null && m.treatAsDownloadable() != Message.Decision.NEVER)
@@ -687,8 +685,12 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
private void downloadFile(Message message) {
- HttpDownloadConnection downloadConnection = HttpConnectionManager.createNewDownloadConnection(message, true);
- if (null == downloadConnection) {
+ FileTransferManager ftm = FileTransferManager.getInstance();
+ boolean created = false;
+ if (ftm.accept(message)) {
+ created = ftm.transferFile(message);
+ }
+ if (!created) {
Toast.makeText(activity, R.string.file_not_on_remote_host, Toast.LENGTH_LONG).show();
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
index 726facac..6785dd31 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
@@ -17,28 +17,22 @@ import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.content.ServiceConnection;
-import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Point;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.NfcEvent;
-import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.SystemClock;
-import android.preference.PreferenceManager;
import android.text.InputType;
import android.util.DisplayMetrics;
import android.view.Menu;
@@ -62,17 +56,13 @@ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import net.java.otr4j.session.SessionID;
-import java.io.FileNotFoundException;
-import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
-import java.util.concurrent.RejectedExecutionException;
import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.ConversationsPlusColors;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
-import de.thedevstack.conversationsplus.utils.ImageUtil;
import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession;
@@ -104,7 +94,6 @@ public abstract class XmppActivity extends Activity {
public boolean xmppConnectionServiceBound = false;
protected boolean registeredListeners = false;
- private DisplayMetrics metrics;
protected int mTheme;
private long mLastUiRefresh = 0;
@@ -346,7 +335,6 @@ public abstract class XmppActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- metrics = getResources().getDisplayMetrics();
ExceptionHelper.init(getApplicationContext());
this.mTheme = findTheme();
setTheme(this.mTheme);
@@ -1062,112 +1050,4 @@ public abstract class XmppActivity extends Activity {
}
}
}
-
- class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> {
- private final WeakReference<ImageView> imageViewReference;
- private final boolean setSize;
- private Message message = null;
-
- public BitmapWorkerTask(ImageView imageView, boolean setSize) {
- imageViewReference = new WeakReference<>(imageView);
- this.setSize = setSize;
- }
-
- @Override
- protected Bitmap doInBackground(Message... params) {
- message = params[0];
- try {
- return ImageUtil.getThumbnail(message, (int) (metrics.density * 288), false);
- } catch (FileNotFoundException e) {
- return null;
- }
- }
-
- @Override
- protected void onPostExecute(Bitmap bitmap) {
- if (bitmap != null) {
- final ImageView imageView = imageViewReference.get();
- if (imageView != null) {
- imageView.setImageBitmap(bitmap);
- imageView.setBackgroundColor(0x00000000);
- if (setSize) {
- imageView.setLayoutParams(new LinearLayout.LayoutParams(
- bitmap.getWidth(), bitmap.getHeight()));
- }
- }
- }
- }
- }
-
- public void loadBitmap(Message message, ImageView imageView, boolean setSize) {
- Bitmap bm;
- try {
- bm = ImageUtil.getThumbnail(message,(int) (metrics.density * 288), true);
- } catch (FileNotFoundException e) {
- bm = null;
- }
-
- if (bm != null) {
- imageView.setImageBitmap(bm);
- imageView.setBackgroundColor(0x00000000);
- if (setSize) {
- imageView.setLayoutParams(new LinearLayout.LayoutParams(
- bm.getWidth(), bm.getHeight()));
- }
- } else {
- if (cancelPotentialWork(message, imageView)) {
- imageView.setBackgroundColor(0xff333333);
- imageView.setImageDrawable(null);
- final BitmapWorkerTask task = new BitmapWorkerTask(imageView, setSize);
- final AsyncDrawable asyncDrawable = new AsyncDrawable(
- getResources(), null, task);
- imageView.setImageDrawable(asyncDrawable);
- try {
- task.execute(message);
- } catch (final RejectedExecutionException ignored) {
- }
- }
- }
- }
-
- public static boolean cancelPotentialWork(Message message,
- ImageView imageView) {
- final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
-
- if (bitmapWorkerTask != null) {
- final Message oldMessage = bitmapWorkerTask.message;
- if (oldMessage == null || message != oldMessage) {
- bitmapWorkerTask.cancel(true);
- } else {
- return false;
- }
- }
- return true;
- }
-
- private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
- if (imageView != null) {
- final Drawable drawable = imageView.getDrawable();
- if (drawable instanceof AsyncDrawable) {
- final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
- return asyncDrawable.getBitmapWorkerTask();
- }
- }
- return null;
- }
-
- static class AsyncDrawable extends BitmapDrawable {
- private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference;
-
- public AsyncDrawable(Resources res, Bitmap bitmap,
- BitmapWorkerTask bitmapWorkerTask) {
- super(res, bitmap);
- bitmapWorkerTaskReference = new WeakReference<>(
- bitmapWorkerTask);
- }
-
- public BitmapWorkerTask getBitmapWorkerTask() {
- return bitmapWorkerTaskReference.get();
- }
- }
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java
index e0e672e3..df7fc922 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java
@@ -23,6 +23,7 @@ import java.util.concurrent.RejectedExecutionException;
import de.thedevstack.conversationsplus.ConversationsPlusColors;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.ui.listeners.ShowResourcesListDialogListener;
+import de.thedevstack.conversationsplus.utils.ImageUtil;
import de.tzur.conversations.Settings;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
@@ -100,7 +101,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
|| message.getTransferable().getStatus() != Transferable.STATUS_DELETED)) {
mLastMessage.setVisibility(View.GONE);
imagePreview.setVisibility(View.VISIBLE);
- activity.loadBitmap(message, imagePreview, false);
+ ImageUtil.loadBitmap(message, imagePreview, mLastMessage, false);
} else {
Pair<String,Boolean> preview = UIHelper.getMessagePreview(activity,message);
mLastMessage.setVisibility(View.VISIBLE);
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
index 79ab3bc3..e49575f6 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
@@ -13,9 +13,7 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.text.Spannable;
import android.text.SpannableString;
-import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
-import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.text.util.Linkify;
import android.util.Patterns;
@@ -48,13 +46,14 @@ import de.thedevstack.conversationsplus.entities.FileParams;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.entities.Transferable;
import de.thedevstack.conversationsplus.enums.FileStatus;
-import de.thedevstack.conversationsplus.http.HttpConnectionManager;
import de.thedevstack.conversationsplus.persistance.FileBackend;
import de.thedevstack.conversationsplus.providers.ConversationsPlusFileProvider;
import de.thedevstack.conversationsplus.services.AvatarService;
+import de.thedevstack.conversationsplus.services.filetransfer.http.download.AutomaticFileDownload;
import de.thedevstack.conversationsplus.ui.ConversationActivity;
import de.thedevstack.conversationsplus.utils.CryptoHelper;
import de.thedevstack.conversationsplus.utils.GeoHelper;
+import de.thedevstack.conversationsplus.utils.ImageUtil;
import de.thedevstack.conversationsplus.utils.MessageUtil;
import de.thedevstack.conversationsplus.utils.UIHelper;
import de.thedevstack.conversationsplus.utils.ui.TextViewUtil;
@@ -119,7 +118,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
}
- private void displayStatus(ViewHolder viewHolder, Message message, int type, boolean darkBackground) {
+ private void displayStatus(ViewHolder viewHolder, Message message, int type) {
String filesize = null;
String info = null;
boolean error = false;
@@ -177,12 +176,12 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (error && type == SENT) {
viewHolder.time.setTextColor(ConversationsPlusColors.warning());
} else {
- viewHolder.time.setTextColor(this.getMessageTextColor(darkBackground,false));
+ viewHolder.time.setTextColor(this.getMessageTextColor(viewHolder.darkBackground,false));
}
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
viewHolder.indicator.setVisibility(View.GONE);
} else {
- viewHolder.indicator.setImageResource(darkBackground ? R.drawable.ic_lock_white_18dp : R.drawable.ic_lock_black_18dp);
+ viewHolder.indicator.setImageResource(viewHolder.darkBackground ? R.drawable.ic_lock_white_18dp : R.drawable.ic_lock_black_18dp);
viewHolder.indicator.setVisibility(View.VISIBLE);
if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
XmppAxolotlSession.Trust trust = message.getConversation()
@@ -194,7 +193,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.indicator.setAlpha(1.0f);
} else {
viewHolder.indicator.clearColorFilter();
- if (darkBackground) {
+ if (viewHolder.darkBackground) {
viewHolder.indicator.setAlpha(0.7f);
} else {
viewHolder.indicator.setAlpha(0.57f);
@@ -202,7 +201,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
} else {
viewHolder.indicator.clearColorFilter();
- if (darkBackground) {
+ if (viewHolder.darkBackground) {
viewHolder.indicator.setAlpha(0.7f);
} else {
viewHolder.indicator.setAlpha(0.57f);
@@ -236,7 +235,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (message.hasFileAttached() && null != message.getFileParams() && null != viewHolder.remoteFileStatus) {
FileStatus fileStatus = message.getFileParams().getFileStatus();
- if (fileStatus == FileStatus.DELETE_FAILED || fileStatus == FileStatus.DELETED || fileStatus == FileStatus.DELETING) {
+ if (fileStatus == FileStatus.DELETE_FAILED || fileStatus == FileStatus.DELETED || fileStatus == FileStatus.DELETING || fileStatus == FileStatus.NOT_FOUND) {
viewHolder.remoteFileStatus.setVisibility(View.VISIBLE);
switch (fileStatus) {
case DELETE_FAILED:
@@ -249,24 +248,28 @@ public class MessageAdapter extends ArrayAdapter<Message> {
case DELETING:
viewHolder.remoteFileStatus.setText(R.string.remote_filestatus_delete_inprogress);
break;
+ case NOT_FOUND:
+ TextViewUtil.setColor(viewHolder.remoteFileStatus, R.color.error);
+ viewHolder.remoteFileStatus.setText(R.string.remote_filestatus_not_found);
+ break;
}
}
}
}
- private void displayInfoMessage(ViewHolder viewHolder, String text, boolean darkBackground) {
+ private void displayInfoMessage(ViewHolder viewHolder, String text) {
if (viewHolder.download_button != null) {
viewHolder.download_button.setVisibility(View.GONE);
}
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
viewHolder.messageBody.setText(text);
- viewHolder.messageBody.setTextColor(getMessageTextColor(darkBackground, false));
+ viewHolder.messageBody.setTextColor(getMessageTextColor(viewHolder.darkBackground, false));
viewHolder.messageBody.setTypeface(null, Typeface.ITALIC);
viewHolder.messageBody.setTextIsSelectable(false);
}
- private void displayDecryptionFailed(ViewHolder viewHolder, boolean darkBackground) {
+ private void displayDecryptionFailed(ViewHolder viewHolder) {
if (viewHolder.download_button != null) {
viewHolder.download_button.setVisibility(View.GONE);
}
@@ -274,12 +277,12 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody.setVisibility(View.VISIBLE);
viewHolder.messageBody.setText(getContext().getString(
R.string.decryption_failed));
- viewHolder.messageBody.setTextColor(getMessageTextColor(darkBackground, false));
+ viewHolder.messageBody.setTextColor(getMessageTextColor(viewHolder.darkBackground, false));
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
viewHolder.messageBody.setTextIsSelectable(false);
}
- private void displayTextMessage(final ViewHolder viewHolder, final Message message, boolean darkBackground) {
+ private void displayTextMessage(final ViewHolder viewHolder, final Message message) {
if (viewHolder.download_button != null) {
viewHolder.download_button.setVisibility(View.GONE);
}
@@ -295,12 +298,6 @@ public class MessageAdapter extends ArrayAdapter<Message> {
body = message.getBody();
}
final SpannableString formattedBody = new SpannableString(body);
- int i = body.indexOf(Message.MERGE_SEPARATOR);
- while(i >= 0) {
- final int end = i + Message.MERGE_SEPARATOR.length();
- formattedBody.setSpan(new RelativeSizeSpan(0.3f),i,end,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- i = body.indexOf(Message.MERGE_SEPARATOR,end);
- }
if (message.getType() != Message.TYPE_PRIVATE) {
if (message.hasMeCommand()) {
final Spannable span = new SpannableString(formattedBody);
@@ -326,7 +323,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
final Spannable span = new SpannableString(privateMarker + " "
+ formattedBody);
- span.setSpan(new ForegroundColorSpan(getMessageTextColor(darkBackground,false)), 0, privateMarker
+ span.setSpan(new ForegroundColorSpan(getMessageTextColor(viewHolder.darkBackground,false)), 0, privateMarker
.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new StyleSpan(Typeface.BOLD), 0,
privateMarker.length(),
@@ -366,7 +363,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody.setText("");
viewHolder.messageBody.setTextIsSelectable(false);
}
- viewHolder.messageBody.setTextColor(this.getMessageTextColor(darkBackground, true));
+ viewHolder.messageBody.setTextColor(this.getMessageTextColor(viewHolder.darkBackground, true));
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
}
@@ -403,10 +400,15 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody.setAutoLinkMask(oldAutoLinkMask);
}
- private void displayDownloadableMessage(ViewHolder viewHolder, final Message message, int resId) {
+ private void displayDownloadableMessage(ViewHolder viewHolder, final Message message) {
viewHolder.image.setVisibility(View.GONE);
FileParams fileParams = message.getFileParams();
String btnText;
+ int resId = R.string.download_x_file;
+ if ((message.getTransferable() != null && message.getTransferable().getStatus() == Transferable.STATUS_OFFER_CHECK_FILESIZE)
+ || (null != fileParams && -1 == fileParams.getSize())) {
+ resId = R.string.check_x_filesize;
+ }
if (null != fileParams) {
this.displayFileInfoForFileMessage(message, viewHolder);
btnText = activity.getString(resId, "");
@@ -465,26 +467,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (viewHolder.download_button != null) {
viewHolder.download_button.setVisibility(View.GONE);
}
- viewHolder.messageBody.setVisibility(View.GONE);
- viewHolder.image.setVisibility(View.VISIBLE);
- //TODO: Check what value add the following lines have (compared with setting height/width in XmppActivity.loadBitmap from thumbnail after thumbnail is created)
- /*
- FileParams params = message.getFileParams();
- double target = metrics.density * 288;
- int scalledW;
- int scalledH;
- if (params.width <= params.height) {
- scalledW = (int) (params.width / ((double) params.height / target));
- scalledH = (int) target;
- } else {
- scalledW = (int) target;
- scalledH = (int) (params.height / ((double) params.width / target));
- }
- LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(scalledW, scalledH);
- layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4));
- viewHolder.image.setLayoutParams(layoutParams);*/
- //TODO Why should this be calculated by hand???
- activity.loadBitmap(message, viewHolder.image, true);
+
+ ImageUtil.loadBitmap(message, viewHolder.image, viewHolder.messageBody, true);
viewHolder.image.setOnClickListener(new OnClickListener() {
@Override
@@ -511,19 +495,35 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
private void displayFileMessage(final Message message, ViewHolder viewHolder) {
- final FileParams fileParams = message.getFileParams();
- String mimeType = (null != fileParams) ? fileParams.getMimeType() : null;
- if ((message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)
- || (fileParams != null && fileParams.getWidth() > 0)
- || (null != mimeType && mimeType.startsWith("image/"))) {
+ Transferable transferable = message.getTransferable();
+ if (null != transferable) {
+ switch (transferable.getStatus()) {
+ case Transferable.STATUS_OFFER:
+ case Transferable.STATUS_OFFER_CHECK_FILESIZE:
+ displayDownloadableMessage(viewHolder, message);
+ break;
+ case Transferable.STATUS_UPLOADING:
+ displayFileMessage(message, viewHolder);
+ break;
+ case Transferable.STATUS_DELETED:
+ case Transferable.STATUS_CHECKING:
+ case Transferable.STATUS_FAILED:
+ case Transferable.STATUS_DOWNLOADING:
+ case Transferable.STATUS_UNKNOWN:
+ displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first);
+ break;
+ }
+ } else if (FileStatus.CHECKING_FILE_SIZE == message.getFileParams().getFileStatus()) {
+ displayInfoMessage(viewHolder, activity.getString(R.string.checking_remote_filesize));
+ } else if (MessageUtil.isAttachedFileAnImage(message) && FileStatus.DOWNLOADED == message.getFileParams().getFileStatus()) {
displayImageMessage(viewHolder, message);
- } else if ((message.getType() == Message.TYPE_FILE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)
- && null != fileParams && (FileStatus.NEEDS_DOWNLOAD != fileParams.getFileStatus() || 0 == fileParams.getWidth())) {
+ } else if ((MessageUtil.isTypeFileAndDecrypted(message) || FileStatus.DOWNLOADED == message.getFileParams().getFileStatus())
+ && !MessageUtil.needsDownload(message)) {
displayOpenableMessage(viewHolder, message);
- } else if (Message.Decision.NEVER == message.treatAsDownloadable()) {
- displayTextMessage(viewHolder, message, getItemViewType(message) == RECEIVED && !message.isValidInSession());
+ } else if (Message.Decision.NEVER == message.treatAsDownloadable() || !MessageUtil.mayFileRemoteAvailable(message)) {
+ displayTextMessage(viewHolder, message);
} else {
- displayDownloadableMessage(viewHolder, message, R.string.download_x_file);
+ displayDownloadableMessage(viewHolder, message);
}
}
@@ -660,48 +660,28 @@ public class MessageAdapter extends ArrayAdapter<Message> {
this.displayAvatar(message, type, viewHolder);
- boolean darkBackground = (type == RECEIVED && !isInValidSession);
- this.displayStatus(viewHolder, message, type, darkBackground);
+ viewHolder.darkBackground = (type == RECEIVED && !isInValidSession);
+ this.displayStatus(viewHolder, message, type);
- final Transferable transferable = message.getTransferable();
- if (null != transferable) {
- switch (transferable.getStatus()) {
- case Transferable.STATUS_OFFER:
- displayDownloadableMessage(viewHolder, message, R.string.download_x_file);
- break;
- case Transferable.STATUS_OFFER_CHECK_FILESIZE:
- displayDownloadableMessage(viewHolder, message, R.string.check_x_filesize);
- break;
- case Transferable.STATUS_UPLOADING:
- displayFileMessage(message, viewHolder);
- break;
- case Transferable.STATUS_DELETED:
- case Transferable.STATUS_CHECKING:
- case Transferable.STATUS_FAILED:
- case Transferable.STATUS_UNKNOWN:
- displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first,darkBackground);
- break;
- }
- } else if (message.hasFileAttached()) {
- if (message.trusted()
+ if (null != message.getTransferable() || message.hasFileAttached()) {
+ if (!(message.trusted()
&& MessageUtil.needsDownload(message)
&& ConversationsPlusPreferences.autoAcceptFileSize() > 0
- && (message.isHttpUploaded() || ConversationsPlusPreferences.autoDownloadFileLink())) {
- HttpConnectionManager.createNewDownloadConnection(message);
- } else {
- displayFileMessage(message, viewHolder);
+ && message.isHttpUploaded() || ConversationsPlusPreferences.autoDownloadFileLink())) {
+ new AutomaticFileDownload(false).transferFile(message);
}
+ displayFileMessage(message, viewHolder);
} else if (GeoHelper.isGeoUri(message.getBody())) {
displayLocationMessage(viewHolder, message);
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
if (activity.hasPgp()) {
if (account.getPgpDecryptionService().isRunning()) {
- displayInfoMessage(viewHolder, activity.getString(R.string.message_decrypting), darkBackground);
+ displayInfoMessage(viewHolder, activity.getString(R.string.message_decrypting));
} else {
- displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message), darkBackground);
+ displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message));
}
} else {
- displayInfoMessage(viewHolder,activity.getString(R.string.install_openkeychain),darkBackground);
+ displayInfoMessage(viewHolder, activity.getString(R.string.install_openkeychain));
if (viewHolder != null) {
viewHolder.message_box
.setOnClickListener(new OnClickListener() {
@@ -714,9 +694,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
}
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
- displayDecryptionFailed(viewHolder,darkBackground);
+ displayDecryptionFailed(viewHolder);
} else {
- displayTextMessage(viewHolder, message, darkBackground);
+ displayTextMessage(viewHolder, message);
}
if (type == RECEIVED) {
@@ -812,6 +792,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
protected TextView status_message;
protected TextView encryption;
public TextView remoteFileStatus;
+ protected boolean darkBackground;
}
class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> {