Skip to content

Commit 189e0c0

Browse files
committed
PR fixes
1 parent e20e5d1 commit 189e0c0

File tree

6 files changed

+96
-148
lines changed

6 files changed

+96
-148
lines changed

live-event-app/live-event-app-UITests/LiveEventAppUITests.swift

Lines changed: 0 additions & 57 deletions
This file was deleted.

live-event-app/live-event-app.xcodeproj/project.pbxproj

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
3DE75814292B876D0083EAB0 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3DE75812292B876D0083EAB0 /* LaunchScreen.storyboard */; };
3939
3DE7581D292B88020083EAB0 /* PubNubChat in Frameworks */ = {isa = PBXBuildFile; productRef = 3DE7581C292B88020083EAB0 /* PubNubChat */; };
4040
3DE7581F292B88020083EAB0 /* PubNubChatComponents in Frameworks */ = {isa = PBXBuildFile; productRef = 3DE7581E292B88020083EAB0 /* PubNubChatComponents */; };
41-
3DE75827292F723C0083EAB0 /* LiveEventAppUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DE75826292F723C0083EAB0 /* LiveEventAppUITests.swift */; };
4241
3DED7690295DA16B0048E272 /* YouTubeiOSPlayerHelper in Frameworks */ = {isa = PBXBuildFile; productRef = 3DED768F295DA16B0048E272 /* YouTubeiOSPlayerHelper */; };
4342
3DFB1F9F2934B87500DDF361 /* TimeLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DFB1F952934B87500DDF361 /* TimeLogger.swift */; };
4443
3DFB1FA02934B87500DDF361 /* DebugViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DFB1F962934B87500DDF361 /* DebugViewController.swift */; };
@@ -93,7 +92,6 @@
9392
3DE75813292B876D0083EAB0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
9493
3DE75815292B876D0083EAB0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9594
3DE75824292F723C0083EAB0 /* live-event-app-UITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "live-event-app-UITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
96-
3DE75826292F723C0083EAB0 /* LiveEventAppUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveEventAppUITests.swift; sourceTree = "<group>"; };
9795
3DFB1F952934B87500DDF361 /* TimeLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimeLogger.swift; sourceTree = "<group>"; };
9896
3DFB1F962934B87500DDF361 /* DebugViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DebugViewController.swift; sourceTree = "<group>"; };
9997
3DFB1F982934B87500DDF361 /* UIView+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Extensions.swift"; sourceTree = "<group>"; };
@@ -180,7 +178,6 @@
180178
isa = PBXGroup;
181179
children = (
182180
3DE75806292B876C0083EAB0 /* live-event-app */,
183-
3DE75825292F723C0083EAB0 /* live-event-app-UITests */,
184181
3DE75805292B876C0083EAB0 /* Products */,
185182
);
186183
sourceTree = "<group>";
@@ -213,14 +210,6 @@
213210
path = "live-event-app";
214211
sourceTree = "<group>";
215212
};
216-
3DE75825292F723C0083EAB0 /* live-event-app-UITests */ = {
217-
isa = PBXGroup;
218-
children = (
219-
3DE75826292F723C0083EAB0 /* LiveEventAppUITests.swift */,
220-
);
221-
path = "live-event-app-UITests";
222-
sourceTree = "<group>";
223-
};
224213
3DFB1F932934B87500DDF361 /* FPSDebug */ = {
225214
isa = PBXGroup;
226215
children = (
@@ -411,7 +400,6 @@
411400
isa = PBXSourcesBuildPhase;
412401
buildActionMask = 2147483647;
413402
files = (
414-
3DE75827292F723C0083EAB0 /* LiveEventAppUITests.swift in Sources */,
415403
);
416404
runOnlyForDeploymentPostprocessing = 0;
417405
};

live-event-app/live-event-app/LiveStreamViewController.swift

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,49 @@
4242
import UIKit
4343
import YouTubeiOSPlayerHelper
4444

45-
class LiveStreamViewController: UIViewController {
45+
protocol LiveStreamPlayerView {
46+
func loadVideo()
47+
func play()
48+
}
49+
50+
final class LiveStreamViewController: UIViewController {
51+
private weak var playerView: (UIView & LiveStreamPlayerView)?
52+
4653
override func viewDidLoad() {
4754
super.viewDidLoad()
4855

49-
let playerView = YTPlayerView()
50-
playerView.delegate = self
56+
let playerView = createPlayerView()
5157
playerView.translatesAutoresizingMaskIntoConstraints = false
52-
5358
view.addSubview(playerView)
59+
self.playerView = playerView
5460

55-
playerView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
56-
playerView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
57-
playerView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
58-
playerView.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true
61+
NSLayoutConstraint.activate([
62+
playerView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
63+
playerView.topAnchor.constraint(equalTo: view.topAnchor),
64+
playerView.widthAnchor.constraint(equalTo: view.widthAnchor),
65+
playerView.heightAnchor.constraint(equalTo: view.heightAnchor)
66+
])
5967

60-
playerView.load(
68+
playerView.loadVideo()
69+
}
70+
71+
private func createPlayerView() -> UIView & LiveStreamPlayerView {
72+
let youtubePlayerView = YTPlayerView()
73+
youtubePlayerView.delegate = self
74+
return youtubePlayerView
75+
}
76+
}
77+
78+
extension YTPlayerView: LiveStreamPlayerView {
79+
public func loadVideo() {
80+
load(
6181
withVideoId: "b42bhUfcLxc",
6282
playerVars: ["playsinline": 1]
6383
)
6484
}
85+
public func play() {
86+
playVideo()
87+
}
6588
}
6689

6790
extension LiveStreamViewController: YTPlayerViewDelegate {

live-event-app/live-event-app/RootViewController.swift

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ import UIKit
2929
import PubNubChat
3030
import PubNubChatComponents
3131

32-
class RootViewController: UIViewController {
33-
32+
final class RootViewController: UIViewController {
3433
private let provider: PubNubChatProvider
3534
private let channelId: String
36-
3735
private var portraitConstraints: [NSLayoutConstraint] = []
3836
private var landscapeConstraints: [NSLayoutConstraint] = []
39-
private weak var scene: UIWindowScene?
37+
private var scene: UIWindowScene
4038

4139
init(
4240
channelId: String,
@@ -57,38 +55,55 @@ class RootViewController: UIViewController {
5755
override func viewDidLoad() {
5856
super.viewDidLoad()
5957

60-
guard let scene = scene else {
61-
return
62-
}
63-
// Creates the default MessageList component
6458
guard let messageListViewModel = try? provider.messageListComponentViewModel(pubnubChannelId: channelId) else {
65-
preconditionFailure("Could not create intial view models")
59+
preconditionFailure("Missing required data. Make sure the channel object and current user are stored locally")
6660
}
67-
68-
// Sets the custom title view for the MessageList component
61+
6962
messageListViewModel.customNavigationTitleString = nil
70-
messageListViewModel.customNavigationTitleView = { [weak self] viewModel in
71-
self?.getMessageListCustomTitleView() ?? UIView()
63+
messageListViewModel.customNavigationTitleView = { viewModel in
64+
let customTitleView = UILabel()
65+
customTitleView.font = UIFont(name: "Poppins-Bold", size: 14)
66+
customTitleView.textColor = UIColor(named: "MessageList.NavigationBar.TitleTextColor")
67+
customTitleView.text = "STREAM CHAT"
68+
customTitleView.sizeToFit()
69+
return customTitleView
7270
}
7371

74-
// Creates MessageList and LiveStream view controllers
7572
let messageListViewController = messageListViewModel.configuredComponentView()
7673
let messageListContainerViewController = UINavigationController(rootViewController: messageListViewController)
7774
let streamViewController = LiveStreamViewController()
78-
79-
// Combine the content from MessageList and LiveStream view controllers using a Container View Controller
75+
76+
createContainerViewController(
77+
messageListContainerViewController: messageListContainerViewController,
78+
streamViewController: streamViewController
79+
)
80+
applyConstraints(
81+
streamViewController: streamViewController,
82+
messageListContainerViewController: messageListContainerViewController
83+
)
84+
setUpMetricsView()
85+
}
86+
87+
private func createContainerViewController(
88+
messageListContainerViewController: UINavigationController,
89+
streamViewController: UIViewController
90+
) {
8091
self.addChild(messageListContainerViewController)
8192
self.addChild(streamViewController)
8293
self.view.addSubview(messageListContainerViewController.view)
8394
self.view.addSubview(streamViewController.view)
8495

8596
messageListContainerViewController.didMove(toParent: self)
8697
streamViewController.didMove(toParent: self)
87-
98+
}
99+
100+
private func applyConstraints(
101+
streamViewController: UIViewController,
102+
messageListContainerViewController: UIViewController
103+
) {
88104
messageListContainerViewController.view.translatesAutoresizingMaskIntoConstraints = false
89105
streamViewController.view.translatesAutoresizingMaskIntoConstraints = false
90-
91-
// Creates constraints for Portrait and Landscape orientations
106+
92107
portraitConstraints = [
93108
messageListContainerViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
94109
messageListContainerViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
@@ -99,21 +114,24 @@ class RootViewController: UIViewController {
99114
streamViewController.view.topAnchor.constraint(equalTo: view.topAnchor),
100115
streamViewController.view.bottomAnchor.constraint(equalTo: messageListContainerViewController.view.topAnchor)
101116
]
102-
103117
landscapeConstraints = [
104118
streamViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
105119
streamViewController.view.trailingAnchor.constraint(equalTo: messageListContainerViewController.view.leadingAnchor),
106120
streamViewController.view.topAnchor.constraint(equalTo: view.topAnchor),
107121
streamViewController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
108-
109122
messageListContainerViewController.view.leadingAnchor.constraint(equalTo: streamViewController.view.trailingAnchor),
110123
messageListContainerViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
111124
messageListContainerViewController.view.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 7.0 / 16.0),
112125
messageListContainerViewController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
113126
messageListContainerViewController.view.topAnchor.constraint(equalTo: view.topAnchor)
114127
]
115128

116-
// Creates a debug overlay to display the FPS meter
129+
NSLayoutConstraint.activate(
130+
scene.interfaceOrientation.isPortrait ? portraitConstraints : landscapeConstraints
131+
)
132+
}
133+
134+
private func setUpMetricsView() {
117135
let metricsView = MetricsView()
118136
view.addSubview(metricsView)
119137
view.bringSubviewToFront(metricsView)
@@ -122,22 +140,6 @@ class RootViewController: UIViewController {
122140
$0.topAnchor.constraint(equalTo: $1.topAnchor, constant: 40),
123141
$0.trailingAnchor.constraint(equalTo: $1.trailingAnchor, constant: -20)
124142
]}
125-
126-
// Activates a set of constraints depending on the orientation
127-
NSLayoutConstraint.activate(
128-
scene.interfaceOrientation.isPortrait ? portraitConstraints : landscapeConstraints
129-
)
130-
}
131-
132-
private func getMessageListCustomTitleView() -> UIView {
133-
134-
let customTitleView = UILabel()
135-
customTitleView.font = UIFont(name: "Poppins-Bold", size: 14)
136-
customTitleView.textColor = UIColor(named: "MessageList.NavigationBar.TitleTextColor")
137-
customTitleView.text = "STREAM CHAT"
138-
customTitleView.sizeToFit()
139-
140-
return customTitleView
141143
}
142144

143145
override func willTransition(
@@ -148,12 +150,9 @@ class RootViewController: UIViewController {
148150
to: newCollection,
149151
with: coordinator
150152
)
151-
guard let scene = scene else {
152-
return
153-
}
154153
coordinator.animate { context in
155-
NSLayoutConstraint.deactivate(scene.interfaceOrientation.isPortrait ? self.landscapeConstraints : self.portraitConstraints)
156-
NSLayoutConstraint.activate(scene.interfaceOrientation.isPortrait ? self.portraitConstraints : self.landscapeConstraints)
154+
NSLayoutConstraint.deactivate(self.scene.interfaceOrientation.isPortrait ? self.landscapeConstraints : self.portraitConstraints)
155+
NSLayoutConstraint.activate(self.scene.interfaceOrientation.isPortrait ? self.portraitConstraints : self.landscapeConstraints)
157156
}
158157
}
159158
}

0 commit comments

Comments
 (0)