mirror of
https://github.com/WuKongIM/WuKongIMAndroidSDK
synced 2025-06-05 00:28:22 +00:00
fix:add order message
This commit is contained in:
parent
954751d2f0
commit
12a4df84b5
@ -54,7 +54,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
recyclerView.setAdapter(adapter);
|
||||
onListener();
|
||||
long orderSeq = getIntent().getLongExtra("old_order_seq", 0);
|
||||
getData(orderSeq, 0, true,true);
|
||||
getData(orderSeq, 0, true, true);
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
@ -62,7 +62,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
return;
|
||||
}
|
||||
long orderSeq = adapter.getData().get(0).msg.orderSeq;
|
||||
getData(orderSeq, 0, false,false);
|
||||
getData(orderSeq, 0, false, false);
|
||||
}
|
||||
|
||||
private void more() {
|
||||
@ -70,7 +70,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
return;
|
||||
}
|
||||
long orderSeq = adapter.getData().get(adapter.getData().size() - 1).msg.orderSeq;
|
||||
getData(orderSeq, 1, false,false);
|
||||
getData(orderSeq, 1, false, false);
|
||||
}
|
||||
|
||||
void onListener() {
|
||||
@ -89,6 +89,18 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
});
|
||||
findViewById(R.id.orderBtn).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
OrderMessageContent content = new OrderMessageContent();
|
||||
content.setNum(100);
|
||||
content.setOrderNo("13939223329");
|
||||
content.setPrice(666666);
|
||||
content.setTitle("华为三折叠手机");
|
||||
content.setImgUrl("https://img1.baidu.com/it/u=4053553333,3320441183&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=645");
|
||||
WKIM.getInstance().getMsgManager().send(content, new WKChannel(channelID, channelType));
|
||||
}
|
||||
});
|
||||
findViewById(R.id.sendBtn).setOnClickListener(v -> {
|
||||
String content = contentEt.getText().toString();
|
||||
if (TextUtils.isEmpty(channelID)) {
|
||||
@ -130,14 +142,23 @@ public class MainActivity extends AppCompatActivity {
|
||||
// 新消息监听
|
||||
WKIM.getInstance().getMsgManager().addOnNewMsgListener("new_msg", msgList -> {
|
||||
for (WKMsg msg : msgList) {
|
||||
adapter.addData(new UIMessageEntity(msg, 0));
|
||||
if (msg.type==56) {
|
||||
adapter.addData(new UIMessageEntity(msg, 3));
|
||||
}else {
|
||||
adapter.addData(new UIMessageEntity(msg, 0));
|
||||
}
|
||||
}
|
||||
recyclerView.scrollToPosition(adapter.getData().size() - 1);
|
||||
});
|
||||
// 监听发送消息入库返回
|
||||
WKIM.getInstance().getMsgManager().addOnSendMsgCallback("insert_msg", msg ->{
|
||||
adapter.addData(new UIMessageEntity(msg, 1));
|
||||
WKIM.getInstance().getMsgManager().addOnSendMsgCallback("insert_msg", msg -> {
|
||||
if (msg.type==56){
|
||||
adapter.addData(new UIMessageEntity(msg, 2));
|
||||
}else {
|
||||
adapter.addData(new UIMessageEntity(msg, 1));
|
||||
}
|
||||
recyclerView.scrollToPosition(adapter.getData().size() - 1);
|
||||
} );
|
||||
});
|
||||
// 发送消息回执
|
||||
WKIM.getInstance().getMsgManager().addOnSendMsgAckListener("ack_key", msg -> {
|
||||
for (int i = 0, size = adapter.getData().size(); i < size; i++) {
|
||||
@ -164,7 +185,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
WKIM.getInstance().getConnectionManager().connection();
|
||||
}
|
||||
|
||||
private void getData(long oldOrderSeq, int pullMode, boolean contain,boolean isResetData) {
|
||||
private void getData(long oldOrderSeq, int pullMode, boolean contain, boolean isResetData) {
|
||||
WKIM.getInstance().getMsgManager().getOrSyncHistoryMessages(channelID, channelType, oldOrderSeq, contain, pullMode, 20, 0, new IGetOrSyncHistoryMsgBack() {
|
||||
|
||||
@Override
|
||||
@ -185,9 +206,17 @@ public class MainActivity extends AppCompatActivity {
|
||||
for (int i = 0, size = msgList.size(); i < size; i++) {
|
||||
int itemType;
|
||||
if (msgList.get(i).fromUID.equals(Const.Companion.getUid())) {
|
||||
itemType = 1;
|
||||
if (msgList.get(i).type == 56) {
|
||||
itemType = 2;
|
||||
} else {
|
||||
itemType = 1;
|
||||
}
|
||||
} else {
|
||||
itemType = 0;
|
||||
if (msgList.get(i).type == 56) {
|
||||
itemType = 3;
|
||||
} else {
|
||||
itemType = 0;
|
||||
}
|
||||
}
|
||||
UIMessageEntity entity = new UIMessageEntity(msgList.get(i), itemType);
|
||||
list.add(entity);
|
||||
|
@ -13,16 +13,16 @@ import org.jetbrains.annotations.NotNull;
|
||||
class MessageAdapter extends BaseMultiItemQuickAdapter<UIMessageEntity, BaseViewHolder> {
|
||||
|
||||
public MessageAdapter() {
|
||||
addItemType(1, R.layout.send_item_msg_layout);
|
||||
addItemType(0, R.layout.recv_item_msg_layout);
|
||||
addItemType(1, R.layout.send_text_layout);
|
||||
addItemType(0, R.layout.recv_text_layout);
|
||||
addItemType(2, R.layout.send_order_layout);
|
||||
addItemType(3, R.layout.recv_order_layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(@NotNull BaseViewHolder baseViewHolder, UIMessageEntity uiMessageEntity) {
|
||||
TextView contentTv = baseViewHolder.getView(R.id.contentTv);
|
||||
TextView nameTv = baseViewHolder.getView(R.id.nameIv);
|
||||
if (uiMessageEntity.getItemType() == 1) {
|
||||
|
||||
if (uiMessageEntity.getItemType() == 1 || uiMessageEntity.getItemType() == 2) {
|
||||
ImageView statusIV = baseViewHolder.getView(R.id.statusTv);
|
||||
if (uiMessageEntity.msg.status == WKSendMsgResult.send_success) {
|
||||
statusIV.setImageResource(R.mipmap.success);
|
||||
@ -32,10 +32,22 @@ class MessageAdapter extends BaseMultiItemQuickAdapter<UIMessageEntity, BaseView
|
||||
statusIV.setImageResource(R.mipmap.error);
|
||||
}
|
||||
}
|
||||
String name = uiMessageEntity.msg.fromUID.substring(0, 1);
|
||||
nameTv.setText(name);
|
||||
if (uiMessageEntity.msg.baseContentMsgModel!=null){
|
||||
contentTv.setText(uiMessageEntity.msg.baseContentMsgModel.getDisplayContent());
|
||||
if (uiMessageEntity.getItemType() == 2||uiMessageEntity.getItemType() == 3) {
|
||||
OrderMessageContent orderMsgContent = (OrderMessageContent) uiMessageEntity.msg.baseContentMsgModel;
|
||||
baseViewHolder.setText(R.id.orderNoTV, "订单号:" + orderMsgContent.getOrderNo());
|
||||
GlideUtil.Companion.showAvatarImg(getContext(), orderMsgContent.getImgUrl(), baseViewHolder.getView(R.id.orderIV));
|
||||
baseViewHolder.setText(R.id.titleTV, orderMsgContent.getTitle());
|
||||
baseViewHolder.setText(R.id.priceTV, "$" + orderMsgContent.getPrice());
|
||||
baseViewHolder.setText(R.id.countTV, "共" + orderMsgContent.getNum() + "件");
|
||||
} else {
|
||||
TextView contentTv = baseViewHolder.getView(R.id.contentTv);
|
||||
TextView nameTv = baseViewHolder.getView(R.id.nameIv);
|
||||
String name = uiMessageEntity.msg.fromUID.substring(0, 1);
|
||||
nameTv.setText(name);
|
||||
if (uiMessageEntity.msg.baseContentMsgModel != null) {
|
||||
contentTv.setText(uiMessageEntity.msg.baseContentMsgModel.getDisplayContent());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package com.xinbida.wukongdemo
|
||||
|
||||
import com.xinbida.wukongim.msgmodel.WKMessageContent
|
||||
import org.json.JSONObject
|
||||
|
||||
class OrderMessageContent : WKMessageContent() {
|
||||
var orderNo: String = ""
|
||||
var title: String = ""
|
||||
var imgUrl: String = ""
|
||||
var num: Int = 0
|
||||
var price: Int = 0
|
||||
override fun getDisplayContent(): String {
|
||||
return "[订单消息]"
|
||||
}
|
||||
|
||||
init {
|
||||
type = 56
|
||||
}
|
||||
|
||||
override fun encodeMsg(): JSONObject {
|
||||
val json = JSONObject()
|
||||
json.put("orderNo", orderNo)
|
||||
json.put("title", title)
|
||||
json.put("imgUrl", imgUrl)
|
||||
json.put("num", num)
|
||||
json.put("price", price)
|
||||
return json
|
||||
}
|
||||
|
||||
override fun decodeMsg(jsonObject: JSONObject): WKMessageContent {
|
||||
orderNo = jsonObject.optString("orderNo")
|
||||
title = jsonObject.optString("title")
|
||||
imgUrl = jsonObject.optString("imgUrl")
|
||||
num = jsonObject.optInt("num")
|
||||
price = jsonObject.optInt("price")
|
||||
return this
|
||||
}
|
||||
}
|
@ -40,6 +40,8 @@ class WKApplication : Application() {
|
||||
)
|
||||
|
||||
private fun initListener() {
|
||||
// 注册自定义消息
|
||||
WKIM.getInstance().msgManager.registerContentMsg(OrderMessageContent::class.java)
|
||||
// 连接地址
|
||||
WKIM.getInstance().connectionManager.addOnGetIpAndPortListener { andPortListener: IGetSocketIpAndPortListener ->
|
||||
Thread {
|
||||
@ -70,7 +72,7 @@ class WKApplication : Application() {
|
||||
} else {
|
||||
channel.channelName = "群聊${channelId.hashCode()}"
|
||||
}
|
||||
val index = (channelId.hashCode()) % (avatars.size )
|
||||
val index = (channelId.hashCode()) % (avatars.size)
|
||||
channel.avatar = avatars[abs(index)]
|
||||
// channel.avatar ="https://api.multiavatar.com/${channel.channelID}.png"
|
||||
WKIM.getInstance().channelManager.saveOrUpdateChannel(channel)
|
||||
|
@ -63,6 +63,12 @@
|
||||
android:hint="@string/input"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/orderBtn"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/send_order" />
|
||||
<Button
|
||||
android:id="@+id/sendBtn"
|
||||
android:layout_width="wrap_content"
|
||||
|
120
app/src/main/res/layout/recv_order_layout.xml
Normal file
120
app/src/main/res/layout/recv_order_layout.xml
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:paddingBottom="5dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nameIv"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:background="@drawable/send_rand"
|
||||
android:gravity="center"
|
||||
android:text="鞋"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<com.cxd.chatview.moudle.ChatView xmlns:chat="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:paddingStart="15dp"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:paddingBottom="10dp"
|
||||
chat:arrow_direction="left"
|
||||
chat:arrow_height="12dp"
|
||||
chat:arrow_up_distance="10dp"
|
||||
chat:arrow_width="5dp"
|
||||
chat:conner_radius="6dp"
|
||||
chat:fill_color="@color/success"
|
||||
chat:is_arrow_center="true"
|
||||
chat:press_fill_color="#50111111"
|
||||
chat:press_stroke_color="#50111111"
|
||||
chat:stroke_color="@color/success"
|
||||
chat:stroke_width="1px">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/orderNoTV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="dskdksldslk"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/orderIV"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/conn" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleTV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="sdkkdlssdkl"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/priceTV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="1ddd"
|
||||
android:textColor="@color/error"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/countTV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:text="1ddd"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</com.cxd.chatview.moudle.ChatView>
|
||||
|
||||
</LinearLayout>
|
125
app/src/main/res/layout/send_order_layout.xml
Normal file
125
app/src/main/res/layout/send_order_layout.xml
Normal file
@ -0,0 +1,125 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginStart="50dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:gravity="end"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="5dp">
|
||||
|
||||
<com.cxd.chatview.moudle.ChatView xmlns:chat="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:paddingStart="15dp"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:paddingBottom="10dp"
|
||||
chat:arrow_direction="right"
|
||||
chat:arrow_height="12dp"
|
||||
chat:arrow_up_distance="10dp"
|
||||
chat:arrow_width="5dp"
|
||||
chat:conner_radius="6dp"
|
||||
chat:fill_color="@color/send_chat_bg"
|
||||
chat:is_arrow_center="false"
|
||||
chat:press_fill_color="#50111111"
|
||||
chat:press_stroke_color="#50111111"
|
||||
chat:stroke_color="@color/send_chat_bg"
|
||||
chat:stroke_width="1px">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/orderNoTV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="dskdksldslk"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/orderIV"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/conn" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleTV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="sdkkdlssdkl"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/priceTV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="1ddd"
|
||||
android:textColor="@color/error"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/countTV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:text="1ddd"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/statusTv"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:layout_gravity="end"
|
||||
android:src="@mipmap/loading" />
|
||||
</LinearLayout>
|
||||
|
||||
</com.cxd.chatview.moudle.ChatView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nameIv"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:background="@drawable/send_rand"
|
||||
android:gravity="center"
|
||||
android:text="鞋"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
@ -14,5 +14,6 @@
|
||||
<string name="other_device_login">Kicked</string>
|
||||
<string name="input_content">Input content</string>
|
||||
<string name="send">Send</string>
|
||||
<string name="send_order">Customize</string>
|
||||
<string name="input">Input…</string>
|
||||
</resources>
|
||||
|
@ -14,5 +14,6 @@
|
||||
<string name="other_device_login">被踢</string>
|
||||
<string name="input_content">请输入聊天内容</string>
|
||||
<string name="send">发送</string>
|
||||
<string name="send_order">自定义</string>
|
||||
<string name="input">请输入内容</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user