@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_group_pick_contacts);

    // String groupName = getIntent().getStringExtra("groupName");
    String groupId = getIntent().getStringExtra("groupId");
    if (groupId == null) { // 创建群组
      isCreatingNewGroup = true;
    } else {
      // 获取此群组的成员列表
      EMGroup group = EMGroupManager.getInstance().getGroup(groupId);
      exitingMembers = group.getMembers();
    }
    if (exitingMembers == null) exitingMembers = new ArrayList<String>();
    // 获取好友列表
    final List<User> alluserList = new ArrayList<User>();
    for (User user : BeewayApplication.getInstance().getContactList().values()) {
      if (!user.getUsername().equals(Constant.NEW_FRIENDS_USERNAME)
          & !user.getUsername().equals(Constant.GROUP_USERNAME)
          & !user.getUsername().equals(Constant.CHAT_ROOM)
          & !user.getUsername().equals(Constant.CHAT_ROBOT)) alluserList.add(user);
    }
    friendDao = new FriendDao(this);
    // 对list进行排序
    Collections.sort(
        alluserList,
        new Comparator<User>() {
          @Override
          public int compare(User lhs, User rhs) {
            return (friendDao.getFriend(lhs.getUsername()).getLetter())
                .compareTo(friendDao.getFriend(rhs.getUsername()).getLetter());
            //				return (lhs.getUsername().compareTo(rhs.getUsername()));

          }
        });

    listView = (ListView) findViewById(R.id.list);
    contactAdapter = new PickContactAdapter(this, R.layout.row_contact_with_checkbox, alluserList);
    listView.setAdapter(contactAdapter);
    ((Sidebar) findViewById(R.id.sidebar)).setListView(listView);
    listView.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkbox);
            checkBox.toggle();
          }
        });
  }
Пример #2
0
  private void initializeContacts() {
    Map<String, User> userlist = new HashMap<String, User>();
    // 添加user"申请与通知"
    User newFriends = new User();
    newFriends.setUsername(Constant.NEW_FRIENDS_USERNAME);
    String strChat = getResources().getString(R.string.Application_and_notify);
    newFriends.setNick(strChat);

    userlist.put(Constant.NEW_FRIENDS_USERNAME, newFriends);
    // 添加"群聊"
    User groupUser = new User();
    String strGroup = getResources().getString(R.string.group_chat);
    groupUser.setUsername(Constant.GROUP_USERNAME);
    groupUser.setNick(strGroup);
    groupUser.setHeader("");
    userlist.put(Constant.GROUP_USERNAME, groupUser);

    // 存入内存
    BeewayApplication.getInstance().setContactList(userlist);
    // 存入db
    UserDao dao = new UserDao(LoginActivity.this);
    List<User> users = new ArrayList<User>(userlist.values());
    dao.saveContactList(users);
  }