update
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package com.shayu.onetoone.manager;
|
||||
|
||||
import com.shayu.onetoone.bean.MessageConsumeConfigBean;
|
||||
import com.shayu.onetoone.bean.SendConsumeBean;
|
||||
import com.shayu.onetoone.listener.OnSendMessageListener;
|
||||
import com.yunbao.common.bean.HttpCallbackModel;
|
||||
import com.yunbao.common.http.base.HttpCallback;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
|
||||
@@ -13,8 +13,8 @@ import java.util.UUID;
|
||||
public class SendMessageManager {
|
||||
private static final Map<String, SendData> cache = new HashMap<>();
|
||||
|
||||
public static void sendMessageForGift(String toUid,String giftId,OnSendMessageListener listener){
|
||||
SendData sendData = new SendData(Integer.parseInt(toUid),
|
||||
public static void sendMessageForGift(String toUid, String giftId, OnSendMessageListener listener) {
|
||||
SendData sendData = new SendData(toUid,
|
||||
3,
|
||||
giftId,
|
||||
"礼物消息",
|
||||
@@ -22,8 +22,9 @@ public class SendMessageManager {
|
||||
1);
|
||||
send(sendData, listener);
|
||||
}
|
||||
public static void sendMessageForAudio(String toUid,OnSendMessageListener listener){
|
||||
SendData sendData = new SendData(Integer.parseInt(toUid),
|
||||
|
||||
public static void sendMessageForAudio(String toUid, OnSendMessageListener listener) {
|
||||
SendData sendData = new SendData(toUid,
|
||||
1,
|
||||
"not",
|
||||
"录音消息",
|
||||
@@ -31,8 +32,9 @@ public class SendMessageManager {
|
||||
1);
|
||||
send(sendData, listener);
|
||||
}
|
||||
|
||||
public static void sendMessageForText(String toUid, String text, OnSendMessageListener messageListener) {
|
||||
SendData sendData = new SendData(Integer.parseInt(toUid),
|
||||
SendData sendData = new SendData(toUid,
|
||||
1,
|
||||
"not",
|
||||
text,
|
||||
@@ -41,6 +43,82 @@ public class SendMessageManager {
|
||||
send(sendData, messageListener);
|
||||
}
|
||||
|
||||
public static void checkVideoMessage(String toUid, String time, OnSendMessageListener listener) {
|
||||
SendData sendData = new SendData(toUid,
|
||||
2,
|
||||
"not",
|
||||
"视频消息",
|
||||
time,
|
||||
2,
|
||||
false
|
||||
);
|
||||
send(sendData, listener);
|
||||
}
|
||||
|
||||
public static void checkAudioMessage(String toUid, String time, OnSendMessageListener listener) {
|
||||
SendData sendData = new SendData(toUid,
|
||||
5,
|
||||
"not",
|
||||
"音频消息",
|
||||
time,
|
||||
2,
|
||||
false
|
||||
);
|
||||
send(sendData, listener);
|
||||
}
|
||||
|
||||
public static void pingVideoMessage(String toUid, String time, OnSendMessageListener listener) {
|
||||
SendData sendData = new SendData(toUid,
|
||||
2,
|
||||
"not",
|
||||
"视频消息",
|
||||
time,
|
||||
2,
|
||||
"after",
|
||||
false
|
||||
);
|
||||
send(sendData, listener);
|
||||
}
|
||||
|
||||
public static void pingAudioMessage(String toUid, String time, OnSendMessageListener listener) {
|
||||
SendData sendData = new SendData(toUid,
|
||||
5,
|
||||
"not",
|
||||
"音频消息",
|
||||
time,
|
||||
2,
|
||||
"after",
|
||||
false
|
||||
);
|
||||
send(sendData, listener);
|
||||
}
|
||||
|
||||
public static void matching(OnSendMessageListener listener) {
|
||||
SendData sendData = new SendData("not",
|
||||
9,
|
||||
"not",
|
||||
"灵魂匹配",
|
||||
"1",
|
||||
1,
|
||||
"after",
|
||||
false
|
||||
);
|
||||
send(sendData, listener);
|
||||
}
|
||||
|
||||
public static void chatUp(String toUid, OnSendMessageListener listener) {
|
||||
SendData sendData = new SendData(toUid,
|
||||
4,
|
||||
"not",
|
||||
"搭讪消息",
|
||||
"1",
|
||||
1,
|
||||
"after",
|
||||
false
|
||||
);
|
||||
send(sendData, listener);
|
||||
}
|
||||
|
||||
private static void send(SendData sendData, OnSendMessageListener messageListener) {
|
||||
OTONetManager.getInstance(null)
|
||||
.sendMessage(sendData.toUid,
|
||||
@@ -49,35 +127,24 @@ public class SendMessageManager {
|
||||
sendData.content,
|
||||
sendData.time,
|
||||
sendData.online,
|
||||
"before",
|
||||
new HttpCallback<HttpCallbackModel>() {
|
||||
sendData.method,
|
||||
new HttpCallback<SendConsumeBean>() {
|
||||
@Override
|
||||
public void onSuccess(HttpCallbackModel data) {
|
||||
if (data.getCode() != 0) {
|
||||
OTONetManager.getInstance(null)
|
||||
.getMessageConsumeConfig(sendData.toUid + "", new HttpCallback<MessageConsumeConfigBean>() {
|
||||
@Override
|
||||
public void onSuccess(MessageConsumeConfigBean data) {
|
||||
String msg;
|
||||
if (sendData.type == 2) {
|
||||
msg = data.getVideoPrice() + "";
|
||||
} else if (sendData.type == 5) {
|
||||
msg = data.getMp3Price() + "";
|
||||
} else {
|
||||
msg = data.getPrice() + "";
|
||||
}
|
||||
messageListener.onError(OnSendMessageListener.STATUS_NOT_PRICE, msg);
|
||||
}
|
||||
public void onSuccess(SendConsumeBean consumeBean) {
|
||||
if (consumeBean.getCode() != 0) {
|
||||
if (consumeBean.getCode() == 500) {
|
||||
messageListener.onError(OnSendMessageListener.STATUS_NOT_PRICE, consumeBean.getMsg(), consumeBean);
|
||||
} else {
|
||||
messageListener.onError(OnSendMessageListener.STATUS_ERROR, consumeBean.getMsg(), consumeBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
String token = UUID.randomUUID().toString();
|
||||
cache.put(token, sendData);
|
||||
messageListener.onSuccess(token);
|
||||
String token = null;
|
||||
if (sendData.needToken) {
|
||||
token = UUID.randomUUID().toString();
|
||||
cache.put(token, sendData);
|
||||
}
|
||||
messageListener.onSuccess(token, consumeBean);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -102,17 +169,17 @@ public class SendMessageManager {
|
||||
sendData.time,
|
||||
sendData.online,
|
||||
"after",
|
||||
new HttpCallback<HttpCallbackModel>() {
|
||||
new HttpCallback<SendConsumeBean>() {
|
||||
@Override
|
||||
public void onSuccess(HttpCallbackModel sd) {
|
||||
public void onSuccess(SendConsumeBean sd) {
|
||||
if (sd.getCode() != 0) {
|
||||
if(listener!=null) {
|
||||
listener.onSuccess(sd.getMsg());
|
||||
if (listener != null) {
|
||||
listener.onSuccess(sd.getMsg(), sd);
|
||||
}
|
||||
} else {
|
||||
cache.remove(token);
|
||||
if(listener!=null) {
|
||||
listener.onSuccess(null);
|
||||
if (listener != null) {
|
||||
listener.onSuccess(null, sd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +189,7 @@ public class SendMessageManager {
|
||||
public void onError(String error) {
|
||||
ToastUtil.show(error);
|
||||
System.err.println(error);
|
||||
if(listener!=null) {
|
||||
if (listener != null) {
|
||||
listener.onError(OnSendMessageListener.STATUS_ERROR, error);
|
||||
}
|
||||
}
|
||||
@@ -140,14 +207,16 @@ public class SendMessageManager {
|
||||
}
|
||||
|
||||
public static class SendData {
|
||||
private int toUid;
|
||||
public boolean needToken = true;
|
||||
private String toUid;
|
||||
private int type;
|
||||
private String giftId;
|
||||
private String content;
|
||||
private String time;
|
||||
private int online;
|
||||
private String method = "before";
|
||||
|
||||
public SendData(int toUid, int type, String giftId, String content, String time, int online) {
|
||||
public SendData(String toUid, int type, String giftId, String content, String time, int online) {
|
||||
this.toUid = toUid;
|
||||
this.type = type;
|
||||
this.giftId = giftId;
|
||||
@@ -155,6 +224,37 @@ public class SendMessageManager {
|
||||
this.time = time;
|
||||
this.online = online;
|
||||
}
|
||||
|
||||
public SendData(String toUid, int type, String giftId, String content, String time, int online, boolean needToken) {
|
||||
this.needToken = needToken;
|
||||
this.toUid = toUid;
|
||||
this.type = type;
|
||||
this.giftId = giftId;
|
||||
this.content = content;
|
||||
this.time = time;
|
||||
this.online = online;
|
||||
}
|
||||
|
||||
public SendData(String toUid, int type, String giftId, String content, String time, int online, String method) {
|
||||
this.toUid = toUid;
|
||||
this.type = type;
|
||||
this.giftId = giftId;
|
||||
this.content = content;
|
||||
this.time = time;
|
||||
this.online = online;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public SendData(String toUid, int type, String giftId, String content, String time, int online, String method, boolean needToken) {
|
||||
this.needToken = needToken;
|
||||
this.toUid = toUid;
|
||||
this.type = type;
|
||||
this.giftId = giftId;
|
||||
this.content = content;
|
||||
this.time = time;
|
||||
this.online = online;
|
||||
this.method = method;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user