UPDATE聊天页面改版UI
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package com.yunbao.common.event;
|
||||
|
||||
import com.yunbao.common.bean.BaseModel;
|
||||
|
||||
import io.rong.imkit.conversation.extension.InputMode;
|
||||
|
||||
public class PDChatInputModeEvent extends BaseModel {
|
||||
InputMode inputMode;
|
||||
|
||||
public PDChatInputModeEvent(InputMode inputMode) {
|
||||
this.inputMode = inputMode;
|
||||
}
|
||||
|
||||
public InputMode getInputMode() {
|
||||
return inputMode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.yunbao.common.interfaces;
|
||||
|
||||
|
||||
public abstract class OnSendMessageListener<T> {
|
||||
public static final int STATUS_NOT_PRICE = 0;//金额不够
|
||||
public static final int STATUS_ERROR = 1;//接口错误
|
||||
|
||||
|
||||
public void onSuccess(String token, T bean) {
|
||||
|
||||
}
|
||||
|
||||
public void onError(int status, String msg) {
|
||||
}
|
||||
public void onError(int status, String msg, T bean){
|
||||
onError(status, msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.yunbao.common.message.content;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
||||
import com.yunbao.common.interfaces.OnSendMessageListener;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import io.rong.common.ParcelUtils;
|
||||
import io.rong.imkit.IMCenter;
|
||||
import io.rong.imlib.MessageTag;
|
||||
import io.rong.imlib.RongIMClient;
|
||||
import io.rong.imlib.model.Conversation;
|
||||
import io.rong.imlib.model.Message;
|
||||
import io.rong.imlib.model.MessageContent;
|
||||
|
||||
@MessageTag(value = "MessageChatTipsContent", flag = MessageTag.ISPERSISTED)
|
||||
public class MessageChatTipsContent extends MessageContent implements Parcelable {
|
||||
private String content;
|
||||
|
||||
public static <T> void sendMessage(Conversation.ConversationType type, String targetId, MessageChatTipsContent tipsContent, OnSendMessageListener<T> listener) {
|
||||
IMCenter.getInstance().insertOutgoingMessage(type, targetId, Message.SentStatus.SENT, tipsContent, System.currentTimeMillis(), new RongIMClient.ResultCallback<Message>() {
|
||||
@Override
|
||||
public void onSuccess(Message message) {
|
||||
if (listener != null) {
|
||||
listener.onSuccess(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(RongIMClient.ErrorCode e) {
|
||||
if (listener != null) {
|
||||
listener.onError(e.code, e.msg);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private MessageChatTipsContent() {
|
||||
}
|
||||
|
||||
public MessageChatTipsContent(byte[] data) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
String jsonStr = null;
|
||||
try {
|
||||
jsonStr = new String(data, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
}
|
||||
if (jsonStr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject jsonObj = new JSONObject(jsonStr);
|
||||
// 消息携带用户信息时, 自定义消息需添加下面代码
|
||||
if (jsonObj.has("user")) {
|
||||
setUserInfo(parseJsonToUserInfo(jsonObj.getJSONObject("user")));
|
||||
}
|
||||
// 用于群组聊天, 消息携带 @ 人信息时, 自定义消息需添加下面代码
|
||||
if (jsonObj.has("mentionedInfo")) {
|
||||
setMentionedInfo(parseJsonToMentionInfo(jsonObj.getJSONObject("mentionedInfo")));
|
||||
}
|
||||
// 将所有自定义变量从收到的 json 解析并赋值
|
||||
if (jsonObj.has("content")) {
|
||||
content = jsonObj.optString("content");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public MessageChatTipsContent setContent(String content) {
|
||||
this.content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
protected MessageChatTipsContent(Parcel in) {
|
||||
setExtra(ParcelUtils.readFromParcel(in));
|
||||
setContent(ParcelUtils.readFromParcel(in));
|
||||
}
|
||||
|
||||
// 快速构建消息对象方法
|
||||
public static MessageChatTipsContent obtain(String content) {
|
||||
MessageChatTipsContent msg = new MessageChatTipsContent();
|
||||
msg.content = content;
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
public static final Creator<MessageChatTipsContent> CREATOR = new Creator<MessageChatTipsContent>() {
|
||||
@Override
|
||||
public MessageChatTipsContent createFromParcel(Parcel in) {
|
||||
return new MessageChatTipsContent(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageChatTipsContent[] newArray(int size) {
|
||||
return new MessageChatTipsContent[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public byte[] encode() {
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
try {
|
||||
// 消息携带用户信息时, 自定义消息需添加下面代码
|
||||
if (getJSONUserInfo() != null) {
|
||||
jsonObj.putOpt("user", getJSONUserInfo());
|
||||
}
|
||||
// 用于群组聊天, 消息携带 @ 人信息时, 自定义消息需添加下面代码
|
||||
if (getJsonMentionInfo() != null) {
|
||||
jsonObj.putOpt("mentionedInfo", getJsonMentionInfo());
|
||||
}
|
||||
// 将所有自定义消息的内容,都序列化至 json 对象中
|
||||
jsonObj.put("content", this.content);
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
return jsonObj.toString().getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
ParcelUtils.writeToParcel(dest, getExtra());
|
||||
ParcelUtils.writeToParcel(dest, content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.yunbao.common.provider;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Spannable;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.message.content.MessageChatTipsContent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.rong.imkit.conversation.messgelist.provider.BaseMessageItemProvider;
|
||||
import io.rong.imkit.model.UiMessage;
|
||||
import io.rong.imkit.widget.adapter.IViewProviderListener;
|
||||
import io.rong.imkit.widget.adapter.ViewHolder;
|
||||
import io.rong.imlib.model.MessageContent;
|
||||
|
||||
public class MessageChatTipsItemProvider extends BaseMessageItemProvider<MessageChatTipsContent> {
|
||||
private Context mContext;
|
||||
|
||||
public MessageChatTipsItemProvider(Context mContext) {
|
||||
this.mContext = mContext;
|
||||
mConfig.showPortrait = false;
|
||||
mConfig.showSummaryWithName = false;
|
||||
mConfig.showContentBubble = false;
|
||||
mConfig.centerInHorizontal = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ViewHolder onCreateMessageContentViewHolder(ViewGroup parent, int viewType) {
|
||||
return ViewHolder.createViewHolder(mContext, parent, R.layout.view_message_chat_tip);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindMessageContentViewHolder(ViewHolder holder, ViewHolder parentHolder, MessageChatTipsContent messageChatTipsContent, UiMessage uiMessage, int position, List<UiMessage> list, IViewProviderListener<UiMessage> listener) {
|
||||
holder.setText(R.id.tips, messageChatTipsContent.getContent());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onItemClick(ViewHolder holder, MessageChatTipsContent messageChatTipsContent, UiMessage uiMessage, int position, List<UiMessage> list, IViewProviderListener<UiMessage> listener) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isMessageViewType(MessageContent messageContent) {
|
||||
return messageContent instanceof MessageChatTipsContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spannable getSummarySpannable(Context context, MessageChatTipsContent messageChatTipsContent) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
9
common/src/main/res/drawable/bg_message_chat_tip.xml
Normal file
9
common/src/main/res/drawable/bg_message_chat_tip.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:width="261dp" android:height="50dp">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#99ededed" />
|
||||
<corners android:topLeftRadius="8dp" android:topRightRadius="8dp" android:bottomLeftRadius="8dp" android:bottomRightRadius="8dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
24
common/src/main/res/layout/view_message_chat_tip.xml
Normal file
24
common/src/main/res/layout/view_message_chat_tip.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tips"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_message_chat_tip"
|
||||
android:maxWidth="261dp"
|
||||
android:padding="5dp"
|
||||
android:paddingStart="11dp"
|
||||
android:paddingEnd="11dp"
|
||||
tools:text="【安全提示】為保障您的權益,慶提高警惕,不要輕易添加或提供第三方聯繫方式"
|
||||
android:textColor="#76777B"
|
||||
android:textSize="10sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
BIN
common/src/main/res/mipmap-xxhdpi/bg_msg_chat.png
Normal file
BIN
common/src/main/res/mipmap-xxhdpi/bg_msg_chat.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 584 KiB |
BIN
common/src/main/res/mipmap-xxhdpi/bg_msg_chat_title.png
Normal file
BIN
common/src/main/res/mipmap-xxhdpi/bg_msg_chat_title.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 626 KiB |
BIN
common/src/main/res/mipmap-xxhdpi/bg_msg_chat_title_avater.png
Normal file
BIN
common/src/main/res/mipmap-xxhdpi/bg_msg_chat_title_avater.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
BIN
common/src/main/res/mipmap-xxhdpi/bg_msg_chat_title_follow.png
Normal file
BIN
common/src/main/res/mipmap-xxhdpi/bg_msg_chat_title_follow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
common/src/main/res/mipmap-xxhdpi/ic_message_chat_input.png
Normal file
BIN
common/src/main/res/mipmap-xxhdpi/ic_message_chat_input.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 988 B |
@@ -1450,4 +1450,5 @@ Limited ride And limited avatar frame</string>
|
||||
<string name="community_back">Are you sure to return?</string>
|
||||
|
||||
<string name="back_community_sure">Sure</string>
|
||||
<string name="activity_msg_chat_input_hint">Say something</string>
|
||||
</resources>
|
||||
|
||||
@@ -1448,4 +1448,5 @@
|
||||
<string name="community_back">是否確認返回?</string>
|
||||
|
||||
<string name="back_community_sure">確定</string>
|
||||
<string name="activity_msg_chat_input_hint">說點什麼</string>
|
||||
</resources>
|
||||
|
||||
@@ -1447,5 +1447,5 @@
|
||||
<string name="community_back">是否確認返回?</string>
|
||||
|
||||
<string name="back_community_sure">確定</string>
|
||||
|
||||
<string name="activity_msg_chat_input_hint">說點什麼</string>
|
||||
</resources>
|
||||
|
||||
@@ -1444,5 +1444,5 @@
|
||||
<string name="community_back">是否確認返回?</string>
|
||||
|
||||
<string name="back_community_sure">確定</string>
|
||||
|
||||
<string name="activity_msg_chat_input_hint">說點什麼</string>
|
||||
</resources>
|
||||
|
||||
@@ -1454,5 +1454,5 @@ Limited ride And limited avatar frame</string>
|
||||
<string name="community_back">Are you sure to return?</string>
|
||||
|
||||
<string name="back_community_sure">Sure</string>
|
||||
|
||||
<string name="activity_msg_chat_input_hint">Say something</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user