Commit 0c145ad0 by Dmitriy Stepanets

Working on selecting short as viewed

parent 0b2dd7b8
......@@ -59,6 +59,23 @@ class ShortsManager {
}
}
func reordering() {
var reorderingArray = self.shorts
var itemsToReorder = [ShortsItem]()
self.shorts.enumerated().forEach {
if $1.isViewed {
itemsToReorder.append(reorderingArray.remove(at: $0))
}
}
reorderingArray.append(contentsOf: itemsToReorder)
self.shorts = reorderingArray
self.multicastDelegate.invoke { delegate in
delegate.shortsDidChange()
}
}
func like(item: ShortsItem) {
guard let shortsToLikeIndex = (shorts.firstIndex { $0.id == item.id }) else {
return
......@@ -67,8 +84,9 @@ class ShortsManager {
}
func markAsViewed(item: ShortsItem) {
// guard let sourceIndex = (self.shorts.firstIndex{ $0.id == item.id }) else {
// return
// }
guard let sourceIndex = (self.shorts.firstIndex{ $0.id == item.id }) else {
return
}
self.shorts[sourceIndex].markAsViewed()
}
}
......@@ -22,6 +22,7 @@ class ShortsViewController: UIViewController {
private let tableView = UITableView()
private var averageColorCache = [AnyHashable:UIColor]()
private var lastOffset: CGFloat = 0
private var visibleRow = 0
deinit {
print("[ShortsViewController] deinit")
......@@ -44,6 +45,11 @@ class ShortsViewController: UIViewController {
prepareTableView()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
print("[ShortsViewController] Will disappear")
}
private func scrollTo(newOffset:CGPoint, velocity:CGPoint) {
let animation = POPBasicAnimation(propertyNamed: kPOPScrollViewContentOffset)
animation?.timingFunction = CAMediaTimingFunction(name: .easeOut)
......@@ -51,6 +57,8 @@ class ShortsViewController: UIViewController {
animation?.toValue = newOffset
animation?.fromValue = tableView.contentOffset
print("[ShortsViewController] diff: \(abs(tableView.contentOffset.y)/newOffset.y)")
tableView.pop_add(animation, forKey: kAnimationKey)
}
}
......@@ -97,6 +105,10 @@ extension ShortsViewController: UITableViewDelegate {
return tableView.bounds.height
}
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
viewModel.markAsViewed(item: viewModel.shorts[indexPath.row])
}
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
//Get direction
let direction:ScrollDirection
......
......@@ -217,7 +217,7 @@ class TodayCellFactory: CellFactoryProtocol {
rowsToHide.insert(.moon)
}
if !ShortsManager.shared.shortsAvailable || todayViewModel.shorts.isEmpty {
if !ShortsManager.shared.shortsAvailable {
rowsToHide.insert(.shorts)
}
......
......@@ -38,6 +38,10 @@ class ShortsViewModel: ViewModelProtocol {
UIApplication.shared.open(url, options: [:])
}
}
func markAsViewed(item: ShortsItem) {
shortsManager.markAsViewed(item: item)
}
}
//MARK:- ShortManager Delegate
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment