-
-
Notifications
You must be signed in to change notification settings - Fork 297
Expand file tree
/
Copy pathNotificationSection.swift
More file actions
110 lines (95 loc) · 4.56 KB
/
NotificationSection.swift
File metadata and controls
110 lines (95 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// NotificationSection.swift
// Mastodon
//
// Created by sxiaojian on 2021/4/13.
//
import Combine
import CoreData
import CoreDataStack
import Foundation
import MastodonSDK
import UIKit
import MetaTextKit
import MastodonMeta
import MastodonAsset
import MastodonCore
import MastodonUI
import MastodonLocalization
enum NotificationSection: Equatable, Hashable {
case main
}
extension NotificationSection {
struct Configuration {
let authenticationBox: MastodonAuthenticationBox
weak var notificationTableViewCellDelegate: NotificationTableViewCellDelegate?
let filterContext: Mastodon.Entity.FilterContext?
}
static func diffableDataSource(
tableView: UITableView,
configuration: Configuration
) -> UITableViewDiffableDataSource<NotificationSection, NotificationItem> {
tableView.register(NotificationTableViewCell.self, forCellReuseIdentifier: String(describing: NotificationTableViewCell.self))
tableView.register(AccountWarningNotificationCell.self, forCellReuseIdentifier: AccountWarningNotificationCell.reuseIdentifier)
tableView.register(TimelineBottomLoaderTableViewCell.self, forCellReuseIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self))
tableView.register(NotificationFilteringBannerTableViewCell.self, forCellReuseIdentifier: NotificationFilteringBannerTableViewCell.reuseIdentifier)
return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item -> UITableViewCell? in
switch item {
case .feed(let feed):
if let notification = feed.notification, let accountWarning = notification.accountWarning {
guard let cell = tableView.dequeueReusableCell(withIdentifier: AccountWarningNotificationCell.reuseIdentifier, for: indexPath) as?
AccountWarningNotificationCell else { fatalError("WTF?! Wrong cell.") }
cell.configure(with: accountWarning)
return cell
} else {
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: NotificationTableViewCell.self), for: indexPath) as?
NotificationTableViewCell else { fatalError("WTF?! Wrong cell.") }
configure(
tableView: tableView,
cell: cell,
viewModel: NotificationTableViewCell.ViewModel(value: .feed(feed)),
configuration: configuration
)
return cell
}
case .feedLoader:
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as?
TimelineBottomLoaderTableViewCell else { fatalError("WTF?! Wrong cell.") }
cell.activityIndicatorView.startAnimating()
return cell
case .bottomLoader:
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as?
TimelineBottomLoaderTableViewCell else { fatalError("WTF?! Wrong cell.") }
cell.activityIndicatorView.startAnimating()
return cell
case .filteredNotifications(let policy):
guard let cell = tableView.dequeueReusableCell(withIdentifier: NotificationFilteringBannerTableViewCell.reuseIdentifier, for: indexPath) as? NotificationFilteringBannerTableViewCell else { fatalError("WTF?! Wrong cell.") }
cell.configure(with: policy)
return cell
}
}
}
}
extension NotificationSection {
static func configure(
tableView: UITableView,
cell: NotificationTableViewCell,
viewModel: NotificationTableViewCell.ViewModel,
configuration: Configuration
) {
StatusSection.setupStatusPollDataSource(
authenticationBox: configuration.authenticationBox,
statusView: cell.notificationView.statusView
)
StatusSection.setupStatusPollDataSource(
authenticationBox: configuration.authenticationBox,
statusView: cell.notificationView.quoteStatusView
)
cell.configure(
tableView: tableView,
viewModel: viewModel,
delegate: configuration.notificationTableViewCellDelegate,
authenticationBox: configuration.authenticationBox
)
}
}