use of cn.wildfire.chat.kit.group.GroupViewModel in project android-chat by wildfirechat.
the class ConversationViewHolder method onBind.
public void onBind(ConversationInfo conversationInfo) {
secretChatIndicator.setVisibility(View.GONE);
onBindConversationInfo(conversationInfo);
timeTextView.setText(TimeUtils.getMsgFormatTime(conversationInfo.timestamp));
silentImageView.setVisibility(conversationInfo.isSilent ? View.VISIBLE : View.GONE);
statusImageView.setVisibility(View.GONE);
itemView.setBackgroundResource(conversationInfo.isTop ? R.drawable.selector_stick_top_item : R.drawable.selector_common_item);
redDotView.setVisibility(View.GONE);
if (conversationInfo.isSilent) {
if (conversationInfo.unreadCount.unread > 0) {
// 显示红点
unreadCountTextView.setText("");
unreadCountTextView.setVisibility(View.GONE);
redDotView.setVisibility(View.VISIBLE);
} else {
unreadCountTextView.setVisibility(View.GONE);
}
} else {
if (conversationInfo.unreadCount.unread > 0) {
unreadCountTextView.setVisibility(View.VISIBLE);
unreadCountTextView.setText(conversationInfo.unreadCount.unread > 99 ? "99+" : conversationInfo.unreadCount.unread + "");
} else {
unreadCountTextView.setVisibility(View.GONE);
}
}
Draft draft = Draft.fromDraftJson(conversationInfo.draft);
if (draft != null) {
String draftString = draft.getContent() != null ? draft.getContent() : "[草稿]";
MoonUtils.identifyFaceExpression(fragment.getActivity(), contentTextView, draft.getContent(), ImageSpan.ALIGN_BOTTOM);
setViewVisibility(R.id.promptTextView, View.VISIBLE);
setViewVisibility(R.id.contentTextView, View.VISIBLE);
} else {
if (conversationInfo.unreadCount.unreadMentionAll > 0 || conversationInfo.unreadCount.unreadMention > 0) {
promptTextView.setText("[有人@我]");
promptTextView.setVisibility(View.VISIBLE);
} else {
promptTextView.setVisibility(View.GONE);
}
setViewVisibility(R.id.contentTextView, View.VISIBLE);
if (conversationInfo.lastMessage != null && conversationInfo.lastMessage.content != null) {
String content = "";
Message lastMessage = conversationInfo.lastMessage;
// the message maybe invalid
try {
if (conversationInfo.conversation.type == Conversation.ConversationType.Group && lastMessage.direction == MessageDirection.Receive && !(lastMessage.content instanceof NotificationMessageContent)) {
GroupViewModel groupViewModel = ViewModelProviders.of(fragment).get(GroupViewModel.class);
String senderDisplayName = groupViewModel.getGroupMemberDisplayName(conversationInfo.conversation.target, conversationInfo.lastMessage.sender);
content = senderDisplayName + ":" + lastMessage.digest();
} else {
content = lastMessage.digest();
}
} catch (Exception e) {
e.printStackTrace();
}
content = WfcTextUtils.htmlToText(content);
MoonUtils.identifyFaceExpression(fragment.getActivity(), contentTextView, content, ImageSpan.ALIGN_BOTTOM);
switch(lastMessage.status) {
case Sending:
statusImageView.setVisibility(View.VISIBLE);
// TODO update sending image resource
statusImageView.setImageResource(R.mipmap.ic_sending);
break;
case Send_Failure:
statusImageView.setVisibility(View.VISIBLE);
statusImageView.setImageResource(R.mipmap.img_error);
break;
default:
statusImageView.setVisibility(View.GONE);
break;
}
} else {
contentTextView.setText("");
}
}
}
use of cn.wildfire.chat.kit.group.GroupViewModel in project android-chat by wildfirechat.
the class NormalMessageContentViewHolder method contextMenuItemFilter.
@Override
public boolean contextMenuItemFilter(UiMessage uiMessage, String tag) {
Message message = uiMessage.message;
if (message.conversation.type == Conversation.ConversationType.SecretChat) {
if (MessageContextMenuItemTags.TAG_FORWARD.equals(tag)) {
return true;
}
if (MessageContextMenuItemTags.TAG_FAV.equals(tag)) {
return true;
}
return false;
}
if (MessageContextMenuItemTags.TAG_RECALL.equals(tag)) {
String userId = ChatManager.Instance().getUserId();
if (message.conversation.type == Conversation.ConversationType.Group) {
GroupViewModel groupViewModel = ViewModelProviders.of(fragment).get(GroupViewModel.class);
GroupInfo groupInfo = groupViewModel.getGroupInfo(message.conversation.target, false);
if (groupInfo != null && userId.equals(groupInfo.owner)) {
return false;
}
GroupMember groupMember = groupViewModel.getGroupMember(message.conversation.target, ChatManager.Instance().getUserId());
if (groupMember != null && (groupMember.type == GroupMember.GroupMemberType.Manager || groupMember.type == GroupMember.GroupMemberType.Owner)) {
return false;
}
}
long delta = ChatManager.Instance().getServerDeltaTime();
long now = System.currentTimeMillis();
if (message.direction == MessageDirection.Send && TextUtils.equals(message.sender, ChatManager.Instance().getUserId()) && now - (message.serverTime - delta) < Config.RECALL_TIME_LIMIT * 1000) {
return false;
} else {
return true;
}
}
// 只有channel 主可以发起
if (MessageContextMenuItemTags.TAG_CHANEL_PRIVATE_CHAT.equals(tag)) {
if (uiMessage.message.conversation.type == Conversation.ConversationType.Channel && uiMessage.message.direction == MessageDirection.Receive) {
return false;
}
return true;
}
// 只有部分消息支持引用
if (MessageContextMenuItemTags.TAG_QUOTE.equals(tag)) {
MessageContent messageContent = message.content;
if (messageContent instanceof TextMessageContent || messageContent instanceof FileMessageContent || messageContent instanceof VideoMessageContent || messageContent instanceof StickerMessageContent || messageContent instanceof ImageMessageContent) {
return false;
}
return true;
}
// 只有部分消息支持收藏
if (MessageContextMenuItemTags.TAG_FAV.equals(tag)) {
MessageContent messageContent = message.content;
if (messageContent instanceof TextMessageContent || messageContent instanceof FileMessageContent || messageContent instanceof CompositeMessageContent || messageContent instanceof VideoMessageContent || messageContent instanceof SoundMessageContent || messageContent instanceof ImageMessageContent) {
return false;
}
return true;
}
return false;
}
use of cn.wildfire.chat.kit.group.GroupViewModel in project android-chat by wildfirechat.
the class ForwardActivity method afterViews.
@Override
protected void afterViews() {
super.afterViews();
messages = getIntent().getParcelableArrayListExtra("messages");
if (messages == null || messages.isEmpty()) {
Message message = getIntent().getParcelableExtra("message");
if (message != null) {
messages = new ArrayList<>();
messages.add(message);
}
}
if (messages == null || messages.isEmpty()) {
finish();
}
forwardViewModel = ViewModelProviders.of(this).get(ForwardViewModel.class);
userViewModel = ViewModelProviders.of(this).get(UserViewModel.class);
groupViewModel = ViewModelProviders.of(this).get(GroupViewModel.class);
}
use of cn.wildfire.chat.kit.group.GroupViewModel in project android-chat by wildfirechat.
the class ConversationInputPanel method mentionGroupMember.
private void mentionGroupMember() {
Intent intent = new Intent(activity, MentionGroupMemberActivity.class);
GroupViewModel groupViewModel = ViewModelProviders.of(fragment).get(GroupViewModel.class);
GroupInfo groupInfo = groupViewModel.getGroupInfo(conversation.target, false);
intent.putExtra("groupInfo", groupInfo);
fragment.startActivityForResult(intent, REQUEST_PICK_MENTION_CONTACT);
}
use of cn.wildfire.chat.kit.group.GroupViewModel in project android-chat by wildfirechat.
the class PickOrCreateConversationTargetActivity method onContactPicked.
@Override
protected void onContactPicked(List<UIUserInfo> newlyCheckedUserInfos) {
if (singleMode && newlyCheckedUserInfos.size() > 1) {
// 先创建群组
MaterialDialog dialog = new MaterialDialog.Builder(this).content("创建中...").progress(true, 100).build();
dialog.show();
List<UserInfo> userInfos = new ArrayList<>();
for (UIUserInfo info : newlyCheckedUserInfos) {
userInfos.add(info.getUserInfo());
}
GroupViewModel groupViewModel = ViewModelProviders.of(this).get(GroupViewModel.class);
groupViewModel.createGroup(this, userInfos, null, Arrays.asList(0)).observe(this, new Observer<OperateResult<String>>() {
@Override
public void onChanged(@Nullable OperateResult<String> result) {
dialog.dismiss();
if (result.isSuccess()) {
GroupInfo groupInfo = groupViewModel.getGroupInfo(result.getResult(), false);
Intent intent = new Intent();
intent.putExtra("groupInfo", groupInfo);
setResult(RESULT_OK, intent);
finish();
} else {
Toast.makeText(PickOrCreateConversationTargetActivity.this, "create group error", Toast.LENGTH_SHORT).show();
}
}
});
} else {
Intent intent = new Intent();
intent.putExtra("userInfo", newlyCheckedUserInfos.get(0).getUserInfo());
setResult(RESULT_OK, intent);
finish();
}
}
Aggregations