@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent;

    RongContext.getInstance().getEventBus().register(this);

    if (getActivity() != null) {

      intent = getActivity().getIntent();

      if (intent.getData() != null) {

        mConversationType =
            Conversation.ConversationType.valueOf(
                intent.getData().getLastPathSegment().toUpperCase());

        mTargetId = intent.getData().getQueryParameter("targetId");
      }
    }
    mAdapter = new RongConversationAddMemberAdapter(getActivity());
    mAdapter.setDeleteIconListener(this);

    if (RongIM.getInstance() != null && RongIM.getInstance().getRongIMClient() != null) {
      initData();
    }
  }
    @Override
    public void run() {
      RLog.d(this, "AttachRunnable", "insert image and save to db, uri = " + mUri);
      final ImageMessage content = ImageMessage.obtain(mUri, mUri);
      if (RongIM.getInstance() != null && RongIM.getInstance().getRongIMClient() != null) ;
      RongIM.getInstance()
          .getRongIMClient()
          .insertMessage(
              getCurrentConversation().getConversationType(),
              getCurrentConversation().getTargetId(),
              null,
              content,
              new RongIMClient.ResultCallback<Message>() {
                @Override
                public void onSuccess(Message message) {
                  RLog.d(this, "AttachRunnable", "onSuccess insert image");
                  message.setSentStatus(Message.SentStatus.SENDING);
                  RongIM.getInstance()
                      .getRongIMClient()
                      .setMessageSentStatus(
                          message.getMessageId(), Message.SentStatus.SENDING, null);
                  getContext().executorBackground(new UploadRunnable(message));
                }

                @Override
                public void onError(RongIMClient.ErrorCode e) {
                  RLog.d(this, "AttachRunnable", "onError insert image, error = " + e);
                }
              });
    }
    @Override
    public void run() {

      // 封装image类型的IM消息
      final ImageMessage content = ImageMessage.obtain(mUri, mUri);

      if (RongIM.getInstance() != null && RongIM.getInstance().getRongIMClient() != null)
        RongIM.getInstance()
            .getRongIMClient()
            .sendImageMessage(
                getCurrentConversation().getConversationType(),
                getCurrentConversation().getTargetId(),
                content,
                null,
                null,
                new RongIMClient.SendImageMessageCallback() {
                  @Override
                  public void onAttached(Message message) {}

                  @Override
                  public void onError(Message message, RongIMClient.ErrorCode errorCode) {}

                  @Override
                  public void onSuccess(Message message) {}

                  @Override
                  public void onProgress(Message message, int i) {}
                });
    }
  @Override
  protected void initData() {

    if (RongContext.getInstance() != null) RongContext.getInstance().getEventBus().register(this);

    if (RongIM.getInstance() != null && RongIM.getInstance().getRongIMClient() != null) {
      RongIM.getInstance()
          .getRongIMClient()
          .getConversationNotificationStatus(
              getConversationType(),
              getTargetId(),
              new RongIMClient.ResultCallback<Conversation.ConversationNotificationStatus>() {

                @Override
                public void onSuccess(
                    final Conversation.ConversationNotificationStatus notificationStatus) {

                  if (notificationStatus != null) {
                    setSwitchBtnStatus(
                        notificationStatus
                                == Conversation.ConversationNotificationStatus.DO_NOT_DISTURB
                            ? false
                            : true);
                  }
                }

                @Override
                public void onError(RongIMClient.ErrorCode errorCode) {

                  setSwitchBtnStatus(!getSwitchBtnStatus());
                }
              });
    }
  }
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.add_black:
        if (RongIM.getInstance() != null && Util.getNetWorkType(this) != -1) {
          RongIM.getInstance()
              .addToBlacklist(
                  userId,
                  new RongIM.OperationCallback() {

                    @Override
                    public void onError(ErrorCode errorCode) {
                      Log.e(
                          TAG, "-------addToBlacklist onError----------:" + errorCode.getMessage());
                      Log.e(TAG, "-------addToBlacklist onError---------:" + errorCode.getValue());
                    }

                    @Override
                    public void onSuccess() {
                      Log.e(TAG, "-------添加到黑名单--------:");

                      Message msg = Message.obtain();
                      msg.what = 1;
                      mHandler.sendMessage(msg);
                    }
                  });
        } else {
          WinToast.toast(this, R.string.network_not);
        }
        break;
      case R.id.remove_black:
        if (RongIM.getInstance() != null && Util.getNetWorkType(this) != -1) {
          RongIM.getInstance()
              .removeFromBlacklist(
                  userId,
                  new RongIM.OperationCallback() {

                    @Override
                    public void onError(ErrorCode errorCode) {
                      Log.e(TAG, "------- removeFromBlacklist onError-------:" + errorCode);
                    }

                    @Override
                    public void onSuccess() {
                      Log.e(TAG, "-------被移除黑名单-------:");
                      Message msg = Message.obtain();
                      msg.what = 2;
                      mHandler.sendMessage(msg);
                    }
                  });
        } else {
          WinToast.toast(this, R.string.network_not);
        }
        break;
      default:
        break;
    }
  }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.de_ac_main);
   RongIM.getInstance().enableNewComingMessageIcon(true);
   RongIM.getInstance().enableUnreadMessageIcon(true);
   initView();
   initData();
   getPushMessage();
 }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   Bundle bundle = getIntent().getExtras();
   Log.i("yifan", "get intent, test is : " + bundle.getString("test"));
   if (RongIM.getInstance() != null) {
     RongIM.getInstance().startConversationList(this);
   }
   finish();
 }
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.customer_chat:
       if (RongIM.getInstance() != null)
         // KEFU146001495753714 正式  KEFU145930951497220 测试
         RongIM.getInstance()
             .startCustomerServiceChat(getActivity(), "KEFU146001495753714", "在线客服", null);
       break;
   }
 }
Beispiel #9
0
  @Override
  public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    RongIM.getInstance()
        .init(this, Const.APP_KEY, R.drawable.ic_launcher); // 只执行一次,中间字符串,写private Key(开发环境的)

    String token = Const.TOKEN; // 用网页调试生成现成的token

    RongIM.connect(
        token,
        new RongIMClient.ConnectCallback() // 工程中只调用一次,如果断线,由融云SDK自动启重连
        {

          @Override
          public void onError(ErrorCode arg0) {
            // TODO Auto-generated method stub
            Log.d("Connect:", "Login Failed " + arg0.getValue());
          }

          @Override
          public void onSuccess(String arg0) {
            // TODO Auto-generated method stub
            Log.d("Connect:", "Login Success " + arg0);
          }
        });
  }
  public static void setConverstionNotif(
      final Context context,
      Conversation.ConversationType conversationType,
      String targetId,
      boolean state) {
    Conversation.ConversationNotificationStatus cns;
    if (state) {
      cns = Conversation.ConversationNotificationStatus.DO_NOT_DISTURB;
    } else {
      cns = Conversation.ConversationNotificationStatus.NOTIFY;
    }
    RongIM.getInstance()
        .setConversationNotificationStatus(
            conversationType,
            targetId,
            cns,
            new RongIMClient.ResultCallback<Conversation.ConversationNotificationStatus>() {
              @Override
              public void onSuccess(
                  Conversation.ConversationNotificationStatus conversationNotificationStatus) {
                if (conversationNotificationStatus
                    == Conversation.ConversationNotificationStatus.DO_NOT_DISTURB) {
                  //                    NToast.shortToast(context, "设置免打扰成功");
                } else if (conversationNotificationStatus
                    == Conversation.ConversationNotificationStatus.NOTIFY) {
                  //                    NToast.shortToast(context, "取消免打扰成功");
                }
              }

              @Override
              public void onError(RongIMClient.ErrorCode errorCode) {
                NToast.shortToast(context, "设置失败");
              }
            });
  }
    @Override
    public void run() {
      mLock = new CountDownLatch(1);
      RLog.d(this, "UploadRunnable", "sendImageMessage");
      RongIM.getInstance()
          .getRongIMClient()
          .sendImageMessage(
              msg,
              null,
              null,
              new RongIMClient.SendImageMessageCallback() {
                @Override
                public void onAttached(Message message) {
                  mLock.countDown();
                }

                @Override
                public void onError(Message message, RongIMClient.ErrorCode code) {
                  mLock.countDown();
                }

                @Override
                public void onSuccess(Message message) {
                  mLock.countDown();
                }

                @Override
                public void onProgress(Message message, int progress) {}
              });
      try {
        mLock.await();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  private void initData() {
    if (mConversationType.equals(Conversation.ConversationType.DISCUSSION)) {
      RongIM.getInstance()
          .getRongIMClient()
          .getDiscussion(
              mTargetId,
              new RongIMClient.ResultCallback<Discussion>() {
                @Override
                public void onSuccess(Discussion discussion) {
                  mIdList = discussion.getMemberIdList();
                  mAdapter.setCreatorId(discussion.getCreatorId());
                  Message msg = new Message();
                  msg.what = PREPARE_LIST;
                  msg.obj = mIdList;
                  getHandler().sendMessage(msg);
                }

                @Override
                public void onError(RongIMClient.ErrorCode errorCode) {
                  getHandler().sendEmptyMessage(SHOW_TOAST);
                }
              });
    } else if (mConversationType.equals(Conversation.ConversationType.PRIVATE)) {
      mIdList.add(mTargetId);
      Message msg = new Message();
      msg.what = PREPARE_LIST;
      msg.obj = mIdList;
      getHandler().sendMessage(msg);
    }
  }
    @Override
    public View getViewForRow(View convertView, ViewGroup parent, int section, int row) {
      View view = null;
      if (section == 0) {
        if (AccountService.instance().isLogin()) {
          MineHeaderView headerView = MineHeaderView.create(getActivity());
          Account account = AccountService.instance().account();
          headerView.getAvartaIv().setImageUrl(account.getAvatar());
          headerView.getNameTv().setText(account.getNickName());
          headerView.getAgeTv().setText(account.getMobile());
          view = headerView;

        } else {
          view =
              LayoutInflater.from(getActivity())
                  .inflate(R.layout.layout_mine_header_not_login, null);
          view.findViewById(R.id.login_btn)
              .setOnClickListener(
                  new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                      Intent intent =
                          new Intent(Intent.ACTION_VIEW, Uri.parse("sgteacher://login"));
                      startActivity(intent);
                    }
                  });
        }

      } else {
        SimpleListItem simpleListItem = SimpleListItem.create(getActivity());
        simpleListItem.setShowArrow(true);
        if (section == 1) {
          if (row == 0) {
            simpleListItem.setTitle("成为助教");
            simpleListItem.setIcon(R.drawable.ic_mine_order);
          }
        } else if (section == 2) {
          if (row == 0) {
            simpleListItem.setTitle("系统消息");
            simpleListItem.setIcon(R.drawable.ic_mine_feedback);
            int unreadSys =
                RongIM.getInstance()
                    .getRongIMClient()
                    .getUnreadCount(Conversation.ConversationType.SYSTEM);
            if (unreadSys > 0) {
              simpleListItem.getDotView().setVisibility(View.VISIBLE);
            } else {
              simpleListItem.getDotView().setVisibility(View.GONE);
            }

          } else {
            simpleListItem.setTitle("关于我们");
            simpleListItem.setIcon(R.drawable.ic_mine_setting);
          }
        }
        view = simpleListItem;
      }
      return view;
    }
  @Override
  protected void toggleSwitch(boolean toggle) {

    if (getConversationType() != null && !TextUtils.isEmpty(getTargetId())) {
      RongIM.getInstance()
          .getRongIMClient()
          .setConversationToTop(getConversationType(), getTargetId(), toggle, null);
    }
  }
  @Override
  protected void initData() {
    mAddBlack.setOnClickListener(this);
    mRemoveBlack.setOnClickListener(this);
    if (RongIM.getInstance() != null && Util.getNetWorkType(this) != -1) {
      if (userId.equals(LoginActivity.mUserID)) {
        mUserInfo.setVisibility(View.GONE);
      } else {
        RongIM.getInstance()
            .getBlacklistStatus(
                userId,
                new RongIM.GetUserBlacklistCallback() {

                  @Override
                  public void onError(ErrorCode errorCode) {
                    Log.e(
                        TAG,
                        "-------getBlacklistStatus onError---------:"
                            + errorCode.getMessage()
                            + ",:"
                            + errorCode.getValue());
                    mUserInfo.setText(errorCode + "");
                  }

                  @Override
                  public void onSuccess(RongIMClient.BlacklistStatus status) {
                    Log.e(TAG, "-------getBlacklistStatus onSuccess---------:" + status);
                    if (status == RongIMClient.BlacklistStatus.NOT_EXIT_BLACK_LIST) {
                      mUserInfo.setText(title);

                      mAddBlack.setVisibility(View.VISIBLE);
                    } else if (status == RongIMClient.BlacklistStatus.EXIT_BLACK_LIST) {
                      mUserInfo.setText(title + "已被加入黑名单,无法收到此用户消息");
                      mRemoveBlack.setVisibility(View.VISIBLE);
                    }
                  }
                });
      }
    } else {
      WinToast.toast(UserInfoActivity.this, R.string.network_not);
    }
  }
  @Override
  protected void toggleSwitch(boolean toggle) {

    Conversation.ConversationNotificationStatus status;

    if (toggle) {
      status = Conversation.ConversationNotificationStatus.NOTIFY;
    } else {
      status = Conversation.ConversationNotificationStatus.DO_NOT_DISTURB;
    }

    if (getConversationType() != null
        && !TextUtils.isEmpty(getTargetId())
        && RongIM.getInstance() != null
        && RongIM.getInstance().getRongIMClient() != null) {

      RongIM.getInstance()
          .getRongIMClient()
          .setConversationNotificationStatus(
              getConversationType(),
              getTargetId(),
              status,
              new RongIMClient.ResultCallback<Conversation.ConversationNotificationStatus>() {

                @Override
                public void onSuccess(Conversation.ConversationNotificationStatus status) {
                  RLog.i(this, "SetConversationNotificationFragment", "onSuccess--");
                }

                @Override
                public void onError(RongIMClient.ErrorCode errorCode) {
                  setSwitchBtnStatus(!getSwitchBtnStatus());
                  // Toast.makeText(getActivity(),
                  // getString(R.string.rc_setting_conversation_notify_fail),
                  // Toast.LENGTH_SHORT).show();
                }
              });

    } else {
      RLog.e(this, "SetConversationNotificationFragment", "Arguments is null");
    }
  }
  private void refreshDot() {
    int unreadGroup =
        RongIM.getInstance()
            .getRongIMClient()
            .getUnreadCount(
                Conversation.ConversationType.PRIVATE, Conversation.ConversationType.GROUP);
    if (unreadGroup > 0) {
      groupDot.setVisibility(View.VISIBLE);
    } else {
      groupDot.setVisibility(View.GONE);
    }

    int unreadSys =
        RongIM.getInstance().getRongIMClient().getUnreadCount(Conversation.ConversationType.SYSTEM);
    if (unreadSys > 0) {
      mineDot.setVisibility(View.VISIBLE);
    } else {
      mineDot.setVisibility(View.GONE);
    }
  }
  @Override
  protected void initData() {

    if (RongContext.getInstance() != null) RongContext.getInstance().getEventBus().register(this);

    if (RongIM.getInstance() != null && RongIM.getInstance().getRongIMClient() != null) {
      RongIM.getInstance()
          .getRongIMClient()
          .getConversation(
              getConversationType(),
              getTargetId(),
              new RongIMClient.ResultCallback<Conversation>() {

                @Override
                public void onSuccess(final Conversation conversation) {
                  if (conversation != null) setSwitchBtnStatus(conversation.isTop());
                }

                @Override
                public void onError(RongIMClient.ErrorCode e) {}
              });
    }
  }
  @Override
  public void onStatusChange(final RealTimeLocationConstant.RealTimeLocationStatus status) {
    Log.e(TAG, "onStatusChange:---" + status);
    currentLocationStatus = status;

    EventBus.getDefault().post(status);

    if (status
        == RealTimeLocationConstant.RealTimeLocationStatus.RC_REAL_TIME_LOCATION_STATUS_IDLE) {
      hideRealTimeBar();

      RealTimeLocationConstant.RealTimeLocationErrorCode errorCode =
          RongIMClient.getInstance().getRealTimeLocation(mConversationType, targetId);

      if (errorCode
          == RealTimeLocationConstant.RealTimeLocationErrorCode.RC_REAL_TIME_LOCATION_SUCCESS) {
        RongIM.getInstance()
            .getRongIMClient()
            .insertMessage(
                mConversationType,
                targetId,
                RongIM.getInstance().getRongIMClient().getCurrentUserId(),
                InformationNotificationMessage.obtain("位置共享已结束"));
      }
    } else if (status
        == RealTimeLocationConstant.RealTimeLocationStatus
            .RC_REAL_TIME_LOCATION_STATUS_OUTGOING) { // 发自定义消息
      showRealTimeLocationBar(status);
    } else if (status
        == RealTimeLocationConstant.RealTimeLocationStatus.RC_REAL_TIME_LOCATION_STATUS_INCOMING) {
      showRealTimeLocationBar(status);
    } else if (status
        == RealTimeLocationConstant.RealTimeLocationStatus.RC_REAL_TIME_LOCATION_STATUS_CONNECTED) {
      showRealTimeLocationBar(status);
    }
  }
  public static void setConversationTop(
      final Context context,
      Conversation.ConversationType conversationType,
      String targetId,
      boolean state) {
    if (!TextUtils.isEmpty(targetId) && RongIM.getInstance() != null) {
      RongIM.getInstance()
          .setConversationToTop(
              conversationType,
              targetId,
              state,
              new RongIMClient.ResultCallback<Boolean>() {
                @Override
                public void onSuccess(Boolean aBoolean) {
                  //                    NToast.shortToast(context, "设置成功");
                }

                @Override
                public void onError(RongIMClient.ErrorCode errorCode) {
                  NToast.shortToast(context, "设置失败");
                }
              });
    }
  }
  private void getMyGroupApiSuccess(Object obj) {
    if (obj instanceof Groups) {
      final Groups groups = (Groups) obj;

      if (groups.getCode() == 200) {
        List<Group> grouplist = new ArrayList<Group>();
        if (groups.getResult() != null) {
          for (int i = 0; i < groups.getResult().size(); i++) {

            String id = groups.getResult().get(i).getId();
            String name = groups.getResult().get(i).getName();
            if (groups.getResult().get(i).getPortrait() != null) {
              Uri uri = Uri.parse(groups.getResult().get(i).getPortrait());
              grouplist.add(new Group(id, name, uri));
            } else {
              grouplist.add(new Group(id, name, null));
            }
          }
          HashMap<String, Group> groupM = new HashMap<String, Group>();
          for (int i = 0; i < grouplist.size(); i++) {
            groupM.put(groups.getResult().get(i).getId(), grouplist.get(i));
          }
          if (DemoContext.getInstance() != null) DemoContext.getInstance().setGroupMap(groupM);

          Intent in = new Intent();
          in.setAction(MainActivity.ACTION_DMEO_GROUP_MESSAGE);
          sendBroadcast(in);

          if (grouplist.size() > 0)
            RongIM.getInstance()
                .getRongIMClient()
                .syncGroup(
                    grouplist,
                    new RongIMClient.OperationCallback() {
                      @Override
                      public void onSuccess() {
                        Log.e(TAG, "---syncGroup-onSuccess---");
                      }

                      @Override
                      public void onError(RongIMClient.ErrorCode errorCode) {
                        Log.e(TAG, "---syncGroup-onError---");
                      }
                    });
        }
      }
    }
  }
  private void getMyGroupApiSuccess(Object obj) {
    if (obj instanceof Groups) {
      final Groups groups = (Groups) obj;

      if (groups.getCode() == 200) {
        List<Group> grouplist = new ArrayList<>();
        if (groups.getResult() != null) {
          for (int i = 0; i < groups.getResult().size(); i++) {

            String id = groups.getResult().get(i).getId();
            String name = groups.getResult().get(i).getName();
            if (groups.getResult().get(i).getPortrait() != null) {
              Uri uri = Uri.parse(groups.getResult().get(i).getPortrait());
              grouplist.add(new Group(id, name, uri));
            } else {
              grouplist.add(new Group(id, name, null));
            }
          }
          HashMap<String, Group> groupM = new HashMap<String, Group>();
          for (int i = 0; i < grouplist.size(); i++) {
            groupM.put(groups.getResult().get(i).getId(), grouplist.get(i));
            Log.e("login", "------get Group id---------" + groups.getResult().get(i).getId());
          }

          if (DemoContext.getInstance() != null) DemoContext.getInstance().setGroupMap(groupM);

          if (grouplist.size() > 0)
            RongIM.getInstance()
                .getRongIMClient()
                .syncGroup(
                    grouplist,
                    new RongIMClient.OperationCallback() {
                      @Override
                      public void onSuccess() {
                        Log.e(TAG, "---syncGroup-onSuccess---");
                      }

                      @Override
                      public void onError(RongIMClient.ErrorCode errorCode) {
                        Log.e(TAG, "---syncGroup-onError---");
                      }
                    });
        }
      } else {
        //                    WinToast.toast(this, groups.getCode());
      }
    }
  }
 private void startDoubleChatroom(Context context, String chatroomId1, String chatroomId2) {
   if (TextUtils.isEmpty(chatroomId1) && TextUtils.isEmpty(chatroomId2)) {
     NToast.shortToast(context, "chatroom ids is null");
     return;
   }
   if (RongIM.getInstance()
       .getCurrentConnectionStatus()
       .equals(RongIMClient.ConnectionStatusListener.ConnectionStatus.DISCONNECTED)) {
     NToast.shortToast(context, "please connection");
     return;
   }
   Intent intent = new Intent(context, DoubleChatRoomActivity.class);
   intent.putExtra("chatroomId1", chatroomId1);
   intent.putExtra("chatroomId2", chatroomId2);
   startActivity(intent);
 }
  /** 根据 targetid 和 ConversationType 进入到设置页面 */
  private void enterSettingActivity() {

    if (mConversationType == Conversation.ConversationType.PUBLIC_SERVICE
        || mConversationType == Conversation.ConversationType.APP_PUBLIC_SERVICE) {

      RongIM.getInstance().startPublicServiceProfile(this, mConversationType, targetId);
    } else {
      // 通过targetId 和 会话类型 打开指定的设置页面
      if (!TextUtils.isEmpty(targetId)) {

        Uri uri =
            Uri.parse("demo://" + getApplicationInfo().packageName)
                .buildUpon()
                .appendPath("conversationSetting")
                .appendPath(mConversationType.getName())
                .appendQueryParameter("targetId", targetId)
                .build();

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(uri);
        startActivity(intent);
        // 当你刚刚创建完讨论组以后获得的是 targetIds
      } else if (!TextUtils.isEmpty(targetIds)) {

        UriFragment fragment = (UriFragment) getSupportFragmentManager().getFragments().get(0);
        fragment.getUri();
        // 得到讨论组的 targetId
        targetId = fragment.getUri().getQueryParameter("targetId");

        if (!TextUtils.isEmpty(targetId)) {
          Uri uri =
              Uri.parse("demo://" + getApplicationInfo().packageName)
                  .buildUpon()
                  .appendPath("conversationSetting")
                  .appendPath(mConversationType.getName())
                  .appendQueryParameter("targetId", targetId)
                  .build();

          Intent intent = new Intent(Intent.ACTION_VIEW);
          intent.setData(uri);
          startActivity(intent);
        } else {
          WinToast.toast(RongActivity.this, "讨论组尚未创建成功");
        }
      }
    }
  }
  @Override
  public boolean handleMessage(android.os.Message msg) {
    switch (msg.what) {
      case PREPARE_LIST:
        List<String> mMemberInfo = (List<String>) msg.obj;
        int i = 0;
        for (String id : mMemberInfo) {
          if (i < 50) {
            UserInfo userInfo = RongContext.getInstance().getUserInfoFromCache(id);
            if (userInfo == null) {
              mMembers.add(new UserInfo(id, null, null));
            } else mMembers.add(userInfo);
          } else {
            break;
          }

          i++;
        }
        UserInfo addBtn = new UserInfo("RongAddBtn", null, null);
        mMembers.add(addBtn);

        String curUserId = RongIM.getInstance().getRongIMClient().getCurrentUserId();
        if (mAdapter.getCreatorId() != null
            && mConversationType.equals(Conversation.ConversationType.DISCUSSION)
            && curUserId.equals(mAdapter.getCreatorId())) {
          UserInfo deleteBtn = new UserInfo("RongDelBtn", null, null);
          mMembers.add(deleteBtn);
        }

        mAdapter.addCollection(mMembers);
        mAdapter.notifyDataSetChanged();
        break;
      case REMOVE_ITEM:
        int position = (Integer) msg.obj;
        mAdapter.remove(position);
        mAdapter.notifyDataSetChanged();
        break;
      case SHOW_TOAST:
        break;
    }
    return true;
  }
  @Override
  public void onDeleteIconClick(View view, final int position) {
    UserInfo temp = mAdapter.getItem(position);
    RongIM.getInstance()
        .getRongIMClient()
        .removeMemberFromDiscussion(
            mTargetId,
            temp.getUserId(),
            new RongIMClient.OperationCallback() {
              @Override
              public void onSuccess() {
                Message msg = new Message();
                msg.what = REMOVE_ITEM;
                msg.obj = position;
                getHandler().sendMessage(msg);
              }

              @Override
              public void onError(RongIMClient.ErrorCode errorCode) {
                getHandler().sendEmptyMessage(SHOW_TOAST);
              }
            });
  }
  /** 得到 push 消息 */
  private void getPushMessage() {

    Intent intent = getIntent();
    if (intent != null && intent.getData() != null && intent.getData().getScheme().equals("rong")) {
      String content = intent.getData().getQueryParameter("pushContent");
      String data = intent.getData().getQueryParameter("pushData");
      String id = intent.getData().getQueryParameter("pushId");
      RongIMClient.recordNotificationEvent(id);
      Log.e("RongPushActivity", "--content--" + content + "--data--" + data + "--id--" + id);
      if (RongIM.getInstance() != null && RongIM.getInstance().getRongIMClient() != null) {
        RongIM.getInstance().getRongIMClient().clearNotifications();
      }
      if (DemoContext.getInstance() != null) {
        String token =
            DemoContext.getInstance().getSharedPreferences().getString("DEMO_TOKEN", "default");
        if (token.equals("default")) {
          startActivity(new Intent(MainActivity.this, LoginActivity.class));
        } else {
          if (RongIM.getInstance() != null && RongIM.getInstance().getRongIMClient() != null) {
            RongIMClient.ConnectionStatusListener.ConnectionStatus status =
                RongIM.getInstance().getRongIMClient().getCurrentConnectionStatus();
            if (RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTED.equals(status)) {
              return;
            } else if (RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTING.equals(
                status)) {
              return;
            } else {
              Intent intent1 = new Intent(MainActivity.this, LoginActivity.class);
              intent1.putExtra("PUSH_MESSAGE", true);
              startActivity(intent1);
              finish();
            }
          } else {
            Intent intent1 = new Intent(MainActivity.this, LoginActivity.class);
            intent1.putExtra("PUSH_MESSAGE", true);
            startActivity(intent1);
            finish();
          }
        }
      }
    }
  }
  protected void initView() {

    mRealTimeBar = (RelativeLayout) this.findViewById(R.id.layout);

    mRealTimeBar.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {

            if (currentLocationStatus == null)
              currentLocationStatus =
                  RongIMClient.getInstance()
                      .getRealTimeLocationCurrentState(mConversationType, targetId);

            if (currentLocationStatus
                == RealTimeLocationConstant.RealTimeLocationStatus
                    .RC_REAL_TIME_LOCATION_STATUS_INCOMING) {

              final AlterDialogFragment alterDialogFragment =
                  AlterDialogFragment.newInstance("", "加入位置共享", "取消", "加入");
              alterDialogFragment.setOnAlterDialogBtnListener(
                  new AlterDialogFragment.AlterDialogBtnListener() {

                    @Override
                    public void onDialogPositiveClick(AlterDialogFragment dialog) {
                      RealTimeLocationConstant.RealTimeLocationStatus status =
                          RongIMClient.getInstance()
                              .getRealTimeLocationCurrentState(mConversationType, targetId);

                      if (status == null
                          || status
                              == RealTimeLocationConstant.RealTimeLocationStatus
                                  .RC_REAL_TIME_LOCATION_STATUS_IDLE) {
                        startRealTimeLocation();
                      } else {
                        joinRealTimeLocation();
                      }
                    }

                    @Override
                    public void onDialogNegativeClick(AlterDialogFragment dialog) {
                      alterDialogFragment.dismiss();
                    }
                  });
              alterDialogFragment.show(getSupportFragmentManager());

            } else {
              Intent intent = new Intent(RongActivity.this, RealTimeLocationActivity.class);
              intent.putExtra("conversationType", mConversationType.getValue());
              intent.putExtra("targetId", targetId);
              startActivity(intent);
            }
          }
        });

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.de_actionbar_back);
    mHandler = new Handler(this);
    Intent intent = getIntent();
    mUserInfosDao = DBManager.getInstance(this).getDaoSession().getUserInfosDao();

    if (intent != null
        && intent.hasExtra("DEMO_COVERSATIONTYPE")
        && intent.hasExtra("DEMO_TARGETID")
        && intent.hasExtra("DEMO_COVERSATION")) {

      if (DemoContext.getInstance() != null) {
        String conversation = intent.getStringExtra("DEMO_COVERSATION");
        targetId = intent.getStringExtra("DEMO_TARGETID");
        String conversationType = intent.getStringExtra("DEMO_COVERSATIONTYPE");
        openConversationFragment(conversation, targetId, conversationType);
      }
    }

    // push或通知过来
    if (intent != null
        && intent.getData() != null
        && intent.getData().getScheme().equals("rong")
        && intent.getData().getQueryParameter("push") != null) {

      // 通过intent.getData().getQueryParameter("push") 为true,判断是否是push消息
      if (DemoContext.getInstance() != null
          && intent.getData().getQueryParameter("push").equals("true")) {
        String id = intent.getData().getQueryParameter("pushId");
        RongIM.getInstance().getRongIMClient().recordNotificationEvent(id);
        enterActivity(intent);
      }

    } else if (intent != null) {
      // 程序切到后台,收到消息后点击进入,会执行这里
      if (RongIM.getInstance() == null || RongIM.getInstance().getRongIMClient() == null) {
        if (DemoContext.getInstance() != null) {
          String token =
              DemoContext.getInstance().getSharedPreferences().getString("DEMO_TOKEN", "default");
          reconnect(token);
        }
      } else {
        enterFragment(intent);
      }
    }
  }
  public void onEventMainThread(RongEvent.RealTimeLocationMySelfJoinEvent event) {

    onParticipantsJoin(RongIM.getInstance().getRongIMClient().getCurrentUserId());
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.add_item1: // 发起聊天
        startActivity(new Intent(this, FriendListActivity.class));
        break;
      case R.id.add_item2: // 选择群组
        if (RongIM.getInstance() != null)
          RongIM.getInstance().startSubConversationList(this, Conversation.ConversationType.GROUP);
        break;
      case R.id.add_item3: // 通讯录
        startActivity(new Intent(MainActivity.this, ContactsActivity.class));
        break;
      case R.id.set_item1: // 我的账号
        startActivity(new Intent(MainActivity.this, MyAccountActivity.class));
        break;
      case R.id.set_item2: // 新消息提醒
        startActivity(new Intent(MainActivity.this, NewMessageRemindActivity.class));
        break;
      case R.id.set_item3: // 隐私
        startActivity(new Intent(MainActivity.this, PrivacyActivity.class));
        break;
      case R.id.set_item4: // 关于融云
        startActivity(new Intent(MainActivity.this, AboutRongCloudActivity.class));
        break;
      case R.id.set_item5: // 退出
        final AlertDialog.Builder alterDialog = new AlertDialog.Builder(this);
        alterDialog.setMessage("确定退出应用?");
        alterDialog.setCancelable(true);

        alterDialog.setPositiveButton(
            "确定",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {

                if (RongIM.getInstance() != null) {
                  if (DemoContext.getInstance() != null) {
                    SharedPreferences.Editor edit =
                        DemoContext.getInstance().getSharedPreferences().edit();
                    edit.putString(Constants.APP_TOKEN, Constants.DEFAULT);
                    edit.apply();
                  }
                  RongIM.getInstance().logout();
                  try {
                    Thread.sleep(500);
                    Process.killProcess(Process.myPid());
                  } catch (InterruptedException e) {
                    e.printStackTrace();
                  }
                }
              }
            });
        alterDialog.setNegativeButton(
            "取消",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
              }
            });
        alterDialog.show();

        break;
    }
    return super.onOptionsItemSelected(item);
  }