Search in sources :

Example 1 with EMGroup

use of com.easemob.chat.EMGroup in project wechat by motianhuo.

the class AddGroupChatActivity method creatNewGroup.

private void creatNewGroup(final List<String> members) {
    // TODO 请求服务器创建群组,服务端实现接口
    new Thread(new Runnable() {

        @Override
        public void run() {
            // 调用sdk创建群组方法
            try {
                final String[] strmembers = new String[members.size()];
                for (int i = 0; i < members.size(); i++) {
                    User user = GloableParams.Users.get(members.get(i));
                    if (user != null) {
                        if (i < 3) {
                            if (i == 0)
                                groupName = user.getUserName();
                            else
                                groupName += "、" + user.getUserName();
                        } else if (i == 4) {
                            groupName += "...";
                        }
                        strmembers[i] = user.getTelephone();
                        if (i == 0) {
                            manber = user.getTelephone();
                        } else {
                            manber += "、" + user.getTelephone();
                        }
                    }
                }
                final EMGroup group = EMGroupManager.getInstance().createPublicGroup(groupName, "", strmembers, true);
                runOnUiThread(new Runnable() {

                    public void run() {
                        if (group != null) {
                            // TODO 保存本地数据库
                            GloableParams.GroupInfos = new HashMap<String, GroupInfo>();
                            GroupInfo info = new GroupInfo();
                            info.setGroup_id(group.getGroupId());
                            info.setGroup_name(groupName);
                            info.setMembers(manber);
                            String owner_id = Utils.getValue(AddGroupChatActivity.this, Constants.User_ID);
                            info.setOwner_id(owner_id);
                            GloableParams.GroupInfos.put(group.getGroupId(), info);
                            FinalDb db = FinalDb.create(AddGroupChatActivity.this, Constants.DB_NAME, false);
                            db.save(info);
                            addServieGroup(group.getGroupId(), groupName, manber, // 保存服务器
                            owner_id);
                        }
                    }
                });
            } catch (final EaseMobException e) {
                runOnUiThread(new Runnable() {

                    public void run() {
                        Utils.showLongToast(AddGroupChatActivity.this, "创建失败");
                        getLoadingDialog("正在创建群聊...").dismiss();
                    }
                });
            }
        }
    }).start();
}
Also used : User(com.juns.wechat.bean.User) EaseMobException(com.easemob.exceptions.EaseMobException) HashMap(java.util.HashMap) GroupInfo(com.juns.wechat.bean.GroupInfo) EMGroup(com.easemob.chat.EMGroup) FinalDb(net.tsz.afinal.FinalDb)

Aggregations

EMGroup (com.easemob.chat.EMGroup)1 EaseMobException (com.easemob.exceptions.EaseMobException)1 GroupInfo (com.juns.wechat.bean.GroupInfo)1 User (com.juns.wechat.bean.User)1 HashMap (java.util.HashMap)1 FinalDb (net.tsz.afinal.FinalDb)1