Commit 40a375a0 by Dmitriy Stepanets

- Fixed viewed shorts sorting

- Fixed SHORTS_CARD_VIEW event firing
parent 5eb4afef
...@@ -29,7 +29,18 @@ class ShortsManager { ...@@ -29,7 +29,18 @@ class ShortsManager {
private var isUpdating = false private var isUpdating = false
private init() {} private init() {}
//MARK: Private
private func sync(with newShorts: inout [ShortsItem]) {
for (index, newShort) in newShorts.enumerated() {
if let presentShortIndex = (shorts.firstIndex{$0.id == newShort.id}) {
let presentShort = shorts[presentShortIndex]
newShorts[index].isLiked = presentShort.isLiked
newShorts[index].isViewed = presentShort.isViewed
}
}
}
//MARK: Public
func refreshShorts() { func refreshShorts() {
if isUpdating { if isUpdating {
return return
...@@ -46,13 +57,15 @@ class ShortsManager { ...@@ -46,13 +57,15 @@ class ShortsManager {
return return
} }
guard let items = shortItems else { guard var items = shortItems else {
self?.log.debug("Fetched shorts are empty") self?.log.debug("Fetched shorts are empty")
return return
} }
self?.sync(with: &items)
self?.shorts.removeAll() self?.shorts.removeAll()
self?.shorts.append(contentsOf: items) self?.shorts.append(contentsOf: items)
self?.reordering()
self?.multicastDelegate.invoke(invocation: { delegate in self?.multicastDelegate.invoke(invocation: { delegate in
delegate.shortsDidChange() delegate.shortsDidChange()
}) })
......
...@@ -98,6 +98,13 @@ extension ShortsView: UICollectionViewDelegate { ...@@ -98,6 +98,13 @@ extension ShortsView: UICollectionViewDelegate {
} }
} }
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
let visiblePath = (collectionView.indexPathsForVisibleItems.sorted{$0.row < $1.row})
guard let lastVisibleRow = visiblePath.last?.row else { return }
AppAnalytics.shared.log(event: .ANALYTICS_SHORTS_CARD_VIEW,
params: [.ANALYTICS_KEY_SHORTS_CARD_POSITION : lastVisibleRow])
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
let visiblePath = (collectionView.indexPathsForVisibleItems.sorted{$0.row < $1.row}) let visiblePath = (collectionView.indexPathsForVisibleItems.sorted{$0.row < $1.row})
guard let lastVisibleRow = visiblePath.last?.row else { return } guard let lastVisibleRow = visiblePath.last?.row else { return }
......
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