예제 #1
0
  private void showMentions(boolean initEmpty) {
    if (isMentionsVisible) {
      return;
    }
    isMentionsVisible = true;

    GroupVM groupInfo = groups().get(peer.getPeerId());
    mentionsAdapter =
        new MentionsAdapter(
            groupInfo.getId(),
            this,
            new MentionsAdapter.MentionsUpdatedCallback() {

              @Override
              public void onMentionsUpdated(int oldRowsCount, int newRowsCount) {
                onMentionsChanged(oldRowsCount, newRowsCount);
              }
            },
            initEmpty);

    mentionsList.setAdapter(mentionsAdapter);
    mentionsList.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Object item = parent.getItemAtPosition(position);
            if (item != null && item instanceof MentionFilterResult) {

              String origMention = ((MentionFilterResult) item).getMentionString();

              if (mentionStart != -1
                  && mentionStart + mentionSearchString.length() + 1
                      <= messageEditText.getText().length()) {

                String mentionString = origMention + ": ";

                Editable text = messageEditText.getText();

                int cursorPosition = mentionStart + mentionString.length();

                text.replace(
                    mentionStart, mentionStart + mentionSearchString.length() + 1, mentionString);

                messageEditText.setSelection(cursorPosition, cursorPosition);
              }
              hideMentions();
            }
          }
        });

    expandMentions(mentionsList, 0, mentionsList.getCount());
  }
예제 #2
0
  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);
  }
예제 #3
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);
            }
          });
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    type = getArguments().getInt("EXTRA_TYPE");
    id = getArguments().getInt("EXTRA_ID");

    helper = new KeyboardHelper(getActivity());
    View res = inflater.inflate(R.layout.fragment_edit_about, container, false);
    aboutEdit = (EditText) res.findViewById(R.id.nameEdit);
    if (type == EditAboutActivity.TYPE_ME) {
      UserVM userModel = users().get(myUid());
      aboutEdit.setText(userModel.getAbout().get());
    } else if (type == EditAboutActivity.TYPE_GROUP) {
      GroupVM group = groups().get(id);
      aboutEdit.setText(group.getAbout().get());
    }
    res.findViewById(R.id.cancel)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                getActivity().finish();
              }
            });
    res.findViewById(R.id.ok)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                String about = aboutEdit.getText().toString().trim();
                if (about.length() == 0) {
                  Toast.makeText(getActivity(), R.string.toast_empty_about, Toast.LENGTH_SHORT)
                      .show();
                  return;
                }

                if (type == EditAboutActivity.TYPE_ME) {
                  execute(
                      messenger().editMyAbout(about),
                      R.string.progress_common,
                      new CommandCallback<Boolean>() {
                        @Override
                        public void onResult(Boolean res) {
                          getActivity().finish();
                        }

                        @Override
                        public void onError(Exception e) {
                          Toast.makeText(
                                  getActivity(), R.string.toast_unable_change, Toast.LENGTH_SHORT)
                              .show();
                        }
                      });
                  // TODO: set group about
                } else if (type == EditAboutActivity.TYPE_GROUP) {
                  execute(
                      messenger().editGroupAbout(id, about),
                      R.string.edit_about_process,
                      new CommandCallback<Boolean>() {
                        @Override
                        public void onResult(Boolean res) {
                          getActivity().finish();
                        }

                        @Override
                        public void onError(Exception e) {
                          Toast.makeText(
                                  getActivity(), R.string.toast_unable_change, Toast.LENGTH_SHORT)
                              .show();
                        }
                      });
                }
              }
            });
    return res;
  }