playgameservices / android-basic-samples

Google Play game services - Android samples
Apache License 2.0
972 stars 970 forks source link

ButtonClicker - room still open when leaving #140

Closed edesdan closed 9 years ago

edesdan commented 9 years ago

Hi notice that there is a bug in ButtonClicker example:

Games.RealTimeMultiplayer.leave gets called only if mRoomId is not null:

    void leaveRoom() {
        Log.d(TAG, "Leaving room.");
        mSecondsLeft = 0;
        stopKeepingScreenOn();
        if (mRoomId != null) {
            Games.RealTimeMultiplayer.leave(mGoogleApiClient, this, mRoomId);
            mRoomId = null;
            switchToScreen(R.id.screen_wait);
        } else {
            switchToMainScreen();
        }
    }

but at this point:

@Override
    public void onRoomCreated(int statusCode, Room room) {
     .....
        // show the waiting room UI
        showWaitingRoom(room);
    } 

the room is created and if the user quit the UI waiting window the leave method cannot really allow leaving the room because roomId = null but the room is created.

Maybe it could be better to get the roomId inside here:

 @Override
    public void onRoomCreated(int statusCode, Room room) {
        Log.d(TAG, "onRoomCreated(" + statusCode + ", " + room + ")");
        if (statusCode != GamesStatusCodes.STATUS_OK) {
            Log.e(TAG, "*** Error: onRoomCreated, status " + statusCode);
            showGameError();
            return;
        }
//get room ID
roomId = room.getRoomId();
//
        // show the waiting room UI
        showWaitingRoom(room);
    }

rather than within public void onConnectedToRoom(Room room) method.

claywilkinson commented 9 years ago

Nice suggestion! Thanks.