コード例 #1
0
  public static void goToRoomPage(
      final MXSession aSession,
      final String roomId,
      final Activity fromActivity,
      final Intent intentParam) {
    // check first if the 1:1 room already exists
    MXSession session = (aSession == null) ? Matrix.getMXSession(fromActivity, null) : aSession;

    // sanity check
    if ((null == session) || !session.isActive()) {
      return;
    }

    final MXSession fSession = session;

    Room room = session.getDataHandler().getRoom(roomId);

    // do not open a leaving room.
    // it does not make.
    if ((null != room) && (room.isLeaving())) {
      return;
    }

    fromActivity.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            // if the activity is not the home activity
            if (!(fromActivity instanceof HomeActivity)) {
              // pop to the home activity
              Intent intent = new Intent(fromActivity, HomeActivity.class);
              intent.setFlags(
                  android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP
                      | android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP);
              intent.putExtra(HomeActivity.EXTRA_JUMP_TO_ROOM_ID, roomId);
              intent.putExtra(HomeActivity.EXTRA_JUMP_MATRIX_ID, fSession.getCredentials().userId);
              if (null != intentParam) {
                intent.putExtra(HomeActivity.EXTRA_ROOM_INTENT, intentParam);
              }
              fromActivity.startActivity(intent);
            } else {
              // already to the home activity
              // so just need to open the room activity
              Intent intent = new Intent(fromActivity, RoomActivity.class);
              intent.putExtra(RoomActivity.EXTRA_ROOM_ID, roomId);
              intent.putExtra(RoomActivity.EXTRA_MATRIX_ID, fSession.getCredentials().userId);
              if (null != intentParam) {
                intent.putExtra(HomeActivity.EXTRA_ROOM_INTENT, intentParam);
              }
              fromActivity.startActivity(intent);
            }
          }
        });
  }