2021-04-22 13:58:42 +02:00
|
|
|
//
|
|
|
|
// SelectedAccountSection.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/4/22.
|
|
|
|
//
|
|
|
|
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import Foundation
|
|
|
|
import MastodonSDK
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
enum SelectedAccountSection: Equatable, Hashable {
|
|
|
|
case main
|
|
|
|
}
|
|
|
|
|
|
|
|
extension SelectedAccountSection {
|
|
|
|
static func collectionViewDiffableDataSource(
|
2022-02-10 12:30:41 +01:00
|
|
|
collectionView: UICollectionView,
|
|
|
|
context: AppContext
|
2021-04-22 13:58:42 +02:00
|
|
|
) -> UICollectionViewDiffableDataSource<SelectedAccountSection, SelectedAccountItem> {
|
|
|
|
UICollectionViewDiffableDataSource(collectionView: collectionView) { collectionView, indexPath, item -> UICollectionViewCell? in
|
|
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: SuggestionAccountCollectionViewCell.self), for: indexPath) as! SuggestionAccountCollectionViewCell
|
|
|
|
switch item {
|
2022-02-10 12:30:41 +01:00
|
|
|
case .account(let record):
|
|
|
|
context.managedObjectContext.performAndWait {
|
|
|
|
guard let user = record.object(in: context.managedObjectContext) else { return }
|
|
|
|
cell.config(with: user)
|
|
|
|
}
|
2021-04-22 14:32:54 +02:00
|
|
|
case .placeHolder:
|
2021-04-22 13:58:42 +02:00
|
|
|
cell.configAsPlaceHolder()
|
|
|
|
}
|
|
|
|
return cell
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|