Skip to content

Commit

Permalink
Optimize codes
Browse files Browse the repository at this point in the history
  • Loading branch information
linjie-firework committed Dec 21, 2024
1 parent 78b9897 commit 4b9b2c1
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion FireworkVideoUI.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Sample/SampleApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>FireworkVideoAppID</key>
<string></string>
<string>a62317458e1e14f2cea183cd25fd208ff1d66f6e927d586e55a8e5493be87ee2</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down
11 changes: 8 additions & 3 deletions Sample/SampleApp/TableViewExample/TableViewController2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 8 additions & 4 deletions Sources/FireworkVideoUI/Cache/StoryBlockViewCache.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// File.swift
// StoryBlockViewCache.swift
//
// Created by linjie jiang on 8/21/24.
//
Expand All @@ -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
}
Expand Down
14 changes: 10 additions & 4 deletions Sources/FireworkVideoUI/Cache/VideoFeedViewCache.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// File.swift
// VideoFeedViewCache.swift
//
// Created by linjie jiang on 8/16/24.
//
Expand All @@ -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
}
Expand Down

0 comments on commit 4b9b2c1

Please sign in to comment.