diff --git a/app/src/main/java/com/example/kingway/ptt/CallBackResolution.java b/app/src/main/java/com/example/kingway/ptt/CallBackResolution.java index 7fef131..e2a5942 100644 --- a/app/src/main/java/com/example/kingway/ptt/CallBackResolution.java +++ b/app/src/main/java/com/example/kingway/ptt/CallBackResolution.java @@ -5,7 +5,10 @@ import android.util.Log; import timber.log.Timber; import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -17,11 +20,13 @@ public class CallBackResolution { private static String TAG = "PTT_RX"; private static String indexGroupId = "";//用户所在群组Id private static String indexGroupName = "";//用户所在群组名称 - private static List memberInfoDtos = new ArrayList<>(); + private static final int MAX_GROUP_MEMBERS = 500; + private static final int MAX_GROUP_INFOS = 100; + private static final Map memberInfoDtos = new LinkedHashMap<>(MAX_GROUP_MEMBERS); private static int speckType = 1; private static String talkId = ""; private static String talkName = ""; - private static ArrayList groupInfos = new ArrayList<>(); + private static final Map groupInfos = new LinkedHashMap<>(MAX_GROUP_INFOS); private static String oldLoginSate = "00"; private static int logNum = 0; private static long offlineTime = 0; @@ -139,8 +144,12 @@ public class CallBackResolution { CallBackUtil.callBackGroupInfo(groupId, tempTxt, groupNo, groupCount); Timber.tag(TAG).d( "at_OEM_AT_cb group info groupId: " + groupId + ", groupNo: " + groupNo+", groupCount: " +groupCount); if (1 == groupNo) groupInfos.clear(); + if (groupInfos.size() >= MAX_GROUP_INFOS) { + Iterator it = groupInfos.keySet().iterator(); + if (it.hasNext()) { it.next(); it.remove(); } + } GroupInfoDto groupInfo = new GroupInfoDto(groupId, tempTxt, groupNo, groupCount); - groupInfos.add(groupInfo); + groupInfos.put(groupId, groupInfo); } break; @@ -169,7 +178,11 @@ public class CallBackResolution { String tempTxt = unicodeToString(groupMemberName.toString()); GroupMemberInfoDto infoDto = new GroupMemberInfoDto(memberId, tempTxt, status, memberNo, haveVideo); if (memberNo == 1) memberInfoDtos.clear(); - memberInfoDtos.add(infoDto); + if (memberInfoDtos.size() >= MAX_GROUP_MEMBERS) { + Iterator it = memberInfoDtos.keySet().iterator(); + if (it.hasNext()) { it.next(); it.remove(); } + } + memberInfoDtos.put(memberId, infoDto); } break; diff --git a/app/src/main/java/com/example/kingway/ptt/CallBackUtil.java b/app/src/main/java/com/example/kingway/ptt/CallBackUtil.java index e7b5a4a..d8cae23 100644 --- a/app/src/main/java/com/example/kingway/ptt/CallBackUtil.java +++ b/app/src/main/java/com/example/kingway/ptt/CallBackUtil.java @@ -68,11 +68,11 @@ public class CallBackUtil { * 查询群组成员返回 * state true-成功, false-失败 */ - public static void callBackOnMemberSuccess(boolean state, List dtos) { + public static void callBackOnMemberSuccess(boolean state, java.util.Map dtos) { try { org.json.JSONArray arr = new org.json.JSONArray(); if (dtos != null && state) { - for (GroupMemberInfoDto dto : dtos) { + for (GroupMemberInfoDto dto : dtos.values()) { org.json.JSONObject obj = new org.json.JSONObject(); obj.put("memberId", dto.getMemberId()); obj.put("memberName", dto.getGmemberName()); @@ -128,10 +128,10 @@ public class CallBackUtil { * 返回群组集合信息 * GroupInfoDto 群组信息 * */ - public static void callBackGroupInfo (ArrayList < GroupInfoDto > groupInfoDtos) { + public static void callBackGroupInfo (java.util.Map groupInfoDtos) { try { org.json.JSONArray arr = new org.json.JSONArray(); - for (GroupInfoDto dto : groupInfoDtos) { + for (GroupInfoDto dto : groupInfoDtos.values()) { org.json.JSONObject obj = new org.json.JSONObject(); obj.put("groupId", dto.getGroupId()); obj.put("groupName", dto.getGroupName());