Skip to content

Commit

Permalink
Feature/terms type (#341)
Browse files Browse the repository at this point in the history
* Prepare for terms booking type

* Update model

(And address a warning)

* `value` is always a string

* Add two more @mainactor annotations

* Loc tweak
  • Loading branch information
nighthawk authored Mar 6, 2024
1 parent e7a085b commit 9d2fa1e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
8 changes: 8 additions & 0 deletions Sources/TripKit/core/Loc+TripKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ extension Loc {

// MARK: - Permission manager

public static var AuthorizationNeeded: String {
NSLocalizedString("Authorisation needed", tableName: "Shared", bundle: .tripKit, comment: "Authorisation needed title")
}

public static var AuthorizationNeededDescription: String {
NSLocalizedString("Access to this feature has been restricted for your device. Please check the Settings app > General > Restrictions or ask your device provider.", tableName: "Shared", bundle: .tripKit, comment: "Authorization restricted alert message")
}

public static var ContactsAuthorizationAlertText: String {
return NSLocalizedString("You previously denied this app access to your contacts. Please go to the Settings app > Privacy > Contacts and authorise this app to use this feature.", tableName: "Shared", bundle: .tripKit, comment: "Contacts authorisation needed text")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ extension TKPermissionManager {
case .denied:
message = authorizationAlertText
case .restricted:
message = NSLocalizedString("Access to this feature has been restricted for your device. Please check the Settings app > General > Restrictions or ask your device provider.", tableName: "Shared", bundle: .tripKit, comment: "Authorization restricted alert message")
message = Loc.AuthorizationNeededDescription
case .notDetermined,
.authorized:
return
}

let alert = UIAlertController(title: NSLocalizedString("Authorisation needed", tableName: "Shared", bundle: .tripKit, comment: "Authorisation needed title"), message: message, preferredStyle: .alert)
let alert = UIAlertController(title: Loc.AuthorizationNeeded, message: message, preferredStyle: .alert)

if let handler = openSettingsHandler {
alert.addAction(.init(title: Loc.Cancel, style: .cancel))
Expand Down
19 changes: 17 additions & 2 deletions Sources/TripKit/model/TKBookingTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public enum TKBooking {
case multipleSelections = "MULTIPLE_CHOICE"
case requestReturnTrip = "RETURN_TRIP"
case number = "NUMBER"
case terms = "TERMS"
}

public enum ReturnTripDateValue: Hashable {
Expand All @@ -200,6 +201,7 @@ public enum TKBooking {
case longText(String)
case returnTripDate(ReturnTripDateValue)
case number(Int, min: Int?, max: Int?)
case terms(URL, accepted: Bool)
}

public let required: Bool
Expand All @@ -215,6 +217,7 @@ public enum TKBooking {
case .multipleSelections: return .multipleSelections
case .returnTripDate: return .requestReturnTrip
case .number: return .number
case .terms: return .terms
}
}

Expand All @@ -226,6 +229,7 @@ public enum TKBooking {
case title
case value
case values
case urlValue
case minValue
case maxValue
}
Expand Down Expand Up @@ -253,10 +257,18 @@ public enum TKBooking {
let specifiedReturnDate = try container.decode(String.self, forKey: .value)
value = Self.convertStringReturnDateToInputValue(specifiedReturnDate)
case .number:
// SIC. `value` is always a string!
let rawValue = try container.decode(String.self, forKey: .value)
let number = Int(rawValue) ?? 0
let minValue = try container.decodeIfPresent(Int.self, forKey: .minValue)
let maxValue = try container.decodeIfPresent(Int.self, forKey: .maxValue)
value = .number(Int(rawValue) ?? 0, min: minValue, max: maxValue)
value = .number(number, min: minValue, max: maxValue)
case .terms:
// SIC. `value` is always a string!
let rawValue = try container.decode(String.self, forKey: .value)
let accepted = rawValue == "true"
let url = try container.decode(URL.self, forKey: .urlValue)
value = .terms(url, accepted: accepted)
}
}

Expand All @@ -278,10 +290,13 @@ public enum TKBooking {
try container.encode(optionIds, forKey: .values)
case .returnTripDate(let returnDate):
try container.encode(returnDate.toString(), forKey: .value)
case .number(let number, let min, let max):
case let .number(number, min, max):
try container.encode(String(number), forKey: .value)
try container.encode(min, forKey: .minValue)
try container.encode(max, forKey: .maxValue)
case let .terms(url, accepted):
try container.encode(accepted, forKey: .value)
try container.encode(url, forKey: .urlValue)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ public protocol TKUITripModeByModePageBuilder {
}

// MARK: - Default MxM page builder

open class TKUIDefaultPageBuilder: TKUITripModeByModePageBuilder {

public init() {}

/// The default page builder does nothing during clean up
@MainActor
open func cleanUp(existingCards: [TGCard]) {}

@MainActor
open func cards(for segment: TKSegment, mapManager: TKUITripMapManager) -> [(TGCard, TKUISegmentMode)] {
if segment.order != .regular {
return []
Expand Down
2 changes: 1 addition & 1 deletion Sources/TripKitUI/views/TKUIAutocompletionResultCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension UILabel {
return
}

var attributed = NSMutableAttributedString(string: text, attributes: [
let attributed = NSMutableAttributedString(string: text, attributes: [
.foregroundColor: textColor,
.font: TKStyleManager.customFont(forTextStyle: .body),
])
Expand Down

0 comments on commit 9d2fa1e

Please sign in to comment.