2021-03-05 15:50:20 +01:00
|
|
|
//
|
|
|
|
// CategoryPickerSection.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by Cirno MainasuK on 2021/3/5.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
enum CategoryPickerSection: Equatable, Hashable {
|
|
|
|
case main
|
|
|
|
}
|
|
|
|
|
|
|
|
extension CategoryPickerSection {
|
|
|
|
static func collectionViewDiffableDataSource(
|
|
|
|
for collectionView: UICollectionView,
|
|
|
|
dependency: NeedsDependency
|
|
|
|
) -> UICollectionViewDiffableDataSource<CategoryPickerSection, CategoryPickerItem> {
|
2021-04-09 05:05:10 +02:00
|
|
|
UICollectionViewDiffableDataSource(collectionView: collectionView) { [weak dependency] collectionView, indexPath, item -> UICollectionViewCell? in
|
|
|
|
guard let _ = dependency else { return nil }
|
2021-03-05 15:50:20 +01:00
|
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: PickServerCategoryCollectionViewCell.self), for: indexPath) as! PickServerCategoryCollectionViewCell
|
|
|
|
switch item {
|
|
|
|
case .all:
|
|
|
|
cell.categoryView.titleLabel.font = .systemFont(ofSize: 17)
|
|
|
|
case .category:
|
|
|
|
cell.categoryView.titleLabel.font = .systemFont(ofSize: 28)
|
|
|
|
}
|
|
|
|
cell.categoryView.titleLabel.text = item.title
|
2021-03-06 07:46:04 +01:00
|
|
|
cell.observe(\.isSelected, options: [.initial, .new]) { cell, _ in
|
|
|
|
if cell.isSelected {
|
2021-04-06 10:43:08 +02:00
|
|
|
cell.categoryView.bgView.backgroundColor = Asset.Colors.brandBlue.color
|
|
|
|
cell.categoryView.bgView.applyShadow(color: Asset.Colors.brandBlue.color, alpha: 1, x: 0, y: 0, blur: 4.0)
|
2021-03-06 07:46:04 +01:00
|
|
|
if case .all = item {
|
2021-04-06 10:43:08 +02:00
|
|
|
cell.categoryView.titleLabel.textColor = .white
|
2021-03-06 07:46:04 +01:00
|
|
|
}
|
|
|
|
} else {
|
2021-04-06 10:43:08 +02:00
|
|
|
cell.categoryView.bgView.backgroundColor = Asset.Colors.Background.systemBackground.color
|
|
|
|
cell.categoryView.bgView.applyShadow(color: Asset.Colors.brandBlue.color, alpha: 0, x: 0, y: 0, blur: 0.0)
|
2021-03-06 07:46:04 +01:00
|
|
|
if case .all = item {
|
2021-04-06 10:43:08 +02:00
|
|
|
cell.categoryView.titleLabel.textColor = Asset.Colors.brandBlue.color
|
2021-03-06 07:46:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.store(in: &cell.observations)
|
2021-03-05 15:50:20 +01:00
|
|
|
return cell
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|