From 4b9b2c1388dc009a4e43868da639ba8d0245ed2a Mon Sep 17 00:00:00 2001 From: Jayden Date: Sat, 21 Dec 2024 10:44:22 +0800 Subject: [PATCH] Optimize codes --- FireworkVideoUI.podspec | 2 +- .../xcshareddata/swiftpm/Package.resolved | 4 ++-- .../CollectionViewController2.swift | 12 +++++++++--- Sample/SampleApp/Info.plist | 2 +- .../TableViewExample/TableViewController2.swift | 11 ++++++++--- .../Cache/StoryBlockViewCache.swift | 12 ++++++++---- .../FireworkVideoUI/Cache/VideoFeedViewCache.swift | 14 ++++++++++---- 7 files changed, 39 insertions(+), 18 deletions(-) diff --git a/FireworkVideoUI.podspec b/FireworkVideoUI.podspec index 87a352b..6ce0842 100644 --- a/FireworkVideoUI.podspec +++ b/FireworkVideoUI.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'FireworkVideoUI' - s.version = '0.2.5' + s.version = '0.2.6' s.summary = 'An extension library meant to provide easier interfaces for the FireworkVideoSDK.' s.homepage = 'https://github.com/loopsocial/firework_ios_sdk_ui_extensions' s.license = 'Apache License, Version 2.0' diff --git a/Sample/SampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Sample/SampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 04b8831..0aae17c 100644 --- a/Sample/SampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Sample/SampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/loopsocial/firework_ios_sdk.git", "state": { "branch": null, - "revision": "9899acad99b0cd35b1eea0a938fecf2f021fbf0a", - "version": "1.24.2" + "revision": "261beff6af55d30c0c51c0fdf4a48de2093cf854", + "version": "1.27.0" } } ] diff --git a/Sample/SampleApp/CollectionViewExample/CollectionViewController2.swift b/Sample/SampleApp/CollectionViewExample/CollectionViewController2.swift index 610f807..0bc15b6 100644 --- a/Sample/SampleApp/CollectionViewExample/CollectionViewController2.swift +++ b/Sample/SampleApp/CollectionViewExample/CollectionViewController2.swift @@ -21,7 +21,7 @@ class CollectionViewController2: UICollectionViewController, UICollectionViewDel lazy var items: [Item] = [ .text("Non-feed Cell"), - .videoFeed(.discover), + .videoFeed(.channel(channelID: "bJDywZ")), .text("Non-feed Cell"), .videoFeed(.channelPlaylist(channelID: "bJDywZ", playlistID: "g206q5")), .text("Non-feed Cell"), @@ -76,12 +76,18 @@ class CollectionViewController2: UICollectionViewController, UICollectionViewDel return textCell case .videoFeed(let source): let videoFeedCell = collectionView.dequeueReusableCell(withReuseIdentifier: VideoFeedCollectionViewCell2.id, for: indexPath) as! VideoFeedCollectionViewCell2 - let videoFeedView = videoFeedViewCache.getOrCreateVideoFeedView(for: source, at: indexPath) + let videoFeedView = videoFeedViewCache.getOrCreateVideoFeedView( + source: source, + indexPath: indexPath + ) videoFeedCell.videoFeedView = videoFeedView return videoFeedCell case .storyBlock(let source): let storyBlockCell = collectionView.dequeueReusableCell(withReuseIdentifier: StoryBlockViewCollectionViewCell2.id, for: indexPath) as! StoryBlockViewCollectionViewCell2 - let storyBlockView = storyBlockViewCache.getOrCreateVideoFeedView(for: source, at: indexPath) + let storyBlockView = storyBlockViewCache.getOrCreateVideoFeedView( + source: source, + indexPath: indexPath + ) storyBlockCell.storyBlockView = storyBlockView return storyBlockCell } diff --git a/Sample/SampleApp/Info.plist b/Sample/SampleApp/Info.plist index bf11dd4..a5c5244 100644 --- a/Sample/SampleApp/Info.plist +++ b/Sample/SampleApp/Info.plist @@ -3,7 +3,7 @@ FireworkVideoAppID - + a62317458e1e14f2cea183cd25fd208ff1d66f6e927d586e55a8e5493be87ee2 UIApplicationSceneManifest UIApplicationSupportsMultipleScenes diff --git a/Sample/SampleApp/TableViewExample/TableViewController2.swift b/Sample/SampleApp/TableViewExample/TableViewController2.swift index 5484789..05135ff 100644 --- a/Sample/SampleApp/TableViewExample/TableViewController2.swift +++ b/Sample/SampleApp/TableViewExample/TableViewController2.swift @@ -21,7 +21,7 @@ class TableViewController2: UITableViewController { lazy var items: [Item] = [ .text("Non-feed Cell"), - .videoFeed(.discover), + .videoFeed(.channel(channelID: "bJDywZ")), .text("Non-feed Cell"), .text("Non-feed Cell"), .videoFeed(.channelPlaylist(channelID: "bJDywZ", playlistID: "g206q5")), @@ -79,12 +79,17 @@ class TableViewController2: UITableViewController { return textCell case .videoFeed(let source): let videoFeedCell = tableView.dequeueReusableCell(withIdentifier: VideoFeedViewTableViewCell2.id, for: indexPath) as! VideoFeedViewTableViewCell2 - let videoFeedView = videoFeedViewCache.getOrCreateVideoFeedView(for: source, at: indexPath) + let videoFeedView = videoFeedViewCache.getOrCreateVideoFeedView( + source: source, + indexPath: indexPath + ) videoFeedCell.videoFeedView = videoFeedView return videoFeedCell case .storyBlock(let source): let storyBlockCell = tableView.dequeueReusableCell(withIdentifier: StoryBlockViewTableViewCell2.id, for: indexPath) as! StoryBlockViewTableViewCell2 - let storyBlockView = storyBlockViewCache.getOrCreateVideoFeedView(for: source, at: indexPath) + let storyBlockView = storyBlockViewCache.getOrCreateVideoFeedView( + source: source, indexPath: indexPath + ) storyBlockCell.storyBlockView = storyBlockView return storyBlockCell } diff --git a/Sources/FireworkVideoUI/Cache/StoryBlockViewCache.swift b/Sources/FireworkVideoUI/Cache/StoryBlockViewCache.swift index d7e883f..e82706c 100644 --- a/Sources/FireworkVideoUI/Cache/StoryBlockViewCache.swift +++ b/Sources/FireworkVideoUI/Cache/StoryBlockViewCache.swift @@ -1,5 +1,5 @@ // -// File.swift +// StoryBlockViewCache.swift // // Created by linjie jiang on 8/21/24. // @@ -16,14 +16,18 @@ public class StoryBlockViewCache { } public func getOrCreateVideoFeedView( - for source: StoryBlockContentSource, - at indexPath: IndexPath + source: StoryBlockContentSource, + indexPath: IndexPath, + adConfiguration: AdConfiguration = AdConfiguration() ) -> StoryBlockView { let cacheKey = "\(source.cacheKey)_\(indexPath.cacheKey)" if let storyBlockView = lruCache.get(cacheKey) { return storyBlockView } - let newStoryBlockView = StoryBlockView(source: source) + let newStoryBlockView = StoryBlockView( + source: source, + adConfiguration: adConfiguration + ) lruCache.put(cacheKey, value: newStoryBlockView) return newStoryBlockView } diff --git a/Sources/FireworkVideoUI/Cache/VideoFeedViewCache.swift b/Sources/FireworkVideoUI/Cache/VideoFeedViewCache.swift index 0fbd46e..bd4a03f 100644 --- a/Sources/FireworkVideoUI/Cache/VideoFeedViewCache.swift +++ b/Sources/FireworkVideoUI/Cache/VideoFeedViewCache.swift @@ -1,5 +1,5 @@ // -// File.swift +// VideoFeedViewCache.swift // // Created by linjie jiang on 8/16/24. // @@ -16,14 +16,20 @@ public class VideoFeedViewCache { } public func getOrCreateVideoFeedView( - for source: VideoFeedContentSource, - at indexPath: IndexPath + source: VideoFeedContentSource, + indexPath: IndexPath, + layout: VideoFeedLayout = VideoFeedHorizontalLayout(), + adConfiguration: AdConfiguration = AdConfiguration() ) -> VideoFeedView { let cacheKey = "\(source.cacheKey)_\(indexPath.cacheKey)" if let videoFeedView = lruCache.get(cacheKey) { return videoFeedView } - let newVideoFeedView = VideoFeedView(source: source) + let newVideoFeedView = VideoFeedView( + layout: layout, + source: source, + adConfiguration: adConfiguration + ) lruCache.put(cacheKey, value: newVideoFeedView) return newVideoFeedView }