Search in sources :

Example 16 with User

use of com.juns.wechat.bean.User 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)

Example 17 with User

use of com.juns.wechat.bean.User in project wechat by motianhuo.

the class ContactAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    User user = UserInfos.get(position);
    if (convertView == null) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.contact_item, null);
    }
    ImageView ivAvatar = ViewHolder.get(convertView, R.id.contactitem_avatar_iv);
    TextView tvCatalog = ViewHolder.get(convertView, R.id.contactitem_catalog);
    TextView tvNick = ViewHolder.get(convertView, R.id.contactitem_nick);
    String catalog = "";
    if (TextUtils.isEmpty(user.getUserName()))
        catalog = "#";
    else
        catalog = PingYinUtil.converterToFirstSpell(user.getUserName()).substring(0, 1);
    if (position == 0) {
        tvCatalog.setVisibility(View.VISIBLE);
        tvCatalog.setText(catalog);
    } else {
        User Nextuser = UserInfos.get(position - 1);
        String lastCatalog = "";
        if (TextUtils.isEmpty(Nextuser.getUserName()))
            lastCatalog = "#";
        else
            lastCatalog = PingYinUtil.converterToFirstSpell(Nextuser.getUserName()).substring(0, 1);
        if (catalog.equals(lastCatalog)) {
            tvCatalog.setVisibility(View.GONE);
        } else {
            tvCatalog.setVisibility(View.VISIBLE);
            tvCatalog.setText(catalog);
        }
    }
    ivAvatar.setImageResource(R.drawable.head);
    tvNick.setText(user.getUserName());
    return convertView;
}
Also used : User(com.juns.wechat.bean.User) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 18 with User

use of com.juns.wechat.bean.User in project wechat by motianhuo.

the class NewMsgAdpter method getView.

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = LayoutInflater.from(context).inflate(R.layout.layout_item_msg, parent, false);
    }
    ImageView img_avar = ViewHolder.get(convertView, R.id.contactitem_avatar_iv);
    TextView txt_name = ViewHolder.get(convertView, R.id.txt_name);
    TextView txt_state = ViewHolder.get(convertView, R.id.txt_state);
    TextView txt_del = ViewHolder.get(convertView, R.id.txt_del);
    TextView txt_content = ViewHolder.get(convertView, R.id.txt_content);
    TextView txt_time = ViewHolder.get(convertView, R.id.txt_time);
    TextView unreadLabel = ViewHolder.get(convertView, R.id.unread_msg_number);
    SwipeLayout swipe = ViewHolder.get(convertView, R.id.swipe);
    if (PublicMsg != null && position == 0) {
        txt_name.setText("订阅号");
        img_avar.setImageResource(R.drawable.icon_public);
        txt_time.setText(PublicMsg.getTime());
        txt_content.setText(PublicMsg.getContent());
        unreadLabel.setText("3");
        unreadLabel.setVisibility(View.VISIBLE);
        swipe.setSwipeEnabled(false);
    } else {
        swipe.setSwipeEnabled(true);
        // 获取与此用户/群组的会话
        final EMConversation conversation = conversationList.get(position);
        // 获取用户username或者群组groupid
        ChatID = conversation.getUserName();
        txt_del.setTag(ChatID);
        if (conversation.isGroup()) {
            img_avar.setImageResource(R.drawable.defult_group);
            GroupInfo info = GloableParams.GroupInfos.get(ChatID);
            if (info != null) {
                txt_name.setText(info.getGroup_name());
            } else {
            // initGroupInfo(img_avar, txt_name);// 获取群组信息
            }
        } else {
            User user = GloableParams.Users.get(ChatID);
            if (user != null) {
                txt_name.setText(user.getUserName());
            } else {
                txt_name.setText("好友");
                // 获取用户信息
                UserUtils.initUserInfo(context, ChatID, img_avar, txt_name);
            }
        }
        if (conversation.getUnreadMsgCount() > 0) {
            // 显示与此用户的消息未读数
            unreadLabel.setText(String.valueOf(conversation.getUnreadMsgCount()));
            unreadLabel.setVisibility(View.VISIBLE);
        } else {
            unreadLabel.setVisibility(View.INVISIBLE);
        }
        if (conversation.getMsgCount() != 0) {
            // 把最后一条消息的内容作为item的message内容
            EMMessage lastMessage = conversation.getLastMessage();
            txt_content.setText(SmileUtils.getSmiledText(context, getMessageDigest(lastMessage, context)), BufferType.SPANNABLE);
            txt_time.setText(DateUtils.getTimestampString(new Date(lastMessage.getMsgTime())));
            if (lastMessage.status == EMMessage.Status.SUCCESS) {
                txt_state.setText("送达");
            // txt_state.setBackgroundResource(R.drawable.btn_bg_orgen);
            } else if (lastMessage.status == EMMessage.Status.FAIL) {
                txt_state.setText("失败");
            // txt_state.setBackgroundResource(R.drawable.btn_bg_red);
            } else if (lastMessage.direct == EMMessage.Direct.RECEIVE) {
                txt_state.setText("已读");
                txt_state.setBackgroundResource(R.drawable.btn_bg_blue);
            }
        }
        txt_del.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                deleteID = position;
                Tipdialog = new WarnTipDialog((Activity) context, "您确定要删除该聊天吗?");
                Tipdialog.setBtnOkLinstener(onclick);
                Tipdialog.show();
            }
        });
    }
    return convertView;
}
Also used : EMConversation(com.easemob.chat.EMConversation) User(com.juns.wechat.bean.User) GroupInfo(com.juns.wechat.bean.GroupInfo) SwipeLayout(com.juns.wechat.widght.swipe.SwipeLayout) WarnTipDialog(com.juns.wechat.dialog.WarnTipDialog) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Date(java.util.Date) EMMessage(com.easemob.chat.EMMessage)

Example 19 with User

use of com.juns.wechat.bean.User in project wechat by motianhuo.

the class ContactAdapter method getPositionForSection.

@Override
public int getPositionForSection(int section) {
    for (int i = 0; i < UserInfos.size(); i++) {
        User user = UserInfos.get(i);
        String catalog = "";
        if (TextUtils.isEmpty(user.getUserName()))
            catalog = "#";
        else
            catalog = PingYinUtil.converterToFirstSpell(user.getUserName()).substring(0, 1);
        char firstChar = catalog.toUpperCase().charAt(0);
        if (firstChar == section) {
            return i;
        }
    }
    return 0;
}
Also used : User(com.juns.wechat.bean.User)

Example 20 with User

use of com.juns.wechat.bean.User in project wechat by motianhuo.

the class GroupSettingActivity method initData.

@Override
protected void initData() {
    // 获取传过来的groupid
    groupId = getIntent().getStringExtra(Constants.GROUP_ID);
    // 获取本地该群数据
    group = EMGroupManager.getInstance().getGroup(groupId);
    if (group == null) {
        try {
            // 去网络中查找该群
            group = EMGroupManager.getInstance().getGroupFromServer(groupId);
            if (group == null) {
                Toast.makeText(GroupSettingActivity.this, "该群已经被解散...", Toast.LENGTH_SHORT).show();
                setResult(100);
                finish();
                return;
            }
        } catch (EaseMobException e) {
            e.printStackTrace();
            return;
        }
    }
    // 获取封装的群名(里面封装了显示的群名和群组成员的信息)
    String group_name = group.getGroupName();
    // 获取群成员信息
    tv_groupname.setText(group_name);
    GroupInfo groupinfo = GloableParams.GroupInfos.get(groupId);
    if (groupinfo != null) {
        String[] manbers = groupinfo.getMembers().split("、");
        if (manbers != null && manbers.length > 0) {
            m_total = manbers.length;
            txt_title.setText("聊天信息(" + String.valueOf(m_total) + ")");
            // 解析群组成员信息
            for (int i = 0; i < m_total; i++) {
                User user = GloableParams.Users.get(manbers[i]);
                if (user == null) {
                    user = new User();
                    user.setTelephone(manbers[i]);
                }
                members.add(user);
            }
            // 显示群组成员头像和昵称
            showMembers(members);
            // 判断是否是群主,是群主有删成员的权限,并显示减号按钮
            if (null != groupinfo.getOwner_id() && null != hxid && hxid.equals(groupinfo.getOwner_id())) {
                is_admin = true;
            }
        }
    }
}
Also used : EaseMobException(com.easemob.exceptions.EaseMobException) User(com.juns.wechat.bean.User) GroupInfo(com.juns.wechat.bean.GroupInfo)

Aggregations

User (com.juns.wechat.bean.User)23 Intent (android.content.Intent)5 ImageView (android.widget.ImageView)5 GroupInfo (com.juns.wechat.bean.GroupInfo)5 TextView (android.widget.TextView)4 FinalDb (net.tsz.afinal.FinalDb)4 View (android.view.View)3 OnClickListener (android.view.View.OnClickListener)3 EaseMobException (com.easemob.exceptions.EaseMobException)3 BaseJsonRes (com.juns.wechat.net.BaseJsonRes)3 List (java.util.List)3 EMConversation (com.easemob.chat.EMConversation)2 RequestParams (com.juns.health.net.loopj.android.http.RequestParams)2 FriendMsgActivity (com.juns.wechat.view.activity.FriendMsgActivity)2 Bitmap (android.graphics.Bitmap)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 EMGroup (com.easemob.chat.EMGroup)1 EMMessage (com.easemob.chat.EMMessage)1 ImageMessageBody (com.easemob.chat.ImageMessageBody)1