88 lines
3.0 KiB
Swift
88 lines
3.0 KiB
Swift
import UIKit
|
|
import SwiftEntryKit
|
|
import AutoCatCore
|
|
|
|
class MainTabController: UITabBarController, UITabBarControllerDelegate {
|
|
|
|
var settingsCoordinator: SettingsCoordinator?
|
|
var historyViewModel: HistoryViewModel?
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
self.delegate = self
|
|
|
|
#if targetEnvironment(macCatalyst)
|
|
|
|
// Remove "+" tab for macOS version (it will be on the toolbar)
|
|
viewControllers?.remove(at: 2)
|
|
|
|
#endif
|
|
|
|
if #available(iOS 18, *) {
|
|
// Setting the horizontal size class will force the tab bar
|
|
// to be displayed at the bottom.
|
|
traitOverrides.horizontalSizeClass = .compact
|
|
}
|
|
|
|
setupHistoryTab()
|
|
Task { await addSettings() }
|
|
}
|
|
|
|
func setupHistoryTab() {
|
|
|
|
let coordinator = HistoryCoordinator()
|
|
let (controller, viewModel) = coordinator.start()
|
|
controller.tabBarItem = UITabBarItem(title: NSLocalizedString("History", comment: ""),
|
|
image: UIImage(systemName: "clock.arrow.circlepath"), tag: 0)
|
|
viewControllers?[0] = controller
|
|
historyViewModel = viewModel
|
|
}
|
|
|
|
func addSettings() async {
|
|
|
|
let coordinator = SettingsCoordinator(tabController: self)
|
|
settingsCoordinator = coordinator
|
|
try? await coordinator.start()
|
|
}
|
|
|
|
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
|
|
if viewController is DummyNewController {
|
|
showCheckPuller()
|
|
return false
|
|
} else {
|
|
return true
|
|
}
|
|
}
|
|
|
|
func showCheckPuller() {
|
|
guard let historyViewModel else {
|
|
return
|
|
}
|
|
|
|
var attributes = EKAttributes.bottomToast
|
|
attributes.displayDuration = .infinity
|
|
attributes.entryBackground = .color(color: .init(.secondarySystemBackground))
|
|
attributes.screenBackground = .color(color: EKColor(UIColor(white: 0, alpha: 0.7)))
|
|
attributes.roundCorners = .top(radius: 24)
|
|
attributes.screenInteraction = .dismiss
|
|
attributes.scroll = .disabled
|
|
attributes.entryInteraction = .absorbTouches
|
|
attributes.entranceAnimation = .init(translate: .init(duration: 0.2))
|
|
attributes.exitAnimation = .init(translate: .init(duration: 0.2))
|
|
|
|
let newNumberController = NewNumberController()
|
|
newNumberController.onCheck = { number in
|
|
SwiftEntryKit.dismiss {
|
|
self.selectedIndex = 0
|
|
Task { await historyViewModel.checkNewNumber(number) }
|
|
}
|
|
}
|
|
|
|
SwiftEntryKit.display(entry: newNumberController, using: attributes)
|
|
|
|
// User probably just saw a vehicle and is about to start entering plate number
|
|
// Requesting current location ASAP while we still close to initial location
|
|
Task { try? await RxLocationManager.requestCurrentLocation() }
|
|
}
|
|
}
|