@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();
  }
  /**
   * 获取有聊天记录的users和groups
   *
   * @param context
   * @return
   */
  private List<EMContact> loadUsersWithRecentChat() {
    List<EMContact> resultList = new ArrayList<EMContact>();
    // 获取有聊天记录的users,不包括陌生人
    for (User user : contactList.values()) {
      EMConversation conversation = EMChatManager.getInstance().getConversation(user.getUsername());
      if (conversation.getMsgCount() > 0) {
        resultList.add(user);
      }
    }
    for (EMGroup group : EMGroupManager.getInstance().getAllGroups()) {
      EMConversation conversation = EMChatManager.getInstance().getConversation(group.getGroupId());
      if (conversation.getMsgCount() > 0) {
        resultList.add(group);
      }
    }

    // 排序
    sortUserByLastChatTime(resultList);
    return resultList;
  }
示例#3
0
    @Override
    public void onInvitationReceived(
        String groupId, String groupName, String inviter, String reason) {
      Log.i("TAG", "onInvitationReceived " + groupName + " " + inviter + " " + reason);
      boolean hasGroup = false;
      for (EMGroup group : EMGroupManager.getInstance().getAllGroups()) {
        if (group.getGroupId().equals(groupId)) {
          hasGroup = true;
          break;
        }
      }
      if (!hasGroup) return;

      // 被邀请
      //            String st3 = getResources().getString(R.string.Invite_you_to_join_a_group_chat);
      //            EMMessage msg = EMMessage.createReceiveMessage(Type.TXT);
      //            msg.setChatType(ChatType.GroupChat);
      //            msg.setFrom(inviter);
      //            msg.setTo(groupId);
      //            msg.setMsgId(UUID.randomUUID().toString());
      //            getNickName(inviter, msg, st3, ONINVITATIONRECEIVED);

    }
  /** 清空群聊天记录 */
  private void clearGroupHistory() {

    EMChatManager.getInstance().clearConversation(group.getGroupId());
    Toast.makeText(this, RHelper.get("string.messages_are_empty"), 0).show();
  }
  /** 清空群聊天记录 */
  private void clearGroupHistory() {

    EMChatManager.getInstance().clearConversation(group.getGroupId());
    Toast.makeText(this, com.xuhai.telescopes.R.string.messages_are_empty, Toast.LENGTH_LONG)
        .show();
  }