2021-04-01 14:54:57 +02:00
|
|
|
//
|
|
|
|
// RecommendAccountSection.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/4/1.
|
|
|
|
//
|
|
|
|
|
2021-04-09 13:39:35 +02:00
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
2021-04-01 14:54:57 +02:00
|
|
|
import Foundation
|
|
|
|
import MastodonSDK
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
enum RecommendAccountSection: Equatable, Hashable {
|
|
|
|
case main
|
|
|
|
}
|
|
|
|
|
|
|
|
extension RecommendAccountSection {
|
|
|
|
static func collectionViewDiffableDataSource(
|
2021-04-09 07:09:30 +02:00
|
|
|
for collectionView: UICollectionView,
|
2021-04-09 13:39:35 +02:00
|
|
|
delegate: SearchRecommendAccountsCollectionViewCellDelegate,
|
|
|
|
managedObjectContext: NSManagedObjectContext
|
2021-04-09 07:09:30 +02:00
|
|
|
) -> UICollectionViewDiffableDataSource<RecommendAccountSection, NSManagedObjectID> {
|
2021-04-09 13:39:35 +02:00
|
|
|
UICollectionViewDiffableDataSource(collectionView: collectionView) { [weak delegate] collectionView, indexPath, objectID -> UICollectionViewCell? in
|
2021-04-01 14:54:57 +02:00
|
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: SearchRecommendAccountsCollectionViewCell.self), for: indexPath) as! SearchRecommendAccountsCollectionViewCell
|
2021-04-09 13:39:35 +02:00
|
|
|
let user = managedObjectContext.object(with: objectID) as! MastodonUser
|
|
|
|
cell.delegate = delegate
|
2021-04-09 07:59:33 +02:00
|
|
|
cell.config(with: user)
|
2021-04-01 14:54:57 +02:00
|
|
|
return cell
|
|
|
|
}
|
|
|
|
}
|
2021-04-21 08:46:31 +02:00
|
|
|
|
|
|
|
static func tableViewDiffableDataSource(
|
|
|
|
for tableView: UITableView,
|
|
|
|
managedObjectContext: NSManagedObjectContext,
|
|
|
|
viewModel: SuggestionAccountViewModel,
|
|
|
|
delegate: SuggestionAccountTableViewCellDelegate
|
|
|
|
) -> UITableViewDiffableDataSource<RecommendAccountSection, NSManagedObjectID> {
|
2021-04-22 09:45:32 +02:00
|
|
|
UITableViewDiffableDataSource(tableView: tableView) { [weak viewModel, weak delegate] (tableView, indexPath, objectID) -> UITableViewCell? in
|
2021-04-21 08:46:31 +02:00
|
|
|
guard let viewModel = viewModel else { return nil }
|
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SuggestionAccountTableViewCell.self)) as! SuggestionAccountTableViewCell
|
|
|
|
let user = managedObjectContext.object(with: objectID) as! MastodonUser
|
|
|
|
let isSelected = viewModel.selectedAccounts.contains(objectID)
|
|
|
|
cell.delegate = delegate
|
|
|
|
cell.config(with: user, isSelected: isSelected)
|
|
|
|
return cell
|
|
|
|
}
|
|
|
|
}
|
2021-04-01 14:54:57 +02:00
|
|
|
}
|