diff --git a/chatapp/src/main/java/jiguang/chat/adapter/GroupMemberGridAdapter.java b/chatapp/src/main/java/jiguang/chat/adapter/GroupMemberGridAdapter.java index 0cfbd010..9d10cc54 100644 --- a/chatapp/src/main/java/jiguang/chat/adapter/GroupMemberGridAdapter.java +++ b/chatapp/src/main/java/jiguang/chat/adapter/GroupMemberGridAdapter.java @@ -34,7 +34,7 @@ public class GroupMemberGridAdapter extends BaseAdapter { private int mCurrentNum; //用群成员项数余4得到,作为下标查找mRestArray,得到空白项 private int mRestNum; - private static final int MAX_GRID_ITEM = 40; + private int maxGridItem; private boolean mIsGroup; private String mTargetId; private Context mContext; @@ -53,6 +53,7 @@ public GroupMemberGridAdapter(Context context, List memberList, boolea this.mMemberList = memberList; mCurrentNum = mMemberList.size(); this.mIsCreator = isCreator; + maxGridItem = isCreator ? 13 : 14; this.mAvatarSize = size; initBlankItem(mCurrentNum); } @@ -66,8 +67,8 @@ public GroupMemberGridAdapter(Context context, String targetId, String appKey) { } public void initBlankItem(int size) { - if (mMemberList.size() > MAX_GRID_ITEM) { - mCurrentNum = MAX_GRID_ITEM - 1; + if (mMemberList.size() > maxGridItem) { + mCurrentNum = maxGridItem; } else { mCurrentNum = mMemberList.size(); } @@ -75,8 +76,8 @@ public void initBlankItem(int size) { } public void refreshMemberList() { - if (mMemberList.size() > MAX_GRID_ITEM) { - mCurrentNum = MAX_GRID_ITEM - 1; + if (mMemberList.size() > maxGridItem) { + mCurrentNum = maxGridItem; } else { mCurrentNum = mMemberList.size(); } diff --git a/chatapp/src/main/java/jiguang/chat/controller/ChatDetailController.java b/chatapp/src/main/java/jiguang/chat/controller/ChatDetailController.java index e6711efd..3bc58f5c 100644 --- a/chatapp/src/main/java/jiguang/chat/controller/ChatDetailController.java +++ b/chatapp/src/main/java/jiguang/chat/controller/ChatDetailController.java @@ -84,7 +84,7 @@ public class ChatDetailController implements OnClickListener, OnItemClickListene private Dialog mLoadingDialog = null; private static final int ADD_MEMBERS_TO_GRIDVIEW = 2048; private static final int ADD_A_MEMBER_TO_GRIDVIEW = 2049; - private static final int MAX_GRID_ITEM = 40; + private int maxGridItem = 40; private String mGroupName; private String mGroupDesc; private final MyHandler myHandler = new MyHandler(this); @@ -161,6 +161,7 @@ public void initData() { if (mGroupOwnerId != null && mGroupOwnerId.equals(mMyUsername)) { mIsCreator = true; } + maxGridItem = mIsCreator ? 13 : 14; mChatDetailView.setMyName(mMyUsername); mChatDetailView.showBlockView(mGroupInfo.isGroupBlocked()); initAdapter(); @@ -213,8 +214,8 @@ public void gotResult(int i, String s, UserInfo userInfo) { private void initAdapter() { // 初始化头像 mGridAdapter = new GroupMemberGridAdapter(mContext, mMemberInfoList, mIsCreator, mAvatarSize); - if (mMemberInfoList.size() > MAX_GRID_ITEM) { - mCurrentNum = MAX_GRID_ITEM - 1; + if (mMemberInfoList.size() > maxGridItem) { + mCurrentNum = maxGridItem; } else { mCurrentNum = mMemberInfoList.size(); } @@ -637,7 +638,7 @@ public void gotResult(final int status, final String desc) { //添加或者删除成员后重新获得MemberInfoList public void refreshMemberList() { - mCurrentNum = mMemberInfoList.size() > MAX_GRID_ITEM ? MAX_GRID_ITEM - 1 : mMemberInfoList.size(); + mCurrentNum = mMemberInfoList.size() > maxGridItem ? maxGridItem : mMemberInfoList.size(); mGridAdapter.refreshMemberList(); } @@ -912,7 +913,10 @@ public GroupMemberGridAdapter getAdapter() { */ public void refresh(long groupId) { //当前群聊 - if (mGroupId == groupId) { + if (mGroupId == groupId && mGroupInfo != null) { + mMemberInfoList.clear(); + mMemberInfoList.addAll(mGroupInfo.getGroupMembers()); + mChatDetailView.setMemberCount(" " + mMemberInfoList.size() + " 人"); refreshMemberList(); } }