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

54 lines
2.2 KiB
Swift
Raw Normal View History

//
// SearchResultSection.swift
// Mastodon
//
// Created by sxiaojian on 2021/4/6.
//
import Foundation
import MastodonSDK
import UIKit
2021-04-07 13:49:33 +02:00
import CoreData
import CoreDataStack
enum SearchResultSection: Equatable, Hashable {
case account
case hashTag
2021-04-07 13:49:33 +02:00
case mixed
2021-04-06 09:25:04 +02:00
case bottomLoader
}
extension SearchResultSection {
static func tableViewDiffableDataSource(
2021-04-07 13:49:33 +02:00
for tableView: UITableView,
dependency: NeedsDependency
) -> UITableViewDiffableDataSource<SearchResultSection, SearchResultItem> {
UITableViewDiffableDataSource(tableView: tableView) { (tableView, indexPath, result) -> UITableViewCell? in
switch result {
case .account(let account):
2021-04-06 09:25:04 +02:00
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SearchingTableViewCell.self), for: indexPath) as! SearchingTableViewCell
cell.config(with: account)
2021-04-06 09:25:04 +02:00
return cell
case .hashTag(let tag):
2021-04-06 09:25:04 +02:00
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SearchingTableViewCell.self), for: indexPath) as! SearchingTableViewCell
cell.config(with: tag)
2021-04-06 09:25:04 +02:00
return cell
2021-04-07 13:49:33 +02:00
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
2021-04-06 09:25:04 +02:00
case .bottomLoader:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SearchBottomLoader.self)) as! SearchBottomLoader
cell.startAnimating()
return cell
}
}
}
}