Remove collection view from suggestion-screen (IOS-157)
This commit is contained in:
parent
a2729b17c5
commit
c0532d7b56
|
@ -76,8 +76,6 @@
|
|||
2D38F20825CD491300561493 /* DisposeBagCollectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D38F20725CD491300561493 /* DisposeBagCollectable.swift */; };
|
||||
2D3F9E0425DFA133004262D9 /* UITapGestureRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D3F9E0325DFA133004262D9 /* UITapGestureRecognizer.swift */; };
|
||||
2D4AD89C263165B500613EFC /* SuggestionAccountCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D4AD89B263165B500613EFC /* SuggestionAccountCollectionViewCell.swift */; };
|
||||
2D4AD8A226316CD200613EFC /* SelectedAccountSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D4AD8A126316CD200613EFC /* SelectedAccountSection.swift */; };
|
||||
2D4AD8A826316D3500613EFC /* SelectedAccountItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D4AD8A726316D3500613EFC /* SelectedAccountItem.swift */; };
|
||||
2D571B2F26004EC000540450 /* NavigationBarProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D571B2E26004EC000540450 /* NavigationBarProgressView.swift */; };
|
||||
2D59819B25E4A581000FB903 /* MastodonConfirmEmailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D59819A25E4A581000FB903 /* MastodonConfirmEmailViewController.swift */; };
|
||||
2D5981A125E4A593000FB903 /* MastodonConfirmEmailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D5981A025E4A593000FB903 /* MastodonConfirmEmailViewModel.swift */; };
|
||||
|
@ -695,8 +693,6 @@
|
|||
2D38F20725CD491300561493 /* DisposeBagCollectable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisposeBagCollectable.swift; sourceTree = "<group>"; };
|
||||
2D3F9E0325DFA133004262D9 /* UITapGestureRecognizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITapGestureRecognizer.swift; sourceTree = "<group>"; };
|
||||
2D4AD89B263165B500613EFC /* SuggestionAccountCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SuggestionAccountCollectionViewCell.swift; sourceTree = "<group>"; };
|
||||
2D4AD8A126316CD200613EFC /* SelectedAccountSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectedAccountSection.swift; sourceTree = "<group>"; };
|
||||
2D4AD8A726316D3500613EFC /* SelectedAccountItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectedAccountItem.swift; sourceTree = "<group>"; };
|
||||
2D571B2E26004EC000540450 /* NavigationBarProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationBarProgressView.swift; sourceTree = "<group>"; };
|
||||
2D59819A25E4A581000FB903 /* MastodonConfirmEmailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonConfirmEmailViewController.swift; sourceTree = "<group>"; };
|
||||
2D5981A025E4A593000FB903 /* MastodonConfirmEmailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonConfirmEmailViewModel.swift; sourceTree = "<group>"; };
|
||||
|
@ -1625,7 +1621,6 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
DB4F097826A039B400D62E92 /* Onboarding */,
|
||||
DB0617FB27855B740030EE79 /* Account */,
|
||||
DB0617F827855B170030EE79 /* User */,
|
||||
DB0617F927855B460030EE79 /* Profile */,
|
||||
DB0FCB892796BE1E006C02E2 /* RecommandAccount */,
|
||||
|
@ -1907,15 +1902,6 @@
|
|||
path = Settings;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
DB0617FB27855B740030EE79 /* Account */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2D4AD8A126316CD200613EFC /* SelectedAccountSection.swift */,
|
||||
2D4AD8A726316D3500613EFC /* SelectedAccountItem.swift */,
|
||||
);
|
||||
path = Account;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
DB0618082785B2790030EE79 /* Cell */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -3689,7 +3675,6 @@
|
|||
DB63F7542799491600455B82 /* DataSourceFacade+SearchHistory.swift in Sources */,
|
||||
DB7A9F912818EAF10016AF98 /* MastodonRegisterView.swift in Sources */,
|
||||
DBF1572F27046F1A00EC00B7 /* SecondaryPlaceholderViewController.swift in Sources */,
|
||||
2D4AD8A826316D3500613EFC /* SelectedAccountItem.swift in Sources */,
|
||||
DBE3CDFB261C6CA500430CC6 /* FavoriteViewModel.swift in Sources */,
|
||||
2AB12E4629362F27006BC925 /* DataSourceFacade+Translate.swift in Sources */,
|
||||
DBE3CE01261D623D00430CC6 /* FavoriteViewModel+State.swift in Sources */,
|
||||
|
@ -3927,7 +3912,6 @@
|
|||
DBB525412611ED54002F1F29 /* ProfileHeaderViewController.swift in Sources */,
|
||||
DBDFF19A28055A1400557A48 /* DiscoveryViewController.swift in Sources */,
|
||||
DB9D6BFF25E4F5940051B173 /* ProfileViewController.swift in Sources */,
|
||||
2D4AD8A226316CD200613EFC /* SelectedAccountSection.swift in Sources */,
|
||||
DB3EA8F1281B9EF600598866 /* DiscoveryCommunityViewModel+Diffable.swift in Sources */,
|
||||
85BC11B32932414900E191CD /* AltTextViewController.swift in Sources */,
|
||||
DB63F775279A997D00455B82 /* NotificationTableViewCell+ViewModel.swift in Sources */,
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
//
|
||||
// SelectedAccountItem.swift
|
||||
// Mastodon
|
||||
//
|
||||
// Created by sxiaojian on 2021/4/22.
|
||||
//
|
||||
|
||||
import CoreData
|
||||
import Foundation
|
||||
import CoreDataStack
|
||||
|
||||
enum SelectedAccountItem: Hashable {
|
||||
case account(ManagedObjectRecord<MastodonUser>)
|
||||
case placeHolder(uuid: UUID)
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
//
|
||||
// SelectedAccountSection.swift
|
||||
// Mastodon
|
||||
//
|
||||
// Created by sxiaojian on 2021/4/22.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import CoreData
|
||||
import CoreDataStack
|
||||
import MastodonCore
|
||||
import MastodonSDK
|
||||
|
||||
enum SelectedAccountSection: Equatable, Hashable {
|
||||
case main
|
||||
}
|
||||
|
||||
extension SelectedAccountSection {
|
||||
static func collectionViewDiffableDataSource(
|
||||
collectionView: UICollectionView,
|
||||
context: AppContext
|
||||
) -> 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 {
|
||||
case .account(let record):
|
||||
context.managedObjectContext.performAndWait {
|
||||
guard let user = record.object(in: context.managedObjectContext) else { return }
|
||||
cell.config(with: user)
|
||||
}
|
||||
case .placeHolder:
|
||||
cell.configAsPlaceHolder()
|
||||
}
|
||||
return cell
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,9 +17,7 @@ import MastodonUI
|
|||
import MastodonLocalization
|
||||
|
||||
class SuggestionAccountViewController: UIViewController, NeedsDependency {
|
||||
|
||||
static let collectionViewHeight: CGFloat = 24 + 64 + 24
|
||||
|
||||
|
||||
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
|
||||
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
||||
|
||||
|
@ -41,19 +39,6 @@ class SuggestionAccountViewController: UIViewController, NeedsDependency {
|
|||
return UICollectionViewCompositionalLayout(section: section)
|
||||
}
|
||||
|
||||
let collectionView: UICollectionView = {
|
||||
let collectionViewLayout = SuggestionAccountViewController.createCollectionViewLayout()
|
||||
let view = ControlContainableCollectionView(
|
||||
frame: .zero,
|
||||
collectionViewLayout: collectionViewLayout
|
||||
)
|
||||
view.register(SuggestionAccountCollectionViewCell.self, forCellWithReuseIdentifier: String(describing: SuggestionAccountCollectionViewCell.self))
|
||||
view.backgroundColor = .clear
|
||||
view.showsHorizontalScrollIndicator = false
|
||||
view.showsVerticalScrollIndicator = false
|
||||
view.layer.masksToBounds = false
|
||||
return view
|
||||
}()
|
||||
|
||||
let tableView: UITableView = {
|
||||
let tableView = ControlContainableTableView()
|
||||
|
@ -89,31 +74,16 @@ extension SuggestionAccountViewController {
|
|||
target: self,
|
||||
action: #selector(SuggestionAccountViewController.doneButtonDidClick(_:))
|
||||
)
|
||||
|
||||
collectionView.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(collectionView)
|
||||
NSLayoutConstraint.activate([
|
||||
collectionView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
|
||||
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
collectionView.heightAnchor.constraint(equalToConstant: SuggestionAccountViewController.collectionViewHeight),
|
||||
])
|
||||
defer { view.bringSubviewToFront(collectionView) }
|
||||
|
||||
tableView.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(tableView)
|
||||
NSLayoutConstraint.activate([
|
||||
tableView.topAnchor.constraint(equalTo: collectionView.bottomAnchor),
|
||||
tableView.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
|
||||
collectionView.delegate = self
|
||||
viewModel.setupDiffableDataSource(
|
||||
collectionView: collectionView
|
||||
)
|
||||
|
||||
tableView.delegate = self
|
||||
viewModel.setupDiffableDataSource(
|
||||
tableView: tableView,
|
||||
|
@ -129,26 +99,6 @@ extension SuggestionAccountViewController {
|
|||
|
||||
private func setupBackgroundColor(theme: Theme) {
|
||||
view.backgroundColor = theme.systemBackgroundColor
|
||||
collectionView.backgroundColor = theme.systemGroupedBackgroundColor
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UICollectionViewDelegateFlowLayout
|
||||
extension SuggestionAccountViewController: UICollectionViewDelegate {
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
// guard let diffableDataSource = viewModel.collectionDiffableDataSource else { return }
|
||||
// guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return }
|
||||
// switch item {
|
||||
// case .accountObjectID(let accountObjectID):
|
||||
// let mastodonUser = context.managedObjectContext.object(with: accountObjectID) as! MastodonUser
|
||||
// let viewModel = ProfileViewModel(context: context, optionalMastodonUser: mastodonUser)
|
||||
// DispatchQueue.main.async {
|
||||
// self.coordinator.present(scene: .profile(viewModel: viewModel), from: self, transition: .show)
|
||||
// }
|
||||
// default:
|
||||
// break
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,37 +38,4 @@ extension SuggestionAccountViewModel {
|
|||
}
|
||||
.store(in: &disposeBag)
|
||||
}
|
||||
|
||||
func setupDiffableDataSource(
|
||||
collectionView: UICollectionView
|
||||
) {
|
||||
collectionViewDiffableDataSource = SelectedAccountSection.collectionViewDiffableDataSource(
|
||||
collectionView: collectionView,
|
||||
context: context
|
||||
)
|
||||
|
||||
selectedUserFetchedResultsController.$records
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] records in
|
||||
guard let self = self else { return }
|
||||
guard let collectionViewDiffableDataSource = self.collectionViewDiffableDataSource else { return }
|
||||
|
||||
var snapshot = NSDiffableDataSourceSnapshot<SelectedAccountSection, SelectedAccountItem>()
|
||||
snapshot.appendSections([.main])
|
||||
var items: [SelectedAccountItem] = records.map { SelectedAccountItem.account($0) }
|
||||
|
||||
if items.count < 10 {
|
||||
let count = 10 - items.count
|
||||
let placeholderItems: [SelectedAccountItem] = (0..<count).map { _ in
|
||||
SelectedAccountItem.placeHolder(uuid: UUID())
|
||||
}
|
||||
items.append(contentsOf: placeholderItems)
|
||||
}
|
||||
|
||||
snapshot.appendItems(items, toSection: .main)
|
||||
collectionViewDiffableDataSource.applySnapshotUsingReloadData(snapshot, completion: nil)
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,12 +27,10 @@ final class SuggestionAccountViewModel: NSObject {
|
|||
let context: AppContext
|
||||
let authContext: AuthContext
|
||||
let userFetchedResultsController: UserFetchedResultsController
|
||||
let selectedUserFetchedResultsController: UserFetchedResultsController
|
||||
|
||||
|
||||
var viewWillAppear = PassthroughSubject<Void, Never>()
|
||||
|
||||
// output
|
||||
var collectionViewDiffableDataSource: UICollectionViewDiffableDataSource<SelectedAccountSection, SelectedAccountItem>?
|
||||
var tableViewDiffableDataSource: UITableViewDiffableDataSource<RecommendAccountSection, RecommendAccountItem>?
|
||||
|
||||
init(
|
||||
|
@ -46,20 +44,10 @@ final class SuggestionAccountViewModel: NSObject {
|
|||
domain: nil,
|
||||
additionalPredicate: nil
|
||||
)
|
||||
self.selectedUserFetchedResultsController = UserFetchedResultsController(
|
||||
managedObjectContext: context.managedObjectContext,
|
||||
domain: nil,
|
||||
additionalPredicate: nil
|
||||
)
|
||||
super.init()
|
||||
|
||||
userFetchedResultsController.domain = authContext.mastodonAuthenticationBox.domain
|
||||
selectedUserFetchedResultsController.domain = authContext.mastodonAuthenticationBox.domain
|
||||
selectedUserFetchedResultsController.additionalPredicate = NSCompoundPredicate(orPredicateWithSubpredicates: [
|
||||
MastodonUser.predicate(followingBy: authContext.mastodonAuthenticationBox.userID),
|
||||
MastodonUser.predicate(followRequestedBy: authContext.mastodonAuthenticationBox.userID)
|
||||
])
|
||||
|
||||
|
||||
// fetch recomment users
|
||||
Task {
|
||||
var userIDs: [MastodonUser.ID] = []
|
||||
|
@ -81,7 +69,6 @@ final class SuggestionAccountViewModel: NSObject {
|
|||
|
||||
guard !userIDs.isEmpty else { return }
|
||||
userFetchedResultsController.userIDs = userIDs
|
||||
selectedUserFetchedResultsController.userIDs = userIDs
|
||||
}
|
||||
|
||||
// fetch relationship
|
||||
|
|
Loading…
Reference in New Issue