Files
comaps/iphone/Maps/Classes/CarPlay/Template Builders/SettingsTemplateBuilder.swift
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

74 lines
3.4 KiB
Swift

import CarPlay
final class SettingsTemplateBuilder {
// MARK: - CPGridTemplate builder
class func buildGridTemplate() -> CPGridTemplate {
let actions = SettingsTemplateBuilder.buildGridButtons()
let gridTemplate = CPGridTemplate(title: L("settings"),
gridButtons: actions)
return gridTemplate
}
private class func buildGridButtons() -> [CPGridButton] {
let options = RoutingOptions()
return [createUnpavedButton(options: options),
createTollButton(options: options),
createFerryButton(options: options),
createSpeedcamButton()]
}
// MARK: - CPGridButton builders
private class func createTollButton(options: RoutingOptions) -> CPGridButton {
var tollIconName = "ic_carplay_toll"
if options.avoidToll { tollIconName += "_active" }
let tollButton = CPGridButton(titleVariants: [L("avoid_tolls")],
image: UIImage(named: tollIconName)!) { _ in
options.avoidToll = !options.avoidToll
options.save()
CarPlayService.shared.updateRouteAfterChangingSettings()
CarPlayService.shared.popTemplate(animated: true)
}
return tollButton
}
private class func createUnpavedButton(options: RoutingOptions) -> CPGridButton {
var unpavedIconName = "ic_carplay_unpaved"
if options.avoidDirty { unpavedIconName += "_active" }
let unpavedButton = CPGridButton(titleVariants: [L("avoid_unpaved")],
image: UIImage(named: unpavedIconName)!) { _ in
options.avoidDirty = !options.avoidDirty
options.save()
CarPlayService.shared.updateRouteAfterChangingSettings()
CarPlayService.shared.popTemplate(animated: true)
}
return unpavedButton
}
private class func createFerryButton(options: RoutingOptions) -> CPGridButton {
var ferryIconName = "ic_carplay_ferry"
if options.avoidFerry { ferryIconName += "_active" }
let ferryButton = CPGridButton(titleVariants: [L("avoid_ferry")],
image: UIImage(named: ferryIconName)!) { _ in
options.avoidFerry = !options.avoidFerry
options.save()
CarPlayService.shared.updateRouteAfterChangingSettings()
CarPlayService.shared.popTemplate(animated: true)
}
return ferryButton
}
private class func createSpeedcamButton() -> CPGridButton {
var speedcamIconName = "ic_carplay_speedcam"
let isSpeedCamActivated = CarPlayService.shared.isSpeedCamActivated
if isSpeedCamActivated { speedcamIconName += "_active" }
let speedButton = CPGridButton(titleVariants: [L("speedcams_alert_title_carplay_1"),
L("speedcams_alert_title_carplay_2")],
image: UIImage(named: speedcamIconName)!) { _ in
CarPlayService.shared.isSpeedCamActivated = !isSpeedCamActivated
CarPlayService.shared.popTemplate(animated: true)
}
return speedButton
}
}