Commit 0c145ad0 by Dmitriy Stepanets

Working on selecting short as viewed

parent 0b2dd7b8
...@@ -59,6 +59,23 @@ class ShortsManager { ...@@ -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) { func like(item: ShortsItem) {
guard let shortsToLikeIndex = (shorts.firstIndex { $0.id == item.id }) else { guard let shortsToLikeIndex = (shorts.firstIndex { $0.id == item.id }) else {
return return
...@@ -67,8 +84,9 @@ class ShortsManager { ...@@ -67,8 +84,9 @@ class ShortsManager {
} }
func markAsViewed(item: ShortsItem) { func markAsViewed(item: ShortsItem) {
// guard let sourceIndex = (self.shorts.firstIndex{ $0.id == item.id }) else { guard let sourceIndex = (self.shorts.firstIndex{ $0.id == item.id }) else {
// return return
// } }
self.shorts[sourceIndex].markAsViewed()
} }
} }
...@@ -22,6 +22,7 @@ class ShortsViewController: UIViewController { ...@@ -22,6 +22,7 @@ class ShortsViewController: UIViewController {
private let tableView = UITableView() private let tableView = UITableView()
private var averageColorCache = [AnyHashable:UIColor]() private var averageColorCache = [AnyHashable:UIColor]()
private var lastOffset: CGFloat = 0 private var lastOffset: CGFloat = 0
private var visibleRow = 0
deinit { deinit {
print("[ShortsViewController] deinit") print("[ShortsViewController] deinit")
...@@ -44,6 +45,11 @@ class ShortsViewController: UIViewController { ...@@ -44,6 +45,11 @@ class ShortsViewController: UIViewController {
prepareTableView() prepareTableView()
} }
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
print("[ShortsViewController] Will disappear")
}
private func scrollTo(newOffset:CGPoint, velocity:CGPoint) { private func scrollTo(newOffset:CGPoint, velocity:CGPoint) {
let animation = POPBasicAnimation(propertyNamed: kPOPScrollViewContentOffset) let animation = POPBasicAnimation(propertyNamed: kPOPScrollViewContentOffset)
animation?.timingFunction = CAMediaTimingFunction(name: .easeOut) animation?.timingFunction = CAMediaTimingFunction(name: .easeOut)
...@@ -51,6 +57,8 @@ class ShortsViewController: UIViewController { ...@@ -51,6 +57,8 @@ class ShortsViewController: UIViewController {
animation?.toValue = newOffset animation?.toValue = newOffset
animation?.fromValue = tableView.contentOffset animation?.fromValue = tableView.contentOffset
print("[ShortsViewController] diff: \(abs(tableView.contentOffset.y)/newOffset.y)")
tableView.pop_add(animation, forKey: kAnimationKey) tableView.pop_add(animation, forKey: kAnimationKey)
} }
} }
...@@ -97,6 +105,10 @@ extension ShortsViewController: UITableViewDelegate { ...@@ -97,6 +105,10 @@ extension ShortsViewController: UITableViewDelegate {
return tableView.bounds.height 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>) { func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
//Get direction //Get direction
let direction:ScrollDirection let direction:ScrollDirection
......
...@@ -217,7 +217,7 @@ class TodayCellFactory: CellFactoryProtocol { ...@@ -217,7 +217,7 @@ class TodayCellFactory: CellFactoryProtocol {
rowsToHide.insert(.moon) rowsToHide.insert(.moon)
} }
if !ShortsManager.shared.shortsAvailable || todayViewModel.shorts.isEmpty { if !ShortsManager.shared.shortsAvailable {
rowsToHide.insert(.shorts) rowsToHide.insert(.shorts)
} }
......
...@@ -38,6 +38,10 @@ class ShortsViewModel: ViewModelProtocol { ...@@ -38,6 +38,10 @@ class ShortsViewModel: ViewModelProtocol {
UIApplication.shared.open(url, options: [:]) UIApplication.shared.open(url, options: [:])
} }
} }
func markAsViewed(item: ShortsItem) {
shortsManager.markAsViewed(item: item)
}
} }
//MARK:- ShortManager Delegate //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