mirror of
https://github.com/WuKongIM/WuKongIMAndroidSDK
synced 2025-06-05 00:28:22 +00:00
fix:udpate demo
This commit is contained in:
parent
c5f52cdb24
commit
70a9054c5f
@ -1,7 +1,6 @@
|
||||
package com.xinbida.wukongdemo
|
||||
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter
|
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder
|
||||
@ -17,8 +16,12 @@ class ConvAdapter :
|
||||
super.convert(holder, item, payloads)
|
||||
val msg = payloads[0] as WKUIConversationMsg
|
||||
if (msg.wkChannel != null) {
|
||||
holder.setText(R.id.nameTV,item.wkChannel.channelName)
|
||||
GlideUtil.showAvatarImg(context, msg.wkChannel.avatar, holder.getView(R.id.avatarIV))
|
||||
holder.setText(R.id.nameTV, item.wkChannel.channelName)
|
||||
GlideUtil.showAvatarImg(context,
|
||||
HttpUtil.getInstance()
|
||||
.getAvatar(item.wkChannel.channelID, item.wkChannel.channelType),
|
||||
holder.getView(R.id.avatarIV)
|
||||
)
|
||||
}
|
||||
if (msg.wkMsg != null && msg.wkMsg.baseContentMsgModel != null) {
|
||||
val content = msg.wkMsg.baseContentMsgModel.displayContent
|
||||
@ -39,17 +42,20 @@ 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, item.wkChannel.avatar, holder.getView(R.id.avatarIV))
|
||||
holder.setText(R.id.nameTV, item.wkChannel.channelName)
|
||||
GlideUtil.showAvatarImg(context,
|
||||
HttpUtil.getInstance()
|
||||
.getAvatar(item.wkChannel.channelID, item.wkChannel.channelType),
|
||||
holder.getView(R.id.avatarIV))
|
||||
} else {
|
||||
WKIM.getInstance().channelManager.fetchChannelInfo(item.channelID, item.channelType)
|
||||
}
|
||||
|
||||
holder.getView<View>(R.id.contentLayout).setOnClickListener {
|
||||
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)
|
||||
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)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,11 @@ import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import com.xinbida.wukongim.WKIM;
|
||||
import com.xinbida.wukongim.entity.WKChannel;
|
||||
import com.xinbida.wukongim.entity.WKChannelType;
|
||||
import com.xinbida.wukongim.entity.WKSyncChannelMsg;
|
||||
import com.xinbida.wukongim.entity.WKSyncExtraMsg;
|
||||
import com.xinbida.wukongim.entity.WKSyncRecent;
|
||||
import com.xinbida.wukongim.utils.WKLoggerUtils;
|
||||
|
||||
@ -26,8 +30,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class HttpUtil {
|
||||
// public String apiURL = "http://62.234.8.38:7090/v1";
|
||||
public String apiURL = "http://175.27.245.108:15001";
|
||||
public String apiURL = "http://62.234.8.38:7090/v1";
|
||||
|
||||
private static class HttpUtilTypeClass {
|
||||
private static final HttpUtil instance = new HttpUtil();
|
||||
@ -37,6 +40,13 @@ public class HttpUtil {
|
||||
return HttpUtilTypeClass.instance;
|
||||
}
|
||||
|
||||
public String getAvatar(String channelId, byte channelType) {
|
||||
if (channelType == WKChannelType.PERSONAL) {
|
||||
return apiURL + "/users/" + channelId + "/avatar";
|
||||
}
|
||||
return apiURL + "/groups/" + channelId + "/avatar";
|
||||
}
|
||||
|
||||
public void post(String url, JSONObject data, final IResult iResult) {
|
||||
try {
|
||||
HttpURLConnection conn = (HttpURLConnection) new URL(apiURL + url).openConnection();
|
||||
@ -118,7 +128,7 @@ public class HttpUtil {
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
post("/channel/messagesync", jsonObject, (code, data) -> {
|
||||
post("/message/channel/sync", jsonObject, (code, data) -> {
|
||||
if (code == 200) {
|
||||
try {
|
||||
WKSyncChannelMsg msg = new WKSyncChannelMsg();
|
||||
@ -146,9 +156,10 @@ public class HttpUtil {
|
||||
String channel_id = msgJson.optString("channel_id");
|
||||
byte channel_type = (byte) msgJson.optInt("channel_type");
|
||||
long timestamp = msgJson.optLong("timestamp");
|
||||
String payload = msgJson.optString("payload");
|
||||
byte[] b = Base64.decode(payload, Base64.DEFAULT);
|
||||
String content = new String(b);
|
||||
|
||||
String content = msgJson.optString("payload");
|
||||
// byte[] b = Base64.decode(payload, Base64.DEFAULT);
|
||||
// String content = new String(b);
|
||||
WKSyncRecent recent = new WKSyncRecent();
|
||||
recent.from_uid = from_uid;
|
||||
recent.message_id = msgJson.optString("message_id");
|
||||
@ -169,6 +180,20 @@ public class HttpUtil {
|
||||
recent.payload = hashMap;
|
||||
}
|
||||
}
|
||||
if (msgJson.has("message_extra")) {
|
||||
JSONObject extraJson = msgJson.optJSONObject("message_extra");
|
||||
if (extraJson == null) {
|
||||
return recent;
|
||||
}
|
||||
WKSyncExtraMsg extraMsg = new WKSyncExtraMsg();
|
||||
extraMsg.message_id_str = extraJson.optString("message_id_str");
|
||||
extraMsg.revoke = extraJson.optInt("revoke");
|
||||
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");
|
||||
recent.message_extra = extraMsg;
|
||||
}
|
||||
return recent;
|
||||
}
|
||||
|
||||
@ -187,4 +212,39 @@ public class HttpUtil {
|
||||
public interface IMsgResult {
|
||||
void onResult(WKSyncChannelMsg msg);
|
||||
}
|
||||
|
||||
public void getUserInfo(String uid) {
|
||||
new Thread(() -> get("/users/" + uid, (code, data) -> {
|
||||
if (code == 200 && !TextUtils.isEmpty(data)) {
|
||||
try {
|
||||
JSONObject json = new JSONObject(data);
|
||||
WKChannel channel = new WKChannel(uid, WKChannelType.PERSONAL);
|
||||
channel.channelName = json.optString("name");
|
||||
channel.avatar = json.optString("avatar");
|
||||
WKIM.getInstance().getChannelManager().saveOrUpdateChannel(channel);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
})).start();
|
||||
}
|
||||
|
||||
public void getGroupInfo(String groupNO) {
|
||||
new Thread(() -> get("/groups/" + groupNO, (code, data) -> {
|
||||
if (code == 200 && !TextUtils.isEmpty(data)) {
|
||||
try {
|
||||
JSONObject json = new JSONObject(data);
|
||||
WKChannel channel = new WKChannel(groupNO, WKChannelType.GROUP);
|
||||
channel.channelName = json.optString("name");
|
||||
channel.avatar = json.optString("avatar");
|
||||
WKIM.getInstance().getChannelManager().saveOrUpdateChannel(channel);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
})).start();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
new Thread(() -> HttpUtil.getInstance().post("/user/token", jsonObject, (code, data) -> {
|
||||
new Thread(() -> HttpUtil.getInstance().post("/user/login", jsonObject, (code, data) -> {
|
||||
if (code == 200) {
|
||||
runOnUiThread(()->{
|
||||
Const.Companion.setToken(token);
|
||||
|
@ -181,14 +181,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
@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) {
|
||||
@ -243,8 +243,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
// 断开连接
|
||||
WKIM.getInstance().getConnectionManager().disconnect(true);
|
||||
// WKIM.getInstance().getConnectionManager().disconnect(true);
|
||||
// 取消监听
|
||||
WKIM.getInstance().getMsgManager().removeNewMsgListener("new_msg");
|
||||
WKIM.getInstance().getMsgManager().removeSendMsgCallBack("insert_msg");
|
||||
|
@ -23,29 +23,13 @@ class WKApplication : Application() {
|
||||
}
|
||||
|
||||
|
||||
private val avatars = arrayOf(
|
||||
"https://lmg.jj20.com/up/allimg/tx29/06052048151752929.png",
|
||||
"https://img1.baidu.com/it/u=1653751609,236581088&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500",
|
||||
"https://img0.baidu.com/it/u=1008951549,1654888911&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800",
|
||||
"https://lmg.jj20.com/up/allimg/tx30/10121138219844229.jpg",
|
||||
"https://lmg.jj20.com/up/allimg/tx28/430423183653303.jpg",
|
||||
"https://lmg.jj20.com/up/allimg/tx23/520420024834916.jpg",
|
||||
"https://himg.bdimg.com/sys/portraitn/item/public.1.a535a65d.tJe8MgWmP8zJ456B73Kzfg",
|
||||
"https://img2.baidu.com/it/u=3324164588,1070151830&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500",
|
||||
"https://img1.baidu.com/it/u=3916753633,2634890492&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400",
|
||||
"https://img0.baidu.com/it/u=4210586523,443489101&fm=253&fmt=auto&app=138&f=JPEG?w=304&h=304",
|
||||
"https://img2.baidu.com/it/u=2559320899,1546883787&fm=253&fmt=auto&app=138&f=JPEG?w=441&h=499",
|
||||
"https://img0.baidu.com/it/u=2952429745,3806929819&fm=253&fmt=auto&app=138&f=JPEG?w=380&h=380",
|
||||
"https://img2.baidu.com/it/u=3783923022,668713258&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
|
||||
)
|
||||
|
||||
private fun initListener() {
|
||||
// 注册自定义消息
|
||||
WKIM.getInstance().msgManager.registerContentMsg(OrderMessageContent::class.java)
|
||||
// 连接地址
|
||||
WKIM.getInstance().connectionManager.addOnGetIpAndPortListener { andPortListener: IGetSocketIpAndPortListener ->
|
||||
Thread {
|
||||
HttpUtil.getInstance()["/route", { code: Int, data: String ->
|
||||
HttpUtil.getInstance()["/users/${Const.uid}/route", { code: Int, data: String ->
|
||||
if (code == 200 && !TextUtils.isEmpty(data)) {
|
||||
try {
|
||||
val jsonObject = JSONObject(data)
|
||||
@ -66,16 +50,11 @@ class WKApplication : Application() {
|
||||
}
|
||||
// 对接频道资料(群信息/用户信息)
|
||||
WKIM.getInstance().channelManager.addOnGetChannelInfoListener { channelId, channelType, _ ->
|
||||
val channel = WKChannel(channelId, channelType)
|
||||
if (channelType == WKChannelType.PERSONAL) {
|
||||
channel.channelName = "单聊${channelId.hashCode()}"
|
||||
HttpUtil.getInstance().getUserInfo(channelId)
|
||||
} else {
|
||||
channel.channelName = "群聊${channelId.hashCode()}"
|
||||
HttpUtil.getInstance().getGroupInfo(channelId)
|
||||
}
|
||||
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)
|
||||
null
|
||||
}
|
||||
|
||||
@ -112,20 +91,27 @@ class WKApplication : Application() {
|
||||
iSyncConvChatBack: ISyncConversationChatBack?
|
||||
) {
|
||||
val json = JSONObject()
|
||||
json.put("uid", Const.uid)
|
||||
json.put("login_uid", Const.uid)
|
||||
json.put("version", version)
|
||||
json.put("last_msg_seqs", lastMsgSeqs)
|
||||
json.put("msg_count", msgCount)
|
||||
json.put("device_uuid", Const.uid)
|
||||
Thread {
|
||||
HttpUtil.getInstance().post(
|
||||
"/conversation/sync", json
|
||||
) { code, data ->
|
||||
if (code != 200 || TextUtils.isEmpty(data)) {
|
||||
iSyncConvChatBack?.onBack(null)
|
||||
return@post
|
||||
}
|
||||
val arr = JSONArray(data!!)
|
||||
val chat = getWKSyncChat(arr)
|
||||
iSyncConvChatBack?.onBack(chat)
|
||||
val dataJson = JSONObject(data)
|
||||
val arr = dataJson.optJSONArray("conversations")
|
||||
if (arr != null && arr.length() > 0) {
|
||||
val chat = getWKSyncChat(arr)
|
||||
iSyncConvChatBack?.onBack(chat)
|
||||
return@post
|
||||
}
|
||||
iSyncConvChatBack?.onBack(null)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user