Search in sources :

Example 1 with ImageMessageContent

use of cn.wildfirechat.message.ImageMessageContent in project android-chat by wildfirechat.

the class MessageViewModel method sendImgMsg.

public void sendImgMsg(Conversation conversation, Uri imageFileThumbUri, Uri imageFileSourceUri) {
    ImageMessageContent imgContent = new ImageMessageContent(imageFileSourceUri.getEncodedPath());
    String thumbParam = ChatManager.Instance().getImageThumbPara();
    if (!TextUtils.isEmpty(thumbParam)) {
        imgContent.setThumbPara(ChatManager.Instance().getImageThumbPara());
    }
    sendMessage(conversation, imgContent);
}
Also used : ImageMessageContent(cn.wildfirechat.message.ImageMessageContent)

Example 2 with ImageMessageContent

use of cn.wildfirechat.message.ImageMessageContent 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;
}
Also used : GroupMember(cn.wildfirechat.model.GroupMember) ImageMessageContent(cn.wildfirechat.message.ImageMessageContent) StickerMessageContent(cn.wildfirechat.message.StickerMessageContent) FileMessageContent(cn.wildfirechat.message.FileMessageContent) SoundMessageContent(cn.wildfirechat.message.SoundMessageContent) VideoMessageContent(cn.wildfirechat.message.VideoMessageContent) MessageContent(cn.wildfirechat.message.MessageContent) CallStartMessageContent(cn.wildfirechat.message.CallStartMessageContent) CompositeMessageContent(cn.wildfirechat.message.CompositeMessageContent) TextMessageContent(cn.wildfirechat.message.TextMessageContent) StickerMessageContent(cn.wildfirechat.message.StickerMessageContent) Message(cn.wildfirechat.message.Message) UiMessage(cn.wildfire.chat.kit.conversation.message.model.UiMessage) GroupInfo(cn.wildfirechat.model.GroupInfo) ImageMessageContent(cn.wildfirechat.message.ImageMessageContent) CompositeMessageContent(cn.wildfirechat.message.CompositeMessageContent) FileMessageContent(cn.wildfirechat.message.FileMessageContent) SoundMessageContent(cn.wildfirechat.message.SoundMessageContent) GroupViewModel(cn.wildfire.chat.kit.group.GroupViewModel) TextMessageContent(cn.wildfirechat.message.TextMessageContent) VideoMessageContent(cn.wildfirechat.message.VideoMessageContent)

Example 3 with ImageMessageContent

use of cn.wildfirechat.message.ImageMessageContent in project android-chat by wildfirechat.

the class ImageMessageContentViewHolder method setSendStatus.

@Override
protected void setSendStatus(Message item) {
    super.setSendStatus(item);
    MessageContent msgContent = item.content;
    if (msgContent instanceof ImageMessageContent) {
        boolean isSend = item.direction == MessageDirection.Send;
        if (isSend) {
            MessageStatus sentStatus = item.status;
            if (sentStatus == MessageStatus.Sending) {
                imageView.setPercent(message.progress);
                imageView.setProgressVisible(true);
                imageView.showShadow(true);
            } else if (sentStatus == MessageStatus.Send_Failure) {
                imageView.setProgressVisible(false);
                imageView.showShadow(false);
            } else if (sentStatus == MessageStatus.Sent) {
                imageView.setProgressVisible(false);
                imageView.showShadow(false);
            }
        } else {
            imageView.setProgressVisible(false);
            imageView.showShadow(false);
        }
    }
}
Also used : MessageContent(cn.wildfirechat.message.MessageContent) ImageMessageContent(cn.wildfirechat.message.ImageMessageContent) MessageStatus(cn.wildfirechat.message.core.MessageStatus) ImageMessageContent(cn.wildfirechat.message.ImageMessageContent)

Example 4 with ImageMessageContent

use of cn.wildfirechat.message.ImageMessageContent in project android-chat by wildfirechat.

the class ImageMessageContentViewHolder method onBind.

@Override
public void onBind(UiMessage message) {
    ImageMessageContent imageMessage = (ImageMessageContent) message.message.content;
    Bitmap thumbnail = imageMessage.getThumbnail();
    int[] imageSize = WeChatImageUtils.getImageSizeByOrgSizeToWeChat((int) imageMessage.getImageWidth(), (int) imageMessage.getImageHeight());
    int width = imageSize[0] > 0 ? imageSize[0] : 200;
    int height = imageSize[1] > 0 ? imageSize[1] : 200;
    imageView.getLayoutParams().width = width;
    imageView.getLayoutParams().height = height;
    if (FileUtils.isFileExists(imageMessage.localPath)) {
        imagePath = imageMessage.localPath;
    } else {
        imagePath = imageMessage.remoteUrl;
    }
    if (message.message.conversation.type == Conversation.ConversationType.SecretChat) {
        imagePath += "?target=" + message.message.conversation.target + "&secret=true";
    }
    loadMedia(thumbnail, imagePath, imageView);
}
Also used : Bitmap(android.graphics.Bitmap) ImageMessageContent(cn.wildfirechat.message.ImageMessageContent)

Example 5 with ImageMessageContent

use of cn.wildfirechat.message.ImageMessageContent in project android-chat by wildfirechat.

the class ForwardActivity method forward.

private void forward(String targetName, String targetPortrait, Conversation targetConversation) {
    ForwardPromptView view = new ForwardPromptView(this);
    if (messages.size() == 1) {
        Message message = messages.get(0);
        if (message.content instanceof ImageMessageContent) {
            view.bind(targetName, targetPortrait, ((ImageMessageContent) message.content).getThumbnail());
        } else if (message.content instanceof VideoMessageContent) {
            view.bind(targetName, targetPortrait, ((VideoMessageContent) message.content).getThumbnail());
        } else if (message.content instanceof CompositeMessageContent) {
            view.bind(targetName, targetPortrait, "[聊天记录]: " + ((CompositeMessageContent) message.content).getTitle());
        } else {
            view.bind(targetName, targetPortrait, WfcTextUtils.htmlToText(message.digest()));
        }
    } else {
        view.bind(targetName, targetPortrait, "[逐条转发]共" + messages.size() + "条消息");
    }
    MaterialDialog dialog = new MaterialDialog.Builder(this).customView(view, false).negativeText("取消").positiveText("发送").onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            Message extraMsg = null;
            if (!TextUtils.isEmpty(view.getEditText())) {
                TextMessageContent content = new TextMessageContent(view.getEditText());
                extraMsg = new Message();
                extraMsg.content = content;
            }
            if (extraMsg != null) {
                messages.add(extraMsg);
            }
            forwardViewModel.forward(targetConversation, messages.toArray(new Message[0])).observe(ForwardActivity.this, new Observer<OperateResult<Integer>>() {

                @Override
                public void onChanged(@Nullable OperateResult<Integer> integerOperateResult) {
                    if (integerOperateResult.isSuccess()) {
                        Toast.makeText(ForwardActivity.this, "转发成功", Toast.LENGTH_SHORT).show();
                        finish();
                    } else {
                        Toast.makeText(ForwardActivity.this, "转发失败" + integerOperateResult.getErrorCode(), Toast.LENGTH_SHORT).show();
                    }
                }
            });
        }
    }).build();
    dialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Message(cn.wildfirechat.message.Message) ImageMessageContent(cn.wildfirechat.message.ImageMessageContent) CompositeMessageContent(cn.wildfirechat.message.CompositeMessageContent) OperateResult(cn.wildfire.chat.kit.common.OperateResult) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(androidx.annotation.NonNull) VideoMessageContent(cn.wildfirechat.message.VideoMessageContent) TextMessageContent(cn.wildfirechat.message.TextMessageContent)

Aggregations

ImageMessageContent (cn.wildfirechat.message.ImageMessageContent)7 CompositeMessageContent (cn.wildfirechat.message.CompositeMessageContent)4 TextMessageContent (cn.wildfirechat.message.TextMessageContent)4 VideoMessageContent (cn.wildfirechat.message.VideoMessageContent)4 FileMessageContent (cn.wildfirechat.message.FileMessageContent)3 Message (cn.wildfirechat.message.Message)3 SoundMessageContent (cn.wildfirechat.message.SoundMessageContent)3 MessageContent (cn.wildfirechat.message.MessageContent)2 MessagePayload (cn.wildfirechat.message.core.MessagePayload)2 GroupInfo (cn.wildfirechat.model.GroupInfo)2 JSONObject (org.json.JSONObject)2 Bitmap (android.graphics.Bitmap)1 NonNull (androidx.annotation.NonNull)1 OperateResult (cn.wildfire.chat.kit.common.OperateResult)1 UiMessage (cn.wildfire.chat.kit.conversation.message.model.UiMessage)1 GroupViewModel (cn.wildfire.chat.kit.group.GroupViewModel)1 CallStartMessageContent (cn.wildfirechat.message.CallStartMessageContent)1 LinkMessageContent (cn.wildfirechat.message.LinkMessageContent)1 StickerMessageContent (cn.wildfirechat.message.StickerMessageContent)1 MessageStatus (cn.wildfirechat.message.core.MessageStatus)1