Search in sources :

Example 1 with FinalDb

use of net.tsz.afinal.FinalDb in project wechat by motianhuo.

the class SplashActivity method initData.

private void initData() {
    GloableParams.UserInfos = new ArrayList<User>();
    GloableParams.Users = new HashMap<String, User>();
    GloableParams.ListGroupInfos = new ArrayList<GroupInfo>();
    GloableParams.GroupInfos = new HashMap<String, GroupInfo>();
    FinalDb db = FinalDb.create(this, Constants.DB_NAME, false);
    GloableParams.ListGroupInfos = db.findAll(GroupInfo.class);
    GloableParams.UserInfos = db.findAll(User.class);
}
Also used : User(com.juns.wechat.bean.User) GroupInfo(com.juns.wechat.bean.GroupInfo) FinalDb(net.tsz.afinal.FinalDb)

Example 2 with FinalDb

use of net.tsz.afinal.FinalDb in project wechat by motianhuo.

the class Fragment_Friends method initData.

private void initData() {
    if (GloableParams.UserInfos != null) {
        lvContact.setAdapter(new ContactAdapter(getActivity(), GloableParams.UserInfos));
    } else {
        FinalDb db = FinalDb.create(getActivity(), Constants.DB_NAME, false);
        GloableParams.UserInfos = db.findAllByWhere(User.class, "type='N'");
        lvContact.setAdapter(new ContactAdapter(getActivity(), GloableParams.UserInfos));
        for (User user : GloableParams.UserInfos) {
            GloableParams.Users.put(user.getTelephone(), user);
        }
    // Intent intent = new Intent(getActivity(), UpdateService.class);
    // getActivity().startService(intent);
    }
}
Also used : User(com.juns.wechat.bean.User) ContactAdapter(com.juns.wechat.adpter.ContactAdapter) FinalDb(net.tsz.afinal.FinalDb)

Example 3 with FinalDb

use of net.tsz.afinal.FinalDb 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)

Example 4 with FinalDb

use of net.tsz.afinal.FinalDb in project wechat by motianhuo.

the class UserUtils method initUserInfo.

public static void initUserInfo(final Context context, final String telphone, final ImageView img_avar, final TextView txt_name) {
    NetClient netClient = new NetClient(context);
    RequestParams params = new RequestParams();
    params.put("telphone", telphone);
    netClient.post(Constants.getUserInfoURL, params, new BaseJsonRes() {

        @Override
        public void onMySuccess(String data) {
            User user = JSON.parseObject(data, User.class);
            if (user != null) {
                if (user.getUserName() != null) {
                    txt_name.setText(user.getUserName());
                }
                if (user.getHeadUrl() != null) {
                    NetClient.getIconBitmap(img_avar, user.getHeadUrl());
                }
                FinalDb db = FinalDb.create(context, Constants.DB_NAME, false);
                if (db.findById(user.getId(), User.class) != null)
                    db.deleteById(User.class, user.getId());
                db.save(user);
                GloableParams.UserInfos.add(user);
                GloableParams.Users.put(user.getTelephone(), user);
            }
        }

        @Override
        public void onMyFailure() {
        }
    });
}
Also used : NetClient(com.juns.wechat.net.NetClient) User(com.juns.wechat.bean.User) FinalDb(net.tsz.afinal.FinalDb) RequestParams(com.juns.health.net.loopj.android.http.RequestParams) BaseJsonRes(com.juns.wechat.net.BaseJsonRes)

Aggregations

User (com.juns.wechat.bean.User)4 FinalDb (net.tsz.afinal.FinalDb)4 GroupInfo (com.juns.wechat.bean.GroupInfo)2 EMGroup (com.easemob.chat.EMGroup)1 EaseMobException (com.easemob.exceptions.EaseMobException)1 RequestParams (com.juns.health.net.loopj.android.http.RequestParams)1 ContactAdapter (com.juns.wechat.adpter.ContactAdapter)1 BaseJsonRes (com.juns.wechat.net.BaseJsonRes)1 NetClient (com.juns.wechat.net.NetClient)1 HashMap (java.util.HashMap)1