コード例 #1
0
  @Override
  public int getItemPosition(Object object) {
    SurespotLog.v(TAG, "getItemPosition, object: " + object.getClass().getName());
    if (object instanceof FriendFragment) {
      SurespotLog.v(TAG, "getItemPosition, returning 0");
      return 0;
    }

    ChatFragment chatFragment = (ChatFragment) object;

    String user = chatFragment.getTheirUsername();
    int index = getFriendIndex(user);

    if (index == -1) {
      SurespotLog.v(TAG, "getItemPosition, returning POSITION_NONE for: " + user);
      return POSITION_NONE;
    } else {
      SurespotLog.v(TAG, "getItemPosition, returning " + (index + 1) + " for: " + user);
      return index + 1;
    }
  }
コード例 #2
0
  @Override
  public Fragment getItem(int i) {
    SurespotLog.v(TAG, "getItem, I: " + i);
    if (i == 0) {

      FriendFragment ff = FriendFragment.newInstance(mOurUSername);
      SurespotLog.v(TAG, "created new friend fragment: " + ff);

      // ff.setRetainInstance(true);

      return ff;
    } else {
      String name = mChatFriends.get(i - 1).getName();
      ChatFragment cf = ChatFragment.newInstance(mOurUSername, name);
      SurespotLog.v(TAG, "created new chat fragment: " + cf);

      // cf.setRetainInstance(true);

      return cf;
    }
  }
コード例 #3
0
  private synchronized int getFriendIndex(String username) {
    ListIterator<Friend> iterator = mChatFriends.listIterator();

    while (iterator.hasNext()) {
      if (iterator.next().getName().equals(username)) {
        int index = iterator.previousIndex();
        SurespotLog.v(TAG, "friend index for %s: %d", username, index);
        return index;
      }
    }

    return -1;
  }