发送文本消息
这个提交包含在:
父节点
03a5b6ecb3
当前提交
50dbad6855
@ -1,56 +0,0 @@
|
|||||||
package cn.org.bjca.trust.android.lib.im.bean;
|
|
||||||
|
|
||||||
import cn.org.bjca.trust.android.lib.im.bean.message.TextMessage;
|
|
||||||
import cn.org.bjca.trust.android.lib.im.enums.MsgType;
|
|
||||||
|
|
||||||
public class SZYXMessage {
|
|
||||||
/**
|
|
||||||
* 消息id
|
|
||||||
*/
|
|
||||||
private String msgId;
|
|
||||||
/**
|
|
||||||
*发送者信息
|
|
||||||
*/
|
|
||||||
private UserInfo fromClient;
|
|
||||||
/**
|
|
||||||
*接收者信息
|
|
||||||
*/
|
|
||||||
private UserInfo toClient;
|
|
||||||
/**
|
|
||||||
*真实讲话人
|
|
||||||
*/
|
|
||||||
private UserInfo speaker;
|
|
||||||
/**
|
|
||||||
*自定义信息
|
|
||||||
*/
|
|
||||||
private String describe;
|
|
||||||
/**
|
|
||||||
*是不是群消息
|
|
||||||
*/
|
|
||||||
private boolean isGroup;
|
|
||||||
/**
|
|
||||||
*是不是接收消息
|
|
||||||
*/
|
|
||||||
private boolean isArrive;
|
|
||||||
/**
|
|
||||||
*消息发送状态
|
|
||||||
*/
|
|
||||||
private boolean isSuccess;
|
|
||||||
/**
|
|
||||||
*时间戳
|
|
||||||
*/
|
|
||||||
private long timestamp;
|
|
||||||
/**
|
|
||||||
*租户编号
|
|
||||||
*/
|
|
||||||
private String tenantNo;
|
|
||||||
/**
|
|
||||||
*消息序列号
|
|
||||||
*/
|
|
||||||
private long seq;
|
|
||||||
/**
|
|
||||||
* 消息类型
|
|
||||||
*/
|
|
||||||
private MsgType msgType;
|
|
||||||
private TextMessage textMessage;
|
|
||||||
}
|
|
||||||
@ -2,21 +2,14 @@ package cn.org.bjca.trust.android.lib.im.bean;
|
|||||||
|
|
||||||
public class UserInfo {
|
public class UserInfo {
|
||||||
private String userId;
|
private String userId;
|
||||||
|
private String userName;
|
||||||
|
private String password;
|
||||||
|
private String appId;
|
||||||
|
private String osType;
|
||||||
private String nickName;
|
private String nickName;
|
||||||
private String faceUrl;
|
private String faceUrl;
|
||||||
private String gender;
|
private String gender;
|
||||||
|
|
||||||
public UserInfo(String userId) {
|
|
||||||
this.userId = userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserInfo(String userId, String nickName, String faceUrl, String gender) {
|
|
||||||
this.userId = userId;
|
|
||||||
this.nickName = nickName;
|
|
||||||
this.faceUrl = faceUrl;
|
|
||||||
this.gender = gender;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserId() {
|
public String getUserId() {
|
||||||
return userId;
|
return userId;
|
||||||
}
|
}
|
||||||
@ -25,6 +18,38 @@ public class UserInfo {
|
|||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppId() {
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppId(String appId) {
|
||||||
|
this.appId = appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOsType() {
|
||||||
|
return osType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOsType(String osType) {
|
||||||
|
this.osType = osType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getNickName() {
|
public String getNickName() {
|
||||||
return nickName;
|
return nickName;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,27 +0,0 @@
|
|||||||
package cn.org.bjca.trust.android.lib.im.bean.message;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
public class TextMessage {
|
|
||||||
private String text;
|
|
||||||
|
|
||||||
public TextMessage(String text) {
|
|
||||||
this.text = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getText() {
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setText(String text) {
|
|
||||||
this.text = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "TextMessage{" +
|
|
||||||
"text='" + text + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,5 +1,7 @@
|
|||||||
package cn.org.bjca.trust.android.lib.im.cfg;
|
package cn.org.bjca.trust.android.lib.im.cfg;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public class Constant {
|
public class Constant {
|
||||||
public static final String BaseUrl = "https://221n3i2201.goho.co";
|
public static final String BaseUrl = "https://221n3i2201.goho.co";
|
||||||
|
|
||||||
@ -11,11 +13,11 @@ public class Constant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getSdkAppID() {
|
public static String getSdkAppID() {
|
||||||
return sdkAppID;
|
return Constant.sdkAppID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getUserId() {
|
public static String getUserId() {
|
||||||
return userId;
|
return Constant.userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setUserId(String userId) {
|
public static void setUserId(String userId) {
|
||||||
|
|||||||
@ -6,15 +6,18 @@ public enum PacketType {
|
|||||||
CONNECTED(11),
|
CONNECTED(11),
|
||||||
//发送消息
|
//发送消息
|
||||||
SEND(20),
|
SEND(20),
|
||||||
ARRIVE(21),
|
SEND_ACK(21),
|
||||||
|
ARRIVE(30),
|
||||||
|
ARRIVE_ACK(31),
|
||||||
//心跳包
|
//心跳包
|
||||||
PING(30),
|
PING(40),
|
||||||
PANG(31),
|
PANG(41),
|
||||||
//数据请求
|
//数据请求
|
||||||
REQUEST(40),
|
REQUEST(50),
|
||||||
RESULT(41),
|
RESULT(51),
|
||||||
//系统通知
|
//系统通知
|
||||||
SYSTEM(50),
|
SYSTEM(60),
|
||||||
|
SYSTEM_ACK(61),
|
||||||
UNKNOWN(-1);
|
UNKNOWN(-1);
|
||||||
|
|
||||||
private int type = -1;
|
private int type = -1;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ public class IMHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static IMInterface getInstance() {
|
public static IMInterface getInstance() {
|
||||||
return IMHelper.IMHelperHolder.instance;
|
return IMHelperHolder.instance;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,15 @@
|
|||||||
package cn.org.bjca.trust.android.lib.im.im.bean;
|
package cn.org.bjca.trust.android.lib.im.im.bean;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import cn.org.bjca.trust.android.lib.im.cfg.Constant;
|
import cn.org.bjca.trust.android.lib.im.cfg.Constant;
|
||||||
import cn.org.bjca.trust.android.lib.im.enums.PacketType;
|
import cn.org.bjca.trust.android.lib.im.enums.PacketType;
|
||||||
|
|
||||||
public abstract class PacketMessage {
|
public abstract class PacketMessage {
|
||||||
|
/**
|
||||||
|
* 消息id
|
||||||
|
*/
|
||||||
|
private String msgId = UUID.randomUUID().toString();
|
||||||
private PacketType packetType;
|
private PacketType packetType;
|
||||||
private long timestamp = System.currentTimeMillis();
|
private long timestamp = System.currentTimeMillis();
|
||||||
private String appId = Constant.getSdkAppID();
|
private String appId = Constant.getSdkAppID();
|
||||||
@ -13,6 +19,14 @@ public abstract class PacketMessage {
|
|||||||
this.packetType = packetType;
|
this.packetType = packetType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMsgId() {
|
||||||
|
return msgId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsgId(String msgId) {
|
||||||
|
this.msgId = msgId;
|
||||||
|
}
|
||||||
|
|
||||||
public PacketType getPacketType() {
|
public PacketType getPacketType() {
|
||||||
return packetType;
|
return packetType;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package cn.org.bjca.trust.android.lib.im.im.kit;
|
package cn.org.bjca.trust.android.lib.im.im.kit;
|
||||||
|
|
||||||
|
import cn.org.bjca.trust.android.lib.im.enums.MsgType;
|
||||||
import cn.org.bjca.trust.android.lib.im.im.msg.SZYXMessage;
|
import cn.org.bjca.trust.android.lib.im.im.msg.SZYXMessage;
|
||||||
import cn.org.bjca.trust.android.lib.im.im.opt.ImConnectOptions;
|
import cn.org.bjca.trust.android.lib.im.im.opt.ImConnectOptions;
|
||||||
import cn.org.bjca.trust.android.lib.im.kit.IMSDKCallback;
|
import cn.org.bjca.trust.android.lib.im.kit.IMSDKCallback;
|
||||||
@ -8,13 +9,23 @@ import cn.org.bjca.trust.android.lib.im.kit.MsgListener;
|
|||||||
|
|
||||||
public interface IMInterface {
|
public interface IMInterface {
|
||||||
void addMsgListener(MsgListener listener);
|
void addMsgListener(MsgListener listener);
|
||||||
|
|
||||||
void removeMsgListener(MsgListener listener);
|
void removeMsgListener(MsgListener listener);
|
||||||
|
|
||||||
void setStatusListener(IMSDKListener listener);
|
void setStatusListener(IMSDKListener listener);
|
||||||
|
|
||||||
void removeStatusListener(IMSDKListener listener);
|
void removeStatusListener(IMSDKListener listener);
|
||||||
|
|
||||||
void login(ImConnectOptions imConnectOptions);
|
void login(ImConnectOptions imConnectOptions);
|
||||||
|
|
||||||
void logout();
|
void logout();
|
||||||
|
|
||||||
boolean isConnect();
|
boolean isConnect();
|
||||||
|
|
||||||
boolean isConnecting();
|
boolean isConnecting();
|
||||||
|
|
||||||
void sendSZYXMessage(SZYXMessage message, IMSDKCallback callback);
|
void sendSZYXMessage(SZYXMessage message, IMSDKCallback callback);
|
||||||
|
|
||||||
|
SZYXMessage createMsg(MsgType msgType, String toUserId, boolean isGroup, Object message, String describe);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
package cn.org.bjca.trust.android.lib.im.im.manager;
|
package cn.org.bjca.trust.android.lib.im.im.manager;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.os.Message;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
||||||
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
|
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
|
||||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||||
@ -10,13 +16,23 @@ import org.eclipse.paho.client.mqttv3.MqttException;
|
|||||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import cn.org.bjca.trust.android.lib.im.cfg.Constant;
|
import cn.org.bjca.trust.android.lib.im.cfg.Constant;
|
||||||
import cn.org.bjca.trust.android.lib.im.common.DeviceHelper;
|
import cn.org.bjca.trust.android.lib.im.common.DeviceHelper;
|
||||||
import cn.org.bjca.trust.android.lib.im.common.json.GsonImplHelp;
|
import cn.org.bjca.trust.android.lib.im.common.json.GsonImplHelp;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.enums.MsgType;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.enums.PacketType;
|
||||||
import cn.org.bjca.trust.android.lib.im.im.bean.PacketMessage;
|
import cn.org.bjca.trust.android.lib.im.im.bean.PacketMessage;
|
||||||
import cn.org.bjca.trust.android.lib.im.im.kit.IMInterface;
|
import cn.org.bjca.trust.android.lib.im.im.kit.IMInterface;
|
||||||
import cn.org.bjca.trust.android.lib.im.im.msg.ConnectMessage;
|
import cn.org.bjca.trust.android.lib.im.im.msg.ConnectMessage;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.im.msg.ConnectedMessage;
|
||||||
import cn.org.bjca.trust.android.lib.im.im.msg.SZYXMessage;
|
import cn.org.bjca.trust.android.lib.im.im.msg.SZYXMessage;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.im.msg.SendAckMessage;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.im.msg.message.SZYXTextMessage;
|
||||||
import cn.org.bjca.trust.android.lib.im.im.opt.ImConnectOptions;
|
import cn.org.bjca.trust.android.lib.im.im.opt.ImConnectOptions;
|
||||||
import cn.org.bjca.trust.android.lib.im.kit.IMSDKCallback;
|
import cn.org.bjca.trust.android.lib.im.kit.IMSDKCallback;
|
||||||
import cn.org.bjca.trust.android.lib.im.kit.IMSDKListener;
|
import cn.org.bjca.trust.android.lib.im.kit.IMSDKListener;
|
||||||
@ -26,6 +42,25 @@ import kotlin.text.Charsets;
|
|||||||
public class ImManager implements IMInterface {
|
public class ImManager implements IMInterface {
|
||||||
private final String TAG = "ImManager";
|
private final String TAG = "ImManager";
|
||||||
|
|
||||||
|
//登录成功
|
||||||
|
private String topic_connected;
|
||||||
|
|
||||||
|
// 新消息到达
|
||||||
|
private String topic_arrive;
|
||||||
|
|
||||||
|
// 发送消息应答
|
||||||
|
private String topic_send_ack;
|
||||||
|
|
||||||
|
// 心跳应答
|
||||||
|
private String topic_pang;
|
||||||
|
|
||||||
|
|
||||||
|
// 数据请求回复
|
||||||
|
private String topic_result;
|
||||||
|
|
||||||
|
// 系统消息
|
||||||
|
private String topic_system;
|
||||||
|
|
||||||
private MqttClient mqttClient;
|
private MqttClient mqttClient;
|
||||||
private MqttConnectOptions connectOptions;
|
private MqttConnectOptions connectOptions;
|
||||||
|
|
||||||
@ -33,15 +68,18 @@ public class ImManager implements IMInterface {
|
|||||||
|
|
||||||
private IMSDKListener statusListener;
|
private IMSDKListener statusListener;
|
||||||
|
|
||||||
|
private final List<MsgListener> msgListeners = new ArrayList<>();
|
||||||
|
private final Map<String, IMSDKCallback> msgListenerMap = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addMsgListener(MsgListener listener) {
|
public void addMsgListener(MsgListener listener) {
|
||||||
|
msgListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeMsgListener(MsgListener listener) {
|
public void removeMsgListener(MsgListener listener) {
|
||||||
|
msgListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -54,6 +92,16 @@ public class ImManager implements IMInterface {
|
|||||||
this.statusListener = null;
|
this.statusListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void initTopic() {
|
||||||
|
topic_send_ack = Constant.getSdkAppID() + "/" + PacketType.SEND_ACK + Constant.getUserId();
|
||||||
|
topic_connected = Constant.getSdkAppID() + "/" + PacketType.CONNECTED + Constant.getUserId();
|
||||||
|
topic_arrive = Constant.getSdkAppID() + "/" + PacketType.ARRIVE + Constant.getUserId();
|
||||||
|
topic_pang = Constant.getSdkAppID() + "/" + PacketType.PANG + Constant.getUserId();
|
||||||
|
topic_result = Constant.getSdkAppID() + "/" + PacketType.RESULT + Constant.getUserId();
|
||||||
|
topic_system = Constant.getSdkAppID() + "/" + PacketType.SYSTEM + Constant.getUserId();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void login(ImConnectOptions imConnectOptions) {
|
public void login(ImConnectOptions imConnectOptions) {
|
||||||
if (this.isConnect()) this.logout();
|
if (this.isConnect()) this.logout();
|
||||||
@ -65,6 +113,7 @@ public class ImManager implements IMInterface {
|
|||||||
connectOptions.setConnectionTimeout(30);
|
connectOptions.setConnectionTimeout(30);
|
||||||
connectOptions.setKeepAliveInterval(20);
|
connectOptions.setKeepAliveInterval(20);
|
||||||
connectOptions.setAutomaticReconnect(true);
|
connectOptions.setAutomaticReconnect(true);
|
||||||
|
initTopic();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mqttClient = new MqttClient("tcp://" + imConnectOptions.getHost() + ":" + imConnectOptions.getPort(),
|
mqttClient = new MqttClient("tcp://" + imConnectOptions.getHost() + ":" + imConnectOptions.getPort(),
|
||||||
@ -76,11 +125,13 @@ public class ImManager implements IMInterface {
|
|||||||
status = 0;
|
status = 0;
|
||||||
if (reconnect) return;
|
if (reconnect) return;
|
||||||
try {
|
try {
|
||||||
mqttClient.subscribe(Constant.getSdkAppID() + "/message:" + Constant.getUserId(), 2);
|
mqttClient.subscribe(topic_connected, 2);
|
||||||
mqttClient.subscribe(Constant.getSdkAppID() + "/pang:" + Constant.getUserId(), 2);
|
mqttClient.subscribe(topic_arrive, 2);
|
||||||
mqttClient.subscribe(Constant.getSdkAppID() + "/connect:" + Constant.getUserId(), 2);
|
mqttClient.subscribe(topic_send_ack, 2);
|
||||||
mqttClient.subscribe(Constant.getSdkAppID() + "/result:" + Constant.getUserId(), 2);
|
mqttClient.subscribe(topic_pang, 2);
|
||||||
mqttClient.subscribe(Constant.getSdkAppID() + "/notice:" + Constant.getUserId(), 2);
|
mqttClient.subscribe(topic_result, 2);
|
||||||
|
mqttClient.subscribe(topic_system, 2);
|
||||||
|
Log.e("======>connectComplete", topic_send_ack);
|
||||||
} catch (MqttException e) {
|
} catch (MqttException e) {
|
||||||
Log.e(TAG, "=====>connectComplete", e);
|
Log.e(TAG, "=====>connectComplete", e);
|
||||||
}
|
}
|
||||||
@ -97,12 +148,52 @@ public class ImManager implements IMInterface {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageArrived(String topic, MqttMessage message) throws Exception {
|
public void messageArrived(String topic, MqttMessage message) throws Exception {
|
||||||
Log.e("======>messageArrived", topic + "::" + new String(message.getPayload(), Charsets.UTF_8));
|
String msg = new String(message.getPayload(), Charsets.UTF_8);
|
||||||
|
// 登录应答
|
||||||
|
if (topic.equals(topic_connected)) {
|
||||||
|
ConnectedMessage connectedMessage = GsonImplHelp.get().toObject(msg, ConnectedMessage.class);
|
||||||
|
if (connectedMessage.getStatus() == 200) {
|
||||||
|
if (statusListener != null) statusListener.onConnectSuccess();
|
||||||
|
} else {
|
||||||
|
if (statusListener != null)
|
||||||
|
statusListener.onConnectFailed(connectedMessage.getStatus(), connectedMessage.getMsg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 发送消息应答
|
||||||
|
else if (topic.equals(topic_send_ack)) {
|
||||||
|
SendAckMessage sendAckMessage = GsonImplHelp.get().toObject(msg, SendAckMessage.class);
|
||||||
|
|
||||||
|
Message m = new Message();
|
||||||
|
m.obj = sendAckMessage.getAckId();
|
||||||
|
m.what = 10002;
|
||||||
|
handler.sendMessage(m);
|
||||||
|
|
||||||
|
}
|
||||||
|
// 新消息送达
|
||||||
|
else if (topic.equals(topic_arrive)) {
|
||||||
|
SZYXMessage szyxMessage = GsonImplHelp.get().toObject(msg, SZYXMessage.class);
|
||||||
|
sendAckMsg(szyxMessage.getMsgId());
|
||||||
|
Log.d("======>新消息送达", topic + "::\n" + msg);
|
||||||
|
for (MsgListener listener : msgListeners) {
|
||||||
|
listener.messageArrive(new ArrayList<SZYXMessage>() {
|
||||||
|
{
|
||||||
|
add(szyxMessage);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
Log.e("======>messageArrived", topic + "::" + msg);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deliveryComplete(IMqttDeliveryToken token) {
|
public void deliveryComplete(IMqttDeliveryToken token) {
|
||||||
Log.e("======>deliveryComplete", "token.getMessage().toString()");
|
try {
|
||||||
|
if (token.getMessage() != null && token.getMessage().getPayload() != null)
|
||||||
|
Log.e("======>deliveryComplete", new String(token.getMessage().getPayload(), Charsets.UTF_8));
|
||||||
|
} catch (MqttException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -145,17 +236,47 @@ public class ImManager implements IMInterface {
|
|||||||
return this.status == 1;
|
return this.status == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SZYXMessage createMsg(MsgType msgType, String toUserId, boolean isGroup, Object message, String describe) {
|
||||||
|
|
||||||
|
SZYXMessage szyxMessage = new SZYXMessage(msgType);
|
||||||
|
szyxMessage.setArrive(false);
|
||||||
|
szyxMessage.setDescribe(describe);
|
||||||
|
szyxMessage.setGroup(isGroup);
|
||||||
|
szyxMessage.setStatus(1);
|
||||||
|
szyxMessage.setFromClient(UserManager.getInstance().getUserInfo());
|
||||||
|
if (isGroup)
|
||||||
|
szyxMessage.setGroupID(toUserId);
|
||||||
|
else
|
||||||
|
szyxMessage.setToClientId(toUserId);
|
||||||
|
switch (msgType) {
|
||||||
|
case Text:
|
||||||
|
szyxMessage.setTextMessage((SZYXTextMessage) message);
|
||||||
|
break;
|
||||||
|
case Voice:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return szyxMessage;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendSZYXMessage(SZYXMessage message, IMSDKCallback callback) {
|
public void sendSZYXMessage(SZYXMessage message, IMSDKCallback callback) {
|
||||||
sendPacketMessage(message, callback);
|
sendPacketMessage(PacketType.SEND, message, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendConnectMsg() {
|
private void sendConnectMsg() {
|
||||||
ConnectMessage message = new ConnectMessage(DeviceHelper.getDevice());
|
ConnectMessage message = new ConnectMessage(DeviceHelper.getDevice());
|
||||||
sendPacketMessage(message, null);
|
sendPacketMessage(PacketType.CONNECT, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendPacketMessage(PacketMessage message, IMSDKCallback callback) {
|
private void sendAckMsg(String msgId) {
|
||||||
|
SendAckMessage message = new SendAckMessage();
|
||||||
|
message.setMsgId(msgId);
|
||||||
|
sendPacketMessage(PacketType.SEND_ACK, message, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendPacketMessage(PacketType packetType, PacketMessage message, IMSDKCallback callback) {
|
||||||
if (null == connectOptions) {
|
if (null == connectOptions) {
|
||||||
if (null != callback) callback.failed(204, "未登录");
|
if (null != callback) callback.failed(204, "未登录");
|
||||||
return;
|
return;
|
||||||
@ -166,10 +287,63 @@ public class ImManager implements IMInterface {
|
|||||||
}
|
}
|
||||||
String msg = GsonImplHelp.get().toJson(message);
|
String msg = GsonImplHelp.get().toJson(message);
|
||||||
try {
|
try {
|
||||||
mqttClient.publish("server", msg.getBytes(Charsets.UTF_8), 2, false);
|
mqttClient.publish("server" + packetType, msg.getBytes(Charsets.UTF_8), 2, false);
|
||||||
|
// 如果是发送的消息,需要应答
|
||||||
|
if (PacketType.SEND == packetType) {
|
||||||
|
if (null != callback)
|
||||||
|
msgListenerMap.put(message.getMsgId(), callback);
|
||||||
|
else msgListenerMap.put(message.getMsgId(), new IMSDKCallback() {
|
||||||
|
@Override
|
||||||
|
public void success() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(int code, String error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Message m = new Message();
|
||||||
|
m.obj = message.getMsgId();
|
||||||
|
m.what = 10001;
|
||||||
|
handler.sendMessageDelayed(m, 1500);
|
||||||
|
}
|
||||||
} catch (MqttException e) {
|
} catch (MqttException e) {
|
||||||
if (null != callback) callback.failed(206, e.getMessage());
|
if (null != callback) callback.failed(206, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Handler handler = new Handler(Looper.getMainLooper()) {
|
||||||
|
@SuppressLint("HandlerLeak")
|
||||||
|
@Override
|
||||||
|
public void handleMessage(@NonNull Message msg) {
|
||||||
|
super.handleMessage(msg);
|
||||||
|
String msgId = (String) msg.obj;
|
||||||
|
switch (msg.what) {
|
||||||
|
case 10001:
|
||||||
|
IMSDKCallback callback = msgListenerMap.get(msgId);
|
||||||
|
if (null != callback) {
|
||||||
|
callback.failed(207, "发送超时");
|
||||||
|
msgListenerMap.remove(msgId);
|
||||||
|
|
||||||
|
for (MsgListener listener : msgListeners) {
|
||||||
|
listener.statusChange(msgId, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 10002:
|
||||||
|
IMSDKCallback callback1 = msgListenerMap.get(msgId);
|
||||||
|
if (null != callback1) {
|
||||||
|
for (MsgListener listener : msgListeners) {
|
||||||
|
listener.statusChange(msgId, 0);
|
||||||
|
}
|
||||||
|
callback1.success();
|
||||||
|
msgListenerMap.remove(msgId);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,30 @@
|
|||||||
|
package cn.org.bjca.trust.android.lib.im.im.manager;
|
||||||
|
|
||||||
|
import cn.org.bjca.trust.android.lib.im.bean.UserInfo;
|
||||||
|
|
||||||
|
public class UserManager {
|
||||||
|
|
||||||
|
public static UserManager getInstance() {
|
||||||
|
return UserManagerHolder.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class UserManagerHolder {
|
||||||
|
static final UserManager instance = new UserManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
private UserManager() {
|
||||||
|
|
||||||
|
}
|
||||||
|
private UserInfo userInfo;
|
||||||
|
|
||||||
|
public UserInfo getUserInfo() {
|
||||||
|
return userInfo;
|
||||||
|
}
|
||||||
|
public UserInfo getUserInfoForMessage() {
|
||||||
|
return userInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserInfo(UserInfo userInfo) {
|
||||||
|
this.userInfo = userInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package cn.org.bjca.trust.android.lib.im.im.msg;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.org.bjca.trust.android.lib.im.enums.PacketType;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.im.bean.PacketMessage;
|
||||||
|
|
||||||
|
public class ConnectedMessage extends PacketMessage {
|
||||||
|
public ConnectedMessage() {
|
||||||
|
super(PacketType.CONNECTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int status;
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,10 +1,121 @@
|
|||||||
package cn.org.bjca.trust.android.lib.im.im.msg;
|
package cn.org.bjca.trust.android.lib.im.im.msg;
|
||||||
|
|
||||||
|
import cn.org.bjca.trust.android.lib.im.bean.UserInfo;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.enums.MsgType;
|
||||||
import cn.org.bjca.trust.android.lib.im.enums.PacketType;
|
import cn.org.bjca.trust.android.lib.im.enums.PacketType;
|
||||||
import cn.org.bjca.trust.android.lib.im.im.bean.PacketMessage;
|
import cn.org.bjca.trust.android.lib.im.im.bean.PacketMessage;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.im.msg.message.SZYXTextMessage;
|
||||||
|
|
||||||
public class SZYXMessage extends PacketMessage {
|
public class SZYXMessage extends PacketMessage {
|
||||||
public SZYXMessage() {
|
public SZYXMessage(MsgType msgType) {
|
||||||
super(PacketType.SEND);
|
super(PacketType.SEND);
|
||||||
|
this.msgType = msgType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送者信息
|
||||||
|
*/
|
||||||
|
private UserInfo fromClient;
|
||||||
|
/**
|
||||||
|
* 接收者信息
|
||||||
|
*/
|
||||||
|
private String toClientId;
|
||||||
|
/**
|
||||||
|
* 群id
|
||||||
|
*/
|
||||||
|
private String groupID;
|
||||||
|
/**
|
||||||
|
* 自定义信息(备注信息,描述信息)
|
||||||
|
*/
|
||||||
|
private String describe;
|
||||||
|
/**
|
||||||
|
* 是不是群消息
|
||||||
|
*/
|
||||||
|
private boolean isGroup;
|
||||||
|
/**
|
||||||
|
* 是不是接收消息
|
||||||
|
*/
|
||||||
|
private boolean isArrive;
|
||||||
|
/**
|
||||||
|
* 消息发送状态 -1=失败;0=成功;1=发送中
|
||||||
|
*/
|
||||||
|
private int status;
|
||||||
|
/**
|
||||||
|
* 消息类型
|
||||||
|
*/
|
||||||
|
private MsgType msgType;
|
||||||
|
private SZYXTextMessage textMessage;
|
||||||
|
|
||||||
|
public UserInfo getFromClient() {
|
||||||
|
return fromClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFromClient(UserInfo fromClient) {
|
||||||
|
this.fromClient = fromClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getToClientId() {
|
||||||
|
return toClientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToClientId(String toClientId) {
|
||||||
|
this.toClientId = toClientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupID() {
|
||||||
|
return groupID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupID(String groupID) {
|
||||||
|
this.groupID = groupID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescribe() {
|
||||||
|
return describe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescribe(String describe) {
|
||||||
|
this.describe = describe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGroup() {
|
||||||
|
return isGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroup(boolean group) {
|
||||||
|
isGroup = group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isArrive() {
|
||||||
|
return isArrive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArrive(boolean arrive) {
|
||||||
|
isArrive = arrive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MsgType getMsgType() {
|
||||||
|
return msgType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsgType(MsgType msgType) {
|
||||||
|
this.msgType = msgType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SZYXTextMessage getTextMessage() {
|
||||||
|
return textMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTextMessage(SZYXTextMessage textMessage) {
|
||||||
|
this.textMessage = textMessage;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,20 @@
|
|||||||
|
package cn.org.bjca.trust.android.lib.im.im.msg;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.org.bjca.trust.android.lib.im.enums.PacketType;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.im.bean.PacketMessage;
|
||||||
|
|
||||||
|
public class SendAckMessage extends PacketMessage {
|
||||||
|
public SendAckMessage() {
|
||||||
|
super(PacketType.SEND_ACK);
|
||||||
|
}
|
||||||
|
private String ackId;
|
||||||
|
|
||||||
|
public String getAckId() {
|
||||||
|
return ackId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAckId(String ackId) {
|
||||||
|
this.ackId = ackId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package cn.org.bjca.trust.android.lib.im.im.msg.message;
|
||||||
|
|
||||||
|
public class SZYXTextMessage {
|
||||||
|
private String text;
|
||||||
|
|
||||||
|
public SZYXTextMessage(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,8 +2,14 @@ package cn.org.bjca.trust.android.lib.im.kit;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import cn.org.bjca.trust.android.lib.im.bean.SZYXMessage;
|
import cn.org.bjca.trust.android.lib.im.im.msg.SZYXMessage;
|
||||||
|
|
||||||
public interface MsgListener {
|
public interface MsgListener {
|
||||||
void messageArrive(List<SZYXMessage> messages);
|
void messageArrive(List<SZYXMessage> messages);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param msgId 消息唯一id
|
||||||
|
* @param status -1=失败;0=成功;1=发送中
|
||||||
|
*/
|
||||||
|
void statusChange(String msgId, int status);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package cn.org.bjca.trust.android.lib.im.kit;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import cn.org.bjca.trust.android.lib.im.im.msg.SZYXMessage;
|
||||||
|
|
||||||
public interface SdkInterface {
|
public interface SdkInterface {
|
||||||
|
|
||||||
void setIMSDKListener(IMSDKListener listener);
|
void setIMSDKListener(IMSDKListener listener);
|
||||||
@ -18,9 +20,9 @@ public interface SdkInterface {
|
|||||||
|
|
||||||
void removeMsgListener(MsgListener listener);
|
void removeMsgListener(MsgListener listener);
|
||||||
|
|
||||||
void sendMsgForTextToC(String toUserId, String text, IMSDKCallback callback);
|
SZYXMessage sendMsgForTextToC(String toUserId, String text, IMSDKCallback callback);
|
||||||
|
|
||||||
void sendMsgForTextToG(String toGroupId, String text, IMSDKCallback callback);
|
SZYXMessage sendMsgForTextToG(String toGroupId, String text, IMSDKCallback callback);
|
||||||
|
|
||||||
String getVersion();
|
String getVersion();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,12 @@ import cn.org.bjca.trust.android.lib.im.BuildConfig;
|
|||||||
import cn.org.bjca.trust.android.lib.im.SZYXDbHelper;
|
import cn.org.bjca.trust.android.lib.im.SZYXDbHelper;
|
||||||
import cn.org.bjca.trust.android.lib.im.cfg.Constant;
|
import cn.org.bjca.trust.android.lib.im.cfg.Constant;
|
||||||
import cn.org.bjca.trust.android.lib.im.common.DeviceHelper;
|
import cn.org.bjca.trust.android.lib.im.common.DeviceHelper;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.enums.MsgType;
|
||||||
import cn.org.bjca.trust.android.lib.im.http.HttpManage;
|
import cn.org.bjca.trust.android.lib.im.http.HttpManage;
|
||||||
import cn.org.bjca.trust.android.lib.im.im.IMHelper;
|
import cn.org.bjca.trust.android.lib.im.im.IMHelper;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.im.manager.UserManager;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.im.msg.SZYXMessage;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.im.msg.message.SZYXTextMessage;
|
||||||
import cn.org.bjca.trust.android.lib.im.im.opt.ImConnectOptions;
|
import cn.org.bjca.trust.android.lib.im.im.opt.ImConnectOptions;
|
||||||
import cn.org.bjca.trust.android.lib.im.kit.IMSDKCallback;
|
import cn.org.bjca.trust.android.lib.im.kit.IMSDKCallback;
|
||||||
import cn.org.bjca.trust.android.lib.im.kit.IMSDKListener;
|
import cn.org.bjca.trust.android.lib.im.kit.IMSDKListener;
|
||||||
@ -58,7 +62,8 @@ public class SZYXImManager implements SdkInterface {
|
|||||||
if (null != callback) callback.success();
|
if (null != callback) callback.success();
|
||||||
if (null != imsdkListener) imsdkListener.onConnecting();
|
if (null != imsdkListener) imsdkListener.onConnecting();
|
||||||
LoginBean bean = httpResult.getData();
|
LoginBean bean = httpResult.getData();
|
||||||
imLogin(bean.getHost(), bean.getPort(), bean.getClientId(), bean.getToken());
|
UserManager.getInstance().setUserInfo(bean.getUserInfo());
|
||||||
|
imLogin(bean.getHost(), bean.getPort(), bean.getUserInfo().getUserName(), bean.getUserInfo().getPassword());
|
||||||
} else if (null != callback) callback.failed(1001, httpResult.getMsg());
|
} else if (null != callback) callback.failed(1001, httpResult.getMsg());
|
||||||
}, throwable -> {
|
}, throwable -> {
|
||||||
if (null != callback) callback.failed(1001, throwable.getMessage());
|
if (null != callback) callback.failed(1001, throwable.getMessage());
|
||||||
@ -85,13 +90,23 @@ public class SZYXImManager implements SdkInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMsgForTextToC(String toUserId, String text, IMSDKCallback callback) {
|
public SZYXMessage sendMsgForTextToC(String toUserId, String text, IMSDKCallback callback) {
|
||||||
// IMHelper.getInstance().sendSZYXMessage();
|
SZYXTextMessage textMessage = new SZYXTextMessage(text);
|
||||||
|
|
||||||
|
SZYXMessage szyxMessage = IMHelper.getInstance().createMsg(MsgType.Text, toUserId, false, textMessage, null);
|
||||||
|
|
||||||
|
IMHelper.getInstance().sendSZYXMessage(szyxMessage, callback);
|
||||||
|
return szyxMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMsgForTextToG(String toGroupId, String text, IMSDKCallback callback) {
|
public SZYXMessage sendMsgForTextToG(String toGroupId, String text, IMSDKCallback callback) {
|
||||||
|
SZYXTextMessage textMessage = new SZYXTextMessage(text);
|
||||||
|
|
||||||
|
SZYXMessage szyxMessage = IMHelper.getInstance().createMsg(MsgType.Text, toGroupId, true, textMessage, null);
|
||||||
|
|
||||||
|
IMHelper.getInstance().sendSZYXMessage(szyxMessage, callback);
|
||||||
|
return szyxMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
package cn.org.bjca.trust.android.lib.im.repository.bean;
|
package cn.org.bjca.trust.android.lib.im.repository.bean;
|
||||||
|
|
||||||
|
import cn.org.bjca.trust.android.lib.im.bean.UserInfo;
|
||||||
|
|
||||||
public class LoginBean {
|
public class LoginBean {
|
||||||
private String host;
|
private String host;
|
||||||
private String port;
|
private String port;
|
||||||
private String clientId;
|
private UserInfo userInfo;
|
||||||
private String token;
|
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return host;
|
return host;
|
||||||
@ -22,19 +23,11 @@ public class LoginBean {
|
|||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClientId() {
|
public UserInfo getUserInfo() {
|
||||||
return clientId;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClientId(String clientId) {
|
public void setUserInfo(UserInfo userInfo) {
|
||||||
this.clientId = clientId;
|
this.userInfo = userInfo;
|
||||||
}
|
|
||||||
|
|
||||||
public String getToken() {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setToken(String token) {
|
|
||||||
this.token = token;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
package cn.org.bjca.trust.android.imdemo.ui;
|
package cn.org.bjca.trust.android.imdemo.ui;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.xuqm.base.common.ToolsHelper;
|
||||||
import com.xuqm.base.ui.BaseActivity;
|
import com.xuqm.base.ui.BaseActivity;
|
||||||
|
|
||||||
import cn.org.bjca.trust.android.imdemo.R;
|
import cn.org.bjca.trust.android.imdemo.R;
|
||||||
import cn.org.bjca.trust.android.imdemo.databinding.ActivityChatBinding;
|
import cn.org.bjca.trust.android.imdemo.databinding.ActivityChatBinding;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.SZYXImSdk;
|
||||||
|
import cn.org.bjca.trust.android.lib.im.kit.IMSDKCallback;
|
||||||
|
|
||||||
public class ChatActivity extends BaseActivity<ActivityChatBinding> {
|
public class ChatActivity extends BaseActivity<ActivityChatBinding> {
|
||||||
|
|
||||||
@ -18,6 +22,25 @@ public class ChatActivity extends BaseActivity<ActivityChatBinding> {
|
|||||||
public void initView(Bundle savedInstanceState) {
|
public void initView(Bundle savedInstanceState) {
|
||||||
super.initView(savedInstanceState);
|
super.initView(savedInstanceState);
|
||||||
String userId = getIntent().getStringExtra("userId");
|
String userId = getIntent().getStringExtra("userId");
|
||||||
getBinding().text.setText(userId);
|
String userName = getIntent().getStringExtra("userName");
|
||||||
|
setTitleText(userName + "(" + userId + ")");
|
||||||
|
getBaseBinding().baseToolbar.getToolbarMenu().setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
getBinding().btnSend.setOnClickListener(v -> {
|
||||||
|
String msg = getBinding().et.getText().toString();
|
||||||
|
if (!ToolsHelper.isNull(msg)) {
|
||||||
|
SZYXImSdk.getInstance().sendMsgForTextToC(userId, "hello world", new IMSDKCallback() {
|
||||||
|
@Override
|
||||||
|
public void success() {
|
||||||
|
ToolsHelper.showMessage("发送消息成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(int code, String error) {
|
||||||
|
ToolsHelper.showMessage("发送消息失败" + error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,6 +30,7 @@ public class FriendsActivity extends BaseListActivity<UserItem, FriendsVM> {
|
|||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(mContext, ChatActivity.class);
|
Intent intent = new Intent(mContext, ChatActivity.class);
|
||||||
intent.putExtra("userId", item.getUserId());
|
intent.putExtra("userId", item.getUserId());
|
||||||
|
intent.putExtra("userName", item.getNickName());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -120,8 +120,8 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
loadingProgressBar.setVisibility(View.VISIBLE);
|
loadingProgressBar.setVisibility(View.VISIBLE);
|
||||||
loginViewModel.login(usernameEditText.getText().toString(),
|
// loginViewModel.login(usernameEditText.getText().toString(),
|
||||||
passwordEditText.getText().toString());
|
// passwordEditText.getText().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUiWithUser(LoggedInUserView model) {
|
private void updateUiWithUser(LoggedInUserView model) {
|
||||||
|
|||||||
@ -8,15 +8,64 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".ui.ChatActivity">
|
tools:context=".ui.ChatActivity">
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/text"
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
android:layout_width="wrap_content"
|
android:id="@+id/refreshLayout"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:text="hello"
|
android:layout_height="0dp"
|
||||||
|
android:tag="layout/activity_base_list_0"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/line"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<com.xuqm.base.view.EmptyView
|
||||||
|
android:id="@+id/baseEmptyView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/baseRecyclerView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:overScrollMode="never" />
|
||||||
|
|
||||||
|
</com.xuqm.base.view.EmptyView>
|
||||||
|
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/line"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="@color/line"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/tools" />
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:id="@+id/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="60dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/et"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:layout_marginHorizontal="5dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toStartOf="@+id/btn_send"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_send"
|
||||||
|
android:layout_width="65dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:layout_marginHorizontal="5dp"
|
||||||
|
android:text="发送"
|
||||||
|
android:textSize="11sp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</layout>
|
</layout>
|
||||||
正在加载...
在新工单中引用
屏蔽一个用户