Search in sources :

Example 1 with FileParams

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

the class MessageAdapter method displayImageMessage.

private void displayImageMessage(ViewHolder viewHolder, final Message message) {
    viewHolder.download_button.setVisibility(View.GONE);
    viewHolder.messageBody.setVisibility(View.GONE);
    viewHolder.audioPlayer.setVisibility(View.GONE);
    viewHolder.image.setVisibility(View.VISIBLE);
    FileParams params = message.getFileParams();
    double target = metrics.density * 200;
    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(v -> openDownloadable(message));
}
Also used : FileParams(de.pixart.messenger.entities.Message.FileParams) LinearLayout(android.widget.LinearLayout)

Example 2 with FileParams

use of de.pixart.messenger.entities.Message.FileParams 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)

Aggregations

FileParams (de.pixart.messenger.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 (de.pixart.messenger.crypto.axolotl.FingerprintStatus)1 DownloadableFile (de.pixart.messenger.entities.DownloadableFile)1 Message (de.pixart.messenger.entities.Message)1 Transferable (de.pixart.messenger.entities.Transferable)1 CopyTextView (de.pixart.messenger.ui.widget.CopyTextView)1