chore: rename file name and code format

This commit is contained in:
sunxiaojian 2021-04-02 12:10:12 +08:00
parent 458ab6bcda
commit f24aee739e
6 changed files with 34 additions and 59 deletions

View File

@ -30,7 +30,7 @@
2D32EAAC25CB96DC00C9ED86 /* TimelineMiddleLoaderTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D32EAAB25CB96DC00C9ED86 /* TimelineMiddleLoaderTableViewCell.swift */; };
2D32EABA25CB9B0500C9ED86 /* UIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D32EAB925CB9B0500C9ED86 /* UIView.swift */; };
2D32EADA25CBCC3300C9ED86 /* PublicTimelineViewModel+LoadMiddleState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D32EAD925CBCC3300C9ED86 /* PublicTimelineViewModel+LoadMiddleState.swift */; };
2D34D9CB261489930081BFC0 /* SearchViewController+recomendView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D34D9CA261489930081BFC0 /* SearchViewController+recomendView.swift */; };
2D34D9CB261489930081BFC0 /* SearchViewController+RecomendView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D34D9CA261489930081BFC0 /* SearchViewController+RecomendView.swift */; };
2D34D9D126148D9E0081BFC0 /* APIService+Recommend.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D34D9D026148D9E0081BFC0 /* APIService+Recommend.swift */; };
2D34D9DB261494120081BFC0 /* APIService+Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D34D9DA261494120081BFC0 /* APIService+Search.swift */; };
2D34D9E226149C920081BFC0 /* SearchRecommendTagsCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D34D9E126149C920081BFC0 /* SearchRecommendTagsCollectionViewCell.swift */; };
@ -344,7 +344,7 @@
2D32EAAB25CB96DC00C9ED86 /* TimelineMiddleLoaderTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineMiddleLoaderTableViewCell.swift; sourceTree = "<group>"; };
2D32EAB925CB9B0500C9ED86 /* UIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIView.swift; sourceTree = "<group>"; };
2D32EAD925CBCC3300C9ED86 /* PublicTimelineViewModel+LoadMiddleState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PublicTimelineViewModel+LoadMiddleState.swift"; sourceTree = "<group>"; };
2D34D9CA261489930081BFC0 /* SearchViewController+recomendView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SearchViewController+recomendView.swift"; sourceTree = "<group>"; };
2D34D9CA261489930081BFC0 /* SearchViewController+RecomendView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SearchViewController+RecomendView.swift"; sourceTree = "<group>"; };
2D34D9D026148D9E0081BFC0 /* APIService+Recommend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIService+Recommend.swift"; sourceTree = "<group>"; };
2D34D9DA261494120081BFC0 /* APIService+Search.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIService+Search.swift"; sourceTree = "<group>"; };
2D34D9E126149C920081BFC0 /* SearchRecommendTagsCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchRecommendTagsCollectionViewCell.swift; sourceTree = "<group>"; };
@ -1439,7 +1439,7 @@
children = (
2DE0FAC62615F5D200CDF649 /* View */,
DB9D6BE825E4F5340051B173 /* SearchViewController.swift */,
2D34D9CA261489930081BFC0 /* SearchViewController+recomendView.swift */,
2D34D9CA261489930081BFC0 /* SearchViewController+RecomendView.swift */,
2D6DE3FF26141DF600A63F6A /* SearchViewModel.swift */,
2D34D9E026149C550081BFC0 /* CollectionViewCell */,
);
@ -2021,7 +2021,7 @@
DB49A63D25FF609300B98345 /* PlayerContainerView+MediaTypeIndicotorView.swift in Sources */,
DB0140CF25C42AEE00F9F3CF /* OSLog.swift in Sources */,
DB44384F25E8C1FA008912A2 /* CALayer.swift in Sources */,
2D34D9CB261489930081BFC0 /* SearchViewController+recomendView.swift in Sources */,
2D34D9CB261489930081BFC0 /* SearchViewController+RecomendView.swift in Sources */,
2D206B8625F5FB0900143C56 /* Double.swift in Sources */,
DB9A485C2603010E008B817C /* PHPickerResultLoader.swift in Sources */,
2D76319F25C1521200929FB9 /* StatusSection.swift in Sources */,

View File

@ -6,8 +6,8 @@
//
import Foundation
import UIKit
import MastodonSDK
import UIKit
class SearchRecommendAccountsCollectionViewCell: UICollectionViewCell {
let avatarImageView: UIImageView = {
@ -75,7 +75,7 @@ extension SearchRecommendAccountsCollectionViewCell {
clipsToBounds = true
contentView.addSubview(headerImageView)
headerImageView.pin(top: 16, left: 0, bottom: 0, right: 0 )
headerImageView.pin(top: 16, left: 0, bottom: 0, right: 0)
contentView.addSubview(avatarImageView)
avatarImageView.pin(toSize: CGSize(width: 88, height: 88))
@ -86,20 +86,20 @@ extension SearchRecommendAccountsCollectionViewCell {
contentView.addSubview(displayNameLabel)
displayNameLabel.constrain([
displayNameLabel.constraint(.top, toView: contentView,constant: 108),
displayNameLabel.constraint(.top, toView: contentView, constant: 108),
displayNameLabel.constraint(.centerX, toView: contentView)
])
contentView.addSubview(acctLabel)
acctLabel.constrain([
acctLabel.constraint(.top, toView: contentView,constant: 132),
acctLabel.constraint(.top, toView: contentView, constant: 132),
acctLabel.constraint(.centerX, toView: contentView)
])
contentView.addSubview(followButton)
followButton.pin(toSize: CGSize(width: 76, height: 24))
followButton.constrain([
followButton.constraint(.top, toView: contentView,constant: 159),
followButton.constraint(.top, toView: contentView, constant: 159),
followButton.constraint(.centerX, toView: contentView)
])
}
@ -124,10 +124,9 @@ extension SearchRecommendAccountsCollectionViewCell {
import SwiftUI
struct SearchRecommendAccountsCollectionViewCell_Previews: PreviewProvider {
static var controls: some View {
Group {
UIViewPreview() {
UIViewPreview {
let cell = SearchRecommendAccountsCollectionViewCell()
cell.avatarImageView.backgroundColor = .white
cell.headerImageView.backgroundColor = .red
@ -146,7 +145,6 @@ struct SearchRecommendAccountsCollectionViewCell_Previews: PreviewProvider {
}
.background(Color.gray)
}
}
#endif

View File

@ -6,8 +6,8 @@
//
import Foundation
import UIKit
import MastodonSDK
import UIKit
class SearchRecommendTagsCollectionViewCell: UICollectionViewCell {
let backgroundImageView: UIImageView = {
@ -74,12 +74,11 @@ extension SearchRecommendTagsCollectionViewCell {
contentView.addSubview(flameIconView)
flameIconView.pinTopRight(padding: 16)
}
func config(with tag: Mastodon.Entity.Tag) {
hashTagTitleLabel.text = "# " + tag.name
if let peopleAreTalking = tag.history?.compactMap({ Int($0.uses)}).reduce(0, +) {
if let peopleAreTalking = tag.history?.compactMap({ Int($0.uses) }).reduce(0, +) {
let string = L10n.Scene.Search.Recommend.HashTag.peopleTalking(String(peopleAreTalking))
peopleLabel.text = string
} else {
@ -92,10 +91,9 @@ extension SearchRecommendTagsCollectionViewCell {
import SwiftUI
struct SearchRecommendTagsCollectionViewCell_Previews: PreviewProvider {
static var controls: some View {
Group {
UIViewPreview() {
UIViewPreview {
let cell = SearchRecommendTagsCollectionViewCell()
cell.hashTagTitleLabel.text = "# test"
cell.peopleLabel.text = "128 people are talking"
@ -112,7 +110,6 @@ struct SearchRecommendTagsCollectionViewCell_Previews: PreviewProvider {
}
.background(Color.gray)
}
}
#endif

View File

@ -1,14 +1,14 @@
//
// SearchViewController+hashTagCollectionView.swift
// SearchViewController+RecomendView.swift
// Mastodon
//
// Created by sxiaojian on 2021/3/31.
//
import Foundation
import UIKit
import OSLog
import MastodonSDK
import OSLog
import UIKit
extension SearchViewController {
func setupHashTagCollectionView() {
@ -17,15 +17,15 @@ extension SearchViewController {
header.descriptionLabel.text = L10n.Scene.Search.Recommend.HashTag.description
header.seeAllButton.addTarget(self, action: #selector(SearchViewController.hashTagSeeAllButtonPressed(_:)), for: .touchUpInside)
stackView.addArrangedSubview(header)
hashTagCollectionView.register(SearchRecommendTagsCollectionViewCell.self, forCellWithReuseIdentifier: String(describing: SearchRecommendTagsCollectionViewCell.self))
hashTagCollectionView.delegate = self
stackView.addArrangedSubview(hashTagCollectionView)
hashTagCollectionView.constrain([
hashTagCollectionView.frameLayoutGuide.heightAnchor.constraint(equalToConstant: 130)
])
viewModel.requestRecommendHashTags()
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
@ -39,10 +39,10 @@ extension SearchViewController {
self.hashTagDiffableDataSource = dataSource
}
} receiveValue: { _ in
}
.store(in: &disposeBag)
}
func setupAccountsCollectionView() {
let header = SearchRecommendCollectionHeader()
header.titleLabel.text = L10n.Scene.Search.Recommend.Accounts.title
@ -71,11 +71,10 @@ extension SearchViewController {
self.accountDiffableDataSource = dataSource
}
} receiveValue: { _ in
}
.store(in: &disposeBag)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
hashTagCollectionView.collectionViewLayout.invalidateLayout()
@ -85,16 +84,16 @@ extension SearchViewController {
extension SearchViewController: UICollectionViewDelegate {
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)
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: indexPath: %s", (#file as NSString).lastPathComponent, #line, #function, indexPath.debugDescription)
collectionView.selectItem(at: indexPath, animated: true, scrollPosition: .centeredHorizontally)
}
}
// MARK: - UICollectionViewDelegateFlowLayout
extension SearchViewController: UICollectionViewDelegateFlowLayout {
extension SearchViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
@ -104,24 +103,18 @@ extension SearchViewController: UICollectionViewDelegateFlowLayout {
return 12
}
}
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)
}
}
}
extension SearchViewController {
@objc func hashTagSeeAllButtonPressed(_ sender: UIButton) {
}
@objc func accountSeeAllButtonPressed(_ sender: UIButton) {
}
@objc func hashTagSeeAllButtonPressed(_ sender: UIButton) {}
@objc func accountSeeAllButtonPressed(_ sender: UIButton) {}
}

View File

@ -5,12 +5,11 @@
// Created by sxiaojian on 2021/3/31.
//
import UIKit
import Combine
import MastodonSDK
import UIKit
final class SearchViewController: UIViewController, NeedsDependency {
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
@ -57,10 +56,10 @@ final class SearchViewController: UIViewController, NeedsDependency {
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
var hashTagDiffableDataSource: UICollectionViewDiffableDataSource<RecomendHashTagSection, Mastodon.Entity.Tag>?
var accountDiffableDataSource: UICollectionViewDiffableDataSource<RecommendAccountSection, Mastodon.Entity.Account>?
let accountsCollectionView: UICollectionView = {
let flowLayout = UICollectionViewFlowLayout()
flowLayout.scrollDirection = .horizontal
@ -75,7 +74,6 @@ final class SearchViewController: UIViewController, NeedsDependency {
}
extension SearchViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = Asset.Colors.Background.search.color
@ -85,8 +83,8 @@ extension SearchViewController {
setupScrollView()
setupHashTagCollectionView()
setupAccountsCollectionView()
}
func setupScrollView() {
view.addSubview(scrollView)
scrollView.constrain([
@ -94,7 +92,7 @@ extension SearchViewController {
scrollView.frameLayoutGuide.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
scrollView.frameLayoutGuide.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
scrollView.frameLayoutGuide.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
scrollView.contentLayoutGuide.widthAnchor.constraint(equalTo: view.widthAnchor)
scrollView.contentLayoutGuide.widthAnchor.constraint(equalTo: view.widthAnchor),
])
scrollView.addSubview(stackView)
@ -105,7 +103,6 @@ extension SearchViewController {
stackView.widthAnchor.constraint(equalTo: scrollView.contentLayoutGuide.widthAnchor),
scrollView.contentLayoutGuide.bottomAnchor.constraint(equalTo: stackView.bottomAnchor),
])
}
}
@ -128,20 +125,13 @@ extension SearchViewController: UISearchBarDelegate {
viewModel.searchText.send(searchText)
}
func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar) {
}
}
extension SearchViewController {
func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar) {}
}
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct SearchViewController_Previews: PreviewProvider {
static var previews: some View {
UIViewControllerPreview {
let viewController = SearchViewController()
@ -149,7 +139,6 @@ struct SearchViewController_Previews: PreviewProvider {
}
.previewLayout(.fixed(width: 375, height: 800))
}
}
#endif

View File

@ -62,10 +62,9 @@ extension SearchRecommendCollectionHeader {
import SwiftUI
struct SearchRecommendCollectionHeader_Previews: PreviewProvider {
static var controls: some View {
Group {
UIViewPreview() {
UIViewPreview {
let cell = SearchRecommendCollectionHeader()
cell.titleLabel.text = "Trending in your timeline"
cell.descriptionLabel.text = "Hashtags that are getting quite a bit of attention among people you follow"
@ -83,7 +82,6 @@ struct SearchRecommendCollectionHeader_Previews: PreviewProvider {
}
.background(Color.gray)
}
}
#endif