Ejemplo n.º 1
0
 @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;
   }
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 private boolean isDriver(Ride ride) {
   return user.getObjectId().equals(ride.getDriverId());
 }
Ejemplo n.º 4
0
 private boolean isNotUpdatedByUser(Ride newRide) {
   return newRide == null
       || newRide.getLastUpdatedBy() == null
       || !newRide.getLastUpdatedBy().equals(user.getLoginUserId());
 }