Search in sources :

Example 6 with FingerprintStatus

use of eu.siacs.conversations.crypto.axolotl.FingerprintStatus 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

FingerprintStatus (eu.siacs.conversations.crypto.axolotl.FingerprintStatus)6 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)2 XmppUri (eu.siacs.conversations.utils.XmppUri)2 PendingIntent (android.app.PendingIntent)1 SendIntentException (android.content.IntentSender.SendIntentException)1 Cursor (android.database.Cursor)1 SpannableString (android.text.SpannableString)1 LayoutInflater (android.view.LayoutInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageButton (android.widget.ImageButton)1 TextView (android.widget.TextView)1 PgpEngine (eu.siacs.conversations.crypto.PgpEngine)1 XmppAxolotlSession (eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession)1 Account (eu.siacs.conversations.entities.Account)1 ListItem (eu.siacs.conversations.entities.ListItem)1 FileParams (eu.siacs.conversations.entities.Message.FileParams)1 Transferable (eu.siacs.conversations.entities.Transferable)1