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);
}
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();
}
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);
}
}
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;
});
}
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);
}
Aggregations