use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class NotificationService method buildSingleConversations.
private Builder buildSingleConversations(final ArrayList<Message> messages) {
final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
if (messages.size() >= 1) {
final Conversation conversation = messages.get(0).getConversation();
final UnreadConversation.Builder mUnreadBuilder = new UnreadConversation.Builder(conversation.getName());
mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService().get(conversation, getPixel(64)));
mBuilder.setContentTitle(conversation.getName());
if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
int count = messages.size();
mBuilder.setContentText(mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages, count, count));
} else {
Message message;
if ((message = getImage(messages)) != null) {
modifyForImage(mBuilder, mUnreadBuilder, message, messages);
} else {
modifyForTextOnly(mBuilder, mUnreadBuilder, messages);
}
RemoteInput remoteInput = new RemoteInput.Builder("text_reply").setLabel(UIHelper.getMessageHint(mXmppConnectionService, conversation)).build();
PendingIntent markAsReadPendingIntent = createReadPendingIntent(conversation);
NotificationCompat.Action markReadAction = new NotificationCompat.Action.Builder(R.drawable.ic_email_open_outline_white_24dp, mXmppConnectionService.getString(R.string.mark_as_read), markAsReadPendingIntent).build();
String replyLabel = mXmppConnectionService.getString(R.string.reply);
NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_white_24dp, replyLabel, createReplyIntent(conversation, false)).addRemoteInput(remoteInput).build();
NotificationCompat.Action wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_wear_reply, replyLabel, createReplyIntent(conversation, true)).addRemoteInput(remoteInput).build();
mBuilder.extend(new NotificationCompat.WearableExtender().addAction(wearReplyAction));
mUnreadBuilder.setReplyAction(createReplyIntent(conversation, true), remoteInput);
mUnreadBuilder.setReadPendingIntent(markAsReadPendingIntent);
mBuilder.extend(new NotificationCompat.CarExtender().setUnreadConversation(mUnreadBuilder.build()));
int addedActionsCount = 1;
mBuilder.addAction(markReadAction);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
mBuilder.addAction(replyAction);
++addedActionsCount;
}
if (displaySnoozeAction(messages)) {
String label = mXmppConnectionService.getString(R.string.snooze);
PendingIntent pendingSnoozeIntent = createSnoozeIntent(conversation);
NotificationCompat.Action snoozeAction = new NotificationCompat.Action.Builder(R.drawable.ic_notifications_paused_white_24dp, label, pendingSnoozeIntent).build();
mBuilder.addAction(snoozeAction);
++addedActionsCount;
}
if (addedActionsCount < 3) {
final Message firstLocationMessage = getFirstLocationMessage(messages);
if (firstLocationMessage != null) {
String label = mXmppConnectionService.getResources().getString(R.string.show_location);
PendingIntent pendingShowLocationIntent = createShowLocationIntent(firstLocationMessage);
NotificationCompat.Action locationAction = new NotificationCompat.Action.Builder(R.drawable.ic_room_white_24dp, label, pendingShowLocationIntent).build();
mBuilder.addAction(locationAction);
++addedActionsCount;
}
}
if (addedActionsCount < 3) {
Message firstDownloadableMessage = getFirstDownloadableMessage(messages);
if (firstDownloadableMessage != null) {
String label = mXmppConnectionService.getResources().getString(R.string.download_x_file, UIHelper.getFileDescriptionString(mXmppConnectionService, firstDownloadableMessage));
PendingIntent pendingDownloadIntent = createDownloadIntent(firstDownloadableMessage);
NotificationCompat.Action downloadAction = new NotificationCompat.Action.Builder(R.drawable.ic_file_download_white_24dp, label, pendingDownloadIntent).build();
mBuilder.addAction(downloadAction);
++addedActionsCount;
}
}
}
if (conversation.getMode() == Conversation.MODE_SINGLE) {
Contact contact = conversation.getContact();
Uri systemAccount = contact.getSystemAccount();
if (systemAccount != null) {
mBuilder.addPerson(systemAccount.toString());
}
}
mBuilder.setWhen(conversation.getLatestMessage().getTimeSent());
mBuilder.setSmallIcon(R.drawable.ic_notification);
mBuilder.setDeleteIntent(createDeleteIntent(conversation));
mBuilder.setContentIntent(createContentIntent(conversation));
}
return mBuilder;
}
use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method findConversation.
public Conversation findConversation(final Account account, final Jid jid, final boolean muc) {
synchronized (this.conversations) {
Conversation conversation = find(account, jid);
if (conversation != null) {
return conversation;
}
conversation = databaseBackend.findConversation(account, jid);
final boolean loadMessagesFromDb;
if (conversation != null) {
conversation.setStatus(Conversation.STATUS_AVAILABLE);
conversation.setAccount(account);
if (muc) {
conversation.setMode(Conversation.MODE_MULTI);
conversation.setContactJid(jid);
} else {
conversation.setMode(Conversation.MODE_SINGLE);
conversation.setContactJid(jid.toBareJid());
}
databaseBackend.updateConversation(conversation);
loadMessagesFromDb = conversation.messagesLoaded.compareAndSet(true, false);
} else {
String conversationName;
Contact contact = account.getRoster().getContact(jid);
if (contact != null) {
conversationName = contact.getDisplayName();
} else {
conversationName = jid.getLocalpart();
}
if (muc) {
conversation = new Conversation(conversationName, account, jid, Conversation.MODE_MULTI);
} else {
conversation = new Conversation(conversationName, account, jid.toBareJid(), Conversation.MODE_SINGLE);
}
this.databaseBackend.createConversation(conversation);
loadMessagesFromDb = false;
}
final Conversation c = conversation;
mDatabaseReaderExecutor.execute(new Runnable() {
@Override
public void run() {
if (loadMessagesFromDb) {
c.addAll(0, databaseBackend.getMessages(c, Config.PAGE_SIZE));
updateConversationUi();
c.messagesLoaded.set(true);
}
checkDeletedFiles(c);
}
});
updateConversationUi();
return conversation;
}
}
use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method fetchAvatarPep.
private void fetchAvatarPep(Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
IqPacket packet = this.mIqGenerator.retrievePepAvatar(avatar);
sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket result) {
synchronized (mInProgressAvatarFetches) {
mInProgressAvatarFetches.remove(generateFetchKey(account, avatar));
}
final String ERROR = account.getJid().toBareJid() + ": fetching avatar for " + avatar.owner + " failed ";
if (result.getType() == IqPacket.TYPE.RESULT) {
avatar.image = mIqParser.avatarData(result);
if (avatar.image != null) {
if (getFileBackend().save(avatar)) {
if (account.getJid().toBareJid().equals(avatar.owner)) {
if (account.setAvatar(avatar.getFilename())) {
databaseBackend.updateAccount(account);
}
getAvatarService().clear(account);
updateConversationUi();
updateAccountUi();
} else {
Contact contact = account.getRoster().getContact(avatar.owner);
contact.setAvatar(avatar);
getAvatarService().clear(contact);
updateConversationUi();
updateRosterUi();
}
if (callback != null) {
callback.success(avatar);
}
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": successfully fetched pep avatar for " + avatar.owner);
return;
}
} else {
Log.d(Config.LOGTAG, ERROR + "(parsing error)");
}
} else {
Element error = result.findChild("error");
if (error == null) {
Log.d(Config.LOGTAG, ERROR + "(server error)");
} else {
Log.d(Config.LOGTAG, ERROR + error.toString());
}
}
if (callback != null) {
callback.error(0, null);
}
}
});
}
use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class DatabaseBackend method writeRoster.
public void writeRoster(final Roster roster) {
final Account account = roster.getAccount();
final SQLiteDatabase db = this.getWritableDatabase();
db.beginTransaction();
for (Contact contact : roster.getContacts()) {
if (contact.getOption(Contact.Options.IN_ROSTER)) {
db.insert(Contact.TABLENAME, null, contact.getContentValues());
} else {
String where = Contact.ACCOUNT + "=? AND " + Contact.JID + "=?";
String[] whereArgs = { account.getUuid(), contact.getJid().toPreppedString() };
db.delete(Contact.TABLENAME, where, whereArgs);
}
}
db.setTransactionSuccessful();
db.endTransaction();
account.setRosterVersion(roster.getVersion());
updateAccount(account);
}
use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class ConferenceDetailsActivity method updateView.
private void updateView() {
invalidateOptionsMenu();
final MucOptions mucOptions = mConversation.getMucOptions();
final User self = mucOptions.getSelf();
String account;
if (Config.DOMAIN_LOCK != null) {
account = mConversation.getAccount().getJid().getLocalpart();
} else {
account = mConversation.getAccount().getJid().toBareJid().toString();
}
if (getSupportActionBar() != null) {
final ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setCustomView(R.layout.ab_title);
ab.setDisplayShowCustomEnabled(true);
TextView abtitle = findViewById(android.R.id.text1);
TextView absubtitle = findViewById(android.R.id.text2);
abtitle.setText(mConversation.getName());
abtitle.setSelected(true);
abtitle.setClickable(false);
absubtitle.setVisibility(View.GONE);
absubtitle.setClickable(false);
}
}
ConferenceName.setText(mConversation.getName());
mAccountJid.setText(getString(R.string.using_account, account));
if (xmppConnectionService.multipleAccounts()) {
mAccountJid.setVisibility(View.VISIBLE);
} else {
mAccountJid.setVisibility(View.GONE);
}
mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48)));
setTitle(mConversation.getName());
mFullJid.setText(mConversation.getJid().toBareJid().toString());
mYourNick.setText(mucOptions.getActualNick());
TextView mRoleAffiliaton = findViewById(R.id.muc_role);
if (mucOptions.online()) {
mMoreDetails.setVisibility(View.VISIBLE);
mMucSettings.setVisibility(View.VISIBLE);
mConferenceInfoTable.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE);
final String status = getStatus(self);
if (status != null) {
mRoleAffiliaton.setVisibility(View.VISIBLE);
mRoleAffiliaton.setText(status);
} else {
mRoleAffiliaton.setVisibility(View.GONE);
}
if (mucOptions.membersOnly()) {
mConferenceType.setText(R.string.private_conference);
} else {
mConferenceType.setText(R.string.public_conference);
}
if (mucOptions.mamSupport()) {
mConferenceInfoMam.setText(R.string.server_info_available);
} else {
mConferenceInfoMam.setText(R.string.server_info_unavailable);
}
if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
mDestroyButton.setVisibility(View.VISIBLE);
mChangeConferenceSettingsButton.setVisibility(View.VISIBLE);
} else {
mDestroyButton.setVisibility(View.GONE);
mChangeConferenceSettingsButton.setVisibility(View.GONE);
}
} else {
mMoreDetails.setVisibility(View.GONE);
mMucSettings.setVisibility(View.GONE);
mConferenceInfoTable.setVisibility(View.GONE);
}
long mutedTill = mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0);
if (mutedTill == Long.MAX_VALUE) {
mNotifyStatusText.setText(R.string.notify_never);
mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_off_grey600_24dp);
} else if (System.currentTimeMillis() < mutedTill) {
mNotifyStatusText.setText(R.string.notify_paused);
mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_paused_grey600_24dp);
} else if (mConversation.alwaysNotify()) {
mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_grey600_24dp);
mNotifyStatusText.setText(R.string.notify_on_all_messages);
} else {
mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_none_grey600_24dp);
mNotifyStatusText.setText(R.string.notify_only_when_highlighted);
}
final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
membersView.removeAllViews();
if (inflater == null) {
return;
}
final ArrayList<User> users = mucOptions.getUsers();
Collections.sort(users);
for (final User user : users) {
ContactBinding binding = DataBindingUtil.inflate(inflater, R.layout.contact, membersView, false);
final Contact contact = user.getContact();
final String name = user.getName();
this.setListItemBackgroundOnView(binding.getRoot());
if (contact != null && contact.showInRoster()) {
binding.getRoot().setOnClickListener((OnClickListener) view -> switchToContactDetails(contact));
}
registerForContextMenu(binding.getRoot());
binding.getRoot().setTag(user);
if (mAdvancedMode && user.getPgpKeyId() != 0) {
binding.key.setVisibility(View.VISIBLE);
binding.key.setOnClickListener(v -> viewPgpKey(user));
binding.key.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
}
if (contact != null) {
binding.contactDisplayName.setText(contact.getDisplayName());
binding.contactJid.setText((name != null ? name + " \u2022 " : "") + getStatus(user));
} else {
binding.contactDisplayName.setText(name == null ? "" : name);
binding.contactJid.setText(getStatus(user));
}
loadAvatar(user, binding.contactPhoto);
if (user.getRole() == MucOptions.Role.NONE) {
binding.contactDisplayName.setAlpha(INACTIVE_ALPHA);
binding.key.setAlpha(INACTIVE_ALPHA);
binding.contactJid.setAlpha(INACTIVE_ALPHA);
binding.contactPhoto.setAlpha(INACTIVE_ALPHA);
}
membersView.addView(binding.getRoot());
if (mConversation.getMucOptions().canInvite()) {
mInviteButton.setVisibility(View.VISIBLE);
} else {
mInviteButton.setVisibility(View.GONE);
}
}
}
Aggregations