use of de.pixart.messenger.xmpp.chatstate.ChatState in project Pix-Art-Messenger by kriztan.
the class ConversationActivity method invalidateActionBarTitle.
private void invalidateActionBarTitle() {
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
if (mainFragment != null && mainFragment instanceof ConversationFragment) {
final Conversation conversation = ((ConversationFragment) mainFragment).getConversation();
if (conversation != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
View view = getLayoutInflater().inflate(R.layout.ab_title, null);
getSupportActionBar().setCustomView(view);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
TextView abtitle = findViewById(android.R.id.text1);
TextView absubtitle = findViewById(android.R.id.text2);
abtitle.setText(conversation.getName());
abtitle.setOnClickListener(view1 -> {
if (conversation.getMode() == Conversation.MODE_SINGLE) {
switchToContactDetails(conversation.getContact());
} else if (conversation.getMode() == Conversation.MODE_MULTI) {
Intent intent = new Intent(ConversationActivity.this, ConferenceDetailsActivity.class);
intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
intent.putExtra("uuid", conversation.getUuid());
startActivity(intent);
}
});
abtitle.setSelected(true);
if (conversation.getMode() == Conversation.MODE_SINGLE && !conversation.withSelf()) {
ChatState state = conversation.getIncomingChatState();
if (conversation.getContact().getShownStatus() == Presence.Status.OFFLINE) {
absubtitle.setText(getString(R.string.account_status_offline));
absubtitle.setSelected(true);
absubtitle.setOnClickListener(view12 -> {
if (conversation.getMode() == Conversation.MODE_SINGLE) {
switchToContactDetails(conversation.getContact());
} else if (conversation.getMode() == Conversation.MODE_MULTI) {
Intent intent = new Intent(ConversationActivity.this, ConferenceDetailsActivity.class);
intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
intent.putExtra("uuid", conversation.getUuid());
startActivity(intent);
}
});
} else {
if (state == ChatState.COMPOSING) {
absubtitle.setText(getString(R.string.is_typing));
absubtitle.setTypeface(null, Typeface.BOLD_ITALIC);
absubtitle.setSelected(true);
absubtitle.setOnClickListener(view13 -> {
if (conversation.getMode() == Conversation.MODE_SINGLE) {
switchToContactDetails(conversation.getContact());
} else if (conversation.getMode() == Conversation.MODE_MULTI) {
Intent intent = new Intent(ConversationActivity.this, ConferenceDetailsActivity.class);
intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
intent.putExtra("uuid", conversation.getUuid());
startActivity(intent);
}
});
} else {
if (showLastSeen && conversation.getContact().getLastseen() > 0) {
absubtitle.setText(UIHelper.lastseen(getApplicationContext(), conversation.getContact().isActive(), conversation.getContact().getLastseen()));
} else {
absubtitle.setText(getString(R.string.account_status_online));
}
absubtitle.setSelected(true);
absubtitle.setOnClickListener(view14 -> {
if (conversation.getMode() == Conversation.MODE_SINGLE) {
switchToContactDetails(conversation.getContact());
} else if (conversation.getMode() == Conversation.MODE_MULTI) {
Intent intent = new Intent(ConversationActivity.this, ConferenceDetailsActivity.class);
intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
intent.putExtra("uuid", conversation.getUuid());
startActivity(intent);
}
});
}
}
} else {
if (conversation.getParticipants() != null) {
ChatState state = ChatState.COMPOSING;
List<MucOptions.User> userWithChatStates = conversation.getMucOptions().getUsersWithChatState(state, 5);
if (userWithChatStates.size() == 0) {
state = ChatState.PAUSED;
userWithChatStates = conversation.getMucOptions().getUsersWithChatState(state, 5);
}
List<MucOptions.User> users = conversation.getMucOptions().getUsers(true);
if (state == ChatState.COMPOSING) {
if (userWithChatStates.size() > 0) {
if (userWithChatStates.size() == 1) {
MucOptions.User user = userWithChatStates.get(0);
absubtitle.setText(getString(R.string.contact_is_typing, UIHelper.getDisplayName(user)));
} else {
StringBuilder builder = new StringBuilder();
for (MucOptions.User user : userWithChatStates) {
if (builder.length() != 0) {
builder.append(", ");
}
builder.append(UIHelper.getDisplayName(user));
}
absubtitle.setText(getString(R.string.contacts_are_typing, builder.toString()));
}
}
} else {
if (users.size() == 1) {
absubtitle.setText(getString(R.string.one_participant));
} else {
absubtitle.setText(getString(R.string.more_participants, users.size()));
}
}
absubtitle.setSelected(true);
absubtitle.setOnClickListener(view15 -> {
if (conversation.getMode() == Conversation.MODE_SINGLE) {
switchToContactDetails(conversation.getContact());
} else if (conversation.getMode() == Conversation.MODE_MULTI) {
Intent intent = new Intent(ConversationActivity.this, ConferenceDetailsActivity.class);
intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
intent.putExtra("uuid", conversation.getUuid());
startActivity(intent);
}
});
} else {
absubtitle.setText(R.string.no_participants);
abtitle.setSelected(true);
absubtitle.setOnClickListener(view16 -> {
if (conversation.getMode() == Conversation.MODE_SINGLE) {
switchToContactDetails(conversation.getContact());
} else if (conversation.getMode() == Conversation.MODE_MULTI) {
Intent intent = new Intent(ConversationActivity.this, ConferenceDetailsActivity.class);
intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
intent.putExtra("uuid", conversation.getUuid());
startActivity(intent);
}
});
}
}
return;
}
}
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayShowCustomEnabled(false);
actionBar.setTitle(R.string.app_name);
actionBar.setSubtitle(null);
actionBar.setDisplayHomeAsUpEnabled(false);
}
}
use of de.pixart.messenger.xmpp.chatstate.ChatState in project Pix-Art-Messenger by kriztan.
the class ConversationFragment method updateStatusMessages.
protected void updateStatusMessages() {
updateDateBubbles();
synchronized (this.messageList) {
if (showLoadMoreMessages(conversation)) {
this.messageList.add(0, Message.createLoadMoreMessage(conversation));
}
if (conversation.getMode() == Conversation.MODE_MULTI) {
final MucOptions mucOptions = conversation.getMucOptions();
final List<MucOptions.User> allUsers = mucOptions.getUsers();
final Set<ReadByMarker> addedMarkers = new HashSet<>();
ChatState state = ChatState.COMPOSING;
List<MucOptions.User> users = conversation.getMucOptions().getUsersWithChatState(state, 5);
if (users.size() == 0) {
state = ChatState.PAUSED;
users = conversation.getMucOptions().getUsersWithChatState(state, 5);
}
if (mucOptions.isPrivateAndNonAnonymous()) {
for (int i = this.messageList.size() - 1; i >= 0; --i) {
final Set<ReadByMarker> markersForMessage = messageList.get(i).getReadByMarkers();
final List<MucOptions.User> shownMarkers = new ArrayList<>();
for (ReadByMarker marker : markersForMessage) {
if (!ReadByMarker.contains(marker, addedMarkers)) {
// may be put outside this condition. set should do dedup anyway
addedMarkers.add(marker);
MucOptions.User user = mucOptions.findUser(marker);
shownMarkers.add(user);
}
}
final ReadByMarker markerForSender = ReadByMarker.from(messageList.get(i));
final Message statusMessage;
final int size = shownMarkers.size();
if (size > 1) {
final String body;
if (size <= 4) {
body = getString(R.string.contacts_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers));
} else {
body = getString(R.string.contacts_and_n_more_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers, 3), size - 3);
}
statusMessage = Message.createStatusMessage(conversation, body);
statusMessage.setCounterparts(shownMarkers);
} else if (size == 1) {
statusMessage = Message.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, UIHelper.getDisplayName(shownMarkers.get(0))));
statusMessage.setCounterpart(shownMarkers.get(0).getFullJid());
statusMessage.setTrueCounterpart(shownMarkers.get(0).getRealJid());
} else {
statusMessage = null;
}
if (statusMessage != null) {
this.messageList.add(i + 1, statusMessage);
}
addedMarkers.add(markerForSender);
if (ReadByMarker.allUsersRepresented(allUsers, addedMarkers)) {
break;
}
}
}
}
}
}
use of de.pixart.messenger.xmpp.chatstate.ChatState in project Pix-Art-Messenger by kriztan.
the class MessageParser method extractChatState.
private boolean extractChatState(Conversation c, final boolean isTypeGroupChat, final MessagePacket packet) {
ChatState state = ChatState.parse(packet);
if (state != null && c != null) {
final Account account = c.getAccount();
Jid from = packet.getFrom();
if (from.toBareJid().equals(account.getJid().toBareJid())) {
c.setOutgoingChatState(state);
if (state == ChatState.ACTIVE || state == ChatState.COMPOSING) {
mXmppConnectionService.markRead(c);
activateGracePeriod(account);
}
return false;
} else {
if (isTypeGroupChat) {
MucOptions.User user = c.getMucOptions().findUserByFullJid(from);
if (user != null) {
return user.setChatState(state);
} else {
return false;
}
} else {
return c.setIncomingChatState(state);
}
}
}
return false;
}
use of de.pixart.messenger.xmpp.chatstate.ChatState in project Pix-Art-Messenger by kriztan.
the class ConversationFragment method updateChatState.
private void updateChatState(final Conversation conversation, final String msg) {
ChatState state = msg.length() == 0 ? Config.DEFAULT_CHATSTATE : ChatState.PAUSED;
Account.State status = conversation.getAccount().getStatus();
if (status == Account.State.ONLINE && conversation.setOutgoingChatState(state)) {
activity.xmppConnectionService.sendChatState(conversation);
}
}
use of de.pixart.messenger.xmpp.chatstate.ChatState in project Pix-Art-Messenger by kriztan.
the class ConversationAdapter method getView.
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.conversation_list_row, parent, false);
}
ViewHolder viewHolder = ViewHolder.get(view);
Conversation conversation = getItem(position);
if (this.activity instanceof XmppActivity) {
int c = Color.get(activity, conversation == selectedConversation ? R.attr.color_background_secondary : R.attr.color_background_primary);
viewHolder.swipeableItem.setBackgroundColor(c);
}
if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) {
viewHolder.name.setText(EmojiWrapper.transform(conversation.getName()));
} else {
viewHolder.name.setText(conversation.getJid().toBareJid().toString());
}
Message message = conversation.getLatestMessage();
int unreadcount = conversation.unreadCount();
int failedcount = conversation.failedCount();
viewHolder.receivedStatus.setVisibility(View.GONE);
viewHolder.readStatus.setVisibility(View.GONE);
if (!conversation.isRead()) {
viewHolder.name.setTypeface(null, Typeface.BOLD);
} else {
viewHolder.name.setTypeface(null, Typeface.NORMAL);
}
if (unreadcount > 0) {
viewHolder.unreadCount.setVisibility(View.VISIBLE);
viewHolder.unreadCount.setText(unreadcount > 99 ? "\u221E" : String.valueOf(unreadcount));
} else {
viewHolder.unreadCount.setVisibility(View.GONE);
}
if (failedcount > 0) {
viewHolder.failedCount.setVisibility(View.VISIBLE);
viewHolder.failedCount.setText(failedcount > 99 ? "\u221E" : String.valueOf(failedcount));
} else {
viewHolder.failedCount.setVisibility(View.GONE);
}
final boolean fileAvailable = message.getTransferable() == null || message.getTransferable().getStatus() != Transferable.STATUS_DELETED;
final boolean showPreviewText;
if (fileAvailable && (message.isFileOrImage() || message.treatAsDownloadable() || message.isGeoUri())) {
final int imageResource;
if (message.isGeoUri()) {
imageResource = activity.getThemeResource(R.attr.ic_attach_location, R.drawable.ic_attach_location);
showPreviewText = false;
} else {
final String mime = message.getMimeType();
switch(mime == null ? "" : mime.split("/")[0]) {
case "image":
imageResource = activity.getThemeResource(R.attr.ic_attach_photo, R.drawable.ic_attach_photo);
showPreviewText = false;
break;
case "video":
imageResource = activity.getThemeResource(R.attr.ic_attach_video, R.drawable.ic_attach_video);
showPreviewText = false;
break;
case "audio":
imageResource = activity.getThemeResource(R.attr.ic_attach_record, R.drawable.ic_attach_record);
showPreviewText = false;
break;
default:
imageResource = activity.getThemeResource(R.attr.ic_attach_document, R.drawable.ic_attach_document);
showPreviewText = true;
break;
}
}
viewHolder.lastMessageIcon.setImageResource(imageResource);
viewHolder.lastMessageIcon.setVisibility(View.VISIBLE);
} else {
viewHolder.lastMessageIcon.setVisibility(View.GONE);
showPreviewText = true;
}
final Pair<String, Boolean> preview = UIHelper.getMessagePreview(activity, message);
if (showPreviewText) {
viewHolder.lastMessage.setText(EmojiWrapper.transform(preview.first));
} else {
viewHolder.lastMessageIcon.setContentDescription(preview.first);
}
viewHolder.lastMessage.setVisibility(showPreviewText ? View.VISIBLE : View.GONE);
if (preview.second) {
if (conversation.isRead()) {
viewHolder.lastMessage.setTypeface(null, Typeface.ITALIC);
viewHolder.sender.setTypeface(null, Typeface.NORMAL);
} else {
viewHolder.lastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
viewHolder.sender.setTypeface(null, Typeface.BOLD);
}
} else {
if (conversation.isRead()) {
viewHolder.lastMessage.setTypeface(null, Typeface.NORMAL);
viewHolder.sender.setTypeface(null, Typeface.NORMAL);
} else {
viewHolder.lastMessage.setTypeface(null, Typeface.BOLD);
viewHolder.sender.setTypeface(null, Typeface.BOLD);
}
}
if (message.getStatus() == Message.STATUS_RECEIVED) {
if (conversation.getMode() == Conversation.MODE_MULTI) {
viewHolder.sender.setVisibility(View.VISIBLE);
viewHolder.sender.setText(UIHelper.getMessageDisplayName(message).split("\\s+")[0] + ':');
} else {
viewHolder.sender.setVisibility(View.GONE);
}
} else if (message.getType() != Message.TYPE_STATUS) {
viewHolder.sender.setVisibility(View.VISIBLE);
viewHolder.sender.setText(activity.getString(R.string.me) + ':');
} else {
viewHolder.sender.setVisibility(View.GONE);
}
long muted_till = conversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0);
if (muted_till == Long.MAX_VALUE) {
viewHolder.notificationIcon.setVisibility(View.VISIBLE);
viewHolder.notificationIcon.setImageResource(R.drawable.ic_notifications_off_grey600_24dp);
} else if (muted_till >= System.currentTimeMillis()) {
viewHolder.notificationIcon.setVisibility(View.VISIBLE);
viewHolder.notificationIcon.setImageResource(R.drawable.ic_notifications_paused_grey600_24dp);
} else if (conversation.alwaysNotify()) {
viewHolder.notificationIcon.setVisibility(View.GONE);
} else {
viewHolder.notificationIcon.setVisibility(View.VISIBLE);
viewHolder.notificationIcon.setImageResource(R.drawable.ic_notifications_none_grey600_24dp);
}
viewHolder.timestamp.setText(UIHelper.readableTimeDifference(activity, conversation.getLatestMessage().getTimeSent()));
loadAvatar(conversation, viewHolder.avatar);
if (conversation.getMode() == Conversation.MODE_SINGLE && ShowPresenceColoredNames()) {
switch(conversation.getContact().getPresences().getShownStatus()) {
case CHAT:
case ONLINE:
viewHolder.name.setTextColor(ContextCompat.getColor(activity, R.color.online));
break;
case AWAY:
viewHolder.name.setTextColor(ContextCompat.getColor(activity, R.color.away));
break;
case XA:
case DND:
viewHolder.name.setTextColor(ContextCompat.getColor(activity, R.color.notavailable));
break;
default:
viewHolder.name.setTextColor(ContextCompat.getColor(activity, R.color.black87));
break;
}
} else {
viewHolder.name.setTextColor(ContextCompat.getColor(activity, R.color.black87));
}
if (activity.xmppConnectionService.indicateReceived()) {
switch(message.getMergedStatus()) {
case Message.STATUS_SEND_RECEIVED:
viewHolder.receivedStatus.setVisibility(View.VISIBLE);
break;
case Message.STATUS_SEND_DISPLAYED:
viewHolder.receivedStatus.setVisibility(View.VISIBLE);
viewHolder.readStatus.setVisibility(View.VISIBLE);
break;
}
}
if (conversation.getMode() == Conversation.MODE_SINGLE) {
if (conversation.getIncomingChatState().equals(ChatState.COMPOSING)) {
viewHolder.lastMessage.setText(R.string.is_typing);
viewHolder.lastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
viewHolder.sender.setVisibility(View.GONE);
}
} else {
if (conversation.getParticipants() != null) {
ChatState state = ChatState.COMPOSING;
List<MucOptions.User> userWithChatStates = conversation.getMucOptions().getUsersWithChatState(state, 5);
if (userWithChatStates.size() == 0) {
state = ChatState.PAUSED;
userWithChatStates = conversation.getMucOptions().getUsersWithChatState(state, 5);
}
if (state == ChatState.COMPOSING) {
if (userWithChatStates.size() > 0) {
if (userWithChatStates.size() == 1) {
MucOptions.User user = userWithChatStates.get(0);
viewHolder.lastMessage.setText(activity.getString(R.string.contact_is_typing, UIHelper.getDisplayName(user)));
viewHolder.lastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
viewHolder.sender.setVisibility(View.GONE);
} else {
StringBuilder builder = new StringBuilder();
for (MucOptions.User user : userWithChatStates) {
if (builder.length() != 0) {
builder.append(", ");
}
builder.append(UIHelper.getDisplayName(user));
}
viewHolder.lastMessage.setText(activity.getString(R.string.contacts_are_typing, builder.toString()));
viewHolder.lastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
viewHolder.sender.setVisibility(View.GONE);
}
}
}
}
}
return view;
}
Aggregations