コード例 #1
0
  /** refresh each activity views */
  private void refresh() {

    final View refreshingView = findViewById(R.id.profile_mask);
    refreshingView.setVisibility(View.GONE);

    mMatrixIdTextView.setText(mMemberId);
    this.setTitle(mMember.displayname);
    this.refreshProfileThumbnail();

    ArrayList<String> buttonTitles = new ArrayList<String>();

    // Check user's power level before allowing an action (kick, ban, ...)
    PowerLevels powerLevels = mRoom.getLiveState().getPowerLevels();

    int userPowerLevel = powerLevels.getUserPowerLevel(mMemberId);
    int myPowerLevel = powerLevels.getUserPowerLevel(mFromUserId);

    // Consider the case of the user himself
    if (mMemberId.equals(mFromUserId)) {
      buttonTitles.add(getResources().getString(R.string.leave));

      if (userPowerLevel >= powerLevels.stateDefault) {
        buttonTitles.add(getResources().getString(R.string.set_power_level));
      }
    } else {

      if ((RoomMember.MEMBERSHIP_JOIN.equals(mMember.membership))
          || (RoomMember.MEMBERSHIP_INVITE.equals(mMember.membership))) {
        // Check conditions to be able to kick someone
        if ((myPowerLevel >= powerLevels.kick) && (myPowerLevel >= userPowerLevel)) {
          buttonTitles.add(getResources().getString(R.string.kick));
        }

        // Check conditions to be able to ban someone
        if ((myPowerLevel >= powerLevels.ban) && (myPowerLevel >= userPowerLevel)) {
          buttonTitles.add(getResources().getString(R.string.ban));
        }
      } else if (RoomMember.MEMBERSHIP_LEAVE.equals(mMember.membership)) {
        // Check conditions to be able to invite someone
        if (myPowerLevel >= powerLevels.invite) {
          buttonTitles.add(getResources().getString(R.string.invite));
        }
        // Check conditions to be able to ban someone
        if (myPowerLevel >= powerLevels.ban) {
          buttonTitles.add(getResources().getString(R.string.ban));
        }
      } else if (RoomMember.MEMBERSHIP_BAN.equals(mMember.membership)) {
        // Check conditions to be able to invite someone
        if (myPowerLevel >= powerLevels.ban) {
          buttonTitles.add(getResources().getString(R.string.unban));
        }
      }

      // update power level
      if (myPowerLevel >= powerLevels.stateDefault) {
        buttonTitles.add(getResources().getString(R.string.set_power_level));
      }

      // allow to invite an user if the room has > 2 users
      // else it will reopen this chat
      if (mRoom.getMembers().size() > 2) {
        buttonTitles.add(getResources().getString(R.string.chat));
      }
    }

    // display the available buttons
    int buttonIndex = 0;
    for (; buttonIndex < buttonTitles.size(); buttonIndex++) {
      Button button = mButtonsList.get(buttonIndex);
      button.setVisibility(View.VISIBLE);
      button.setEnabled(true);
      button.setText(buttonTitles.get(buttonIndex));
    }

    for (; buttonIndex < mButtonsList.size(); buttonIndex++) {
      Button button = mButtonsList.get(buttonIndex);
      button.setVisibility(View.INVISIBLE);
    }
    updatePresenceInfo();
  }
  /**
   * Init the dialog view.
   *
   * @param v the dialog view.
   */
  void initView(View v) {
    mListView = ((ListView) v.findViewById(R.id.listView_members));

    IMXStore store = mSession.getDataHandler().getStore();

    // remove the current room members
    ArrayList<String> idsToIgnore = new ArrayList<String>();
    Room room = store.getRoom(mRoomId);
    Collection<RoomMember> currentMembers = room.getMembers();

    for (RoomMember member : currentMembers) {
      idsToIgnore.add(member.getUserId());
    }

    // get the members list
    ArrayList<RoomMember> members_OneToOne = new ArrayList<RoomMember>();
    ArrayList<String> ids_OneToOne = new ArrayList<String>();

    ArrayList<RoomMember> members_MaxTenMembers = new ArrayList<RoomMember>();
    ArrayList<String> ids_MaxTenMembers = new ArrayList<String>();

    ArrayList<RoomMember> members_BigRooms = new ArrayList<RoomMember>();
    ArrayList<String> ids_BigRooms = new ArrayList<String>();

    Collection<RoomSummary> summaries = store.getSummaries();

    for (RoomSummary summary : summaries) {
      // not the current summary
      if (!summary.getRoomId().equals(mRoomId)) {
        Collection<RoomMember> otherRoomMembers = room.getMembers();

        for (RoomMember member : otherRoomMembers) {
          String userID = member.getUserId();

          // accepted User ID or still active users
          if ((idsToIgnore.indexOf(userID) < 0)
              && (RoomMember.MEMBERSHIP_JOIN.equals(member.membership))) {
            int posOneToOne = ids_OneToOne.indexOf(userID);
            int posTenMembers = ids_MaxTenMembers.indexOf(userID);
            int posBigRooms = ids_BigRooms.indexOf(userID);

            if (otherRoomMembers.size() <= 2) {
              if (posBigRooms >= 0) {
                members_BigRooms.remove(posBigRooms);
                ids_BigRooms.remove(posBigRooms);
              }

              if (posTenMembers >= 0) {
                members_MaxTenMembers.remove(posTenMembers);
                ids_MaxTenMembers.remove(posTenMembers);
              }

              if (posOneToOne < 0) {
                members_OneToOne.add(member);
                ids_OneToOne.add(member.getUserId());
              }
            } else if (otherRoomMembers.size() <= 10) {
              if (posBigRooms >= 0) {
                members_BigRooms.remove(posBigRooms);
                ids_BigRooms.remove(posBigRooms);
              }

              if ((posTenMembers < 0) && (posOneToOne < 0)) {
                members_MaxTenMembers.add(member);
                ids_MaxTenMembers.add(member.getUserId());
              }
            } else {
              if ((posBigRooms < 0) && (posTenMembers < 0) && (posOneToOne < 0)) {
                members_BigRooms.add(member);
                ids_BigRooms.add(member.getUserId());
              }
            }
          }
        }
      }
    }

    mAdapter =
        new MembersInvitationAdapter(
            getActivity(), R.layout.adapter_item_members_invitation, getMXMediasCache());

    Collections.sort(members_OneToOne, alphaComparator);
    Collections.sort(members_MaxTenMembers, alphaComparator);
    Collections.sort(members_BigRooms, alphaComparator);

    mAdapter.addAll(members_OneToOne);
    mAdapter.addAll(members_MaxTenMembers);
    mAdapter.addAll(members_BigRooms);

    ArrayList<Integer> bounds = new ArrayList<Integer>();
    ArrayList<String> sectionTitles = new ArrayList<String>();

    int index = 0;

    if (members_OneToOne.size() > 0) {
      bounds.add(index);
      sectionTitles.add(getActivity().getResources().getString(R.string.members_one_to_one));
      index += members_OneToOne.size();
    }

    if (members_MaxTenMembers.size() > 0) {
      bounds.add(index);
      sectionTitles.add(
          getActivity().getResources().getString(R.string.members_small_room_members));
      index += members_MaxTenMembers.size();
    }

    if (members_BigRooms.size() > 0) {
      bounds.add(index);
      sectionTitles.add(
          getActivity().getResources().getString(R.string.members_large_room_members));
      index += members_BigRooms.size();
    }

    mAdapter.setSectionTiles(bounds, sectionTitles);

    mListView.setAdapter(mAdapter);
  }