Search in sources :

Example 1 with Transferable

use of de.pixart.messenger.entities.Transferable in project Pix-Art-Messenger by kriztan.

the class MessageAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    final Message message = getItem(position);
    final boolean omemoEncryption = message.getEncryption() == Message.ENCRYPTION_AXOLOTL;
    final boolean isInValidSession = message.isValidInSession() && (!omemoEncryption || message.isTrusted());
    final Conversation conversation = message.getConversation();
    final Account account = conversation.getAccount();
    final int type = getItemViewType(position);
    ViewHolder viewHolder;
    if (view == null) {
        viewHolder = new ViewHolder();
        switch(type) {
            case DATE_SEPARATOR:
                view = activity.getLayoutInflater().inflate(R.layout.message_date_bubble, parent, false);
                viewHolder.status_message = view.findViewById(R.id.status_message);
                break;
            case SENT:
                view = activity.getLayoutInflater().inflate(R.layout.message_sent, parent, false);
                viewHolder.message_box = view.findViewById(R.id.message_box);
                viewHolder.contact_picture = view.findViewById(R.id.message_photo);
                viewHolder.audioPlayer = view.findViewById(R.id.audio_player);
                viewHolder.download_button = view.findViewById(R.id.download_button);
                viewHolder.resend_button = view.findViewById(R.id.resend_button);
                viewHolder.indicator = view.findViewById(R.id.security_indicator);
                viewHolder.edit_indicator = view.findViewById(R.id.edit_indicator);
                viewHolder.image = view.findViewById(R.id.message_image);
                viewHolder.messageBody = view.findViewById(R.id.message_body);
                viewHolder.time = view.findViewById(R.id.message_time);
                viewHolder.indicatorReceived = view.findViewById(R.id.indicator_received);
                viewHolder.indicatorRead = view.findViewById(R.id.indicator_read);
                break;
            case RECEIVED:
                view = activity.getLayoutInflater().inflate(R.layout.message_received, parent, false);
                viewHolder.message_box = view.findViewById(R.id.message_box);
                viewHolder.contact_picture = view.findViewById(R.id.message_photo);
                viewHolder.audioPlayer = view.findViewById(R.id.audio_player);
                viewHolder.download_button = view.findViewById(R.id.download_button);
                viewHolder.indicator = view.findViewById(R.id.security_indicator);
                viewHolder.edit_indicator = view.findViewById(R.id.edit_indicator);
                viewHolder.image = view.findViewById(R.id.message_image);
                viewHolder.messageBody = view.findViewById(R.id.message_body);
                viewHolder.time = view.findViewById(R.id.message_time);
                viewHolder.indicatorReceived = view.findViewById(R.id.indicator_received);
                viewHolder.encryption = view.findViewById(R.id.message_encryption);
                break;
            case STATUS:
                view = activity.getLayoutInflater().inflate(R.layout.message_status, parent, false);
                viewHolder.contact_picture = view.findViewById(R.id.message_photo);
                viewHolder.status_message = view.findViewById(R.id.status_message);
                viewHolder.load_more_messages = view.findViewById(R.id.load_more_messages);
                break;
            default:
                throw new AssertionError("Unknown view type");
        }
        if (viewHolder.messageBody != null) {
            listSelectionManager.onCreate(viewHolder.messageBody, new MessageBodyActionModeCallback(viewHolder.messageBody));
            viewHolder.messageBody.setCopyHandler(this);
        }
        view.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) view.getTag();
        if (viewHolder == null) {
            return view;
        }
    }
    // default: (type == SENT && (!isInValidSession || !mUseWhiteBackground));
    boolean darkBackground = false;
    if (type == DATE_SEPARATOR) {
        if (UIHelper.today(message.getTimeSent())) {
            viewHolder.status_message.setText(R.string.today);
        } else if (UIHelper.yesterday(message.getTimeSent())) {
            viewHolder.status_message.setText(R.string.yesterday);
        } else {
            viewHolder.status_message.setText(DateUtils.formatDateTime(activity, message.getTimeSent(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR));
        }
        return view;
    } else if (type == STATUS) {
        if ("LOAD_MORE".equals(message.getBody())) {
            viewHolder.status_message.setVisibility(View.GONE);
            viewHolder.contact_picture.setVisibility(View.GONE);
            viewHolder.load_more_messages.setVisibility(View.VISIBLE);
            viewHolder.load_more_messages.setOnClickListener(v -> loadMoreMessages(message.getConversation()));
        } else {
            viewHolder.status_message.setVisibility(View.VISIBLE);
            viewHolder.load_more_messages.setVisibility(View.GONE);
            viewHolder.status_message.setText(message.getBody());
            boolean showAvatar;
            if (conversation.getMode() == Conversation.MODE_SINGLE) {
                showAvatar = true;
                loadAvatar(message, viewHolder.contact_picture, activity.getPixel(32));
            } else if (message.getCounterpart() != null || message.getTrueCounterpart() != null || (message.getCounterparts() != null && message.getCounterparts().size() > 0)) {
                showAvatar = true;
                loadAvatar(message, viewHolder.contact_picture, activity.getPixel(32));
            } else {
                showAvatar = false;
            }
            if (showAvatar) {
                viewHolder.contact_picture.setAlpha(0.5f);
                viewHolder.contact_picture.setVisibility(View.VISIBLE);
            } else {
                viewHolder.contact_picture.setVisibility(View.GONE);
            }
        }
        return view;
    } else {
        loadAvatar(message, viewHolder.contact_picture, activity.getPixel(48));
    }
    viewHolder.contact_picture.setOnClickListener(v -> {
        if (MessageAdapter.this.mOnContactPictureClickedListener != null) {
            MessageAdapter.this.mOnContactPictureClickedListener.onContactPictureClicked(message);
        }
    });
    viewHolder.contact_picture.setOnLongClickListener(v -> {
        if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
            MessageAdapter.this.mOnContactPictureLongClickedListener.onContactPictureLongClicked(message);
            return true;
        } else {
            return false;
        }
    });
    final Transferable transferable = message.getTransferable();
    if (transferable != null && transferable.getStatus() != Transferable.STATUS_UPLOADING) {
        if (transferable.getStatus() == Transferable.STATUS_OFFER) {
            displayDownloadableMessage(viewHolder, message, activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, message)));
        } else if (transferable.getStatus() == Transferable.STATUS_OFFER_CHECK_FILESIZE) {
            displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)));
        } else {
            displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first, darkBackground);
        }
    } else if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
        displayImageMessage(viewHolder, message);
    } else if (message.getType() == Message.TYPE_FILE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
        if (message.getFileParams().width > 0 && message.getFileParams().height > 0) {
            displayImageMessage(viewHolder, message);
        } else if (message.getFileParams().runtime > 0) {
            displayAudioMessage(viewHolder, message, darkBackground);
        } else {
            displayOpenableMessage(viewHolder, message);
        }
    } else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
        if (account.isPgpDecryptionServiceConnected()) {
            if (!account.hasPendingPgpIntent(conversation)) {
                displayInfoMessage(viewHolder, activity.getString(R.string.message_decrypting), darkBackground);
            } else {
                displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message), darkBackground);
            }
        } else {
            displayInfoMessage(viewHolder, activity.getString(R.string.install_openkeychain), darkBackground);
            viewHolder.message_box.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    activity.showInstallPgpDialog();
                }
            });
        }
    } else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
        displayDecryptionFailed(viewHolder, darkBackground);
    } else {
        if (message.isGeoUri()) {
            displayLocationMessage(viewHolder, message);
        } else if (message.bodyIsOnlyEmojis() && message.getType() != Message.TYPE_PRIVATE) {
            displayEmojiMessage(viewHolder, message.getBody().trim());
        } else if (message.isXmppUri()) {
            displayXmppMessage(viewHolder, message.getBody().trim());
        } else if (message.treatAsDownloadable()) {
            try {
                URL url = new URL(message.getBody());
                displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize_on_host, UIHelper.getFileDescriptionString(activity, message), url.getHost()));
            } catch (Exception e) {
                displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)));
            }
        } else {
            displayTextMessage(viewHolder, message, darkBackground, type);
        }
    }
    if (type == RECEIVED) {
        if (isInValidSession) {
            viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received_white);
            viewHolder.encryption.setVisibility(View.GONE);
        } else {
            viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received_lightred);
            viewHolder.encryption.setVisibility(View.VISIBLE);
            viewHolder.encryption.setTextColor(activity.getWarningTextColor());
            if (omemoEncryption && !message.isTrusted()) {
                viewHolder.encryption.setText(R.string.not_trusted);
            } else {
                viewHolder.encryption.setText(CryptoHelper.encryptionTypeToText(message.getEncryption()));
            }
        }
    }
    if (type == SENT) {
        if (mUseWhiteBackground) {
            viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_sent_white);
        } else {
            viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_sent_lightblue);
        }
    }
    displayStatus(viewHolder, message, type, darkBackground);
    return view;
}
Also used : EmojiWrapper(de.pixart.messenger.utils.EmojiWrapper) ActionMode(android.view.ActionMode) LinearLayout(android.widget.LinearLayout) DateUtils(android.text.format.DateUtils) PackageManager(android.content.pm.PackageManager) URL(java.net.URL) GeoHelper(de.pixart.messenger.utils.GeoHelper) Spannable(android.text.Spannable) Uri(android.net.Uri) WindowManager(android.view.WindowManager) ImageView(android.widget.ImageView) Drawable(android.graphics.drawable.Drawable) Account(de.pixart.messenger.entities.Account) Emoticons(de.pixart.messenger.utils.Emoticons) Manifest(android.Manifest) Matcher(java.util.regex.Matcher) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) PreferenceManager(android.preference.PreferenceManager) XmppUri(de.pixart.messenger.utils.XmppUri) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Log(android.util.Log) AsyncTask(android.os.AsyncTask) ClickableMovementMethod(de.pixart.messenger.ui.widget.ClickableMovementMethod) ContextCompat(android.support.v4.content.ContextCompat) AudioPlayer(de.pixart.messenger.services.AudioPlayer) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ActivityCompat(android.support.v4.app.ActivityCompat) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) ListSelectionManager(de.pixart.messenger.ui.widget.ListSelectionManager) List(java.util.List) TextView(android.widget.TextView) FileParams(de.pixart.messenger.entities.Message.FileParams) Transferable(de.pixart.messenger.entities.Transferable) ActivityNotFoundException(android.content.ActivityNotFoundException) RelativeLayout(android.widget.RelativeLayout) CryptoHelper(de.pixart.messenger.utils.CryptoHelper) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DividerSpan(de.pixart.messenger.ui.text.DividerSpan) Typeface(android.graphics.Typeface) UIHelper(de.pixart.messenger.utils.UIHelper) Spanned(android.text.Spanned) MamReference(de.pixart.messenger.xmpp.mam.MamReference) MessageArchiveService(de.pixart.messenger.services.MessageArchiveService) ConversationActivity(de.pixart.messenger.ui.ConversationActivity) Intent(android.content.Intent) Linkify(android.text.util.Linkify) MenuItem(android.view.MenuItem) SpannableStringBuilder(android.text.SpannableStringBuilder) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) FileBackend(de.pixart.messenger.persistance.FileBackend) Conversation(de.pixart.messenger.entities.Conversation) Patterns(de.pixart.messenger.utils.Patterns) R(de.pixart.messenger.R) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) NotificationService(de.pixart.messenger.services.NotificationService) ShowFullscreenMessageActivity(de.pixart.messenger.ui.ShowFullscreenMessageActivity) Menu(android.view.Menu) WeakReference(java.lang.ref.WeakReference) Config(de.pixart.messenger.Config) Message(de.pixart.messenger.entities.Message) ConversationFragment(de.pixart.messenger.ui.ConversationFragment) SpannableString(android.text.SpannableString) FingerprintStatus(de.pixart.messenger.crypto.axolotl.FingerprintStatus) StyleSpan(android.text.style.StyleSpan) BackgroundColorSpan(android.text.style.BackgroundColorSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) DownloadableFile(de.pixart.messenger.entities.DownloadableFile) ResolveInfo(android.content.pm.ResolveInfo) Color(android.graphics.Color) ColorInt(android.support.annotation.ColorInt) XmppActivity(de.pixart.messenger.ui.XmppActivity) ArrayAdapter(android.widget.ArrayAdapter) CopyTextView(de.pixart.messenger.ui.widget.CopyTextView) StylingHelper(de.pixart.messenger.utils.StylingHelper) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) Bitmap(android.graphics.Bitmap) FixedURLSpan(de.pixart.messenger.ui.text.FixedURLSpan) QuoteSpan(de.pixart.messenger.ui.text.QuoteSpan) Base64(android.util.Base64) Activity(android.app.Activity) Resources(android.content.res.Resources) OnClickListener(android.view.View.OnClickListener) Account(de.pixart.messenger.entities.Account) Message(de.pixart.messenger.entities.Message) Transferable(de.pixart.messenger.entities.Transferable) Conversation(de.pixart.messenger.entities.Conversation) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CopyTextView(de.pixart.messenger.ui.widget.CopyTextView) URL(java.net.URL) ActivityNotFoundException(android.content.ActivityNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) OnClickListener(android.view.View.OnClickListener)

Example 2 with Transferable

use of de.pixart.messenger.entities.Transferable in project Pix-Art-Messenger by kriztan.

the class MessageAdapter method displayStatus.

private void displayStatus(ViewHolder viewHolder, final Message message, int type, boolean darkBackground) {
    String filesize = null;
    String info = null;
    boolean error = false;
    if (viewHolder.indicatorReceived != null) {
        viewHolder.indicatorReceived.setVisibility(View.GONE);
        viewHolder.indicatorRead.setVisibility(View.GONE);
    }
    if (viewHolder.edit_indicator != null) {
        if (message.edited()) {
            viewHolder.edit_indicator.setVisibility(View.VISIBLE);
            viewHolder.edit_indicator.setAlpha(0.7f);
        } else {
            viewHolder.edit_indicator.setVisibility(View.GONE);
        }
    }
    boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI && message.getMergedStatus() <= Message.STATUS_RECEIVED;
    if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.getTransferable() != null) {
        FileParams params = message.getFileParams();
        if (params.size > (1 * 1024 * 1024)) {
            filesize = Math.round(params.size * 1f / (1024 * 1024)) + " MiB";
        } else if (params.size >= (1 * 1024)) {
            filesize = Math.round(params.size * 1f / 1024) + " KiB";
        } else if (params.size > 0) {
            filesize = params.size + " B";
        }
        if (message.getTransferable() != null && message.getTransferable().getStatus() == Transferable.STATUS_FAILED) {
            error = true;
        }
    }
    switch(message.getMergedStatus()) {
        case Message.STATUS_WAITING:
            info = getContext().getString(R.string.waiting);
            break;
        case Message.STATUS_UNSEND:
            Transferable d = message.getTransferable();
            if (d != null) {
                info = getContext().getString(R.string.sending_file, d.getProgress());
            } else {
                info = getContext().getString(R.string.sending);
            }
            break;
        case Message.STATUS_OFFERED:
            info = getContext().getString(R.string.offering);
            break;
        case Message.STATUS_SEND_RECEIVED:
            if (mIndicateReceived) {
                viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
            }
            break;
        case Message.STATUS_SEND_DISPLAYED:
            if (mIndicateReceived) {
                viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
                viewHolder.indicatorRead.setVisibility(View.VISIBLE);
            }
            break;
        case Message.STATUS_SEND_FAILED:
            if (isResendable) {
                info = getContext().getString(R.string.send_failed_resend);
            } else {
                info = getContext().getString(R.string.send_failed);
            }
            error = true;
            break;
        default:
            if (multiReceived) {
                info = UIHelper.getMessageDisplayName(message);
            }
            break;
    }
    if (error && type == SENT) {
        viewHolder.time.setTextAppearance(getContext(), R.style.TextAppearance_Conversations_Caption_Waring);
        DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
        if (file.exists()) {
            if (activity.xmppConnectionService.mHttpConnectionManager.getAutoAcceptFileSize() >= message.getFileParams().size) {
                isResendable = true;
                viewHolder.resend_button.setVisibility(View.GONE);
            } else {
                isResendable = false;
                viewHolder.resend_button.setVisibility(View.VISIBLE);
            }
        }
        viewHolder.resend_button.setText(R.string.send_again);
        viewHolder.resend_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_resend_grey600_48dp, 0, 0, 0);
        viewHolder.resend_button.setOnClickListener(new OnClickListener() {

            final Message mMessage = message;

            @Override
            public void onClick(View v) {
                mConversationFragment.resendMessage(mMessage);
            }
        });
    } else if (!error && type == SENT) {
        viewHolder.resend_button.setVisibility(View.GONE);
        viewHolder.time.setTextColor(this.getMessageTextColor(darkBackground, false));
    } else {
        if (darkBackground) {
            viewHolder.time.setTextAppearance(getContext(), R.style.TextAppearance_Conversations_Caption_OnDark);
        } else {
            viewHolder.time.setTextAppearance(getContext(), R.style.TextAppearance_Conversations_Caption);
        }
        viewHolder.time.setTextColor(this.getMessageTextColor(darkBackground, false));
    }
    if (message.getEncryption() == Message.ENCRYPTION_NONE) {
        viewHolder.indicator.setVisibility(View.GONE);
    } else {
        boolean verified = false;
        if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
            final FingerprintStatus status = message.getConversation().getAccount().getAxolotlService().getFingerprintTrust(message.getFingerprint());
            if (status != null && status.isVerified()) {
                verified = true;
            }
        }
        if (verified) {
            viewHolder.indicator.setImageResource(R.drawable.ic_verified_user_blue_18dp);
        } else {
            viewHolder.indicator.setImageResource(R.drawable.ic_lock_blue_18dp);
        }
        viewHolder.indicator.setAlpha(0.7f);
        viewHolder.indicator.setVisibility(View.VISIBLE);
    }
    String formatedTime = UIHelper.readableTimeDifferenceFull(getContext(), message.getMergedTimeSent());
    if (message.getStatus() <= Message.STATUS_RECEIVED) {
        if ((filesize != null) && (info != null)) {
            viewHolder.time.setText(formatedTime + " \u00B7 " + filesize + " \u00B7 " + info);
        } else if ((filesize == null) && (info != null)) {
            viewHolder.time.setText(formatedTime + " \u00B7 " + info);
        } else if ((filesize != null) && (info == null)) {
            viewHolder.time.setText(formatedTime + " \u00B7 " + filesize);
        } else {
            viewHolder.time.setText(formatedTime);
        }
    } 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);
        }
    }
}
Also used : Message(de.pixart.messenger.entities.Message) FingerprintStatus(de.pixart.messenger.crypto.axolotl.FingerprintStatus) FileParams(de.pixart.messenger.entities.Message.FileParams) Transferable(de.pixart.messenger.entities.Transferable) OnClickListener(android.view.View.OnClickListener) SpannableString(android.text.SpannableString) DownloadableFile(de.pixart.messenger.entities.DownloadableFile) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CopyTextView(de.pixart.messenger.ui.widget.CopyTextView)

Example 3 with Transferable

use of de.pixart.messenger.entities.Transferable in project Pix-Art-Messenger by kriztan.

the class UIHelper method getMessagePreview.

public static Pair<String, Boolean> getMessagePreview(final Context context, final Message message) {
    final Transferable d = message.getTransferable();
    if (d != null) {
        switch(d.getStatus()) {
            case Transferable.STATUS_CHECKING:
                return new Pair<>(context.getString(R.string.checking_x, getFileDescriptionString(context, message)), true);
            case Transferable.STATUS_DOWNLOADING:
                return new Pair<>(context.getString(R.string.receiving_x_file, getFileDescriptionString(context, message), d.getProgress()), true);
            case Transferable.STATUS_OFFER:
            case Transferable.STATUS_OFFER_CHECK_FILESIZE:
                return new Pair<>(context.getString(R.string.x_file_offered_for_download, getFileDescriptionString(context, message)), true);
            case Transferable.STATUS_DELETED:
                return new Pair<>(context.getString(R.string.file_deleted), true);
            case Transferable.STATUS_FAILED:
                return new Pair<>(context.getString(R.string.file_transmission_failed), true);
            case Transferable.STATUS_UPLOADING:
                if (message.getStatus() == Message.STATUS_OFFERED) {
                    return new Pair<>(context.getString(R.string.offering_x_file, getFileDescriptionString(context, message)), true);
                } else {
                    return new Pair<>(context.getString(R.string.sending_x_file, getFileDescriptionString(context, message)), true);
                }
            default:
                return new Pair<>("", false);
        }
    } else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
        return new Pair<>(context.getString(R.string.pgp_message), true);
    } else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
        return new Pair<>(context.getString(R.string.decryption_failed), true);
    } else if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) {
        if (message.getStatus() == Message.STATUS_RECEIVED) {
            return new Pair<>(context.getString(R.string.received_x_file, getFileDescriptionString(context, message)), true);
        } else {
            return new Pair<>(getFileDescriptionString(context, message), true);
        }
    } else {
        final String body = message.getBody();
        if (body.startsWith(Message.ME_COMMAND)) {
            return new Pair<>(body.replaceAll("^" + Message.ME_COMMAND, UIHelper.getMessageDisplayName(message)), false);
        } else if (message.isGeoUri()) {
            if (message.getStatus() == Message.STATUS_RECEIVED) {
                return new Pair<>(context.getString(R.string.received_location), true);
            } else {
                return new Pair<>(context.getString(R.string.location), true);
            }
        } else if (message.isXmppUri()) {
            if (message.getStatus() == Message.STATUS_RECEIVED) {
                return new Pair<>(context.getString(R.string.received_contact), true);
            } else {
                return new Pair<>(context.getString(R.string.contact), true);
            }
        } else if (message.treatAsDownloadable()) {
            return new Pair<>(context.getString(R.string.x_file_offered_for_download, getFileDescriptionString(context, message)), true);
        } else {
            String[] lines = body.split("\n");
            StringBuilder builder = new StringBuilder();
            for (String l : lines) {
                if (l.length() > 0) {
                    char first = l.charAt(0);
                    if ((first != '>' || !isPositionFollowedByQuoteableCharacter(l, 0)) && first != '\u00bb') {
                        String line = l.trim();
                        if (line.isEmpty()) {
                            continue;
                        }
                        char last = line.charAt(line.length() - 1);
                        if (builder.length() != 0) {
                            builder.append(' ');
                        }
                        builder.append(line);
                        if (!PUNCTIONATION.contains(last)) {
                            break;
                        }
                    }
                }
            }
            if (builder.length() == 0) {
                builder.append(body.trim());
            }
            return new Pair<>(builder.length() > 256 ? builder.substring(0, 256) : builder.toString(), false);
        }
    }
}
Also used : Transferable(de.pixart.messenger.entities.Transferable) Pair(android.util.Pair)

Example 4 with Transferable

use of de.pixart.messenger.entities.Transferable in project Pix-Art-Messenger by kriztan.

the class JingleConnectionManager method createNewConnection.

public JingleConnection createNewConnection(Message message) {
    Transferable old = message.getTransferable();
    if (old != null) {
        old.cancel();
    }
    JingleConnection connection = new JingleConnection(this);
    mXmppConnectionService.markMessage(message, Message.STATUS_WAITING);
    connection.init(message);
    this.connections.add(connection);
    return connection;
}
Also used : Transferable(de.pixart.messenger.entities.Transferable)

Example 5 with Transferable

use of de.pixart.messenger.entities.Transferable in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method populateContextMenu.

private void populateContextMenu(ContextMenu menu) {
    final Message m = this.selectedMessage;
    final Transferable t = m.getTransferable();
    Message relevantForCorrection = m;
    while (relevantForCorrection.mergeable(relevantForCorrection.next())) {
        relevantForCorrection = relevantForCorrection.next();
    }
    if (m.getType() != Message.TYPE_STATUS) {
        final boolean treatAsFile = m.getType() != Message.TYPE_TEXT && m.getType() != Message.TYPE_PRIVATE && t == null;
        final boolean encrypted = m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED || m.getEncryption() == Message.ENCRYPTION_PGP;
        activity.getMenuInflater().inflate(R.menu.message_context, menu);
        menu.setHeaderTitle(R.string.message_options);
        MenuItem copyMessage = menu.findItem(R.id.copy_message);
        MenuItem quoteMessage = menu.findItem(R.id.quote_message);
        MenuItem retryDecryption = menu.findItem(R.id.retry_decryption);
        MenuItem correctMessage = menu.findItem(R.id.correct_message);
        MenuItem shareWith = menu.findItem(R.id.share_with);
        MenuItem sendAgain = menu.findItem(R.id.send_again);
        MenuItem copyUrl = menu.findItem(R.id.copy_url);
        MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
        MenuItem downloadFile = menu.findItem(R.id.download_file);
        MenuItem deleteFile = menu.findItem(R.id.delete_file);
        MenuItem showErrorMessage = menu.findItem(R.id.show_error_message);
        if (!treatAsFile && !encrypted && !m.isGeoUri() && !m.treatAsDownloadable()) {
            copyMessage.setVisible(true);
            quoteMessage.setVisible(MessageUtils.prepareQuote(m).length() > 0);
        }
        if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
            retryDecryption.setVisible(true);
        }
        if (relevantForCorrection.getType() == Message.TYPE_TEXT && relevantForCorrection.isLastCorrectableMessage() && (m.getConversation().getMucOptions().nonanonymous() || m.getConversation().getMode() == Conversation.MODE_SINGLE)) {
            correctMessage.setVisible(true);
        }
        if (treatAsFile || (m.getType() == Message.TYPE_TEXT && !m.treatAsDownloadable())) {
            shareWith.setVisible(true);
        }
        if (m.getStatus() == Message.STATUS_SEND_FAILED && !m.isFileOrImage()) {
            sendAgain.setVisible(true);
        }
        if (m.hasFileOnRemoteHost() || m.isGeoUri() || m.isXmppUri() || m.treatAsDownloadable() || (t != null && t instanceof HttpDownloadConnection)) {
            copyUrl.setVisible(true);
        }
        if ((m.isFileOrImage() && t instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())) {
            downloadFile.setVisible(true);
            downloadFile.setTitle(activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, m)));
        }
        boolean waitingOfferedSending = m.getStatus() == Message.STATUS_WAITING || m.getStatus() == Message.STATUS_UNSEND || m.getStatus() == Message.STATUS_OFFERED;
        if ((t != null && !(t instanceof TransferablePlaceholder)) || waitingOfferedSending && m.needsUploading()) {
            cancelTransmission.setVisible(true);
        }
        if (treatAsFile) {
            String path = m.getRelativeFilePath();
            Log.d(Config.LOGTAG, "Path = " + path);
            if (path == null || !path.startsWith("/") || path.contains(FileBackend.getConversationsDirectory("null", false))) {
                deleteFile.setVisible(true);
                deleteFile.setTitle(activity.getString(R.string.delete_x_file, UIHelper.getFileDescriptionString(activity, m)));
            }
        }
        if (m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null) {
            showErrorMessage.setVisible(true);
        }
    }
}
Also used : TransferablePlaceholder(de.pixart.messenger.entities.TransferablePlaceholder) EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) Transferable(de.pixart.messenger.entities.Transferable) MenuItem(android.view.MenuItem) HttpDownloadConnection(de.pixart.messenger.http.HttpDownloadConnection)

Aggregations

Transferable (de.pixart.messenger.entities.Transferable)5 Message (de.pixart.messenger.entities.Message)3 SpannableString (android.text.SpannableString)2 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 FingerprintStatus (de.pixart.messenger.crypto.axolotl.FingerprintStatus)2 DownloadableFile (de.pixart.messenger.entities.DownloadableFile)2 FileParams (de.pixart.messenger.entities.Message.FileParams)2 CopyTextView (de.pixart.messenger.ui.widget.CopyTextView)2 Manifest (android.Manifest)1 Activity (android.app.Activity)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 Resources (android.content.res.Resources)1 Bitmap (android.graphics.Bitmap)1