Kurdtvs-Live-Kurdish-TV-Kur.../Mastodon/Diffiable/Section/SearchResultSection.swift

54 lines
2.2 KiB
Swift

//
// SearchResultSection.swift
// Mastodon
//
// Created by sxiaojian on 2021/4/6.
//
import Foundation
import MastodonSDK
import UIKit
import CoreData
import CoreDataStack
enum SearchResultSection: Equatable, Hashable {
case account
case hashTag
case mixed
case bottomLoader
}
extension SearchResultSection {
static func tableViewDiffableDataSource(
for tableView: UITableView,
dependency: NeedsDependency
) -> UITableViewDiffableDataSource<SearchResultSection, SearchResultItem> {
UITableViewDiffableDataSource(tableView: tableView) { (tableView, indexPath, result) -> UITableViewCell? in
switch result {
case .account(let account):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SearchingTableViewCell.self), for: indexPath) as! SearchingTableViewCell
cell.config(with: account)
return cell
case .hashTag(let tag):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SearchingTableViewCell.self), for: indexPath) as! SearchingTableViewCell
cell.config(with: tag)
return cell
case .hashTagObjectID(let hashTagObjectID):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SearchingTableViewCell.self), for: indexPath) as! SearchingTableViewCell
let tag = dependency.context.managedObjectContext.object(with: hashTagObjectID) as! Tag
cell.config(with: tag)
return cell
case .accountObjectID(let accountObjectID):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SearchingTableViewCell.self), for: indexPath) as! SearchingTableViewCell
let user = dependency.context.managedObjectContext.object(with: accountObjectID) as! MastodonUser
cell.config(with: user)
return cell
case .bottomLoader:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SearchBottomLoader.self)) as! SearchBottomLoader
cell.startAnimating()
return cell
}
}
}
}