From c0532d7b5618091e3337c0dcdd13fe62bc6a85c2 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Fri, 12 May 2023 21:04:47 +0200 Subject: [PATCH] Remove collection view from suggestion-screen (IOS-157) --- Mastodon.xcodeproj/project.pbxproj | 16 ------ .../Account/SelectedAccountItem.swift | 15 ------ .../Account/SelectedAccountSection.swift | 37 ------------- .../SuggestionAccountViewController.swift | 54 +------------------ .../SuggestionAccountViewModel+Diffable.swift | 33 ------------ .../SuggestionAccountViewModel.swift | 17 +----- 6 files changed, 4 insertions(+), 168 deletions(-) delete mode 100644 Mastodon/Diffable/Account/SelectedAccountItem.swift delete mode 100644 Mastodon/Diffable/Account/SelectedAccountSection.swift diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index 46d7ea619..eaa6de62f 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -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 = ""; }; 2D3F9E0325DFA133004262D9 /* UITapGestureRecognizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITapGestureRecognizer.swift; sourceTree = ""; }; 2D4AD89B263165B500613EFC /* SuggestionAccountCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SuggestionAccountCollectionViewCell.swift; sourceTree = ""; }; - 2D4AD8A126316CD200613EFC /* SelectedAccountSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectedAccountSection.swift; sourceTree = ""; }; - 2D4AD8A726316D3500613EFC /* SelectedAccountItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectedAccountItem.swift; sourceTree = ""; }; 2D571B2E26004EC000540450 /* NavigationBarProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationBarProgressView.swift; sourceTree = ""; }; 2D59819A25E4A581000FB903 /* MastodonConfirmEmailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonConfirmEmailViewController.swift; sourceTree = ""; }; 2D5981A025E4A593000FB903 /* MastodonConfirmEmailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonConfirmEmailViewModel.swift; sourceTree = ""; }; @@ -1625,7 +1621,6 @@ isa = PBXGroup; children = ( DB4F097826A039B400D62E92 /* Onboarding */, - DB0617FB27855B740030EE79 /* Account */, DB0617F827855B170030EE79 /* User */, DB0617F927855B460030EE79 /* Profile */, DB0FCB892796BE1E006C02E2 /* RecommandAccount */, @@ -1907,15 +1902,6 @@ path = Settings; sourceTree = ""; }; - DB0617FB27855B740030EE79 /* Account */ = { - isa = PBXGroup; - children = ( - 2D4AD8A126316CD200613EFC /* SelectedAccountSection.swift */, - 2D4AD8A726316D3500613EFC /* SelectedAccountItem.swift */, - ); - path = Account; - sourceTree = ""; - }; 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 */, diff --git a/Mastodon/Diffable/Account/SelectedAccountItem.swift b/Mastodon/Diffable/Account/SelectedAccountItem.swift deleted file mode 100644 index 05ecdae8d..000000000 --- a/Mastodon/Diffable/Account/SelectedAccountItem.swift +++ /dev/null @@ -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) - case placeHolder(uuid: UUID) -} diff --git a/Mastodon/Diffable/Account/SelectedAccountSection.swift b/Mastodon/Diffable/Account/SelectedAccountSection.swift deleted file mode 100644 index d71cbf326..000000000 --- a/Mastodon/Diffable/Account/SelectedAccountSection.swift +++ /dev/null @@ -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 { - 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 - } - } -} diff --git a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift index 7eacdc205..941b0f429 100644 --- a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift +++ b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift @@ -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 -// } } } diff --git a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel+Diffable.swift b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel+Diffable.swift index afb3eb7ec..08ce749a4 100644 --- a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel+Diffable.swift +++ b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel+Diffable.swift @@ -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() - snapshot.appendSections([.main]) - var items: [SelectedAccountItem] = records.map { SelectedAccountItem.account($0) } - - if items.count < 10 { - let count = 10 - items.count - let placeholderItems: [SelectedAccountItem] = (0..() // output - var collectionViewDiffableDataSource: UICollectionViewDiffableDataSource? var tableViewDiffableDataSource: UITableViewDiffableDataSource? 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