Last active
November 21, 2017 14:22
-
-
Save Bashta/c334a387a5a1c454fb1e446a85e67f05 to your computer and use it in GitHub Desktop.
Revisions
-
Bashta revised this gist
Nov 21, 2017 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ enum BookingState: Int, Comparable { // Booking states, mapped from backend state together with check-in/out status and -
Bashta created this gist
Nov 21, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,212 @@ ``` enum BookingState: Int, Comparable { // Booking states, mapped from backend state together with check-in/out status and // payment progress. // // NOTE: Should also include review status, which is currently not yet implemented // on the backend. case Started = 0 case CheckOutStarted = 1 case NeedsCheckOut = 2 case CheckInStarted = 3 case CanCheckIn = 4 case Paid = 5 case PaymentProcessing = 6 case Accepted = 7 case Requested = 8 case RequestNotSent = 9 case Declined = 10 case Cancelled = 11 case CancelledBySystem = 12 case FinishedNoReview = 13 case PaidOutNoReview = 14 case Finished = 15 case PaidOut = 16 case Expired = 17 case Unknown = 18 public static func <(lhs: BookingState, rhs: BookingState) -> Bool { return lhs.rawValue < rhs.rawValue } var isCheckInOutStatusRelevant: Bool { get { switch self { case .Unknown: fallthrough case .Started: fallthrough case .CheckOutStarted: fallthrough case .NeedsCheckOut: fallthrough case .CheckInStarted: fallthrough case .CanCheckIn: fallthrough case .Paid: fallthrough case .Finished: fallthrough case .FinishedNoReview: return true default: return false } } } var localizationKey: String { get { switch self { case .Started: return "started" case .CheckOutStarted: return "checkout_started" case .NeedsCheckOut: return "needs_checkout" case .CheckInStarted: return "checkin_started" case .CanCheckIn: return "can_checkin" case .Paid: return "paid" case .PaymentProcessing: return "payment_processing" case .Accepted: return "accepted" case .Requested: return "requested" case .RequestNotSent: return "request_not_sent" case .Declined: return "declined" case .Cancelled: return "cancelled" case .CancelledBySystem: return "cancelled_by_system" case .FinishedNoReview: return "finished_no_review" case .PaidOutNoReview: return "paid_out_no_review" case .Finished: return "finished" case .PaidOut: return "paid_out" case .Expired: return "expired" case .Unknown: return "unknown" } } } var color: UIColor { get { switch self { // Green case .Started: fallthrough case .CheckInStarted: fallthrough case .CanCheckIn: fallthrough case .CheckOutStarted: fallthrough case .NeedsCheckOut: fallthrough case .Paid: fallthrough case .PaymentProcessing: fallthrough case .Accepted: fallthrough case .Requested: fallthrough case .FinishedNoReview: fallthrough case .PaidOutNoReview: fallthrough case .Finished: fallthrough case .PaidOut: return Colors.green // Red case .RequestNotSent: return Colors.red // Gray case .Cancelled: fallthrough case .Declined: fallthrough case .CancelledBySystem: fallthrough case .Expired: fallthrough case .Unknown: return Colors.gray } } } } enum BookingLoadingGroup { case RenterFuture case RenterHistory case OwnerFuture case OwnerHistory var isRenter: Bool { get { switch self { case .RenterFuture: fallthrough case .RenterHistory: return true case .OwnerFuture: fallthrough case .OwnerHistory: return false } } } var isFuture: Bool { get { switch self { case .RenterFuture: fallthrough case .OwnerFuture: return true case .RenterHistory: fallthrough case .OwnerHistory: return false } } } func getRentalStates() -> [RentalState] { switch self { case .RenterFuture: return [.Requested, .Accepted, .Denied, .PaymentAuthorized, .RentalStarted, .RentalEnded, .NotSend, .Cancelled, .DeclinedBySystem] case .RenterHistory: return [.TransactionDone, .RentalEnded, .Denied, .Cancelled, .Overdue, .DeclinedBySystem] case .OwnerFuture: return [.Requested, .Accepted, .PaymentAuthorized, .RentalStarted, .RentalEnded, .Denied, .Cancelled, .DeclinedBySystem] case .OwnerHistory: return [.TransactionDone, .RentalEnded, .Denied, .Cancelled, .Overdue, .DeclinedBySystem] } } }