@Override protected void onHandleIntent(Intent intent) { // Fetch data passed into the intent on start if (user == null) { user = ((User) intent.getSerializableExtra("user")).rebuild(); if (user.getRideId() != null) { ride = fetchRide(user.getRideId()); } } User newUser = fetchUser(user.getLoginUserId()); Ride newRide = null; if (newUser != null) { if (newUser.getRideId() != null) { newRide = fetchRide(newUser.getRideId()); if (ride == null) { ride = newRide; } } String userStatusChanged = getUserStatusChangeString(newUser); boolean hasRiderChanged = hasRiderChanged(newRide); if (userStatusChanged != null || hasRiderChanged) { // Construct an Intent tying it to the ACTION (arbitrary event namespace) String message = null; if (userStatusChanged != null) { message = "Your ride request has been " + userStatusChanged; } else { message = "You either have a new rider request or a rider has dropped out"; } broadcast(message, userStatusChanged); } user = newUser; ride = newRide; } }
private String getUserStatusChangeString(User newUser) { Date currDate = user.getUpdatedAt(); Date newDate = newUser.getUpdatedAt(); if (isAfter(currDate, newDate)) { if (user.getStatus() != User.Status.PASSENGER && newUser.getStatus() == User.Status.PASSENGER) { return "confirmed"; } else if (user.getStatus() != User.Status.NO_RIDE && newUser.getStatus() == User.Status.NO_RIDE) { return "denied"; } } return null; }
private boolean isDriver(Ride ride) { return user.getObjectId().equals(ride.getDriverId()); }
private boolean isNotUpdatedByUser(Ride newRide) { return newRide == null || newRide.getLastUpdatedBy() == null || !newRide.getLastUpdatedBy().equals(user.getLoginUserId()); }