Skip to content

Commit 1981571

Browse files
committed
Reorder the displayed history after the video player is presented
1 parent 34f69d2 commit 1981571

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

iCookTV/HistoryViewController.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,26 @@ class HistoryViewController: VideosViewController {
7979
return nil
8080
}
8181

82-
override func saveToHistory(video: Video, atIndex index: Int) {
83-
super.saveToHistory(video, atIndex: index)
84-
// Reorder current displayed contents
85-
var reordered = self.videos
86-
reordered.removeAtIndex(index)
87-
reordered.insert(video, atIndex: 0)
88-
self.videos = reordered
89-
}
90-
9182
// MARK: - UICollectionViewDelegate
9283

9384
override func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
9485
// History doesn't need pagination.
9586
}
9687

88+
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
89+
super.collectionView(collectionView, didSelectItemAtIndexPath: indexPath)
90+
91+
let video = videos[indexPath.row]
92+
var reordered = videos
93+
reordered.removeAtIndex(indexPath.row)
94+
reordered.insert(video, atIndex: 0)
95+
96+
// Reorder current displayed contents after the video player is presented.
97+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
98+
self.videos = reordered
99+
}
100+
}
101+
97102
// MARK: - OverlayEnabled
98103

99104
private lazy var emptyStateOverlay: UIView = {

iCookTV/VideosViewController.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class VideosViewController: BlurBackgroundViewController,
191191

192192
let controller = VideoPlayerController(video: video, coverImage: cell?.imageView.image)
193193
navigationController?.pushViewController(controller, animated: true)
194-
saveToHistory(video, atIndex: indexPath.row)
194+
HistoryManager.save(video: video)
195195
}
196196

197197
func collectionView(collectionView: UICollectionView, didUpdateFocusInContext context: UICollectionViewFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
@@ -280,12 +280,6 @@ class VideosViewController: BlurBackgroundViewController,
280280
}
281281
}
282282

283-
// MARK: - Public Methods
284-
285-
func saveToHistory(video: Video, atIndex index: Int) {
286-
HistoryManager.save(video: video)
287-
}
288-
289283
}
290284

291285

0 commit comments

Comments
 (0)