-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
FindFriendsDataSource.swift
51 lines (45 loc) · 1.5 KB
/
FindFriendsDataSource.swift
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
import KsApi
import Library
import Prelude
import UIKit
internal final class FindFriendsDataSource: ValueCellDataSource {
fileprivate enum Section: Int {
case facebookConnect
case stats
case friends
}
internal func facebookConnect(source: FriendsSource, visible: Bool) {
self.set(
values: visible ? [source] : [],
cellClass: FindFriendsFacebookConnectCell.self,
inSection: Section.facebookConnect.rawValue
)
}
internal func stats(stats: FriendStatsEnvelope, source: FriendsSource) {
self.set(
values: [(stats, source)],
cellClass: FindFriendsStatsCell.self,
inSection: Section.stats.rawValue
)
}
internal func friends(_ friends: [User], source: FriendsSource) {
let friendAndSource = friends.map { (friend: $0, source: source) }
self.set(
values: friendAndSource,
cellClass: FindFriendsFriendFollowCell.self,
inSection: Section.friends.rawValue
)
}
override func configureCell(tableCell cell: UITableViewCell, withValue value: Any) {
switch (cell, value) {
case let (cell as FindFriendsStatsCell, value as (FriendStatsEnvelope, FriendsSource)):
cell.configureWith(value: value)
case let (cell as FindFriendsFriendFollowCell, value as (User, FriendsSource)):
cell.configureWith(value: value)
case let (cell as FindFriendsFacebookConnectCell, value as FriendsSource):
cell.configureWith(value: value)
default:
assertionFailure("Unrecognized combo: \(cell), \(value)")
}
}
}