use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.
the class StartConversationActivity method switchToConversation.
protected void switchToConversation(Contact contact, String body) {
Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
switchToConversation(conversation, body, false);
}
use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.
the class StartConversationActivity method openConversationsForBookmark.
protected void openConversationsForBookmark(Bookmark bookmark) {
Jid jid = bookmark.getJid();
if (jid == null) {
Toast.makeText(this, R.string.invalid_jid, Toast.LENGTH_SHORT).show();
return;
}
Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), jid, true, true, true);
bookmark.setConversation(conversation);
if (!bookmark.autojoin() && getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin))) {
bookmark.setAutojoin(true);
xmppConnectionService.pushBookmarks(bookmark.getAccount());
}
switchToConversation(conversation);
}
use of de.pixart.messenger.entities.Conversation 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.Conversation in project Pix-Art-Messenger by kriztan.
the class JingleConnection method init.
public void init(final Message message) {
if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
Conversation conversation = message.getConversation();
conversation.getAccount().getAxolotlService().prepareKeyTransportMessage(conversation, new OnMessageCreatedCallback() {
@Override
public void run(XmppAxolotlMessage xmppAxolotlMessage) {
if (xmppAxolotlMessage != null) {
init(message, xmppAxolotlMessage);
} else {
fail();
}
}
});
} else {
init(message, null);
}
}
use of de.pixart.messenger.entities.Conversation in project Pix-Art-Messenger by kriztan.
the class GeoHelper method createGeoIntentsFromMessage.
public static ArrayList<Intent> createGeoIntentsFromMessage(Message message, Context context) {
final ArrayList<Intent> intents = new ArrayList<>();
Matcher matcher = GEO_URI.matcher(message.getBody());
if (!matcher.matches()) {
return intents;
}
double latitude;
double longitude;
try {
latitude = Double.parseDouble(matcher.group(1));
if (latitude > 90.0 || latitude < -90.0) {
return intents;
}
longitude = Double.parseDouble(matcher.group(2));
if (longitude > 180.0 || longitude < -180.0) {
return intents;
}
} catch (NumberFormatException nfe) {
return intents;
}
final Conversation conversation = message.getConversation();
String label;
if (conversation.getMode() == Conversation.MODE_SINGLE && message.getStatus() == Message.STATUS_RECEIVED) {
try {
label = "(" + URLEncoder.encode(message.getConversation().getName(), "UTF-8") + ")";
} catch (UnsupportedEncodingException e) {
label = "";
}
} else {
label = "";
}
Intent locationPluginIntent = new Intent(context, ShowLocationActivity.class);
locationPluginIntent.putExtra("latitude", latitude);
locationPluginIntent.putExtra("longitude", longitude);
if (message.getStatus() != Message.STATUS_RECEIVED) {
locationPluginIntent.putExtra("jid", conversation.getAccount().getJid().toString());
locationPluginIntent.putExtra("name", conversation.getAccount().getJid().getLocalpart());
} else {
Contact contact = message.getContact();
if (contact != null) {
locationPluginIntent.putExtra("name", contact.getDisplayName());
locationPluginIntent.putExtra("jid", contact.getJid().toString());
} else {
locationPluginIntent.putExtra("name", UIHelper.getDisplayedMucCounterpart(message.getCounterpart()));
}
}
intents.add(locationPluginIntent);
Intent geoIntent = new Intent(Intent.ACTION_VIEW);
geoIntent.setData(Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude) + "?q=" + String.valueOf(latitude) + "," + String.valueOf(longitude) + label));
intents.add(geoIntent);
return intents;
}
Aggregations