第一次提交

This commit is contained in:
被淹死的鱼
2026-03-11 18:26:29 +08:00
commit cd3b53759e
8532 changed files with 522078 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package com.fengliyan.messaging;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.caivideo.messaging.test", appContext.getPackageName());
}
}

View File

@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fengliyan.messaging" />

View File

@@ -0,0 +1,113 @@
package com.fengliyan.messaging;
import com.alibaba.fastjson.JSONObject;
/**
* Created by zhangbin on 2019/1/11.
*/
public class AttentionAttachment extends CustomAttachment {
/**
"nickname":"小墨",
"avatar":"",
"age":19,
"city":"深圳",
"time":"2017-01-11 22:11:23"
* @param type
*/
private int userid;
private String nickname;
private String avatar;
private int age;
private String city;
private String time;
private int sex;
public int getUserid() {
return userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
AttentionAttachment(int type) {
super(type);
}
@Override
protected void parseData(JSONObject data) {
userid = data.getIntValue("userid");
nickname = data.getString("nickname");
avatar = data.getString("avatar");
age = data.getIntValue("age");
city = data.getString("city");
time = data.getString("time");
sex = data.getIntValue("sex");
}
@Override
protected JSONObject packData() {
JSONObject data =new JSONObject();
data.put("userid", userid);
data.put("nickname", nickname);
data.put("avatar", avatar);
data.put("age", age);
data.put("city", city);
data.put("time", time);
data.put("sex", sex);
return data;
}
}

View File

@@ -0,0 +1,515 @@
package com.fengliyan.messaging;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.Observer;
import com.netease.nimlib.sdk.RequestCallback;
import com.netease.nimlib.sdk.RequestCallbackWrapper;
import com.netease.nimlib.sdk.StatusCode;
import com.netease.nimlib.sdk.auth.AuthService;
import com.netease.nimlib.sdk.auth.AuthServiceObserver;
import com.netease.nimlib.sdk.auth.OnlineClient;
import com.netease.nimlib.sdk.msg.MessageBuilder;
import com.netease.nimlib.sdk.msg.MsgService;
import com.netease.nimlib.sdk.msg.MsgServiceObserve;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.CustomNotification;
import com.netease.nimlib.sdk.msg.model.CustomNotificationConfig;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.netease.nimlib.sdk.msg.model.RecentContact;
import com.netease.nimlib.sdk.uinfo.UserService;
import com.netease.nimlib.sdk.uinfo.constant.UserInfoFieldEnum;
import com.netease.nimlib.sdk.uinfo.model.NimUserInfo;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class ChatManager {
public static final int RECENT_TAG_STICKY = 1;
private static ChatManager mInstance;
private List<RecentContact> mRecentContacts = new ArrayList<>();
private String mAccount;
private MessageReceivedListener mMessageReceivedListener;
private RecentContactQueryListener mRecentContactQueryListener;
public static ChatManager getInstance() {
if(null == mInstance){
mInstance = new ChatManager();
}
return mInstance;
}
private ChatManager(){
}
public interface MessageReceivedListener{
void onMessageReceived(List<IMMessage> messages);
}
public interface RecentContactQueryListener{
void onQueryResultReceived(List<RecentContact> recents, Map<String, NimUserInfo> userInfoList);
}
private interface RecentContactUserInfoListener{
void onUserInfoFetched(List<NimUserInfo> userInfoList);
}
public interface CustomNotificationListener{
void onNotificationReceived(CustomNotification notification);
}
public interface OnlineClientStatusListener{
void onStatusChanged(int status);
void onKickOff();
}
public void setMessageReceivedListener(MessageReceivedListener listener){
mMessageReceivedListener = listener;
}
public void setRecentContactQueryListener(RecentContactQueryListener listener){
mRecentContactQueryListener = listener;
}
// public void init(Application application, StatusBarNotificationConfig statusBarNotificationConfig) {
// NIMClient.init(application,
// loginInfo(application), options(application, statusBarNotificationConfig));
//
// NimUIKit.init(application);
// }
// private SDKOptions options(Context context, StatusBarNotificationConfig config) {
// SDKOptions options = new SDKOptions();
//// StatusBarNotificationConfig config = new StatusBarNotificationConfig();
// config.ledARGB = Color.GREEN;
// config.ledOnMs = 1000;
// config.ledOffMs = 1500;
// options.statusBarNotificationConfig = config;
// String sdkPath = getAppCacheDir(context) + "/nim";
// options.sdkStorageRootPath = sdkPath;
// options.preloadAttach = true;
//
// return options;
// }
// // 如果已经存在用户登录信息返回LoginInfo否则返回null即可
// private LoginInfo loginInfo(Context context) {
// // 从本地读取上次登录成功时保存的用户登录信息
// String account = StorageManager.getInstance(context).getString("account");
// String token = StorageManager.getInstance(context).getString("token");
// mAccount = account;
//
// if (!TextUtils.isEmpty(account) && !TextUtils.isEmpty(token)) {
// return new LoginInfo(account, token);
// } else {
// return null;
// }
// }
/**
* 配置 APP 保存图片/语音/文件/log等数据的目录
* 这里示例用SD卡的应用扩展存储目录
*/
// private String getAppCacheDir(Context context) {
// String storageRootPath = null;
// try {
// if (context.getExternalCacheDir() != null) {
// storageRootPath = context.getExternalCacheDir().getCanonicalPath();
// }
// } catch (IOException e) {
//
// }
// if (TextUtils.isEmpty(storageRootPath)) {
// storageRootPath = Environment.getExternalStorageDirectory() + "/" + context.getPackageName();
// }
//
// return storageRootPath;
// }
// public void doManualLogin(final Context context, String account, String token) {
// LoginInfo info = new LoginInfo(account, token); // config...
// RequestCallback<LoginInfo> callback =
// new RequestCallback<LoginInfo>() {
// @Override
// public void onSuccess(LoginInfo param) {
// mAccount = param.getAccount();
// StorageManager.getInstance(context).putString("account", param.getAccount());
// StorageManager.getInstance(context).putString("token", param.getToken());
// Log.d("nail","LoginInfo===" + param.getAccount());
//
// }
//
// @Override
// public void onFailed(int code) {
// Log.d("nail","code===" + code);
// }
//
// @Override
// public void onException(Throwable exception) {
//
// }
// };
//
// NIMClient.getService(AuthService.class).login(info)
// .setCallback(callback);
// }
public void sendText(String account, String text){
SessionTypeEnum sessionType = SessionTypeEnum.P2P;
String message = text;
IMMessage textMessage = MessageBuilder.createTextMessage(account, sessionType, message);
NIMClient.getService(MsgService.class).sendMessage(textMessage, false);
}
public void sendTextWithCost(String account, String text, int cost, int isCut, int coin){
SessionTypeEnum sessionType = SessionTypeEnum.P2P;
String message = text;
IMMessage textMessage = MessageBuilder.createTextMessage(account, sessionType, message);
Map<String, Object> remoteExtension = new HashMap<>();
remoteExtension.put("cut_coin", cost);
remoteExtension.put("is_cut", isCut);
remoteExtension.put("coin", coin);
textMessage.setRemoteExtension(remoteExtension);
NIMClient.getService(MsgService.class).sendMessage(textMessage, false);
}
public void sendImage(String account, String imagePath){
SessionTypeEnum sessionType = SessionTypeEnum.P2P;
File file = new File(imagePath);
IMMessage message = MessageBuilder.createImageMessage(account, sessionType, file, file.getName());
NIMClient.getService(MsgService.class).sendMessage(message, false);
}
public void sendGift(String account, String giftMessage){
SessionTypeEnum sessionType = SessionTypeEnum.P2P;
IMMessage message = MessageBuilder.createCustomMessage(account, sessionType,
giftMessage, null);
NIMClient.getService(MsgService.class).sendMessage(message, false);
}
public void registerMessageObserver(){
Observer<List<IMMessage>> incomingMessageObserver =
new Observer<List<IMMessage>>() {
@Override
public void onEvent(List<IMMessage> messages) {
queryRecentContacts();
if(null != mMessageReceivedListener){
mMessageReceivedListener.onMessageReceived(messages);
}
}
};
// NIMClient.getService(MsgService.class).registerCustomAttachmentParser(new CustomParser());
NIMClient.getService(MsgServiceObserve.class)
.observeReceiveMessage(incomingMessageObserver, true);
}
public void registerRecentContactsObserver(){
Observer<List<RecentContact>> messageObserver =
new Observer<List<RecentContact>>() {
@Override
public void onEvent(List<RecentContact> messages) {
queryRecentContacts();
}
};
NIMClient.getService(MsgServiceObserve.class)
.observeRecentContact(messageObserver, true);
}
public void queryRecentContacts(){
NIMClient.getService(MsgService.class).queryRecentContacts()
.setCallback(new RequestCallbackWrapper<List<RecentContact>>() {
@Override
public void onResult(int code, List<RecentContact> recents, Throwable e) {
if(null == recents){
return;
}
mRecentContacts = sortRecentContacts(recents);
checkRecentContacts(mRecentContacts);
}
@Override
public void onSuccess(List<RecentContact> result){
mRecentContacts = sortRecentContacts(result);
checkRecentContacts(mRecentContacts);
}
});
}
public void clearRecentContact(String account){
NIMClient.getService(MsgService.class).clearUnreadCount(account, SessionTypeEnum.P2P);
}
public int getAllRecentContactNumber(){
return NIMClient.getService(MsgService.class).getTotalUnreadCount();
}
private void checkRecentContacts(List<RecentContact> result){
if(null == result){
return;
}
Iterator<RecentContact> iterator = result.iterator();
List<String> accountList = new ArrayList<>();
while(iterator.hasNext()){
RecentContact recentContact = iterator.next();
accountList.add(recentContact.getContactId());
}
final List<RecentContact> finalResult = result;
getRecentContactUserInfoList(accountList, new RecentContactUserInfoListener() {
@Override
public void onUserInfoFetched(List<NimUserInfo> userInfoList) {
if(userInfoList.size() == 0){
return;
}
Map<String, NimUserInfo> userInfoMap = new HashMap<>();
Iterator<NimUserInfo> userInfoIterator = userInfoList.iterator();
while (userInfoIterator.hasNext()){
NimUserInfo userInfo = userInfoIterator.next();
userInfoMap.put(userInfo.getAccount(), userInfo);
}
if(null != mRecentContactQueryListener) {
mRecentContactQueryListener.onQueryResultReceived(finalResult,
userInfoMap);
}
}
});
}
public void updateUserInfo(String nickName, String avatarUrl, String age){
Map<UserInfoFieldEnum, Object> fields = new HashMap<>();
fields.put(UserInfoFieldEnum.Name, nickName);
fields.put(UserInfoFieldEnum.AVATAR, avatarUrl);
fields.put(UserInfoFieldEnum.EXTEND, age);
NIMClient.getService(UserService.class).updateUserInfo(fields)
.setCallback(new RequestCallbackWrapper<Void>() {
@Override
public void onResult(int code, Void result, Throwable exception) {
}
});
}
public void getRecentContactUserInfoList(List<String> accounts, final RecentContactUserInfoListener listener){
List<NimUserInfo> users = NIMClient.getService(UserService.class).getUserInfoList(accounts);
if(0 == accounts.size()){
return;
}
if(null == users || 0 == users.size() || users.size() != accounts.size()) {
NIMClient.getService(UserService.class).fetchUserInfo(accounts)
.setCallback(new RequestCallback<List<NimUserInfo>>() {
@Override
public void onSuccess(List<NimUserInfo> userInfoList) {
listener.onUserInfoFetched(userInfoList);
}
@Override
public void onFailed(int code) {
}
@Override
public void onException(Throwable exception) {
}
});
}else{
listener.onUserInfoFetched(users);
}
}
public void sendVideoRequest(String jsonContent, String toUid){
CustomNotification notification = new CustomNotification();
notification.setSessionId(toUid);
notification.setSessionType(SessionTypeEnum.P2P);
notification.setContent(jsonContent);
notification.setSendToOnlineUserOnly(false);
notification.setApnsText("你有一个视频请求");
CustomNotificationConfig config = new CustomNotificationConfig();
config.enablePush = true;
config.enableUnreadCount = false;
notification.setConfig(config);
NIMClient.getService(MsgService.class).sendCustomNotification(notification);
}
public void registerCustomNotification(final CustomNotificationListener listener){
NIMClient.getService(MsgServiceObserve.class).observeCustomNotification(new Observer<CustomNotification>() {
@Override
public void onEvent(CustomNotification customNotification) {
listener.onNotificationReceived(customNotification);
}
}, true);
}
// public void clearUnreadCount(String account){
// NIMClient.getService(MsgService.class).clearUnreadCount(account, SessionTypeEnum.P2P);
// }
//
// public int getTotalUnreadCount(){
// return NIMClient.getService(MsgService.class).getTotalUnreadCount();
// }
//
// public void getUnreadDataList(String messageId, int unreadCount) {
//
// // 锚点
// List<String> uuid = new ArrayList<>(1);
// uuid.add(messageId);
//
// List<IMMessage> messages = NIMClient.getService(MsgService.class).queryMessageListByUuidBlock(uuid);
//
// if (messages == null || messages.size() < 1) {
// return;
// }
// final IMMessage anchor = messages.get(0);
//
// // 查未读消息
// NIMClient.getService(MsgService.class).queryMessageListEx(anchor, QueryDirectionEnum.QUERY_OLD,
// 100, false).setCallback(new RequestCallbackWrapper<List<IMMessage>>() {
//
// @Override
// public void onResult(int code, List<IMMessage> result, Throwable exception) {
// if (code == ResponseCode.RES_SUCCESS && result != null) {
// result.add(0, anchor);
// Collections.reverse(result);
// if(null != mMessageReceivedListener){
// mMessageReceivedListener.onMessageReceived(result);
// }
// }
// }
// });
//
// }
public String getAccount() {
return mAccount;
}
public void addTag(String userId, long tag) {
for(RecentContact recent:mRecentContacts){
if(recent.getContactId().equals(userId)){
tag = recent.getTag() | tag;
recent.setTag(tag);
NIMClient.getService(MsgService.class).updateRecent(recent);
}
}
}
public void removeTag(String userId, long tag) {
for(RecentContact recent:mRecentContacts){
if(recent.getContactId().equals(userId)){
tag = recent.getTag() & ~tag;
recent.setTag(tag);
NIMClient.getService(MsgService.class).updateRecent(recent);
}
}
}
public long getTag(String userId){
for(RecentContact recent:mRecentContacts){
if(recent.getContactId().equals(userId)){
return recent.getTag();
}
}
return 0;
}
public void clearChattingHistory(String account){
NIMClient.getService(MsgService.class).clearChattingHistory(account, SessionTypeEnum.P2P);
}
public void kickOtherClient(){
NIMClient.getService(AuthServiceObserver.class).observeOtherClients(new Observer<List<OnlineClient>>() {
@Override
public void onEvent(List<OnlineClient> onlineClients) {
if(null == onlineClients){
return;
}
Iterator<OnlineClient> clientIterator = onlineClients.iterator();
while (clientIterator.hasNext()){
OnlineClient client = clientIterator.next();
NIMClient.getService(AuthService.class).kickOtherClient(client).setCallback(new RequestCallback<Void>() {
@Override
public void onSuccess(Void param) {
}
@Override
public void onFailed(int code) {
}
@Override
public void onException(Throwable exception) {
}
});
}
}
}, true);
}
public void observeOnlineStatus(final OnlineClientStatusListener listener){
NIMClient.getService(AuthServiceObserver.class).observeOnlineStatus(
new Observer<StatusCode> () {
public void onEvent(StatusCode status) {
if(null != listener){
listener.onStatusChanged(status.getValue());
if(StatusCode.KICK_BY_OTHER_CLIENT == status || StatusCode.KICKOUT == status){
listener.onKickOff();
}
}
}
}, true);
}
public void deleteRecentContact(String userId){
for(RecentContact recent:mRecentContacts){
if(recent.getContactId().equals(userId)){
NIMClient.getService(MsgService.class).deleteRecentContact(recent);
mRecentContacts.remove(recent);
}
}
}
private List<RecentContact> sortRecentContacts(List<RecentContact> list) {
if (list.size() == 0) {
return list;
}
Collections.sort(list, mComp);
return list;
}
private Comparator<RecentContact> mComp = new Comparator<RecentContact>() {
@Override
public int compare(RecentContact o1, RecentContact o2) {
long sticky = (o1.getTag() & RECENT_TAG_STICKY) - (o2.getTag() & RECENT_TAG_STICKY);
if (sticky != 0) {
return sticky > 0 ? -1 : 1;
} else {
long time = o1.getTime() - o2.getTime();
return time == 0 ? 0 : (time > 0 ? -1 : 1);
}
}
};
public List<RecentContact> getRecentContects(){
return mRecentContacts;
}
}

View File

@@ -0,0 +1,41 @@
package com.fengliyan.messaging;
import com.alibaba.fastjson.JSONObject;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
public abstract class CustomAttachment implements MsgAttachment {
// 自定义消息附件的类型,根据该字段区分不同的自定义消息
protected int type;
CustomAttachment(int type) {
this.type = type;
}
// 解析附件内容。
public void fromJson(JSONObject data) {
if (data != null) {
parseData(data);
}
}
// 实现 MsgAttachment 的接口,封装公用字段,然后调用子类的封装函数。
@Override
public String toJson(boolean send) {
return CustomParser.packData(type, packData());
}
// 子类的解析和封装接口。
protected abstract void parseData(JSONObject data);
protected abstract JSONObject packData();
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}

View File

@@ -0,0 +1,78 @@
package com.fengliyan.messaging;
import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachmentParser;
import de.greenrobot.event.EventBus;
public class CustomParser implements MsgAttachmentParser {
// 根据解析到的消息类型,确定附件对象类型
@Override
public MsgAttachment parse(String json) {
CustomAttachment attachment = null;
try {
JSONObject object = JSON.parseObject(json);
int type = object.getInteger("type");
JSONObject data = object.getJSONObject("data");
Log.i("Custom", "type---------->" + type + "parse: data------>" + data.toString());
switch (type) {
case 11:
// attachment = new SysInfoTextAttachment(type);
attachment = new SysInfoAttachment(type);
break;
case 12:
attachment = new SysInfoSingleImageAttachment(type);
break;
case 13:
attachment = new SysInfoDoubleImageAttachment(type);
// ((SysInfoDoubleImageAttachment)attachment).parseArray(object.getString("data"));
break;
case 14:
attachment = new GiftAttachment(type);
EventBus.getDefault().post(new EventBusGiftMessage());
break;
case 15:
attachment = new VideoAttachment(type);
break;
case 16:
attachment = new AttentionAttachment(type);
break;
case 17:
case 24:
case 26:
attachment = new DynamicAttachment(type);
break;
case 18:
attachment = new OnlineNoticeAttachment(type);
break;
case 22:
attachment = new YestordayAttachment(type);
break;
default:
break;
}
if (attachment != null) {
attachment.fromJson(data);
}
} catch (Exception e) {
}
return attachment;
}
public static String packData(int type, JSONObject data) {
JSONObject object = new JSONObject();
object.put("type", type);
if (data != null) {
object.put("data", data);
}
return object.toJSONString();
}
}

View File

@@ -0,0 +1,157 @@
package com.fengliyan.messaging;
import com.alibaba.fastjson.JSONObject;
/**
* Created by zhangbin on 2019/3/20.
*/
public class DynamicAttachment extends CustomAttachment {
private int userid;
private String nickname;
private String image;
private String title;
private String time;
private String avatar;
private String dynamic_id; // 动态ID
private String dynamic_url; // 动态图片
private String comment_id;// 评论ID
private String type_desc; // 回复了你的评论
private String comment_content; //评论的内容人
private String dynamic_content; //动态的内容人
public int getUserid() {
return userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public String getDynamic_id() {
return dynamic_id;
}
public void setDynamic_id(String dynamic_id) {
this.dynamic_id = dynamic_id;
}
public String getDynamic_url() {
return dynamic_url;
}
public void setDynamic_url(String dynamic_url) {
this.dynamic_url = dynamic_url;
}
public String getComment_id() {
return comment_id;
}
public void setComment_id(String comment_id) {
this.comment_id = comment_id;
}
public String getType_desc() {
return type_desc;
}
public void setType_desc(String type_desc) {
this.type_desc = type_desc;
}
public String getComment_content() {
return comment_content;
}
public void setComment_content(String comment_content) {
this.comment_content = comment_content;
}
public String getDynamic_content() {
return dynamic_content;
}
public void setDynamic_content(String dynamic_content) {
this.dynamic_content = dynamic_content;
}
DynamicAttachment(int type) {
super(type);
}
@Override
protected void parseData(JSONObject data) {
userid = data.getIntValue("userid");
nickname = data.getString("nickname");
image = data.getString("image");
title = data.getString("title");
time = data.getString("time");
avatar = data.getString("avatar");
dynamic_id = data.getString("dynamic_id");
dynamic_url = data.getString("dynamic_url");
comment_id = data.getString("comment_id");
type_desc = data.getString("type_desc");
comment_content = data.getString("comment_content");
dynamic_content = data.getString("dynamic_content");
}
@Override
protected JSONObject packData() {
JSONObject data = new JSONObject();
data.put("userid", userid);
data.put("nickname", nickname);
data.put("image", image);
data.put("title", title);
data.put("time", time);
data.put("avatar", avatar);
data.put("dynamic_id", dynamic_id);
data.put("dynamic_url", dynamic_url);
data.put("comment_id", comment_id);
data.put("type_desc", type_desc);
data.put("comment_content", comment_content);
data.put("dynamic_content", dynamic_content);
return data;
}
}

View File

@@ -0,0 +1,5 @@
package com.fengliyan.messaging;
public class EventBusGiftMessage {
}

View File

@@ -0,0 +1,32 @@
package com.fengliyan.messaging;
import java.io.Serializable;
public class FieldListA implements Serializable{
private String n;
private String v;
public String getN() {
return n;
}
public void setN(String n) {
this.n = n;
}
public String getV() {
return v;
}
public void setV(String v) {
this.v = v;
}
@Override
public String toString() {
return "FieldListA{" +
"n='" + n + '\'' +
", v='" + v + '\'' +
'}';
}
}

View File

@@ -0,0 +1,79 @@
package com.fengliyan.messaging;
import java.util.ArrayList;
import java.util.List;
public class Gift {
private int gift_id;
private String gift_name;
private String gift_url;
private int gift_count;
private List<String> from = new ArrayList<>();
private List<String> to = new ArrayList<>();
private int link_type;
private String link_url;
public int getGift_id() {
return gift_id;
}
public void setGift_id(int gift_id) {
this.gift_id = gift_id;
}
public String getGift_name() {
return gift_name;
}
public void setGift_name(String gift_name) {
this.gift_name = gift_name;
}
public String getGift_url() {
return gift_url;
}
public void setGift_url(String gift_url) {
this.gift_url = gift_url;
}
public int getGift_count() {
return gift_count;
}
public void setGift_count(int gift_count) {
this.gift_count = gift_count;
}
public List<String> getFrom() {
return from;
}
public void setFrom(List<String> from) {
this.from = from;
}
public List<String> getTo() {
return to;
}
public void setTo(List<String> to) {
this.to = to;
}
public int getLink_type() {
return link_type;
}
public void setLink_type(int link_type) {
this.link_type = link_type;
}
public String getLink_url() {
return link_url;
}
public void setLink_url(String link_url) {
this.link_url = link_url;
}
}

View File

@@ -0,0 +1,153 @@
package com.fengliyan.messaging;
import com.alibaba.fastjson.JSONObject;
public class GiftAttachment extends CustomAttachment {
private int gift_id;
private String gift_name;
private String gift_url;
private String gift_count;
private String gift_effect;
// private List<String> from = new ArrayList<>();
// private List<String> to = new ArrayList<>();
private int from_uid;
private int to_uid;
private int link_type;
private String link_url;
public int getGift_id() {
return gift_id;
}
public void setGift_id(int gift_id) {
this.gift_id = gift_id;
}
public String getGift_name() {
return gift_name;
}
public void setGift_name(String gift_name) {
this.gift_name = gift_name;
}
public String getGift_url() {
return gift_url;
}
public void setGift_url(String gift_url) {
this.gift_url = gift_url;
}
public String getGift_count() {
return gift_count;
}
public void setGift_count(String gift_count) {
this.gift_count = gift_count;
}
public String getGift_effect() {
return gift_effect;
}
public void setGift_effect(String gift_effect) {
this.gift_effect = gift_effect;
}
// public List<String> getFrom() {
// return from;
// }
//
// public void setFrom(List<String> from) {
// this.from = from;
// }
//
// public List<String> getTo() {
// return to;
// }
//
// public void setTo(List<String> to) {
// this.to = to;
// }
public int getFrom_uid() {
return from_uid;
}
public void setFrom_uid(int from_uid) {
this.from_uid = from_uid;
}
public int getTo_uid() {
return to_uid;
}
public void setTo_uid(int to_uid) {
this.to_uid = to_uid;
}
public int getLink_type() {
return link_type;
}
public void setLink_type(int link_type) {
this.link_type = link_type;
}
public String getLink_url() {
return link_url;
}
public void setLink_url(String link_url) {
this.link_url = link_url;
}
GiftAttachment(int type) {
super(type);
}
@Override
protected void parseData(JSONObject data) {
gift_id = (int) data.get("gift_id");
gift_name = data.getString("gift_name");
gift_url = data.getString("gift_url");
gift_count = data.getString("gift_count");
gift_effect = data.getString("gift_effect");
// from = (List<String>) data.get("from");
// to = (List<String>) data.get("to");
from_uid = (int) data.get("from_uid");
to_uid = (int) data.get("to_uid");
link_type = (int) data.get("link_type");
link_url = data.getString("link_url");
}
@Override
protected JSONObject packData() {
JSONObject data = new JSONObject();
data.put("gift_id", gift_id);
data.put("gift_name", gift_name);
data.put("gift_url", gift_url);
data.put("gift_count", gift_count);
data.put("gift_effect", gift_effect);
data.put("from_uid", from_uid);
data.put("to_uid", to_uid);
data.put("link_type", link_type);
data.put("link_url", link_url);
return data;
}
// @Override
// public String toString() {
// return "GiftAttachment{" +
// "gift_id=" + gift_id +
// ", gift_name='" + gift_name + '\'' +
// ", gift_url='" + gift_url + '\'' +
// ", gift_count=" + gift_count +
// ", from_uid=" + from_uid +
// ", to_uid=" + to_uid +
// ", link_type=" + link_type +
// ", link_url='" + link_url + '\'' +
// '}';
// }
}

View File

@@ -0,0 +1,112 @@
package com.fengliyan.messaging;
import com.alibaba.fastjson.JSONObject;
/**
* Created by zhangbin on 2020/2/8.
*/
public class OnlineNoticeAttachment extends CustomAttachment {
/**
"nickname":"小墨",
"avatar":"",
"age":19,
"city":"深圳",
"time":"2017-01-11 22:11:23"
* @param type
*/
private int userid;
private String nickname;
private String avatar;
private int age;
private String city;
private String time;
private int sex;
public int getUserid() {
return userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
OnlineNoticeAttachment(int type) {
super(type);
}
@Override
protected void parseData(JSONObject data) {
userid = data.getIntValue("userid");
nickname = data.getString("nickname");
avatar = data.getString("avatar");
age = data.getIntValue("age");
city = data.getString("city");
time = data.getString("time");
sex = data.getIntValue("sex");
}
@Override
protected JSONObject packData() {
JSONObject data =new JSONObject();
data.put("userid", userid);
data.put("nickname", nickname);
data.put("avatar", avatar);
data.put("age", age);
data.put("city", city);
data.put("time", time);
data.put("sex", sex);
return data;
}
}

View File

@@ -0,0 +1,38 @@
package com.fengliyan.messaging;
import com.alibaba.fastjson.JSONObject;
/**
* Created by zhangbin on 2018/12/11.
*/
public class SysInfoAttachment extends CustomAttachment {
SysInfoTextBean mSysInfoTextBean;
SysInfoAttachment(int type) {
super(type);
}
@Override
protected void parseData(JSONObject data) {
mSysInfoTextBean = JSONObject.toJavaObject(data, SysInfoTextBean.class);
// mSysInfoTextBean = (SysInfoTextBean) data.get("mSysInfoTextBean");
}
@Override
protected JSONObject packData() {
JSONObject object = new JSONObject();
object.put("mSysInfoTextBean", mSysInfoTextBean);
return object;
}
public SysInfoTextBean getSysInfoTextBean() {
return mSysInfoTextBean;
}
public void setSysInfoTextBean(SysInfoTextBean sysInfoTextBean) {
mSysInfoTextBean = sysInfoTextBean;
}
}

View File

@@ -0,0 +1,41 @@
package com.fengliyan.messaging;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class SysInfoDoubleImageAttachment extends CustomAttachment {
List<SysInfoImage> list = new ArrayList<>();
SysInfoDoubleImageAttachment(int type) {
super(type);
}
@Override
protected void parseData(JSONObject data) {
JSONArray array = data.getJSONArray("list");
list = JSONObject.parseArray(array.toJSONString(), SysInfoImage.class);
// list = array.toJavaList(SysInfoImage.class);
}
@Override
protected JSONObject packData() {
JSONObject data = new JSONObject();
data.put("list", list);
return data;
}
public void parseArray(String data) {
list = JSONObject.parseArray(data, SysInfoImage.class);
}
public List<SysInfoImage> getImageList() {
return list;
}
public void setImageList(List<SysInfoImage> imageList) {
this.list = imageList;
}
}

View File

@@ -0,0 +1,53 @@
package com.fengliyan.messaging;
import java.io.Serializable;
public class SysInfoImage implements Serializable {
private static final long serialVersionUID = -6362623073185926877L;
private String image;
private String title;
private int link_type;
private String link_url;
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getLink_type() {
return link_type;
}
public void setLink_type(int link_type) {
this.link_type = link_type;
}
public String getLink_url() {
return link_url;
}
public void setLink_url(String link_url) {
this.link_url = link_url;
}
@Override
public String toString() {
return "SysInfoImage{" +
"image='" + image + '\'' +
", title='" + title + '\'' +
", link_type=" + link_type +
", link_url='" + link_url + '\'' +
'}';
}
}

View File

@@ -0,0 +1,99 @@
package com.fengliyan.messaging;
import com.alibaba.fastjson.JSONObject;
public class SysInfoSingleImageAttachment extends CustomAttachment {
private int act_type;
private String act_string;
private String image;
private String title;
private String txt;
private int link_type;
private String link_url;
SysInfoSingleImageAttachment(int type) {
super(type);
}
public int getAct_type() {
return act_type;
}
public void setAct_type(int act_type) {
this.act_type = act_type;
}
public String getAct_string() {
return act_string;
}
public void setAct_string(String act_string) {
this.act_string = act_string;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTxt() {
return txt;
}
public void setTxt(String txt) {
this.txt = txt;
}
public int getLink_type() {
return link_type;
}
public void setLink_type(int link_type) {
this.link_type = link_type;
}
public String getLink_url() {
return link_url;
}
public void setLink_url(String link_url) {
this.link_url = link_url;
}
@Override
protected void parseData(JSONObject data) {
act_type = (int) data.get("act_type");
act_string = data.getString("act_string");
image = data.getString("image");
title = data.getString("title");
txt = data.getString("txt");
link_type = (int) data.get("link_type");
link_url = data.getString("link_url");
}
@Override
protected JSONObject packData() {
JSONObject data =new JSONObject();
data.put("act_type", act_type);
data.put("act_string", act_string);
data.put("image", image);
data.put("title", title);
data.put("txt", txt);
data.put("link_type", link_type);
data.put("link_url", link_url);
return data;
}
}

View File

@@ -0,0 +1,146 @@
package com.fengliyan.messaging;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class SysInfoTextAttachment extends CustomAttachment {
private int action;
private String title;
private String date;
private String txt1;
// private String fields;
private List<FieldListA> fields = new ArrayList<>();
private String txt2;
private int link_type;
private String link_url;
SysInfoTextAttachment(int type) {
super(type);
}
public int getAction() {
return action;
}
public void setAction(int action) {
this.action = action;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTxt1() {
return txt1;
}
public void setTxt1(String txt1) {
this.txt1 = txt1;
}
// public String getFields() {
// return fieldList;
// }
//
// public void setFields(String fields) {
// this.fieldList = fields;
// }
public List<FieldListA> getFields() {
return fields;
}
public void setFields(List<FieldListA> fields) {
this.fields = fields;
}
public String getTxt2() {
return txt2;
}
public void setTxt2(String txt2) {
this.txt2 = txt2;
}
public int getLink_type() {
return link_type;
}
public void setLink_type(int link_type) {
this.link_type = link_type;
}
public String getLink_url() {
return link_url;
}
public void setLink_url(String link_url) {
this.link_url = link_url;
}
@Override
protected void parseData(JSONObject data) {
// action = (int) data.get("action");
action = data.getIntValue("action");
title = data.getString("title");
date = data.getString("date");
txt1 = data.getString("txt1");
// JSONArray array = (JSONArray) data.get("fields");
JSONArray array = data.getJSONArray("fields");
// fields = array.toJavaList(FieldListA.class);
fields = JSONObject.parseArray(array.toJSONString(), FieldListA.class);
// fieldList = data.getString("fieldList");
// Log.d("nail","fieldList+++" + fieldList);
txt2 = data.getString("txt2");
// link_type = (int) data.get("link_type");
link_type = data.getIntValue("link_type");
link_url = data.getString("link_url");
}
@Override
protected JSONObject packData(){
JSONObject data =new JSONObject();
data.put("action", action);
data.put("title", title);
data.put("date", date);
data.put("txt1", txt1);
// data.put("fieldList", fieldList);
data.put("fields", fields);
data.put("txt2", txt2);
data.put("link_type", link_type);
data.put("link_url", link_url);
return data;
}
@Override
public String toString() {
return "SysInfoTextAttachment{" +
"action=" + action +
", title='" + title + '\'' +
", date='" + date + '\'' +
", txt1='" + txt1 + '\'' +
// ", fieldList=" + fieldList +
", fields=" + fields +
", txt2='" + txt2 + '\'' +
", link_type=" + link_type +
", link_url='" + link_url + '\'' +
'}';
}
}

View File

@@ -0,0 +1,93 @@
package com.fengliyan.messaging;
import java.io.Serializable;
import java.util.List;
/**
* Created by zhangbin on 2018/12/11.
*/
public class SysInfoTextBean implements Serializable {
int action;
String title;
String date;
String txt1;
String txt2;
String txt3;
int link_type;
String link_url;
List<FieldListA> fields;
public int getAction() {
return action;
}
public void setAction(int action) {
this.action = action;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTxt1() {
return txt1;
}
public void setTxt1(String txt1) {
this.txt1 = txt1;
}
public String getTxt2() {
return txt2;
}
public void setTxt2(String txt2) {
this.txt2 = txt2;
}
public String getTxt3() {
return txt3;
}
public void setTxt3(String txt3) {
this.txt3 = txt3;
}
public int getLink_type() {
return link_type;
}
public void setLink_type(int link_type) {
this.link_type = link_type;
}
public String getLink_url() {
return link_url;
}
public void setLink_url(String link_url) {
this.link_url = link_url;
}
public List<FieldListA> getFields() {
return fields;
}
public void setFields(List<FieldListA> fields) {
this.fields = fields;
}
}

View File

@@ -0,0 +1,92 @@
package com.fengliyan.messaging;
import com.alibaba.fastjson.JSONObject;
/**
* Created by zhangbin on 2018/12/6.
* 自定义视频消息接收参数
*/
public class VideoAttachment extends CustomAttachment{
private int calltype;
private int status;
private String from_uid;
private String to_uid;
private int call_time;
VideoAttachment(int type) {
super(type);
}
public int getCalltype() {
return calltype;
}
public void setCalltype(int calltype) {
this.calltype = calltype;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getFrom_uid() {
return from_uid;
}
public void setFrom_uid(String from_uid) {
this.from_uid = from_uid;
}
public String getTo_uid() {
return to_uid;
}
public void setTo_uid(String to_uid) {
this.to_uid = to_uid;
}
public int getCall_time() {
return call_time;
}
public void setCall_time(int call_time) {
this.call_time = call_time;
}
@Override
protected void parseData(JSONObject data) {
calltype = (int) data.get("calltype");
status = (int) data.get("status");
from_uid = (String) data.get("from_uid");
to_uid = (String) data.get("to_uid");
call_time = (int) data.get("call_time");
}
@Override
protected JSONObject packData() {
JSONObject data = new JSONObject();
data.put("calltype", calltype);
data.put("status", status);
data.put("from_uid", from_uid);
data.put("to_uid", to_uid);
data.put("call_time", call_time);
return data;
}
@Override
public String toString() {
return "VideoAttachment{" +
"calltype=" + calltype +
", status=" + status +
", from_uid=" + from_uid +
", to_uid=" + to_uid +
", call_time=" + call_time +
'}';
}
}

View File

@@ -0,0 +1,58 @@
package com.fengliyan.messaging;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
/**
* Created by zhangbin on 2018/12/6.
* 自定义视频消息接收参数
*/
public class YestordayAttachment extends CustomAttachment{
public int action;
public String date;
public List<FieldListA> fields;
public int link_type;
public String title;
public String txt1;
public String txt2;
public String txt3;
YestordayAttachment(int type) {
super(type);
}
@Override
protected void parseData(JSONObject data) {
action = data.getIntValue("action");
title = data.getString("title");
date = data.getString("date");
JSONArray array = data.getJSONArray("fields");
fields = JSONObject.parseArray(array.toJSONString(), FieldListA.class);
txt2 = data.getString("txt2");
txt1 = data.getString("txt1");
txt3 = data.getString("txt3");
link_type = data.getIntValue("link_type");
}
@Override
protected JSONObject packData() {
JSONObject data =new JSONObject();
data.put("action", action);
data.put("title", title);
data.put("date", date);
data.put("txt1", txt1);
data.put("fields", fields);
data.put("txt2", txt2);
data.put("txt3", txt3);
data.put("link_type", link_type);
return data;
}
}

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Messaging</string>
</resources>

View File

@@ -0,0 +1,17 @@
package com.fengliyan.messaging;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}