mastodon-ios/Mastodon/Scene/Search/SearchViewController+Recome...

89 lines
3.7 KiB
Swift
Raw Normal View History

2021-03-31 13:29:54 +02:00
//
// SearchViewController+Recomend.swift
2021-03-31 13:29:54 +02:00
// Mastodon
//
// Created by sxiaojian on 2021/3/31.
//
import Foundation
2021-04-01 14:54:57 +02:00
import MastodonSDK
import OSLog
import UIKit
2021-03-31 13:29:54 +02:00
extension SearchViewController {
2021-04-01 14:54:57 +02:00
func setupHashTagCollectionView() {
let header = SearchRecommendCollectionHeader()
header.titleLabel.text = L10n.Scene.Search.Recommend.HashTag.title
header.descriptionLabel.text = L10n.Scene.Search.Recommend.HashTag.description
header.seeAllButton.addTarget(self, action: #selector(SearchViewController.hashTagSeeAllButtonPressed(_:)), for: .touchUpInside)
stackView.addArrangedSubview(header)
2021-04-01 14:54:57 +02:00
hashTagCollectionView.register(SearchRecommendTagsCollectionViewCell.self, forCellWithReuseIdentifier: String(describing: SearchRecommendTagsCollectionViewCell.self))
hashTagCollectionView.delegate = self
2021-04-01 14:54:57 +02:00
stackView.addArrangedSubview(hashTagCollectionView)
hashTagCollectionView.constrain([
hashTagCollectionView.frameLayoutGuide.heightAnchor.constraint(equalToConstant: 130)
])
}
2021-04-01 14:54:57 +02:00
func setupAccountsCollectionView() {
let header = SearchRecommendCollectionHeader()
header.titleLabel.text = L10n.Scene.Search.Recommend.Accounts.title
header.descriptionLabel.text = L10n.Scene.Search.Recommend.Accounts.description
header.seeAllButton.addTarget(self, action: #selector(SearchViewController.accountSeeAllButtonPressed(_:)), for: .touchUpInside)
stackView.addArrangedSubview(header)
accountsCollectionView.register(SearchRecommendAccountsCollectionViewCell.self, forCellWithReuseIdentifier: String(describing: SearchRecommendAccountsCollectionViewCell.self))
accountsCollectionView.delegate = self
stackView.addArrangedSubview(accountsCollectionView)
accountsCollectionView.constrain([
accountsCollectionView.frameLayoutGuide.heightAnchor.constraint(equalToConstant: 202)
])
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
2021-04-01 14:54:57 +02:00
hashTagCollectionView.collectionViewLayout.invalidateLayout()
accountsCollectionView.collectionViewLayout.invalidateLayout()
2021-03-31 13:29:54 +02:00
}
}
extension SearchViewController: UICollectionViewDelegate {
2021-04-01 14:54:57 +02:00
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: indexPath: %s", (#file as NSString).lastPathComponent, #line, #function, indexPath.debugDescription)
2021-04-01 14:54:57 +02:00
collectionView.selectItem(at: indexPath, animated: true, scrollPosition: .centeredHorizontally)
}
2021-03-31 13:29:54 +02:00
}
2021-04-01 14:54:57 +02:00
// MARK: - UICollectionViewDelegateFlowLayout
extension SearchViewController: UICollectionViewDelegateFlowLayout {
2021-04-01 14:54:57 +02:00
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
}
2021-04-01 14:54:57 +02:00
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
if collectionView == hashTagCollectionView {
return 6
} else {
return 12
}
2021-03-31 13:29:54 +02:00
}
2021-04-01 14:54:57 +02:00
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if collectionView == hashTagCollectionView {
return CGSize(width: 228, height: 130)
} else {
return CGSize(width: 257, height: 202)
}
2021-03-31 13:29:54 +02:00
}
2021-04-01 14:54:57 +02:00
}
extension SearchViewController {
@objc func hashTagSeeAllButtonPressed(_ sender: UIButton) {}
@objc func accountSeeAllButtonPressed(_ sender: UIButton) {}
2021-03-31 13:29:54 +02:00
}