mirror of
https://github.com/WuKongIM/WuKongIMAndroidSDK
synced 2025-06-05 00:28:22 +00:00
fix:update demo
This commit is contained in:
parent
70a9054c5f
commit
002315b82b
@ -17,7 +17,8 @@ class ConvAdapter :
|
||||
val msg = payloads[0] as WKUIConversationMsg
|
||||
if (msg.wkChannel != null) {
|
||||
holder.setText(R.id.nameTV, item.wkChannel.channelName)
|
||||
GlideUtil.showAvatarImg(context,
|
||||
GlideUtil.showAvatarImg(
|
||||
context,
|
||||
HttpUtil.getInstance()
|
||||
.getAvatar(item.wkChannel.channelID, item.wkChannel.channelType),
|
||||
holder.getView(R.id.avatarIV)
|
||||
@ -43,10 +44,12 @@ class ConvAdapter :
|
||||
holder.setText(R.id.timeTV, getShowTime(item.lastMsgTimestamp * 1000L))
|
||||
if (item.wkChannel != null) {
|
||||
holder.setText(R.id.nameTV, item.wkChannel.channelName)
|
||||
GlideUtil.showAvatarImg(context,
|
||||
GlideUtil.showAvatarImg(
|
||||
context,
|
||||
HttpUtil.getInstance()
|
||||
.getAvatar(item.wkChannel.channelID, item.wkChannel.channelType),
|
||||
holder.getView(R.id.avatarIV))
|
||||
holder.getView(R.id.avatarIV)
|
||||
)
|
||||
} else {
|
||||
WKIM.getInstance().channelManager.fetchChannelInfo(item.channelID, item.channelType)
|
||||
}
|
||||
@ -55,7 +58,9 @@ class ConvAdapter :
|
||||
val intent = Intent(context, MainActivity::class.java)
|
||||
intent.putExtra("channel_id", item.channelID)
|
||||
intent.putExtra("channel_type", item.channelType)
|
||||
intent.putExtra("old_order_seq", item.wkMsg.orderSeq)
|
||||
if (item.wkMsg != null) {
|
||||
intent.putExtra("old_order_seq", item.wkMsg.orderSeq)
|
||||
}
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.xinbida.wukongdemo
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
@ -90,14 +91,16 @@ class ConversationActivity : AppCompatActivity() {
|
||||
WKIM.getInstance().conversationManager.addOnRefreshMsgListener(
|
||||
"conv"
|
||||
) { uiConversationMsg, isEnd ->
|
||||
Log.e("修改的值",uiConversationMsg.channelID)
|
||||
var isAdd = true
|
||||
number++
|
||||
for (index in adapter.data.indices) {
|
||||
if (adapter.data[index].channelID == uiConversationMsg?.channelID) {
|
||||
if (adapter.data[index].channelID == uiConversationMsg?.channelID && adapter.data[index].channelType == uiConversationMsg?.channelType) {
|
||||
Log.e("要修改","-->")
|
||||
isAdd = false
|
||||
adapter.data[index].wkMsg = uiConversationMsg?.wkMsg
|
||||
adapter.data[index].wkMsg = uiConversationMsg.wkMsg
|
||||
adapter.data[index].lastMsgSeq =
|
||||
uiConversationMsg?.lastMsgSeq!!
|
||||
uiConversationMsg.lastMsgSeq
|
||||
adapter.data[index].clientMsgNo =
|
||||
uiConversationMsg.clientMsgNo
|
||||
adapter.data[index].unreadCount =
|
||||
|
@ -28,6 +28,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class HttpUtil {
|
||||
public String apiURL = "http://62.234.8.38:7090/v1";
|
||||
@ -82,6 +83,76 @@ public class HttpUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String url, JSONObject data, final IResult iResult) {
|
||||
try {
|
||||
HttpURLConnection conn = (HttpURLConnection) new URL(apiURL + url).openConnection();
|
||||
conn.setRequestMethod("DELETE");
|
||||
conn.setReadTimeout(5000);
|
||||
conn.setConnectTimeout(5000);
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.setUseCaches(false);
|
||||
conn.setRequestProperty("Connection", "keep-Alive");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
OutputStream outputStream = conn.getOutputStream();
|
||||
outputStream.write(data.toString().getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.flush();
|
||||
if (conn.getResponseCode() == 200) {
|
||||
InputStream inputStream = conn.getInputStream();
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
int length;
|
||||
byte[] bytes = new byte[1024];
|
||||
while ((length = inputStream.read(bytes)) != -1) {
|
||||
byteArrayOutputStream.write(bytes, 0, length);
|
||||
}
|
||||
byteArrayOutputStream.close();
|
||||
inputStream.close();
|
||||
String data1 = byteArrayOutputStream.toString();
|
||||
iResult.onResult(200, data1);
|
||||
} else {
|
||||
iResult.onResult(conn.getResponseCode(), "");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
iResult.onResult(500, "");
|
||||
}
|
||||
}
|
||||
|
||||
public void put(String url, JSONObject data, final IResult iResult) {
|
||||
try {
|
||||
HttpURLConnection conn = (HttpURLConnection) new URL(apiURL + url).openConnection();
|
||||
conn.setRequestMethod("PUT");
|
||||
conn.setReadTimeout(5000);
|
||||
conn.setConnectTimeout(5000);
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
conn.setUseCaches(false);
|
||||
conn.setRequestProperty("Connection", "keep-Alive");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
OutputStream outputStream = conn.getOutputStream();
|
||||
outputStream.write(data.toString().getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.flush();
|
||||
if (conn.getResponseCode() == 200) {
|
||||
InputStream inputStream = conn.getInputStream();
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
int length;
|
||||
byte[] bytes = new byte[1024];
|
||||
while ((length = inputStream.read(bytes)) != -1) {
|
||||
byteArrayOutputStream.write(bytes, 0, length);
|
||||
}
|
||||
byteArrayOutputStream.close();
|
||||
inputStream.close();
|
||||
String data1 = byteArrayOutputStream.toString();
|
||||
iResult.onResult(200, data1);
|
||||
} else {
|
||||
iResult.onResult(conn.getResponseCode(), "");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
iResult.onResult(500, "");
|
||||
}
|
||||
}
|
||||
|
||||
public void get(String url1, final IResult iResult) {
|
||||
try {
|
||||
URL url = new URL(apiURL + url1);
|
||||
@ -247,4 +318,132 @@ public class HttpUtil {
|
||||
})).start();
|
||||
}
|
||||
|
||||
public void clearChannelMsg(String channelId, byte channelType) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
long msgSeq = WKIM.getInstance().getMsgManager().getMaxMessageSeqWithChannel(channelId, channelType);
|
||||
json.put("login_uid", Const.Companion.getUid());
|
||||
json.put("channel_id", channelId);
|
||||
json.put("channel_type", channelType);
|
||||
json.put("message_seq", msgSeq);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
new Thread(() -> post("/message/offset", json, (code, data) -> {
|
||||
if (code == 200) {
|
||||
WKIM.getInstance().getMsgManager().clearWithChannel(channelId, channelType);
|
||||
}
|
||||
})).start();
|
||||
}
|
||||
|
||||
public void syncMsgExtra(String channelId, byte channelType) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
long version = WKIM.getInstance().getMsgManager().getMsgExtraMaxVersionWithChannel(channelId, channelType);
|
||||
json.put("login_uid", Const.Companion.getUid());
|
||||
json.put("channel_id", channelId);
|
||||
json.put("channel_type", channelType);
|
||||
json.put("source", Const.Companion.getUid());
|
||||
json.put("extra_version", version);
|
||||
json.put("limit", 100);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
new Thread(() -> post("/message/extra/sync", json, (code, data) -> {
|
||||
if (code == 200 && !TextUtils.isEmpty(data)) {
|
||||
try {
|
||||
JSONArray arr = new JSONArray(data);
|
||||
List<WKSyncExtraMsg> list = new ArrayList<>();
|
||||
for (int i = 0; i < arr.length(); i++) {
|
||||
JSONObject extraJson = arr.optJSONObject(i);
|
||||
WKSyncExtraMsg extraMsg = new WKSyncExtraMsg();
|
||||
extraMsg.message_id_str = extraJson.optString("message_id_str");
|
||||
extraMsg.message_id = extraJson.optString("message_id_str");
|
||||
extraMsg.revoker = extraJson.optString("revoker");
|
||||
extraMsg.readed = extraJson.optInt("readed");
|
||||
extraMsg.readed_count = extraJson.optInt("readed_count");
|
||||
extraMsg.is_mutual_deleted = extraJson.optInt("is_mutual_deleted");
|
||||
extraMsg.extra_version = extraJson.optLong("extra_version");
|
||||
extraMsg.revoke = extraJson.optInt("revoke");
|
||||
list.add(extraMsg);
|
||||
}
|
||||
WKIM.getInstance().getMsgManager().saveRemoteExtraMsg(new WKChannel(channelId, channelType), list);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
})).start();
|
||||
}
|
||||
|
||||
public void updateGroupName(String groupNo, String name) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("login_uid", Const.Companion.getUid());
|
||||
json.put("name", name);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
new Thread(() -> put("/groups/" + groupNo, json, (code, data) -> {
|
||||
if (code == 200) {
|
||||
Log.e("修改成功", "-->");
|
||||
}
|
||||
})).start();
|
||||
}
|
||||
|
||||
public void clearUnread(String channelId, byte channelType) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("login_uid", Const.Companion.getUid());
|
||||
json.put("channel_id", channelId);
|
||||
json.put("channel_type", channelType);
|
||||
json.put("unread", 0);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
new Thread(() -> put("/conversation/clearUnread", json, (code, data) -> {
|
||||
if (code == 200) {
|
||||
Log.e("修改成功", "-->");
|
||||
}
|
||||
})).start();
|
||||
}
|
||||
|
||||
public void revokeMsg(String channelId, byte channelType, String messageId, String clientMsgNo) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("login_uid", Const.Companion.getUid());
|
||||
json.put("channel_id", channelId);
|
||||
json.put("channel_type", channelType);
|
||||
json.put("client_msg_no", clientMsgNo);
|
||||
json.put("message_id", messageId);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
new Thread(() -> post("/message/revoke", json, (code, data) -> {
|
||||
if (code == 200) {
|
||||
Log.e("撤回成功","--->");
|
||||
}
|
||||
})).start();
|
||||
}
|
||||
|
||||
public void deleteMsg(String channelId, byte channelType, int messageSeq, String messageId, String clientMsgNo) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("login_uid", Const.Companion.getUid());
|
||||
json.put("channel_id", channelId);
|
||||
json.put("channel_type", channelType);
|
||||
json.put("message_seq", messageSeq);
|
||||
json.put("message_id", messageId);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
new Thread(() -> delete("/message", json, (code, data) -> {
|
||||
if (code == 200) {
|
||||
WKIM.getInstance().getMsgManager().deleteWithClientMsgNO(clientMsgNo);
|
||||
}
|
||||
})).start();
|
||||
}
|
||||
}
|
||||
|
@ -11,16 +11,17 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.lxj.xpopup.XPopup;
|
||||
import com.xinbida.wukongim.WKIM;
|
||||
import com.xinbida.wukongim.entity.WKChannel;
|
||||
import com.xinbida.wukongim.entity.WKChannelType;
|
||||
import com.xinbida.wukongim.entity.WKMsg;
|
||||
import com.xinbida.wukongim.interfaces.IClearMsgListener;
|
||||
import com.xinbida.wukongim.interfaces.IGetOrSyncHistoryMsgBack;
|
||||
import com.xinbida.wukongim.message.type.WKConnectStatus;
|
||||
import com.xinbida.wukongim.interfaces.IRefreshMsg;
|
||||
import com.xinbida.wukongim.msgmodel.WKTextContent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -30,8 +31,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
RecyclerView recyclerView;
|
||||
MessageAdapter adapter;
|
||||
private TextView statusTv;
|
||||
private View statusIv;
|
||||
private TextView nameTV;
|
||||
private String channelID;
|
||||
private byte channelType;
|
||||
private EditText contentEt;
|
||||
@ -46,8 +46,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
channelID = getIntent().getStringExtra("channel_id");
|
||||
channelType = getIntent().getByteExtra("channel_type", WKChannelType.PERSONAL);
|
||||
recyclerView = findViewById(R.id.recycleView);
|
||||
statusTv = findViewById(R.id.connectionTv);
|
||||
statusIv = findViewById(R.id.connectionIv);
|
||||
nameTV = findViewById(R.id.nameTV);
|
||||
contentEt = findViewById(R.id.contentEt);
|
||||
adapter = new MessageAdapter();
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
|
||||
@ -55,6 +54,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
onListener();
|
||||
long orderSeq = getIntent().getLongExtra("old_order_seq", 0);
|
||||
getData(orderSeq, 0, true, true);
|
||||
|
||||
WKChannel channel = WKIM.getInstance().getChannelManager().getChannel(channelID, channelType);
|
||||
if (channel != null) {
|
||||
nameTV.setText(channel.channelName);
|
||||
}
|
||||
HttpUtil.getInstance().clearUnread(channelID, channelType);
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
@ -80,6 +85,29 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
void onListener() {
|
||||
findViewById(R.id.addIV).setOnClickListener(view -> {
|
||||
final XPopup.Builder builder = new XPopup.Builder(view.getContext())
|
||||
.atView(view).hasShadowBg(false);
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add(getString(R.string.clear_channel_message));
|
||||
if (channelType == WKChannelType.GROUP) {
|
||||
list.add(getString(R.string.update_group_name));
|
||||
}
|
||||
String[] str = new String[list.size()];
|
||||
list.toArray(str);
|
||||
builder.asAttachList(str, null,
|
||||
(position, text) -> {
|
||||
if (position == 0) {
|
||||
HttpUtil.getInstance().clearChannelMsg(channelID, channelType);
|
||||
} else {
|
||||
|
||||
new XPopup.Builder(view.getContext()).asInputConfirm(getString(R.string.update_group_name), getString(R.string.input_group_name),
|
||||
text1 -> HttpUtil.getInstance().updateGroupName(channelID, text1))
|
||||
.show();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
});
|
||||
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
|
||||
@ -121,32 +149,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
contentEt.setText("");
|
||||
});
|
||||
|
||||
// 连接状态监听
|
||||
WKIM.getInstance().getConnectionManager().addOnConnectionStatusListener("main_act", (code, reason) -> {
|
||||
if (code == WKConnectStatus.success) {
|
||||
statusTv.setText(R.string.connect_success);
|
||||
statusTv.setTextColor(ContextCompat.getColor(this, R.color.success));
|
||||
statusIv.setBackgroundResource(R.drawable.success);
|
||||
} else if (code == WKConnectStatus.fail) {
|
||||
statusTv.setText(R.string.connect_fail);
|
||||
statusTv.setTextColor(ContextCompat.getColor(this, R.color.error));
|
||||
statusIv.setBackgroundResource(R.drawable.error);
|
||||
} else if (code == WKConnectStatus.connecting) {
|
||||
statusTv.setText(R.string.connecting);
|
||||
statusTv.setTextColor(ContextCompat.getColor(this, R.color.black));
|
||||
statusIv.setBackgroundResource(R.drawable.conn);
|
||||
} else if (code == WKConnectStatus.noNetwork) {
|
||||
statusTv.setText(R.string.no_net);
|
||||
statusTv.setTextColor(ContextCompat.getColor(this, R.color.nonet));
|
||||
statusIv.setBackgroundResource(R.drawable.nonet);
|
||||
} else if (code == WKConnectStatus.kicked) {
|
||||
statusTv.setText(R.string.other_device_login);
|
||||
statusTv.setTextColor(ContextCompat.getColor(this, R.color.black));
|
||||
statusIv.setBackgroundResource(R.drawable.conn);
|
||||
}
|
||||
});
|
||||
|
||||
// 新消息监听
|
||||
WKIM.getInstance().getMsgManager().addOnNewMsgListener("new_msg", msgList -> {
|
||||
WKIM.getInstance().getMsgManager().addOnNewMsgListener(channelID, msgList -> {
|
||||
for (WKMsg msg : msgList) {
|
||||
if (msg.type == 56) {
|
||||
adapter.addData(new UIMessageEntity(msg, 3));
|
||||
@ -157,7 +162,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
recyclerView.scrollToPosition(adapter.getData().size() - 1);
|
||||
});
|
||||
// 监听发送消息入库返回
|
||||
WKIM.getInstance().getMsgManager().addOnSendMsgCallback("insert_msg", msg -> {
|
||||
WKIM.getInstance().getMsgManager().addOnSendMsgCallback(channelID, msg -> {
|
||||
if (msg.type == 56) {
|
||||
adapter.addData(new UIMessageEntity(msg, 2));
|
||||
} else {
|
||||
@ -166,29 +171,68 @@ public class MainActivity extends AppCompatActivity {
|
||||
recyclerView.scrollToPosition(adapter.getData().size() - 1);
|
||||
});
|
||||
// 发送消息回执
|
||||
WKIM.getInstance().getMsgManager().addOnSendMsgAckListener("ack_key", msg -> {
|
||||
WKIM.getInstance().getMsgManager().addOnSendMsgAckListener(channelID, msg -> {
|
||||
for (int i = 0, size = adapter.getData().size(); i < size; i++) {
|
||||
if (adapter.getData().get(i).msg.clientSeq == msg.clientSeq) {
|
||||
adapter.getData().get(i).msg.status = msg.status;
|
||||
adapter.getData().get(i).msg.messageID = msg.messageID;
|
||||
adapter.getData().get(i).msg.messageSeq= msg.messageSeq;
|
||||
adapter.notifyItemChanged(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 刷新消息
|
||||
WKIM.getInstance().getMsgManager().addOnRefreshMsgListener(channelID, new IRefreshMsg() {
|
||||
@Override
|
||||
public void onRefresh(WKMsg msg, boolean left) {
|
||||
if (msg == null) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < adapter.getData().size(); i++) {
|
||||
if (adapter.getData().get(i).msg.clientMsgNO.equals(msg.clientMsgNO)) {
|
||||
if (msg.remoteExtra != null && msg.remoteExtra.revoke == 1) {
|
||||
adapter.getData().get(i).itemType = 4;
|
||||
adapter.notifyItemChanged(i);
|
||||
}
|
||||
adapter.getData().get(i).msg.remoteExtra = msg.remoteExtra;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 频道刷新
|
||||
WKIM.getInstance().getChannelManager().addOnRefreshChannelInfo(channelID, (channel, isEnd) -> {
|
||||
if (channel == null)
|
||||
return;
|
||||
nameTV.setText(channel.channelName);
|
||||
});
|
||||
|
||||
|
||||
// 监听清空消息
|
||||
WKIM.getInstance().getMsgManager().addOnClearMsgListener(channelID, new IClearMsgListener() {
|
||||
@Override
|
||||
public void clear(String channelID, byte channelType, String fromUID) {
|
||||
if (channelID.equals(MainActivity.this.channelID) && channelType == MainActivity.this.channelType) {
|
||||
adapter.setList(new ArrayList<>());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
// WKIM.getInstance().getConnectionManager().disconnect(false);
|
||||
// WKIM.getInstance().getConnectionManager().disconnect(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// 连接
|
||||
// WKIM.getInstance().getConnectionManager().connection();
|
||||
// WKIM.getInstance().getConnectionManager().connection();
|
||||
}
|
||||
|
||||
private void getData(long oldOrderSeq, int pullMode, boolean contain, boolean isResetData) {
|
||||
@ -224,6 +268,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
itemType = 0;
|
||||
}
|
||||
}
|
||||
if (msgList.get(i).remoteExtra != null && msgList.get(i).remoteExtra.revoke == 1) {
|
||||
itemType = 4;
|
||||
}
|
||||
UIMessageEntity entity = new UIMessageEntity(msgList.get(i), itemType);
|
||||
list.add(entity);
|
||||
}
|
||||
@ -243,12 +290,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
// WKIM.getInstance().getConnectionManager().disconnect(true);
|
||||
// 取消监听
|
||||
WKIM.getInstance().getMsgManager().removeNewMsgListener("new_msg");
|
||||
WKIM.getInstance().getMsgManager().removeSendMsgCallBack("insert_msg");
|
||||
WKIM.getInstance().getMsgManager().removeSendMsgAckListener("ack_key");
|
||||
WKIM.getInstance().getConnectionManager().removeOnConnectionStatusListener("main_act");
|
||||
WKIM.getInstance().getMsgManager().removeNewMsgListener(channelID);
|
||||
WKIM.getInstance().getMsgManager().removeSendMsgCallBack(channelID);
|
||||
WKIM.getInstance().getMsgManager().removeSendMsgAckListener(channelID);
|
||||
WKIM.getInstance().getMsgManager().removeRefreshMsgListener(channelID);
|
||||
WKIM.getInstance().getMsgManager().removeClearMsg(channelID);
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,23 @@
|
||||
package com.xinbida.wukongdemo;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
|
||||
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
|
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
|
||||
import com.lxj.xpopup.XPopup;
|
||||
import com.xinbida.wukongim.WKIM;
|
||||
import com.xinbida.wukongim.entity.WKChannelType;
|
||||
import com.xinbida.wukongim.message.type.WKSendMsgResult;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
class MessageAdapter extends BaseMultiItemQuickAdapter<UIMessageEntity, BaseViewHolder> {
|
||||
|
||||
@ -17,6 +26,7 @@ class MessageAdapter extends BaseMultiItemQuickAdapter<UIMessageEntity, BaseView
|
||||
addItemType(0, R.layout.recv_text_layout);
|
||||
addItemType(2, R.layout.send_order_layout);
|
||||
addItemType(3, R.layout.recv_order_layout);
|
||||
addItemType(4, R.layout.item_revoke_layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -32,22 +42,60 @@ class MessageAdapter extends BaseMultiItemQuickAdapter<UIMessageEntity, BaseView
|
||||
statusIV.setImageResource(R.mipmap.error);
|
||||
}
|
||||
}
|
||||
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());
|
||||
|
||||
|
||||
if (uiMessageEntity.getItemType() != 4) {
|
||||
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);
|
||||
if (uiMessageEntity.msg.baseContentMsgModel != null) {
|
||||
contentTv.setText(uiMessageEntity.msg.baseContentMsgModel.getDisplayContent());
|
||||
}
|
||||
}
|
||||
AppCompatImageView imageView = baseViewHolder.getViewOrNull(R.id.avatarIV);
|
||||
if (imageView != null) {
|
||||
GlideUtil.Companion.showAvatarImg(getContext(), HttpUtil.getInstance().getAvatar(uiMessageEntity.msg.fromUID, WKChannelType.PERSONAL), imageView);
|
||||
}
|
||||
|
||||
View contentLayout = baseViewHolder.getViewOrNull(R.id.contentLayout);
|
||||
if (contentLayout != null) {
|
||||
final XPopup.Builder builder = new XPopup.Builder(contentLayout.getContext())
|
||||
.atView(contentLayout).hasShadowBg(false);
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add(getContext().getString(R.string.msg_delete));
|
||||
if (!TextUtils.isEmpty(uiMessageEntity.msg.fromUID) && uiMessageEntity.msg.fromUID.equals(Const.Companion.getUid())) {
|
||||
list.add(getContext().getString(R.string.msg_revoke));
|
||||
}
|
||||
String[] str = new String[list.size()];
|
||||
list.toArray(str);
|
||||
contentLayout.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
builder.asAttachList(str, null,
|
||||
(position, text) -> {
|
||||
if (position == 0) {
|
||||
if (uiMessageEntity.msg.messageSeq > 0) {
|
||||
HttpUtil.getInstance().deleteMsg(uiMessageEntity.msg.channelID, uiMessageEntity.msg.channelType, uiMessageEntity.msg.messageSeq, uiMessageEntity.msg.messageID, uiMessageEntity.msg.messageID);
|
||||
} else {
|
||||
WKIM.getInstance().getMsgManager().deleteWithClientMsgNO(uiMessageEntity.msg.clientMsgNO);
|
||||
}
|
||||
} else {
|
||||
if (uiMessageEntity.msg.messageSeq > 0) {
|
||||
HttpUtil.getInstance().revokeMsg(uiMessageEntity.msg.channelID, uiMessageEntity.msg.channelType, uiMessageEntity.msg.messageID, uiMessageEntity.msg.messageID);
|
||||
}
|
||||
}
|
||||
})
|
||||
.show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.xinbida.wukongdemo
|
||||
import android.app.Application
|
||||
import android.text.TextUtils
|
||||
import com.xinbida.wukongim.WKIM
|
||||
import com.xinbida.wukongim.entity.WKChannel
|
||||
import com.xinbida.wukongim.entity.WKChannelType
|
||||
import com.xinbida.wukongim.entity.WKSyncChat
|
||||
import com.xinbida.wukongim.entity.WKSyncConvMsg
|
||||
@ -13,7 +12,6 @@ import com.xinbida.wukongim.interfaces.ISyncConversationChatBack
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import kotlin.math.abs
|
||||
|
||||
class WKApplication : Application() {
|
||||
|
||||
@ -82,6 +80,36 @@ class WKApplication : Application() {
|
||||
) { msg -> iSyncChannelMsgBack?.onBack(msg) }
|
||||
}.start()
|
||||
}
|
||||
|
||||
// cmd监听
|
||||
WKIM.getInstance().cmdManager.addCmdListener("application"
|
||||
) { cmd ->
|
||||
if (cmd?.cmdKey == "channelUpdate") {
|
||||
val channelId = cmd.paramJsonObject?.optString("channel_id")
|
||||
val channelType = cmd.paramJsonObject?.optInt("channel_type")
|
||||
if (!TextUtils.isEmpty(channelId)) {
|
||||
if (channelType?.toByte() == WKChannelType.GROUP) {
|
||||
HttpUtil.getInstance().getGroupInfo(channelId)
|
||||
} else {
|
||||
HttpUtil.getInstance().getUserInfo(channelId)
|
||||
}
|
||||
}
|
||||
} else if (cmd?.cmdKey == "unreadClear") {
|
||||
// sdk内部处理了该cmd
|
||||
// val channelId = cmd.paramJsonObject?.optString("channel_id")
|
||||
// val channelType = cmd.paramJsonObject?.optInt("channel_type")
|
||||
// val unread = cmd.paramJsonObject?.optInt("unread")
|
||||
// WKIM.getInstance().conversationManager.updateRedDot(
|
||||
// channelId,
|
||||
// channelType!!.toByte(),
|
||||
// unread!!
|
||||
// )
|
||||
} else if (cmd?.cmdKey == "messageRevoke") {
|
||||
val channelId = cmd.paramJsonObject?.optString("channel_id")
|
||||
val channelType = cmd.paramJsonObject?.optInt("channel_type")
|
||||
HttpUtil.getInstance().syncMsgExtra(channelId, channelType!!.toByte())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun syncConv(
|
||||
|
@ -20,21 +20,13 @@
|
||||
android:layout_weight="1"
|
||||
android:gravity="center|start">
|
||||
|
||||
<View
|
||||
android:id="@+id/connectionIv"
|
||||
android:layout_width="15dp"
|
||||
android:layout_height="15dp"
|
||||
android:background="@drawable/success" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/connectionTv"
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/nameTV"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:text="连接成功"
|
||||
android:textColor="@color/success"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
|
21
app/src/main/res/layout/item_revoke_layout.xml
Normal file
21
app/src/main/res/layout/item_revoke_layout.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?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_margin="10dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp">
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:text="@string/msg_revoked"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
@ -9,18 +9,15 @@
|
||||
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" />
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/avatarIV"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@color/purple_200" />
|
||||
|
||||
<com.cxd.chatview.moudle.ChatView xmlns:chat="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/contentLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
|
@ -9,26 +9,23 @@
|
||||
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" />
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/avatarIV"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@color/purple_200" />
|
||||
|
||||
<com.cxd.chatview.moudle.ChatView xmlns:chat="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/contentLayout"
|
||||
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:layout_marginStart="10dp"
|
||||
android:paddingBottom="10dp"
|
||||
chat:arrow_direction="left"
|
||||
chat:arrow_height="12dp"
|
||||
|
@ -11,6 +11,7 @@
|
||||
android:paddingBottom="5dp">
|
||||
|
||||
<com.cxd.chatview.moudle.ChatView xmlns:chat="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/contentLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
@ -112,14 +113,11 @@
|
||||
|
||||
</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" />
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/avatarIV"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@color/purple_200" />
|
||||
|
||||
</LinearLayout>
|
@ -11,6 +11,7 @@
|
||||
android:paddingBottom="5dp">
|
||||
|
||||
<com.cxd.chatview.moudle.ChatView xmlns:chat="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/contentLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
@ -32,9 +33,9 @@
|
||||
chat:stroke_width="1px">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<TextView
|
||||
@ -59,14 +60,11 @@
|
||||
|
||||
</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" />
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/avatarIV"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@color/purple_200" />
|
||||
|
||||
</LinearLayout>
|
@ -16,4 +16,10 @@
|
||||
<string name="send">Send</string>
|
||||
<string name="send_order">Customize</string>
|
||||
<string name="input">Input…</string>
|
||||
<string name="msg_revoked">Message has been withdrawn</string>
|
||||
<string name="clear_channel_message">Clear channel message</string>
|
||||
<string name="update_group_name">Update group name</string>
|
||||
<string name="input_group_name">Input group name…</string>
|
||||
<string name="msg_delete">Delete</string>
|
||||
<string name="msg_revoke">Revoke</string>
|
||||
</resources>
|
||||
|
@ -16,4 +16,10 @@
|
||||
<string name="send">发送</string>
|
||||
<string name="send_order">自定义</string>
|
||||
<string name="input">请输入内容</string>
|
||||
<string name="msg_revoked">消息被撤回</string>
|
||||
<string name="clear_channel_message">清空聊天记录</string>
|
||||
<string name="update_group_name">修改群名称</string>
|
||||
<string name="input_group_name">请输入群名称…</string>
|
||||
<string name="msg_delete">删除消息</string>
|
||||
<string name="msg_revoke">撤回消息</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user