Search in sources :

Example 1 with FileParams

use of eu.siacs.conversations.entities.Message.FileParams in project Conversations by siacs.

the class MessageAdapter method displayImageMessage.

private void displayImageMessage(ViewHolder viewHolder, final Message message) {
    if (viewHolder.download_button != null) {
        viewHolder.download_button.setVisibility(View.GONE);
    }
    viewHolder.messageBody.setVisibility(View.GONE);
    viewHolder.image.setVisibility(View.VISIBLE);
    FileParams params = message.getFileParams();
    double target = metrics.density * 288;
    int scaledW;
    int scaledH;
    if (Math.max(params.height, params.width) * metrics.density <= target) {
        scaledW = (int) (params.width * metrics.density);
        scaledH = (int) (params.height * metrics.density);
    } else if (Math.max(params.height, params.width) <= target) {
        scaledW = params.width;
        scaledH = params.height;
    } else if (params.width <= params.height) {
        scaledW = (int) (params.width / ((double) params.height / target));
        scaledH = (int) target;
    } else {
        scaledW = (int) target;
        scaledH = (int) (params.height / ((double) params.width / target));
    }
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(scaledW, scaledH);
    layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4));
    viewHolder.image.setLayoutParams(layoutParams);
    activity.loadBitmap(message, viewHolder.image);
    viewHolder.image.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            openDownloadable(message);
        }
    });
}
Also used : FileParams(eu.siacs.conversations.entities.Message.FileParams) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CopyTextView(eu.siacs.conversations.ui.widget.CopyTextView) LinearLayout(android.widget.LinearLayout)

Example 2 with FileParams

use of eu.siacs.conversations.entities.Message.FileParams in project Conversations by siacs.

the class MessageAdapter method displayStatus.

private void displayStatus(ViewHolder viewHolder, Message message, int type, boolean darkBackground, boolean inValidSession) {
    String filesize = null;
    String info = null;
    boolean error = false;
    if (viewHolder.indicatorReceived != null) {
        viewHolder.indicatorReceived.setVisibility(View.GONE);
    }
    if (viewHolder.edit_indicator != null) {
        if (message.edited()) {
            viewHolder.edit_indicator.setVisibility(View.VISIBLE);
            viewHolder.edit_indicator.setImageResource(darkBackground ? R.drawable.ic_mode_edit_white_18dp : R.drawable.ic_mode_edit_black_18dp);
            viewHolder.edit_indicator.setAlpha(darkBackground ? 0.7f : 0.57f);
        } 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.5 * 1024 * 1024)) {
            filesize = params.size / (1024 * 1024) + " MiB";
        } else if (params.size > 0) {
            filesize = params.size / 1024 + " KiB";
        }
        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);
            }
            break;
        case Message.STATUS_SEND_FAILED:
            info = getContext().getString(R.string.send_failed);
            error = true;
            break;
        default:
            if (multiReceived) {
                info = UIHelper.getMessageDisplayName(message);
            }
            break;
    }
    if (error && type == SENT) {
        viewHolder.time.setTextColor(activity.getWarningTextColor());
    } else {
        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(darkBackground ? R.drawable.ic_verified_user_white_18dp : R.drawable.ic_verified_user_black_18dp);
        } else {
            viewHolder.indicator.setImageResource(darkBackground ? R.drawable.ic_lock_white_18dp : R.drawable.ic_lock_black_18dp);
        }
        if (darkBackground) {
            viewHolder.indicator.setAlpha(0.7f);
        } else {
            viewHolder.indicator.setAlpha(0.57f);
        }
        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 + " · " + filesize + " · " + info);
        } else if ((filesize == null) && (info != null)) {
            viewHolder.time.setText(formatedTime + " · " + info);
        } else if ((filesize != null) && (info == null)) {
            viewHolder.time.setText(formatedTime + " · " + filesize);
        } else {
            viewHolder.time.setText(formatedTime);
        }
    } else {
        if ((filesize != null) && (info != null)) {
            viewHolder.time.setText(filesize + " · " + info);
        } else if ((filesize == null) && (info != null)) {
            if (error) {
                viewHolder.time.setText(info + " · " + formatedTime);
            } else {
                viewHolder.time.setText(info);
            }
        } else if ((filesize != null) && (info == null)) {
            viewHolder.time.setText(filesize + " · " + formatedTime);
        } else {
            viewHolder.time.setText(formatedTime);
        }
    }
}
Also used : FingerprintStatus(eu.siacs.conversations.crypto.axolotl.FingerprintStatus) FileParams(eu.siacs.conversations.entities.Message.FileParams) Transferable(eu.siacs.conversations.entities.Transferable) SpannableString(android.text.SpannableString)

Aggregations

FileParams (eu.siacs.conversations.entities.Message.FileParams)2 SpannableString (android.text.SpannableString)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 FingerprintStatus (eu.siacs.conversations.crypto.axolotl.FingerprintStatus)1 Transferable (eu.siacs.conversations.entities.Transferable)1 CopyTextView (eu.siacs.conversations.ui.widget.CopyTextView)1