@Override
  public void onClick(View v) {
    if (v.getId() == RHelper.get("id.rl_switch_block_groupmsg")) {
      toggleBlockGroup();
    } else if (v.getId() == RHelper.get("id.clear_all_history")) {
      String st9 = getResources().getString(RHelper.get("string.sure_to_empty_this"));
      new EaseAlertDialog(
              GroupDetailsActivity.this,
              null,
              st9,
              null,
              new AlertDialogUser() {

                @Override
                public void onResult(boolean confirmed, Bundle bundle) {
                  if (confirmed) {
                    clearGroupHistory();
                  }
                }
              },
              true)
          .show();
    } else if (v.getId() == RHelper.get("id.rl_blacklist")) // 黑名单列表
    startActivity(
          new Intent(GroupDetailsActivity.this, GroupBlacklistActivity.class)
              .putExtra("groupId", groupId));
    else if (v.getId() == RHelper.get("id.rl_change_group_name"))
      startActivityForResult(
          new Intent(this, EditActivity.class).putExtra("data", group.getGroupName()),
          REQUEST_CODE_EDIT_GROUPNAME);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_group_simle_details);
    tv_name = (TextView) findViewById(R.id.name);
    tv_admin = (TextView) findViewById(R.id.tv_admin);
    btn_add_group = (Button) findViewById(R.id.btn_add_to_group);
    tv_introduction = (TextView) findViewById(R.id.tv_introduction);
    progressBar = (ProgressBar) findViewById(R.id.loading);

    EMGroupInfo groupInfo = (EMGroupInfo) getIntent().getSerializableExtra("groupinfo");
    String groupname = null;
    if (groupInfo != null) {
      groupname = groupInfo.getGroupName();
      groupid = groupInfo.getGroupId();
    } else {
      group = PublicGroupsSeachActivity.searchedGroup;
      if (group == null) return;
      groupname = group.getGroupName();
      groupid = group.getGroupId();
    }

    tv_name.setText(groupname);

    if (group != null) {
      showGroupDetail();
      return;
    }
    new Thread(
            new Runnable() {

              public void run() {
                // 从服务器获取详情
                try {
                  group = EMGroupManager.getInstance().getGroupFromServer(groupid);
                  runOnUiThread(
                      new Runnable() {
                        public void run() {
                          showGroupDetail();
                        }
                      });
                } catch (final EaseMobException e) {
                  e.printStackTrace();
                  final String st1 =
                      getResources().getString(R.string.Failed_to_get_group_chat_information);
                  runOnUiThread(
                      new Runnable() {
                        public void run() {
                          progressBar.setVisibility(View.INVISIBLE);
                          Toast.makeText(GroupSimpleDetailActivity.this, st1 + e.getMessage(), 1)
                              .show();
                        }
                      });
                }
              }
            })
        .start();
  }
 private void showGroupDetail() {
   progressBar.setVisibility(View.INVISIBLE);
   // 获取详情成功,并且自己不在群中,才让加入群聊按钮可点击
   if (!group.getMembers().contains(EMChatManager.getInstance().getCurrentUser()))
     btn_add_group.setEnabled(true);
   tv_name.setText(group.getGroupName());
   tv_admin.setText(group.getOwner());
   tv_introduction.setText(group.getDescription());
 }
    @Override
    protected FilterResults performFiltering(CharSequence prefix) {
      FilterResults results = new FilterResults();

      if (mOriginalValues == null) {
        mOriginalValues = new ArrayList<EMConversation>();
      }
      if (prefix == null || prefix.length() == 0) {
        results.values = copyConversationList;
        results.count = copyConversationList.size();
      } else {
        String prefixString = prefix.toString();
        final int count = mOriginalValues.size();
        final ArrayList<EMConversation> newValues = new ArrayList<EMConversation>();

        for (int i = 0; i < count; i++) {
          final EMConversation value = mOriginalValues.get(i);
          String username = value.getUserName();

          EMGroup group = EMGroupManager.getInstance().getGroup(username);
          if (group != null) {
            username = group.getGroupName();
          }

          // First match against the whole ,non-splitted value
          if (username.startsWith(prefixString)) {
            newValues.add(value);
          } else {
            final String[] words = username.split(" ");
            final int wordCount = words.length;

            // Start at index 0, in case valueText starts with space(s)
            for (int k = 0; k < wordCount; k++) {
              if (words[k].startsWith(prefixString)) {
                newValues.add(value);
                break;
              }
            }
          }
        }

        results.values = newValues;
        results.count = newValues.size();
      }
      return results;
    }
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case com.xuhai.telescopes.R.id.rl_switch_block_groupmsg: // 屏蔽或取消屏蔽群组
        toggleBlockGroup();
        break;

      case com.xuhai.telescopes.R.id.clear_all_history: // 清空聊天记录
        String st9 = getResources().getString(com.xuhai.telescopes.R.string.sure_to_empty_this);
        new EaseAlertDialog(
                GroupDetailsActivity.this,
                null,
                st9,
                null,
                new EaseAlertDialog.AlertDialogUser() {

                  @Override
                  public void onResult(boolean confirmed, Bundle bundle) {
                    if (confirmed) {
                      clearGroupHistory();
                    }
                  }
                },
                true)
            .show();

        break;

      case com.xuhai.telescopes.R.id.rl_blacklist: // 黑名单列表
        startActivity(
            new Intent(GroupDetailsActivity.this, GroupBlacklistActivity.class)
                .putExtra("groupId", groupId));
        break;

      case com.xuhai.telescopes.R.id.rl_change_group_name:
        startActivityForResult(
            new Intent(this, EditActivity.class).putExtra("data", group.getGroupName()),
            REQUEST_CODE_EDIT_GROUPNAME);
        break;

      default:
        break;
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // 获取传过来的groupid
    groupId = getIntent().getStringExtra("groupId");
    group = EMGroupManager.getInstance().getGroup(groupId);

    // we are not supposed to show the group if we don't find the group
    if (group == null) {
      finish();
      return;
    }

    setContentView(RHelper.get("layout.em_activity_group_details"));
    instance = this;
    st = getResources().getString(RHelper.get("string.people"));
    clearAllHistory = (RelativeLayout) findViewById(RHelper.get("id.clear_all_history"));
    userGridview = (EaseExpandGridView) findViewById(RHelper.get("id.gridview"));
    loadingPB = (ProgressBar) findViewById(RHelper.get("id.progressBar"));
    exitBtn = (Button) findViewById(RHelper.get("id.btn_exit_grp"));
    deleteBtn = (Button) findViewById(RHelper.get("id.btn_exitdel_grp"));
    blacklistLayout = (RelativeLayout) findViewById(RHelper.get("id.rl_blacklist"));
    changeGroupNameLayout = (RelativeLayout) findViewById(RHelper.get("id.rl_change_group_name"));
    idLayout = (RelativeLayout) findViewById(RHelper.get("id.rl_group_id"));
    idLayout.setVisibility(View.VISIBLE);
    idText = (TextView) findViewById(RHelper.get("id.tv_group_id_value"));

    rl_switch_block_groupmsg =
        (RelativeLayout) findViewById(RHelper.get("id.rl_switch_block_groupmsg"));
    switchButton = (EaseSwitchButton) findViewById(RHelper.get("id.switch_btn"));

    rl_switch_block_groupmsg.setOnClickListener(this);

    idText.setText(groupId);
    if (group.getOwner() == null
        || "".equals(group.getOwner())
        || !group.getOwner().equals(EMChatManager.getInstance().getCurrentUser())) {
      exitBtn.setVisibility(View.GONE);
      deleteBtn.setVisibility(View.GONE);
      blacklistLayout.setVisibility(View.GONE);
      changeGroupNameLayout.setVisibility(View.GONE);
    }
    // 如果自己是群主,显示解散按钮
    if (EMChatManager.getInstance().getCurrentUser().equals(group.getOwner())) {
      exitBtn.setVisibility(View.GONE);
      deleteBtn.setVisibility(View.VISIBLE);
    }

    groupRemoveListener = new GroupRemoveListener();
    EMGroupManager.getInstance().addGroupChangeListener(groupRemoveListener);

    ((TextView) findViewById(RHelper.get("id.group_name")))
        .setText(group.getGroupName() + "(" + group.getAffiliationsCount() + st);

    List<String> members = new ArrayList<String>();
    members.addAll(group.getMembers());

    adapter = new GridAdapter(this, RHelper.get("layout.em_grid"), members);
    userGridview.setAdapter(adapter);

    // 保证每次进详情看到的都是最新的group
    updateGroup();

    // 设置OnTouchListener
    userGridview.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
                if (adapter.isInDeleteMode) {
                  adapter.isInDeleteMode = false;
                  adapter.notifyDataSetChanged();
                  return true;
                }
                break;
              default:
                break;
            }
            return false;
          }
        });

    clearAllHistory.setOnClickListener(this);
    blacklistLayout.setOnClickListener(this);
    changeGroupNameLayout.setOnClickListener(this);
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      convertView = inflater.inflate(R.layout.row_chat_history, parent, false);
    }
    ViewHolder holder = (ViewHolder) convertView.getTag();
    if (holder == null) {
      holder = new ViewHolder();
      holder.name = (TextView) convertView.findViewById(R.id.name);
      holder.unreadLabel = (TextView) convertView.findViewById(R.id.unread_msg_number);
      holder.message = (TextView) convertView.findViewById(R.id.message);
      holder.time = (TextView) convertView.findViewById(R.id.time);
      holder.avatar = (ImageView) convertView.findViewById(R.id.avatar);
      holder.msgState = convertView.findViewById(R.id.msg_state);
      holder.list_item_layout = (RelativeLayout) convertView.findViewById(R.id.list_item_layout);
      convertView.setTag(holder);
    }
    if (position % 2 == 0) {
      holder.list_item_layout.setBackgroundResource(R.drawable.mm_listitem);
    } else {
      holder.list_item_layout.setBackgroundResource(R.drawable.mm_listitem_grey);
    }

    // 获取与此用户/群组的会话
    EMConversation conversation = getItem(position);
    // 获取用户username或者群组groupid
    String username = conversation.getUserName();
    if (conversation.getType() == EMConversationType.GroupChat) {
      // 群聊消息,显示群聊头像
      holder.avatar.setImageResource(R.drawable.group_icon);
      EMGroup group = EMGroupManager.getInstance().getGroup(username);
      holder.name.setText(group != null ? group.getGroupName() : username);
    } else if (conversation.getType() == EMConversationType.ChatRoom) {
      holder.avatar.setImageResource(R.drawable.group_icon);
      EMChatRoom room = EMChatManager.getInstance().getChatRoom(username);
      holder.name.setText(
          room != null && !TextUtils.isEmpty(room.getName()) ? room.getName() : username);
    } else {
      UserUtils.setUserAvatar(getContext(), username, holder.avatar);
      if (username.equals(Constant.GROUP_USERNAME)) {
        holder.name.setText("群聊");

      } else if (username.equals(Constant.NEW_FRIENDS_USERNAME)) {
        holder.name.setText("申请与通知");
      }
      Map<String, RobotUser> robotMap =
          ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
      if (robotMap != null && robotMap.containsKey(username)) {
        String nick = robotMap.get(username).getNick();
        if (!TextUtils.isEmpty(nick)) {
          holder.name.setText(nick);
        } else {
          holder.name.setText(username);
        }
      } else {
        UserUtils.setUserNick(username, holder.name);
      }
    }

    if (conversation.getUnreadMsgCount() > 0) {
      // 显示与此用户的消息未读数
      holder.unreadLabel.setText(String.valueOf(conversation.getUnreadMsgCount()));
      holder.unreadLabel.setVisibility(View.VISIBLE);
    } else {
      holder.unreadLabel.setVisibility(View.INVISIBLE);
    }

    if (conversation.getMsgCount() != 0) {
      // 把最后一条消息的内容作为item的message内容
      EMMessage lastMessage = conversation.getLastMessage();
      holder.message.setText(
          SmileUtils.getSmiledText(
              getContext(), getMessageDigest(lastMessage, (this.getContext()))),
          BufferType.SPANNABLE);

      holder.time.setText(DateUtils.getTimestampString(new Date(lastMessage.getMsgTime())));
      if (lastMessage.direct == EMMessage.Direct.SEND
          && lastMessage.status == EMMessage.Status.FAIL) {
        holder.msgState.setVisibility(View.VISIBLE);
      } else {
        holder.msgState.setVisibility(View.GONE);
      }
    }

    return convertView;
  }