Search in sources :

Example 1 with UiMessage

use of cn.wildfire.chat.kit.conversation.message.model.UiMessage in project android-chat by wildfirechat.

the class ForwardMessageAction method forwardOneByOne.

private void forwardOneByOne(List<UiMessage> messages) {
    ArrayList<Message> msgs = messages.stream().map(uiMessage -> uiMessage.message).collect(Collectors.toCollection(ArrayList::new));
    Intent intent = new Intent(fragment.getContext(), ForwardActivity.class);
    intent.putExtra("messages", msgs);
    fragment.startActivity(intent);
}
Also used : Context(android.content.Context) Message(cn.wildfirechat.message.Message) ChatManager(cn.wildfirechat.remote.ChatManager) Conversation(cn.wildfirechat.model.Conversation) R(cn.wildfire.chat.kit.R) UiMessage(cn.wildfire.chat.kit.conversation.message.model.UiMessage) Intent(android.content.Intent) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) ForwardActivity(cn.wildfire.chat.kit.conversation.forward.ForwardActivity) Toast(android.widget.Toast) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) CompositeMessageContent(cn.wildfirechat.message.CompositeMessageContent) UserInfo(cn.wildfirechat.model.UserInfo) Message(cn.wildfirechat.message.Message) UiMessage(cn.wildfire.chat.kit.conversation.message.model.UiMessage) Intent(android.content.Intent)

Example 2 with UiMessage

use of cn.wildfire.chat.kit.conversation.message.model.UiMessage in project android-chat by wildfirechat.

the class DeleteMultiMessageAction method onClick.

@Override
public void onClick(List<UiMessage> messages) {
    MessageViewModel messageViewModel = new ViewModelProvider(fragment).get(MessageViewModel.class);
    new MaterialDialog.Builder(fragment.getContext()).items("删除本地消息", "删除远程消息").itemsCallback(new MaterialDialog.ListCallback() {

        @Override
        public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
            if (position == 0) {
                for (UiMessage message : messages) {
                    messageViewModel.deleteMessage(message.message);
                }
            } else {
                for (UiMessage message : messages) {
                    messageViewModel.deleteRemoteMessage(message.message);
                }
            }
        }
    }).show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) UiMessage(cn.wildfire.chat.kit.conversation.message.model.UiMessage) MessageViewModel(cn.wildfire.chat.kit.viewmodel.MessageViewModel) View(android.view.View) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 3 with UiMessage

use of cn.wildfire.chat.kit.conversation.message.model.UiMessage in project android-chat by wildfirechat.

the class FavAudioContentViewHolder method playAudio.

@OnClick(R2.id.audioContentLayout)
void playAudio() {
    Message message = favoriteItem.toMessage();
    uiMessage = new UiMessage(message);
    MessageViewModel messageViewModel = ViewModelProviders.of(fragment).get(MessageViewModel.class);
    File file = messageViewModel.mediaMessageContentFile(message);
    if (file == null) {
        return;
    }
    if (file.exists()) {
        messageViewModel.playAudioMessage(uiMessage);
    } else {
        if (uiMessage.isDownloading) {
            return;
        }
        messageViewModel.downloadMedia(uiMessage, file);
    }
}
Also used : Message(cn.wildfirechat.message.Message) UiMessage(cn.wildfire.chat.kit.conversation.message.model.UiMessage) UiMessage(cn.wildfire.chat.kit.conversation.message.model.UiMessage) MessageViewModel(cn.wildfire.chat.kit.viewmodel.MessageViewModel) File(java.io.File) OnClick(butterknife.OnClick)

Example 4 with UiMessage

use of cn.wildfire.chat.kit.conversation.message.model.UiMessage in project android-chat by wildfirechat.

the class ConversationMessageAdapter method processPortraitLongClick.

private void processPortraitLongClick(MessageContentViewHolder viewHolder, View itemView) {
    itemView.findViewById(R.id.portraitImageView).setOnLongClickListener(v -> {
        if (onPortraitLongClickListener != null) {
            int position = viewHolder.getAdapterPosition();
            UiMessage message = getItem(position);
            onPortraitLongClickListener.onPortraitLongClick(ChatManager.Instance().getUserInfo(message.message.sender, false));
            return true;
        }
        return false;
    });
}
Also used : UiMessage(cn.wildfire.chat.kit.conversation.message.model.UiMessage)

Example 5 with UiMessage

use of cn.wildfire.chat.kit.conversation.message.model.UiMessage in project android-chat by wildfirechat.

the class ConversationMessageAdapter method processContentLongClick.

// refer to https://stackoverflow.com/questions/21217397/android-issue-with-onclicklistener-and-onlongclicklistener?noredirect=1&lq=1
private void processContentLongClick(Class<? extends MessageContentViewHolder> viewHolderClazz, MessageContentViewHolder viewHolder, View itemView) {
    if (!viewHolderClazz.isAnnotationPresent(EnableContextMenu.class)) {
        return;
    }
    View.OnLongClickListener listener = new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            List<Method> allMethods = getDeclaredMethodsEx(viewHolderClazz);
            List<ContextMenuItemWrapper> contextMenus = new ArrayList<>();
            for (final Method method : allMethods) {
                if (method.isAnnotationPresent(MessageContextMenuItem.class)) {
                    contextMenus.add(new ContextMenuItemWrapper(method.getAnnotation(MessageContextMenuItem.class), method));
                }
            }
            if (contextMenus.isEmpty()) {
                return false;
            }
            int position = viewHolder.getAdapterPosition();
            UiMessage message = getItem(position);
            Iterator<ContextMenuItemWrapper> iterator = contextMenus.iterator();
            MessageContextMenuItem item;
            while (iterator.hasNext()) {
                item = iterator.next().contextMenuItem;
                if (viewHolder.contextMenuItemFilter(message, item.tag())) {
                    iterator.remove();
                }
            }
            if (contextMenus.isEmpty()) {
                return false;
            }
            Collections.sort(contextMenus, (o1, o2) -> o1.contextMenuItem.priority() - o2.contextMenuItem.priority());
            List<String> titles = new ArrayList<>(contextMenus.size());
            for (ContextMenuItemWrapper itemWrapper : contextMenus) {
                titles.add(viewHolder.contextMenuTitle(fragment.getContext(), itemWrapper.contextMenuItem.tag()));
            }
            new MaterialDialog.Builder(fragment.getContext()).items(titles).itemsCallback(new MaterialDialog.ListCallback() {

                @Override
                public void onSelection(MaterialDialog dialog, View v, int position, CharSequence text) {
                    try {
                        ContextMenuItemWrapper menuItem = contextMenus.get(position);
                        if (menuItem.contextMenuItem.confirm()) {
                            String content;
                            content = viewHolder.contextConfirmPrompt(fragment.getContext(), menuItem.contextMenuItem.tag());
                            new MaterialDialog.Builder(fragment.getContext()).content(content).negativeText("取消").positiveText("确认").onPositive(new MaterialDialog.SingleButtonCallback() {

                                @Override
                                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                    try {
                                        menuItem.method.invoke(viewHolder, itemView, message);
                                    } catch (IllegalAccessException e) {
                                        e.printStackTrace();
                                    } catch (InvocationTargetException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }).build().show();
                        } else {
                            contextMenus.get(position).method.invoke(viewHolder, itemView, message);
                        }
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    }
                }
            }).show();
            return true;
        }
    };
    View contentLayout = itemView.findViewById(R.id.contentFrameLayout);
    contentLayout.setOnLongClickListener(listener);
    setOnLongClickListenerForAllClickableChildView(contentLayout, listener);
}
Also used : UiMessage(cn.wildfire.chat.kit.conversation.message.model.UiMessage) ArrayList(java.util.ArrayList) MessageContextMenuItem(cn.wildfire.chat.kit.annotation.MessageContextMenuItem) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) EnableContextMenu(cn.wildfire.chat.kit.annotation.EnableContextMenu) Method(java.lang.reflect.Method) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) MessageItemView(cn.wildfire.chat.kit.conversation.message.MessageItemView) InvocationTargetException(java.lang.reflect.InvocationTargetException) DialogAction(com.afollestad.materialdialogs.DialogAction)

Aggregations

UiMessage (cn.wildfire.chat.kit.conversation.message.model.UiMessage)20 Message (cn.wildfirechat.message.Message)7 ArrayList (java.util.ArrayList)7 List (java.util.List)5 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)4 MutableLiveData (androidx.lifecycle.MutableLiveData)3 CompositeMessageContent (cn.wildfirechat.message.CompositeMessageContent)3 BurnMessageInfo (cn.wildfirechat.model.BurnMessageInfo)3 Context (android.content.Context)2 Intent (android.content.Intent)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 Toast (android.widget.Toast)2 R (cn.wildfire.chat.kit.R)2 ForwardActivity (cn.wildfire.chat.kit.conversation.forward.ForwardActivity)2 MessageItemView (cn.wildfire.chat.kit.conversation.message.MessageItemView)2 MessageViewModel (cn.wildfire.chat.kit.viewmodel.MessageViewModel)2 Conversation (cn.wildfirechat.model.Conversation)2 ViewGroup (android.view.ViewGroup)1 CheckBox (android.widget.CheckBox)1