Пример #1
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;
    }
  }
Пример #2
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;
    }
  }
Пример #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;
  }
Пример #4
0
  public JSONObject toJSONObject() {
    JSONObject message = new JSONObject();

    try {
      message.put("from", this.getFrom());
      message.put("type", this.getType());
      message.put("id", this.getId());
      message.put("action", this.getAction());
      message.put("data", this.getData());

      if (this.getMoreData() != null) {
        message.put("moredata", this.getMoreData());
      }

      return message;
    } catch (JSONException e) {
      SurespotLog.w(TAG, "toJSONObject", e);
    }
    return null;
  }
Пример #5
0
  public void removeChat(int viewId, int index) {

    Friend friend = mChatFriends.remove(index - 1);

    String fragname = makeFragmentName(viewId, friend.getName().hashCode());
    Fragment fragment = mFragmentManager.findFragmentByTag(fragname);

    SurespotLog.d(TAG, "removeChat, index: %d, name: %s", index, fragname);

    // SurespotLog.v(TAG, "Detaching item #" + getItemId(position-1) + ": f=" + object
    // + " v=" + ((Fragment)object).getView());
    if (fragment != null) {
      // blow the fragment away
      if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
      }

      mCurTransaction.remove(fragment);
      // mCurTransaction.commit();
    }

    notifyDataSetChanged();
  }