use of com.google.samples.apps.iosched.session.data.QueueAction in project iosched by google.
the class SessionDetailModel method attemptReserve.
public void attemptReserve() {
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
if (mQueueReference != null && currentUser != null) {
final String requestId = generateReserveRequestId();
QueueAction queueAction = new QueueAction(mSessionId, "reserve", requestId);
mQueueReference.addValueEventListener(mQueueEventListener);
mQueueReference.setValue(queueAction).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
LOGD(TAG, "Enter queue.");
mReservationPending = true;
mReturnPending = false;
DataQueryCallback<SessionDetailQueryEnum> reservationPendingCallback = mDataQueryCallbacks.get(RESERVATION_PENDING);
reservationPendingCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_PENDING);
mSessionReservationResultReference.child(requestId).addValueEventListener(mSessionReservationResultEventListener);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
LOGE(TAG, e.getMessage());
mReservationPending = false;
mReturnPending = false;
DataQueryCallback<SessionDetailQueryEnum> reservationFailedCallback = mDataQueryCallbacks.get(RESERVATION_FAILED);
reservationFailedCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_FAILED);
}
});
}
}
use of com.google.samples.apps.iosched.session.data.QueueAction in project iosched by google.
the class SessionDetailModel method initReservationListeners.
public void initReservationListeners() {
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
if (currentUser != null) {
mQueueReference = getQueueReference(currentUser.getUid());
mSessionReservationStatusReference = getReservationStatusReference(currentUser.getUid(), mSessionId);
mSessionReservationResultReference = getReservationResultsReference(currentUser.getUid(), mSessionId);
mSeatAvailabilityReference = getSeatAvailabilityReference(mSessionId);
mSessionReservationStatusEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
try {
String reservationStatus = dataSnapshot.getValue(String.class);
if (reservationStatus != null) {
mReservationStatus = reservationStatus;
mSessionsHelper.setReservationStatus(mSessionUri, ScheduleContract.MyReservations.fromFirebaseString(mReservationStatus), mTitle);
final DataQueryCallback<SessionDetailQueryEnum> reservationStatusCallback = mDataQueryCallbacks.get(RESERVATION_STATUS);
reservationStatusCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_STATUS);
}
} catch (DatabaseException e) {
LOGE(TAG, e.getMessage());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
LOGE(TAG, databaseError.getMessage());
}
};
mSessionReservationResultEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
try {
String reservationResult = dataSnapshot.getValue(String.class);
if (reservationResult != null) {
mReservationResult = reservationResult;
DataQueryCallback<SessionDetailQueryEnum> reservationResultCallback = mDataQueryCallbacks.get(RESERVATION_RESULT);
reservationResultCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_RESULT);
mSessionReservationResultReference.removeEventListener(this);
}
} catch (DatabaseException e) {
LOGE(TAG, e.getMessage());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
LOGE(TAG, databaseError.getMessage());
}
};
mQueueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
try {
DataQueryCallback<SessionDetailQueryEnum> reservationPendingCallback = mDataQueryCallbacks.get(RESERVATION_PENDING);
QueueAction queueAction = dataSnapshot.getValue(QueueAction.class);
if (queueAction == null) {
LOGD(TAG, "Exit queue");
mReturnPending = false;
mReservationPending = false;
mQueueReference.removeEventListener(this);
reservationPendingCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_PENDING);
}
} catch (DatabaseException e) {
LOGE(TAG, e.getMessage());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
LOGE(TAG, databaseError.getMessage());
}
};
mSeatAvailabilityEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
DataQueryCallback<SessionDetailQueryEnum> seatAvailabilityCallback = mDataQueryCallbacks.get(RESERVATION_SEAT_AVAILABILITY);
Boolean seatsAvailable = dataSnapshot.getValue(Boolean.class);
if (seatsAvailable != null) {
mSeatsAvailable = seatsAvailable;
seatAvailabilityCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_SEAT_AVAILABILITY);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
LOGE(TAG, databaseError.getMessage());
}
};
mSessionReservationStatusReference.addValueEventListener(mSessionReservationStatusEventListener);
mSeatAvailabilityReference.addValueEventListener(mSeatAvailabilityEventListener);
} else {
LOGD(TAG, "Not signed in.");
invalidateReservationCache();
DataQueryCallback<SessionDetailQueryEnum> authCallback = mDataQueryCallbacks.get(AUTH_REGISTRATION);
authCallback.onModelUpdated(SessionDetailModel.this, AUTH_REGISTRATION);
}
}
use of com.google.samples.apps.iosched.session.data.QueueAction in project iosched by google.
the class SessionDetailModel method attemptReturnReservation.
public void attemptReturnReservation() {
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
if (mQueueReference != null && currentUser != null) {
final String requestId = generateReserveRequestId();
QueueAction queueAction = new QueueAction(mSessionId, "return", requestId);
mQueueReference.addValueEventListener(mQueueEventListener);
mQueueReference.setValue(queueAction).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
LOGD(TAG, "Enter queue.");
mReservationPending = false;
mReturnPending = true;
DataQueryCallback<SessionDetailQueryEnum> reservationPendingCallback = mDataQueryCallbacks.get(RESERVATION_PENDING);
reservationPendingCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_PENDING);
mSessionReservationResultReference.child(requestId).addValueEventListener(mSessionReservationResultEventListener);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
LOGE(TAG, e.getMessage());
mReservationPending = false;
mReturnPending = false;
DataQueryCallback<SessionDetailQueryEnum> reservationFailedCallback = mDataQueryCallbacks.get(RESERVATION_FAILED);
reservationFailedCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_FAILED);
}
});
}
}
Aggregations