Mark items read on selection

This commit is contained in:
Shadowfacts 2022-01-11 11:42:41 -05:00
parent a1cf4a5789
commit 3d07069ee5
2 changed files with 20 additions and 10 deletions

View File

@ -9,7 +9,7 @@ import UIKit
import SwiftSoup
protocol ItemCollectionViewCellDelegate: AnyObject {
func itemCellSelected(item: Item)
func itemCellSelected(cell: ItemCollectionViewCell, item: Item)
}
class ItemCollectionViewCell: UICollectionViewListCell {
@ -80,10 +80,23 @@ class ItemCollectionViewCell: UICollectionViewListCell {
}
contentLabel.isHidden = contentLabel.text?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ?? true
setColors()
updateColors()
}
private func setColors() {
func setRead(_ read: Bool, animated: Bool) {
guard self.item.read != read else { return }
self.item.read = read
if animated {
// i don't know why .transition works but .animate doesn't
UIView.transition(with: self, duration: 0.2, options: .transitionCrossDissolve) {
self.updateColors()
}
} else {
updateColors()
}
}
private func updateColors() {
if item.read {
titleLabel.textColor = .secondaryLabel
feedTitleLabel.textColor = .secondaryLabel
@ -113,16 +126,12 @@ class ItemCollectionViewCell: UICollectionViewListCell {
}
@objc private func cellDoubleTapped() {
self.item.read = !self.item.read
// i don't know why .transition works but .animate doesn't
UIView.transition(with: self, duration: 0.2, options: .transitionCrossDissolve) {
self.setColors()
}
setRead(!item.read, animated: true)
shouldHighlight = true
}
@objc private func cellSingleTapped() {
delegate?.itemCellSelected(item: item)
delegate?.itemCellSelected(cell: self, item: item)
shouldHighlight = true
}

View File

@ -103,7 +103,8 @@ extension ItemsViewController: UICollectionViewDelegate {
}
extension ItemsViewController: ItemCollectionViewCellDelegate {
func itemCellSelected(item: Item) {
func itemCellSelected(cell: ItemCollectionViewCell, item: Item) {
cell.setRead(true, animated: true)
show(ReadViewController(item: item, fervorController: fervorController), sender: nil)
}
}