public static JsGroup fromGroupVM(GroupVM groupVM, JsMessenger messenger) {
    int online = groupVM.getPresence().get();
    String presence = messenger.getFormatter().formatGroupMembers(groupVM.getMembersCount());
    if (online > 0) {
      presence += ", " + messenger.getFormatter().formatGroupOnline(online);
    }
    String fileUrl = null;
    String bigFileUrl = null;
    Avatar avatar = groupVM.getAvatar().get();
    if (avatar != null) {
      if (avatar.getSmallImage() != null) {
        fileUrl = messenger.getFileUrl(avatar.getSmallImage().getFileReference());
      }
      if (avatar.getLargeImage() != null) {
        bigFileUrl = messenger.getFileUrl(avatar.getLargeImage().getFileReference());
      }
    }

    ArrayList<JsGroupMember> convertedMembers = new ArrayList<JsGroupMember>();
    HashSet<GroupMember> groupMembers = groupVM.getMembers().get();
    GroupMember[] members = groupMembers.toArray(new GroupMember[groupMembers.size()]);
    for (GroupMember g : members) {
      JsPeerInfo peerInfo = messenger.buildPeerInfo(Peer.user(g.getUid()));
      Log.d("JsGroup", "PeerInfo: " + peerInfo);
      convertedMembers.add(
          JsGroupMember.create(
              peerInfo,
              g.isAdministrator(),
              g.getInviterUid() == messenger.myUid()
                  || groupVM.getCreatorId() == messenger.myUid()));
    }
    Collections.sort(
        convertedMembers,
        new Comparator<JsGroupMember>() {
          @Override
          public int compare(JsGroupMember o1, JsGroupMember o2) {
            return o1.getPeerInfo().getTitle().compareToIgnoreCase(o2.getPeerInfo().getTitle());
          }
        });
    JsArray<JsGroupMember> jsMembers = JsArray.createArray().cast();
    for (JsGroupMember member : convertedMembers) {
      jsMembers.push(member);
    }
    return create(
        groupVM.getId(),
        groupVM.getName().get(),
        fileUrl,
        bigFileUrl,
        Placeholders.getPlaceholder(groupVM.getId()),
        groupVM.getCreatorId(),
        presence,
        jsMembers);
  }
Example #2
0
  @Override
  protected void onPerformBind() {
    super.onPerformBind();

    // Performing all required Data Binding here

    if (peer.getPeerType() == PeerType.PRIVATE) {

      // Loading user
      final UserVM user = users().get(peer.getPeerId());
      if (user == null) {
        finish();
        return;
      }

      // Binding User Avatar to Toolbar
      bind(barAvatar, user.getId(), user.getAvatar(), user.getName());

      // Binding User name to Toolbar
      bind(barTitle, user.getName());

      // Binding User presence to Toolbar
      bind(barSubtitle, barSubtitleContainer, user);

      // Binding User typing to Toolbar
      bindPrivateTyping(
          barTyping, barTypingContainer, barSubtitle, messenger().getTyping(user.getId()));

      // Hide removedFromGroup panel as we are not in group
      removedFromGroup.setVisibility(View.GONE);

    } else if (peer.getPeerType() == PeerType.GROUP) {

      // Loading group
      GroupVM group = groups().get(peer.getPeerId());
      if (group == null) {
        finish();
        return;
      }

      // Binding Group avatar to Toolbar
      bind(barAvatar, group.getId(), group.getAvatar(), group.getName());

      // Binding Group title to Toolbar
      bind(barTitle, group.getName());

      // Subtitle is always visible for Groups
      barSubtitleContainer.setVisibility(View.VISIBLE);

      // Binding group members
      bind(barSubtitle, barSubtitleContainer, group);

      // Binding group typing
      bindGroupTyping(
          barTyping, barTypingContainer, barSubtitle, messenger().getGroupTyping(group.getId()));

      // Binding membership flag to removedFromGroup panel
      bind(
          messenger().getGroups().get(peer.getPeerId()).isMember(),
          new ValueChangedListener<Boolean>() {
            @Override
            public void onChanged(Boolean val, Value<Boolean> Value) {
              removedFromGroup.setVisibility(val ? View.GONE : View.VISIBLE);
            }
          });
    }
  }