Skip to content

Commit 54a5b27

Browse files
committed
PR fixes
1 parent e20e5d1 commit 54a5b27

File tree

6 files changed

+78
-146
lines changed

6 files changed

+78
-146
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: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
import UIKit
4343
import YouTubeiOSPlayerHelper
4444

45-
class LiveStreamViewController: UIViewController {
45+
final class LiveStreamViewController: UIViewController {
46+
private weak var playerView: YTPlayerView?
47+
4648
override func viewDidLoad() {
4749
super.viewDidLoad()
4850

@@ -51,13 +53,18 @@ class LiveStreamViewController: UIViewController {
5153
playerView.translatesAutoresizingMaskIntoConstraints = false
5254

5355
view.addSubview(playerView)
56+
self.playerView = playerView
5457

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
59-
60-
playerView.load(
58+
NSLayoutConstraint.activate([
59+
playerView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
60+
playerView.topAnchor.constraint(equalTo: view.topAnchor),
61+
playerView.widthAnchor.constraint(equalTo: view.widthAnchor),
62+
playerView.heightAnchor.constraint(equalTo: view.heightAnchor)
63+
])
64+
}
65+
66+
private func loadVideo() {
67+
playerView?.load(
6168
withVideoId: "b42bhUfcLxc",
6269
playerVars: ["playsinline": 1]
6370
)

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
}

live-event-app/live-event-app/SceneDelegate.swift

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ import PubNubChatComponents
3434
let PUBNUB_PUBLISH_KEY = "demo"
3535
let PUBNUB_SUBSCRIBE_KEY = "demo"
3636

37-
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
38-
39-
// Creates PubNub configuration
37+
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
4038
lazy var pubnubConfiguration = {
4139
return PubNubConfiguration(
4240
publishKey: PUBNUB_PUBLISH_KEY,
@@ -48,13 +46,12 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
4846
}()
4947

5048
var window: UIWindow?
51-
5249
var chatProvider: PubNubChatProvider?
5350
var defaultChannelId = "demo"
5451

5552
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
5653
guard let windowScene = (scene as? UIWindowScene) else {
57-
return
54+
preconditionFailure("Cannot cast to UIWindowScene")
5855
}
5956

6057
let window = UIWindow(windowScene: windowScene)
@@ -64,33 +61,35 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
6461
// PubNub.log.writers = [ConsoleLogWriter()]
6562

6663
if chatProvider == nil {
64+
let provider = createChatProviderInstance()
65+
let channelId = defaultChannelId
6766

68-
// Creates a new ChatProvider
69-
let provider = PubNubChatProvider(
70-
pubnubProvider: PubNub(configuration: pubnubConfiguration),
71-
datastoreConfiguration: DatastoreConfiguration(
72-
bundle: .pubnubChat,
73-
dataModelFilename: "PubNubChatModel",
74-
storageDirectlyURL: nil,
75-
storageUniqueFilename: "default",
76-
cleanStorageOnLoad: true
77-
)
78-
)
79-
80-
// Sets custom themes for MessageList and MessageInput components
8167
provider.themeProvider.template.messageListComponent = messageListComponentTheme
8268
provider.themeProvider.template.messageInputComponent = messageInputComponentTheme
8369

84-
// Preloads dummy data
8570
preloadData(provider) { [weak self] in
86-
window.rootViewController = RootViewController(channelId: self?.defaultChannelId ?? "", provider: provider, scene: windowScene)
71+
window.rootViewController = RootViewController(channelId: channelId, provider: provider, scene: windowScene)
8772
self?.window = window
73+
self?.chatProvider = provider
8874
window.makeKeyAndVisible()
8975
}
9076
}
9177
}
9278

93-
func preloadData(_ chatProvider: PubNubChatProvider, completion: @escaping (() -> Void)) {
79+
private func createChatProviderInstance() -> PubNubChatProvider {
80+
PubNubChatProvider(
81+
pubnubProvider: PubNub(configuration: pubnubConfiguration),
82+
datastoreConfiguration: DatastoreConfiguration(
83+
bundle: .pubnubChat,
84+
dataModelFilename: "PubNubChatModel",
85+
storageDirectlyURL: nil,
86+
storageUniqueFilename: "default",
87+
cleanStorageOnLoad: true
88+
)
89+
)
90+
}
91+
92+
private func preloadData(_ chatProvider: PubNubChatProvider, completion: @escaping (() -> Void)) {
9493
let channel = PubNubChatChannel(
9594
id: defaultChannelId,
9695
name: "Default",
@@ -109,10 +108,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
109108
user: user
110109
)
111110

112-
// Subscribes to the default channel
113111
chatProvider.pubnubProvider.subscribe(.init(channels: [defaultChannelId], withPresence: false))
114-
115-
// Fills the database with the user, channel, and memberships data
116112
chatProvider.dataProvider.load(members: [membership], completion: completion)
117113
}
118114
}

0 commit comments

Comments
 (0)