Проверка шаблона шины для iOS

131 lines
3.1KB

  1. import BusX
  2. import Combine
  3. import MeetupIdX
  4. import MicX
  5. import SwiftUI
  6. import UIKit
  7. struct Content: View {
  8. @State private var selectedId = "1"
  9. var ids = ["1", "2", "3", "4"]
  10. @StateObject var adates = BusUI.Value(Mic.K.activityDates, [String: Date]())
  11. func val(_ k: String) -> String {
  12. if let dt = adates.v[k] {
  13. return String(describing: Int(dt.timeIntervalSince1970))
  14. }
  15. return "N/A"
  16. }
  17. var body: some View {
  18. VStack {
  19. HStack {
  20. Text("MicItem id:")
  21. Picker("", selection: $selectedId) {
  22. ForEach(ids, id: \.self) {
  23. Text($0)
  24. }
  25. }
  26. }
  27. .pickerStyle(.segmented)
  28. Divider()
  29. .padding()
  30. MicItem.V(selectedId)
  31. Divider()
  32. .padding()
  33. List {
  34. ForEach(ids, id: \.self) {
  35. Text("\($0): \(val($0))")
  36. }
  37. }
  38. }
  39. .padding()
  40. }
  41. }
  42. @UIApplicationMain
  43. class AppDelegate: UIResponder, UIApplicationDelegate
  44. {
  45. let meetupIS = MeetupId.Service(.init())
  46. let micS = Mic.Service(.init())
  47. var window: UIWindow?
  48. func application(
  49. _ application: UIApplication,
  50. didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  51. ) -> Bool {
  52. window = UIWindow(frame: UIScreen.main.bounds)
  53. let vc = UIViewController()
  54. addSwiftUIViewAsChild(swiftUIView: Content(), parent: vc.view)
  55. vc.view.backgroundColor = .white
  56. window?.rootViewController = vc
  57. window?.backgroundColor = UIColor.white
  58. window?.makeKeyAndVisible()
  59. /**/print("ИГР App.didFLWO")
  60. //testMic1()
  61. //testMic2()
  62. //testMic2_id("1")
  63. /*
  64. DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
  65. self.testMic2_id("2")
  66. }
  67. */
  68. testMic4()
  69. return true
  70. }
  71. func testMic1() {
  72. DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
  73. Bus.send(Mic.K.isActive, true)
  74. }
  75. DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
  76. Bus.send(Mic.K.isActive, false)
  77. }
  78. }
  79. func testMic2() {
  80. DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
  81. Bus.send(Mic.K.activityDate, Date() + 2)
  82. }
  83. DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
  84. Bus.send(Mic.K.activityDate, Date() + 2)
  85. }
  86. DispatchQueue.main.asyncAfter(deadline: .now() + 6) {
  87. Bus.send(Mic.K.activityDate, Date() + 7)
  88. }
  89. }
  90. var subscriptions = [AnyCancellable]()
  91. func testMic2_id(_ id: String) {
  92. DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
  93. Bus.send(Bus.keyId(Mic.K.activityDate, id), Date() + 2)
  94. }
  95. DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
  96. Bus.send(Bus.keyId(Mic.K.activityDate, id), Date() + 2)
  97. }
  98. DispatchQueue.main.asyncAfter(deadline: .now() + 6) {
  99. Bus.send(Bus.keyId(Mic.K.activityDate, id), Date() + 3)
  100. }
  101. }
  102. func testMic4() {
  103. delayedSend(2, Mic.K.activeIds, ["1"])
  104. delayedSend(5, Mic.K.activeIds, ["1", "4"])
  105. delayedSend(11, Mic.K.activeIds, ["3", "4"])
  106. }
  107. func delayedSend(
  108. _ delay: TimeInterval,
  109. _ key: String,
  110. _ value: Any
  111. ) {
  112. DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
  113. Bus.send(key, value)
  114. }
  115. }
  116. }