mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-24 09:10:59 +00:00
Show announcement count
This commit is contained in:
parent
07dad77fd7
commit
cb97e21cd2
5 changed files with 24 additions and 7 deletions
|
@ -609,7 +609,7 @@ public extension ContentDatabase {
|
||||||
ValueObservation.tracking(Announcement.fetchCount)
|
ValueObservation.tracking(Announcement.fetchCount)
|
||||||
.removeDuplicates()
|
.removeDuplicates()
|
||||||
.publisher(in: databaseWriter)
|
.publisher(in: databaseWriter)
|
||||||
.combineLatest(ValueObservation.tracking(Announcement.fetchCount)
|
.combineLatest(ValueObservation.tracking(Announcement.filter(Announcement.Columns.read == false).fetchCount)
|
||||||
.removeDuplicates()
|
.removeDuplicates()
|
||||||
.publisher(in: databaseWriter))
|
.publisher(in: databaseWriter))
|
||||||
.map { (total: $0, unread: $1) }
|
.map { (total: $0, unread: $1) }
|
||||||
|
|
|
@ -141,6 +141,8 @@ class TableViewController: UITableViewController {
|
||||||
if let loadMoreView = cell.contentView as? LoadMoreView {
|
if let loadMoreView = cell.contentView as? LoadMoreView {
|
||||||
visibleLoadMoreViews.insert(loadMoreView)
|
visibleLoadMoreViews.insert(loadMoreView)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(cell.contentView as? AnnouncementView)?.dismissIfUnread()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView,
|
override func tableView(_ tableView: UITableView,
|
||||||
|
|
|
@ -41,7 +41,7 @@ final class TimelinesViewController: UIPageViewController {
|
||||||
image: UIImage(systemName: "newspaper"),
|
image: UIImage(systemName: "newspaper"),
|
||||||
selectedImage: nil)
|
selectedImage: nil)
|
||||||
|
|
||||||
announcementsButton.primaryAction = UIAction(
|
let announcementsAction = UIAction(
|
||||||
title: NSLocalizedString("main-navigation.announcements", comment: ""),
|
title: NSLocalizedString("main-navigation.announcements", comment: ""),
|
||||||
image: UIImage(systemName: "megaphone")) { [weak self] _ in
|
image: UIImage(systemName: "megaphone")) { [weak self] _ in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
@ -52,8 +52,21 @@ final class TimelinesViewController: UIPageViewController {
|
||||||
self.navigationController?.pushViewController(announcementsViewController, animated: true)
|
self.navigationController?.pushViewController(announcementsViewController, animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
announcementsButton.primaryAction = announcementsAction
|
||||||
|
|
||||||
viewModel.$announcementCount
|
viewModel.$announcementCount
|
||||||
.sink { [weak self] in
|
.sink { [weak self] in
|
||||||
|
if $0.unread > 0 {
|
||||||
|
announcementsAction.image = UIImage(systemName: "\($0.unread).circle.fill")
|
||||||
|
?? UIImage(systemName: "megaphone.fill")
|
||||||
|
self?.announcementsButton.primaryAction = announcementsAction
|
||||||
|
self?.announcementsButton.tintColor = .systemRed
|
||||||
|
} else {
|
||||||
|
announcementsAction.image = UIImage(systemName: "megaphone")
|
||||||
|
self?.announcementsButton.primaryAction = announcementsAction
|
||||||
|
self?.announcementsButton.tintColor = nil
|
||||||
|
}
|
||||||
|
|
||||||
self?.navigationItem.rightBarButtonItem = $0.total > 0 ? self?.announcementsButton : nil
|
self?.navigationItem.rightBarButtonItem = $0.total > 0 ? self?.announcementsButton : nil
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
|
@ -33,7 +33,9 @@ public extension AnnouncementViewModel {
|
||||||
.eraseToAnyPublisher())
|
.eraseToAnyPublisher())
|
||||||
}
|
}
|
||||||
|
|
||||||
func dismiss() {
|
func dismissIfUnread() {
|
||||||
|
guard !announcement.read else { return }
|
||||||
|
|
||||||
eventsSubject.send(
|
eventsSubject.send(
|
||||||
announcementService.dismiss()
|
announcementService.dismiss()
|
||||||
.map { _ in .ignorableOutput }
|
.map { _ in .ignorableOutput }
|
||||||
|
|
|
@ -47,6 +47,10 @@ extension AnnouncementView {
|
||||||
static func estimatedHeight(width: CGFloat, announcement: Announcement) -> CGFloat {
|
static func estimatedHeight(width: CGFloat, announcement: Announcement) -> CGFloat {
|
||||||
UITableView.automaticDimension
|
UITableView.automaticDimension
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dismissIfUnread() {
|
||||||
|
announcementConfiguration.viewModel.dismissIfUnread()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension AnnouncementView: UIContentView {
|
extension AnnouncementView: UIContentView {
|
||||||
|
@ -167,9 +171,5 @@ private extension AnnouncementView {
|
||||||
if snapshot.itemIdentifiers != dataSource.snapshot().itemIdentifiers {
|
if snapshot.itemIdentifiers != dataSource.snapshot().itemIdentifiers {
|
||||||
dataSource.apply(snapshot, animatingDifferences: false) { viewModel.reload() }
|
dataSource.apply(snapshot, animatingDifferences: false) { viewModel.reload() }
|
||||||
}
|
}
|
||||||
|
|
||||||
if !viewModel.announcement.read {
|
|
||||||
viewModel.dismiss()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue