diff options
author | steckbrief <steckbrief@chefmail.de> | 2018-02-26 21:07:26 +0100 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2018-02-26 21:07:26 +0100 |
commit | fb9817091a8722782801a34b40e5baaceb777521 (patch) | |
tree | 8ee6fed344addc8c3303e82b50468c6a931d2894 /src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java | |
parent | 010eb44ad971ad9e77b555179d70b6e43d1dec80 (diff) |
improves remote file status display and loading of remote files
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java | 483 |
1 files changed, 183 insertions, 300 deletions
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 96b5954e..4991c512 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java @@ -1,11 +1,7 @@ package de.thedevstack.conversationsplus.ui.adapter; -import android.content.ActivityNotFoundException; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; import android.graphics.Typeface; -import android.net.Uri; +import android.support.annotation.NonNull; import android.text.Spannable; import android.text.SpannableString; @@ -14,7 +10,6 @@ import android.text.style.ForegroundColorSpan; import android.text.style.StyleSpan; import android.text.util.Linkify; -import android.util.DisplayMetrics; import android.util.Patterns; import android.view.View; import android.view.View.OnClickListener; @@ -25,33 +20,30 @@ import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import android.widget.Toast; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; - -import de.thedevstack.conversationsplus.ConversationsPlusApplication; import de.thedevstack.conversationsplus.ConversationsPlusColors; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.R; import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession; import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.entities.Conversation; -import de.thedevstack.conversationsplus.entities.DownloadableFile; 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.persistance.FileBackend; -import de.thedevstack.conversationsplus.providers.ConversationsPlusFileProvider; import de.thedevstack.conversationsplus.services.avatar.AvatarCache; import de.thedevstack.conversationsplus.services.avatar.AvatarService; -import de.thedevstack.conversationsplus.services.filetransfer.FileTransferStatusEnum; import de.thedevstack.conversationsplus.services.filetransfer.http.download.AutomaticFileDownload; import de.thedevstack.conversationsplus.ui.ConversationActivity; +import de.thedevstack.conversationsplus.ui.listeners.ContactPictureOnClickListener; +import de.thedevstack.conversationsplus.ui.listeners.ContactPictureOnLongClickListener; +import de.thedevstack.conversationsplus.ui.listeners.OpenFileOnClickListener; +import de.thedevstack.conversationsplus.ui.listeners.OpenLocationOnClickListener; import de.thedevstack.conversationsplus.utils.CryptoHelper; import de.thedevstack.conversationsplus.utils.GeoHelper; import de.thedevstack.conversationsplus.utils.ImageUtil; @@ -74,11 +66,6 @@ public class MessageAdapter extends ArrayAdapter<Message> { private ConversationActivity activity; - private DisplayMetrics metrics; - - private OnContactPictureClicked mOnContactPictureClickedListener; - private OnContactPictureLongClicked mOnContactPictureLongClickedListener; - private OnLongClickListener openContextMenu = new OnLongClickListener() { @Override @@ -88,20 +75,9 @@ public class MessageAdapter extends ArrayAdapter<Message> { } }; - public MessageAdapter(ConversationActivity activity, List<Message> messages) { super(activity, 0, messages); this.activity = activity; - metrics = getContext().getResources().getDisplayMetrics(); - } - - public void setOnContactPictureClicked(OnContactPictureClicked listener) { - this.mOnContactPictureClickedListener = listener; - } - - public void setOnContactPictureLongClicked( - OnContactPictureLongClicked listener) { - this.mOnContactPictureLongClickedListener = listener; } @Override @@ -138,9 +114,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { String filesize = null; String info = null; boolean error = false; - if (viewHolder.indicatorReceived != null) { - viewHolder.indicatorReceived.setVisibility(View.GONE); - } + ViewUtil.gone(viewHolder.indicatorReceived); boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI && message.getStatus() <= Message.STATUS_RECEIVED; @@ -193,11 +167,76 @@ public class MessageAdapter extends ArrayAdapter<Message> { } break; } - if (error && type == SENT) { + + this.displayEncryptionIndicator(message, viewHolder); + + this.displayMessageTime(message, viewHolder, filesize, info, error, type == SENT); + + this.displayRemoteFileStatus(message, viewHolder); + } + + private void displayRemoteFileStatus(Message message, ViewHolder viewHolder) { + 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 || fileStatus == FileStatus.NOT_FOUND) { + TextViewUtil.visible(viewHolder.remoteFileStatus); + switch (fileStatus) { + case DELETE_FAILED: + TextViewUtil.setColor(viewHolder.remoteFileStatus, R.color.error); + viewHolder.remoteFileStatus.setText(R.string.remote_filestatus_delete_failed); + break; + case DELETED: + viewHolder.remoteFileStatus.setText(R.string.remote_filestatus_delete_success); + break; + 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; + } + } else { + TextViewUtil.gone(viewHolder.remoteFileStatus); + } + } + } + + private void displayMessageTime(Message message, ViewHolder viewHolder, String filesize, String info, boolean error, boolean isSent) { + if (error && isSent) { viewHolder.time.setTextColor(ConversationsPlusColors.warning()); } else { viewHolder.time.setTextColor(this.getMessageTextColor(viewHolder.darkBackground, false)); } + String formatedTime = UIHelper.readableTimeDifferenceFull(getContext(), message.getTimeSent()); + String timeText = null; + if (message.getStatus() <= Message.STATUS_RECEIVED) { + StringBuilder timeTextBuilder = new StringBuilder(); + timeTextBuilder.append((null != formatedTime) ? formatedTime + ((null != info || null != filesize) ? " \u00B7 " : "") : ""); + timeTextBuilder.append((null != filesize) ? filesize + ((null != info) ? " \u00B7 " : "") : ""); + timeTextBuilder.append((null != info) ? info : ""); + + timeText = timeTextBuilder.toString(); + } else { + if ((filesize != null) && (info != null)) { + timeText = filesize + " \u00B7 " + info; + } else if ((filesize == null) && (info != null)) { + if (error) { + timeText = info + " \u00B7 " + formatedTime; + } else { + timeText = info; + } + } else if ((filesize != null) && (info == null)) { + timeText = filesize + " \u00B7 " + formatedTime; + } else { + timeText = formatedTime; + } + } + + TextViewUtil.setTextWithoutAutoLink(viewHolder.time, timeText); + } + + private void displayEncryptionIndicator(Message message, ViewHolder viewHolder) { if (message.getEncryption() == Message.ENCRYPTION_NONE) { viewHolder.indicator.setVisibility(View.GONE); } else { @@ -228,55 +267,6 @@ public class MessageAdapter extends ArrayAdapter<Message> { } } } - - String formatedTime = UIHelper.readableTimeDifferenceFull(getContext(), message.getTimeSent()); - if (message.getStatus() <= Message.STATUS_RECEIVED) { - StringBuilder timeText = new StringBuilder(); - timeText.append((null != formatedTime) ? formatedTime + ((null != info || null != filesize) ? " \u00B7 " : "") : ""); - timeText.append((null != filesize) ? filesize + ((null != info) ? " \u00B7 " : "") : ""); - timeText.append((null != info) ? info : ""); - - viewHolder.time.setText(timeText); - } else { - if ((filesize != null) && (info != null)) { - viewHolder.time.setText(filesize + " \u00B7 " + info); - } else if ((filesize == null) && (info != null)) { - if (error) { - viewHolder.time.setText(info + " \u00B7 " + formatedTime); - } else { - viewHolder.time.setText(info); - } - } else if ((filesize != null) && (info == null)) { - viewHolder.time.setText(filesize + " \u00B7 " + formatedTime); - } else { - viewHolder.time.setText(formatedTime); - } - } - - 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 || fileStatus == FileStatus.NOT_FOUND) { - TextViewUtil.visible(viewHolder.remoteFileStatus); - switch (fileStatus) { - case DELETE_FAILED: - TextViewUtil.setColor(viewHolder.remoteFileStatus, R.color.error); - viewHolder.remoteFileStatus.setText(R.string.remote_filestatus_delete_failed); - break; - case DELETED: - viewHolder.remoteFileStatus.setText(R.string.remote_filestatus_delete_success); - break; - 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; - } - } else { - TextViewUtil.gone(viewHolder.remoteFileStatus); - } - } } private void displayInfoMessage(ViewHolder viewHolder, String text) { @@ -310,92 +300,87 @@ public class MessageAdapter extends ArrayAdapter<Message> { } private void displayTextMessage(final ViewHolder viewHolder, final Message message) { - if (viewHolder.download_button != null) { - viewHolder.download_button.setVisibility(View.GONE); - } - if (null != viewHolder.image) { - viewHolder.image.setVisibility(View.GONE); + ViewUtil.gone(viewHolder.download_button, viewHolder.image); + + viewHolder.messageBody.setVisibility(View.VISIBLE); + viewHolder.messageBody.setIncludeFontPadding(true); + if (message.getBody() != null) { + final String nick = UIHelper.getMessageDisplayName(message); + String body; + if (message.hasMeCommand()) { + body = message.getBodyReplacedMeCommand(nick); + } else { + body = message.getBody(); } + final SpannableString formattedBody = new SpannableString(body); - viewHolder.messageBody.setVisibility(View.VISIBLE); - viewHolder.messageBody.setIncludeFontPadding(true); - if (message.getBody() != null) { - final String nick = UIHelper.getMessageDisplayName(message); - String body; + if (message.getType() != Message.TYPE_PRIVATE) { if (message.hasMeCommand()) { - body = message.getBodyReplacedMeCommand(nick); + final Spannable span = new SpannableString(formattedBody); + span.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, nick.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + viewHolder.messageBody.setText(span); } else { - body = message.getBody(); + viewHolder.messageBody.setText(formattedBody); } - final SpannableString formattedBody = new SpannableString(body); - - if (message.getType() != Message.TYPE_PRIVATE) { - if (message.hasMeCommand()) { - final Spannable span = new SpannableString(formattedBody); - span.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, nick.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - viewHolder.messageBody.setText(span); - } else { - viewHolder.messageBody.setText(formattedBody); - } + } else { + String privateMarker; + if (message.getStatus() <= Message.STATUS_RECEIVED) { + privateMarker = activity.getString(R.string.private_message); } else { - String privateMarker; - if (message.getStatus() <= Message.STATUS_RECEIVED) { - privateMarker = activity.getString(R.string.private_message); + final String to; + if (message.getCounterpart() != null) { + to = message.getCounterpart().getResourcepart(); } else { - final String to; - if (message.getCounterpart() != null) { - to = message.getCounterpart().getResourcepart(); - } else { - to = ""; - } - privateMarker = activity.getString(R.string.private_message_to, to); - } - final Spannable span = new SpannableString(privateMarker + " " - + formattedBody); - span.setSpan(new ForegroundColorSpan(getMessageTextColor(viewHolder.darkBackground, false)), 0, privateMarker - .length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - span.setSpan(new StyleSpan(Typeface.BOLD), 0, - privateMarker.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - if (message.hasMeCommand()) { - span.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), privateMarker.length() + 1, - privateMarker.length() + 1 + nick.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + to = ""; } - viewHolder.messageBody.setText(span); + privateMarker = activity.getString(R.string.private_message_to, to); } - int patternMatchCount = 0; - int oldAutoLinkMask = viewHolder.messageBody.getAutoLinkMask(); - - // first check if we have a match on XMPP_PATTERN so we do not have to check for EMAIL_ADDRESSES - patternMatchCount += countMatches(XMPP_PATTERN, body); - if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0 && patternMatchCount > 0) { - oldAutoLinkMask -= Linkify.EMAIL_ADDRESSES; + final Spannable span = new SpannableString(privateMarker + " " + + formattedBody); + span.setSpan(new ForegroundColorSpan(getMessageTextColor(viewHolder.darkBackground, false)), 0, privateMarker + .length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + span.setSpan(new StyleSpan(Typeface.BOLD), 0, + privateMarker.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + if (message.hasMeCommand()) { + span.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), privateMarker.length() + 1, + privateMarker.length() + 1 + nick.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } + viewHolder.messageBody.setText(span); + } + int patternMatchCount = 0; + int oldAutoLinkMask = viewHolder.messageBody.getAutoLinkMask(); - // count matches for all patterns - if ((Linkify.WEB_URLS & oldAutoLinkMask) != 0) { - patternMatchCount += countMatches(Patterns.WEB_URL, body); - } - if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0) { - patternMatchCount += countMatches(Patterns.EMAIL_ADDRESS, body); - } - if ((Linkify.PHONE_NUMBERS & oldAutoLinkMask) != 0) { - patternMatchCount += countMatches(Patterns.PHONE, body); - } + // first check if we have a match on XMPP_PATTERN so we do not have to check for EMAIL_ADDRESSES + patternMatchCount += countMatches(XMPP_PATTERN, body); + if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0 && patternMatchCount > 0) { + oldAutoLinkMask -= Linkify.EMAIL_ADDRESSES; + } - viewHolder.messageBody.setTextIsSelectable(patternMatchCount <= 1); - viewHolder.messageBody.setAutoLinkMask(0); - Linkify.addLinks(viewHolder.messageBody, XMPP_PATTERN, "xmpp"); - viewHolder.messageBody.setAutoLinkMask(oldAutoLinkMask); - } else { - viewHolder.messageBody.setText(""); - viewHolder.messageBody.setTextIsSelectable(false); + // count matches for all patterns + if ((Linkify.WEB_URLS & oldAutoLinkMask) != 0) { + patternMatchCount += countMatches(Patterns.WEB_URL, body); + } + if ((Linkify.EMAIL_ADDRESSES & oldAutoLinkMask) != 0) { + patternMatchCount += countMatches(Patterns.EMAIL_ADDRESS, body); } - viewHolder.messageBody.setTextColor(this.getMessageTextColor(viewHolder.darkBackground, true)); - viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); - viewHolder.messageBody.setOnLongClickListener(openContextMenu); + if ((Linkify.PHONE_NUMBERS & oldAutoLinkMask) != 0) { + patternMatchCount += countMatches(Patterns.PHONE, body); + } + + viewHolder.messageBody.setTextIsSelectable(patternMatchCount <= 1); + viewHolder.messageBody.setAutoLinkMask(0); + Linkify.addLinks(viewHolder.messageBody, XMPP_PATTERN, "xmpp"); + viewHolder.messageBody.setAutoLinkMask(oldAutoLinkMask); + } else { + viewHolder.messageBody.setText(""); + viewHolder.messageBody.setTextIsSelectable(false); + } + viewHolder.messageBody.setTextColor(this.getMessageTextColor(viewHolder.darkBackground, true)); + viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); + viewHolder.messageBody.setOnLongClickListener(openContextMenu); } /** @@ -427,10 +412,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { String filename = UIHelper.getDisplayFilename(message); fileInfos.append((null != filename && !filename.isEmpty()) ? (filename) : ""); - int oldAutoLinkMask = viewHolder.messageBody.getAutoLinkMask(); - viewHolder.messageBody.setAutoLinkMask(0); - viewHolder.messageBody.setText(fileInfos); - viewHolder.messageBody.setAutoLinkMask(oldAutoLinkMask); + TextViewUtil.setTextWithoutAutoLink(viewHolder.messageBody, fileInfos); } private void displayDownloadableMessage(ViewHolder viewHolder, final Message message) { @@ -471,12 +453,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { btnText = activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity, message)); } - this.displayDownloadButton(viewHolder, btnText, new OnClickListener() { - @Override - public void onClick(View v) { - openDownloadable(message); - } - }); + this.displayDownloadButton(viewHolder, btnText, new OpenFileOnClickListener(this.activity, message)); } @@ -485,51 +462,43 @@ public class MessageAdapter extends ArrayAdapter<Message> { viewHolder.messageBody.setVisibility(View.GONE); viewHolder.download_button.setVisibility(View.VISIBLE); viewHolder.download_button.setText(R.string.show_location); - viewHolder.download_button.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - showLocation(message); - } - }); + viewHolder.download_button.setOnClickListener(new OpenLocationOnClickListener(this.activity, message)); viewHolder.download_button.setOnLongClickListener(openContextMenu); } private void displayImageMessage(ViewHolder viewHolder, final Message message) { - if (viewHolder.download_button != null) { - viewHolder.download_button.setVisibility(View.GONE); - } + ViewUtil.gone(viewHolder.download_button); ImageUtil.loadBitmap(message, viewHolder.image, viewHolder.messageBody, true); - viewHolder.image.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - openDownloadable(message); - } - }); + viewHolder.image.setOnClickListener(new OpenFileOnClickListener(this.activity, message)); viewHolder.image.setOnLongClickListener(openContextMenu); } private View displayStatusMessage(final Message message, ViewHolder viewHolder) { - if (null != viewHolder) { - final Conversation conversation = message.getConversation(); - - viewHolder.status_message.setVisibility(View.VISIBLE); - viewHolder.contact_picture.setVisibility(View.VISIBLE); - if (conversation.getMode() == Conversation.MODE_SINGLE) { - viewHolder.contact_picture.setImageBitmap(AvatarCache.get(conversation.getContact(), - activity.getPixel(32))); - viewHolder.contact_picture.setAlpha(0.5f); - } - viewHolder.status_message.setText(message.getBody()); + final Conversation conversation = message.getConversation(); + + viewHolder.status_message.setVisibility(View.VISIBLE); + viewHolder.contact_picture.setVisibility(View.VISIBLE); + if (conversation.getMode() == Conversation.MODE_SINGLE) { + viewHolder.contact_picture.setImageBitmap(AvatarCache.get(conversation.getContact(), + activity.getPixel(32))); + viewHolder.contact_picture.setAlpha(0.5f); } + viewHolder.status_message.setText(message.getBody()); return viewHolder.view; } private void displayFileMessage(final Message message, ViewHolder viewHolder) { + if (!(message.trusted() + && MessageUtil.needsDownload(message) + && ConversationsPlusPreferences.autoAcceptFileSize() > 0 + && message.isHttpUploaded() || ConversationsPlusPreferences.autoDownloadFileLink())) { + new AutomaticFileDownload(false).transferFile(message); + } Transferable transferable = message.getTransferable(); if (FileStatus.CHECKING_FILE_SIZE == message.getFileParams().getFileStatus()) { displayInfoMessage(viewHolder, activity.getString(R.string.checking_remote_filesize)); @@ -579,31 +548,9 @@ public class MessageAdapter extends ArrayAdapter<Message> { if (null != imageView) { AvatarService.getInstance().loadAvatar(message, imageView); - imageView.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - if (MessageAdapter.this.mOnContactPictureClickedListener != null) { - MessageAdapter.this.mOnContactPictureClickedListener - .onContactPictureClicked(message); - } - - } - }); + imageView.setOnClickListener(new ContactPictureOnClickListener(this.activity, message)); if (message.getConversation().getMode() == Conversation.MODE_MULTI) { - imageView.setOnLongClickListener(new OnLongClickListener() { - - @Override - public boolean onLongClick(View v) { - if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) { - MessageAdapter.this.mOnContactPictureLongClickedListener - .onContactPictureLongClicked(message); - return true; - } else { - return false; - } - } - }); + imageView.setOnLongClickListener(new ContactPictureOnLongClickListener(this.activity, message)); } } } @@ -630,7 +577,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { return activity.getLayoutInflater().inflate(viewResId, parent, false); } - private ViewHolder initializeViewHolderAndView(Message message, int type, ViewGroup parent) { + private ViewHolder initializeViewHolderAndView(int type, ViewGroup parent) { View view = initializeView(type, parent); ViewHolder viewHolder = new ViewHolder(view); if (SENT == type @@ -667,15 +614,18 @@ public class MessageAdapter extends ArrayAdapter<Message> { } @Override - public View getView(int position, View view, ViewGroup parent) { + public View getView(int position, View view, @NonNull ViewGroup parent) { final Message message = getItem(position); + if (null == message) { + return view; + } final boolean isInValidSession = message.isValidInSession(); final Conversation conversation = message.getConversation(); final Account account = conversation.getAccount(); final int type = getItemViewType(position); ViewHolder viewHolder; if (null == view) { - viewHolder = initializeViewHolderAndView(message, type, parent); + viewHolder = initializeViewHolderAndView(type, parent); view = viewHolder.view; } else { viewHolder = (ViewHolder) view.getTag(); @@ -694,33 +644,11 @@ public class MessageAdapter extends ArrayAdapter<Message> { this.displayStatus(viewHolder, message, type); if (null != message.getTransferable() || message.hasFileAttached() || MessageUtil.hasDownloadableLink(message)) { - if (!(message.trusted() - && MessageUtil.needsDownload(message) - && ConversationsPlusPreferences.autoAcceptFileSize() > 0 - && 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)); - } else { - displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message)); - } - } else { - displayInfoMessage(viewHolder, activity.getString(R.string.install_openkeychain)); - if (viewHolder != null) { - viewHolder.message_box.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - activity.showInstallPgpDialog(); - } - }); - } - } + displayPgpEncryptedMessage(viewHolder, account); } else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) { displayDecryptionFailed(viewHolder); } else { @@ -740,67 +668,22 @@ public class MessageAdapter extends ArrayAdapter<Message> { return view; } - public void openDownloadable(Message message) { - DownloadableFile file = FileBackend.getFile(message); - if (!file.exists()) { - Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show(); - return; - } - boolean bInPrivateStorage = false; - if (file.getAbsolutePath().startsWith(FileBackend.getPrivateFileDirectoryPath())) { - bInPrivateStorage = true; - } - Intent openIntent = new Intent(Intent.ACTION_VIEW); - String mime = file.getMimeType(); - if (mime == null) { - mime = "*/*"; - } - Uri uri; - if (bInPrivateStorage) { - uri = ConversationsPlusFileProvider.createUriForPrivateFile(file); - } else { - uri = Uri.fromFile(file); - } - openIntent.setDataAndType(uri, mime); - PackageManager manager = activity.getPackageManager(); - List<ResolveInfo> infos = manager.queryIntentActivities(openIntent, 0); - if (bInPrivateStorage) { - for (ResolveInfo info : infos) { - ConversationsPlusApplication.getAppContext().grantUriPermission(info.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); - } - } - if (infos.size() == 0) { - openIntent.setDataAndType(uri, "*/*"); - } - if (bInPrivateStorage) { - openIntent.putExtra(Intent.EXTRA_STREAM, uri); - openIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - } - try { - getContext().startActivity(openIntent); - return; - } catch (ActivityNotFoundException e) { - //ignored - } - Toast.makeText(activity, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show(); - } - - public void showLocation(Message message) { - for (Intent intent : GeoHelper.createGeoIntentsFromMessage(message)) { - if (intent.resolveActivity(getContext().getPackageManager()) != null) { - getContext().startActivity(intent); - return; + private void displayPgpEncryptedMessage(ViewHolder viewHolder, Account account) { + if (activity.hasPgp()) { + if (account.getPgpDecryptionService().isRunning()) { + displayInfoMessage(viewHolder, activity.getString(R.string.message_decrypting)); + } else { + displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message)); } + } else { + displayInfoMessage(viewHolder, activity.getString(R.string.install_openkeychain)); + viewHolder.message_box.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + activity.showInstallPgpDialog(); + } + }); } - Toast.makeText(activity, R.string.no_application_found_to_display_location, Toast.LENGTH_SHORT).show(); - } - - public interface OnContactPictureClicked { - void onContactPictureClicked(Message message); - } - - public interface OnContactPictureLongClicked { - void onContactPictureLongClicked(Message message); } private static class ViewHolder { |