2021-04-02 10:24:00 +02:00
|
|
|
//
|
|
|
|
// 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
|
2021-04-02 10:24:00 +02:00
|
|
|
|
|
|
|
enum SearchResultSection: Equatable, Hashable {
|
2021-07-14 14:28:41 +02:00
|
|
|
case main
|
2021-04-02 10:24:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extension SearchResultSection {
|
|
|
|
static func tableViewDiffableDataSource(
|
2021-04-07 13:49:33 +02:00
|
|
|
for tableView: UITableView,
|
2021-07-14 14:28:41 +02:00
|
|
|
dependency: NeedsDependency,
|
|
|
|
statusTableViewCellDelegate: StatusTableViewCellDelegate
|
2021-04-02 10:24:00 +02:00
|
|
|
) -> UITableViewDiffableDataSource<SearchResultSection, SearchResultItem> {
|
2021-07-14 14:28:41 +02:00
|
|
|
UITableViewDiffableDataSource(tableView: tableView) { [
|
|
|
|
weak statusTableViewCellDelegate
|
|
|
|
] tableView, indexPath, item -> UITableViewCell? in
|
|
|
|
switch item {
|
2021-04-02 10:24:00 +02:00
|
|
|
case .account(let account):
|
2021-07-14 14:28:41 +02:00
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SearchResultTableViewCell.self), for: indexPath) as! SearchResultTableViewCell
|
2021-04-02 10:24:00 +02:00
|
|
|
cell.config(with: account)
|
2021-04-06 09:25:04 +02:00
|
|
|
return cell
|
2021-04-07 15:01:32 +02:00
|
|
|
case .hashtag(let tag):
|
2021-07-14 14:28:41 +02:00
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SearchResultTableViewCell.self), for: indexPath) as! SearchResultTableViewCell
|
2021-04-02 10:24:00 +02:00
|
|
|
cell.config(with: tag)
|
2021-04-06 09:25:04 +02:00
|
|
|
return cell
|
2021-07-14 14:28:41 +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
|
|
|
|
case .status(let statusObjectID, let attribute):
|
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as! StatusTableViewCell
|
|
|
|
if let status = try? dependency.context.managedObjectContext.existingObject(with: statusObjectID) as? Status {
|
|
|
|
let activeMastodonAuthenticationBox = dependency.context.authenticationService.activeMastodonAuthenticationBox.value
|
|
|
|
let requestUserID = activeMastodonAuthenticationBox?.userID ?? ""
|
|
|
|
StatusSection.configure(
|
|
|
|
cell: cell,
|
|
|
|
tableView: tableView,
|
|
|
|
timelineContext: .search,
|
|
|
|
dependency: dependency,
|
|
|
|
readableLayoutFrame: tableView.readableContentGuide.layoutFrame,
|
|
|
|
status: status,
|
|
|
|
requestUserID: requestUserID,
|
|
|
|
statusItemAttribute: attribute
|
|
|
|
)
|
|
|
|
}
|
|
|
|
cell.delegate = statusTableViewCellDelegate
|
2021-04-07 13:49:33 +02:00
|
|
|
return cell
|
2021-04-06 09:25:04 +02:00
|
|
|
case .bottomLoader:
|
2021-04-16 07:45:54 +02:00
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self)) as! TimelineBottomLoaderTableViewCell
|
2021-04-06 09:25:04 +02:00
|
|
|
cell.startAnimating()
|
|
|
|
return cell
|
2021-07-14 14:28:41 +02:00
|
|
|
default:
|
|
|
|
fatalError()
|
|
|
|
} // end switch
|
|
|
|
} // end UITableViewDiffableDataSource
|
|
|
|
} // end func
|
2021-04-02 10:24:00 +02:00
|
|
|
}
|