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;
}
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);
}
}
}
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);
}
}
}
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;
}
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);
}
}
}
Aggregations