More cleanup (IOS-141)

This commit is contained in:
Nathan Mattes 2023-09-15 10:49:32 +02:00
parent 0fa75fc1d3
commit c892034093
7 changed files with 1 additions and 328 deletions

View File

@ -194,7 +194,6 @@
DB0FCB842796B2A2006C02E2 /* FavoriteViewController+DataSourceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0FCB832796B2A2006C02E2 /* FavoriteViewController+DataSourceProvider.swift */; };
DB0FCB862796BDA1006C02E2 /* SearchSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0FCB852796BDA1006C02E2 /* SearchSection.swift */; };
DB0FCB882796BDA9006C02E2 /* SearchItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0FCB872796BDA9006C02E2 /* SearchItem.swift */; };
DB0FCB8C2796BF8D006C02E2 /* SearchViewModel+Diffable.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0FCB8B2796BF8D006C02E2 /* SearchViewModel+Diffable.swift */; };
DB0FCB8E2796C0B7006C02E2 /* TrendCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0FCB8D2796C0B7006C02E2 /* TrendCollectionViewCell.swift */; };
DB0FCB922796DE19006C02E2 /* TrendSectionHeaderCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0FCB912796DE19006C02E2 /* TrendSectionHeaderCollectionReusableView.swift */; };
DB0FCB942797E2B0006C02E2 /* SearchResultViewModel+Diffable.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0FCB932797E2B0006C02E2 /* SearchResultViewModel+Diffable.swift */; };
@ -847,7 +846,6 @@
DB0FCB832796B2A2006C02E2 /* FavoriteViewController+DataSourceProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FavoriteViewController+DataSourceProvider.swift"; sourceTree = "<group>"; };
DB0FCB852796BDA1006C02E2 /* SearchSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchSection.swift; sourceTree = "<group>"; };
DB0FCB872796BDA9006C02E2 /* SearchItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchItem.swift; sourceTree = "<group>"; };
DB0FCB8B2796BF8D006C02E2 /* SearchViewModel+Diffable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SearchViewModel+Diffable.swift"; sourceTree = "<group>"; };
DB0FCB8D2796C0B7006C02E2 /* TrendCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrendCollectionViewCell.swift; sourceTree = "<group>"; };
DB0FCB912796DE19006C02E2 /* TrendSectionHeaderCollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrendSectionHeaderCollectionReusableView.swift; sourceTree = "<group>"; };
DB0FCB932797E2B0006C02E2 /* SearchResultViewModel+Diffable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SearchResultViewModel+Diffable.swift"; sourceTree = "<group>"; };
@ -2933,7 +2931,6 @@
2DE0FAC62615F5D200CDF649 /* View */,
DB9D6BE825E4F5340051B173 /* SearchViewController.swift */,
2D6DE3FF26141DF600A63F6A /* SearchViewModel.swift */,
DB0FCB8B2796BF8D006C02E2 /* SearchViewModel+Diffable.swift */,
);
path = Search;
sourceTree = "<group>";
@ -3593,7 +3590,6 @@
DB0FCB9C27980AB6006C02E2 /* HashtagTimelineViewController+DataSourceProvider.swift in Sources */,
DB63F76F279A7D1100455B82 /* NotificationTableViewCell.swift in Sources */,
2A1BF99529F7E68400FA1BA5 /* DataSourceFacade+UserView.swift in Sources */,
DB0FCB8C2796BF8D006C02E2 /* SearchViewModel+Diffable.swift in Sources */,
DBEFCD76282A143F00C0ABEA /* ReportStatusViewController.swift in Sources */,
DBDFF1952805561700557A48 /* DiscoveryPostsViewModel+Diffable.swift in Sources */,
DB03A795272A981400EE37C5 /* ContentSplitViewController.swift in Sources */,

View File

@ -1,42 +0,0 @@
//
// SearchViewModel+Diffable.swift
// Mastodon
//
// Created by MainasuK on 2022-1-18.
//
import UIKit
import MastodonSDK
//extension SearchViewModel {
//
// func setupDiffableDataSource(
// collectionView: UICollectionView
// ) {
// diffableDataSource = SearchSection.diffableDataSource(
// collectionView: collectionView,
// context: context
// )
//
// var snapshot = NSDiffableDataSourceSnapshot<SearchSection, SearchItem>()
// snapshot.appendSections([.trend])
// diffableDataSource?.apply(snapshot)
//
// $hashtags
// .receive(on: DispatchQueue.main)
// .sink { [weak self] hashtags in
// guard let self = self else { return }
// guard let diffableDataSource = self.diffableDataSource else { return }
//
// var snapshot = NSDiffableDataSourceSnapshot<SearchSection, SearchItem>()
// snapshot.appendSections([.trend])
//
// let trendItems = hashtags.map { SearchItem.trend($0) }
// snapshot.appendItems(trendItems, toSection: .trend)
//
// diffableDataSource.apply(snapshot)
// }
// .store(in: &disposeBag)
// }
//
//}

View File

@ -17,8 +17,6 @@ protocol SearchHistorySectionHeaderCollectionReusableViewDelegate: AnyObject, Us
final class SearchHistorySectionHeaderCollectionReusableView: UICollectionReusableView {
let logger = Logger(subsystem: "SearchHistorySectionHeaderCollectionReusableView", category: "View")
weak var delegate: SearchHistorySectionHeaderCollectionReusableViewDelegate?
let primaryLabel: UILabel = {
@ -78,7 +76,6 @@ extension SearchHistorySectionHeaderCollectionReusableView {
extension SearchHistorySectionHeaderCollectionReusableView {
@objc private func clearButtonDidPressed(_ sender: UIButton) {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
delegate?.searchHistorySectionHeaderCollectionReusableView(self, clearButtonDidPressed: sender)
}
}

View File

@ -68,8 +68,6 @@ extension SearchHistoryViewController {
extension SearchHistoryViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): select item at: \(indexPath.debugDescription)")
defer {
collectionView.deselectItem(at: indexPath, animated: true)
}
@ -116,8 +114,6 @@ extension SearchHistoryViewController: SearchHistorySectionHeaderCollectionReusa
_ searchHistorySectionHeaderCollectionReusableView: SearchHistorySectionHeaderCollectionReusableView,
clearButtonDidPressed button: UIButton
) {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
Task {
try await DataSourceFacade.responseToDeleteSearchHistory(
provider: self

View File

@ -32,71 +32,3 @@ final class SearchHistoryViewModel {
}
}
//extension SearchHistoryViewModel {
// func persistSearchHistory(for item: SearchHistoryItem) {
// guard let box = context.authenticationService.activeMastodonAuthenticationBox.value else { return }
// let property = SearchHistory.Property(domain: box.domain, userID: box.userID)
//
// switch item {
// case .account(let objectID):
// let managedObjectContext = context.backgroundManagedObjectContext
// managedObjectContext.performChanges {
// guard let user = try? managedObjectContext.existingObject(with: objectID) as? MastodonUser else { return }
// if let searchHistory = user.findSearchHistory(domain: box.domain, userID: box.userID) {
// searchHistory.update(updatedAt: Date())
// } else {
// SearchHistory.insert(into: managedObjectContext, property: property, account: user)
// }
// }
// .sink { result in
// switch result {
// case .failure(let error):
// assertionFailure(error.localizedDescription)
// case .success:
// break
// }
// }
// .store(in: &context.disposeBag)
//
// case .hashtag(let objectID):
// let managedObjectContext = context.backgroundManagedObjectContext
// managedObjectContext.performChanges {
// guard let hashtag = try? managedObjectContext.existingObject(with: objectID) as? Tag else { return }
// if let searchHistory = hashtag.findSearchHistory(domain: box.domain, userID: box.userID) {
// searchHistory.update(updatedAt: Date())
// } else {
// _ = SearchHistory.insert(into: managedObjectContext, property: property, hashtag: hashtag)
// }
// }
// .sink { result in
// switch result {
// case .failure(let error):
// assertionFailure(error.localizedDescription)
// case .success:
// break
// }
// }
// .store(in: &context.disposeBag)
//
// case .status:
// // FIXME:
// break
// }
// }
//
// func clearSearchHistory() {
// let managedObjectContext = context.backgroundManagedObjectContext
// managedObjectContext.performChanges {
// let request = SearchHistory.sortedFetchRequest
// let searchHistories = managedObjectContext.safeFetch(request)
// for searchHistory in searchHistories {
// managedObjectContext.delete(searchHistory)
// }
// }
// .sink { result in
// // do nothing
// }
// .store(in: &context.disposeBag)
// }
//}

View File

@ -53,7 +53,6 @@ extension SearchResultViewController {
tableView.pinToParent()
tableView.delegate = self
// tableView.prefetchDataSource = self
viewModel.setupDiffableDataSource(
tableView: tableView,
statusTableViewCellDelegate: self,
@ -180,81 +179,9 @@ extension SearchResultViewController: UITableViewDelegate, AutoGenerateTableView
func tableView(_ tableView: UITableView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
aspectTableView(tableView, willPerformPreviewActionForMenuWith: configuration, animator: animator)
}
// sourcery:end
// func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
// aspectTableView(tableView, estimatedHeightForRowAt: indexPath)
// }
//
// func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
// aspectTableView(tableView, willDisplay: cell, forRowAt: indexPath)
// }
//
// func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
// aspectTableView(tableView, didEndDisplaying: cell, forRowAt: indexPath)
// }
//
// func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// guard let diffableDataSource = viewModel.diffableDataSource else { return }
// guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return }
//
// viewModel.persistSearchHistory(for: item)
//
// switch item {
// case .account(let account):
// let profileViewModel = RemoteProfileViewModel(context: context, userID: account.id)
// coordinator.present(scene: .profile(viewModel: profileViewModel), from: self, transition: .show)
// case .hashtag(let hashtag):
// let hashtagViewModel = HashtagTimelineViewModel(context: context, hashtag: hashtag.name)
// coordinator.present(scene: .hashtagTimeline(viewModel: hashtagViewModel), from: self, transition: .show)
// case .status:
// aspectTableView(tableView, didSelectRowAt: indexPath)
// case .bottomLoader:
// break
// }
// }
//
// func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
// aspectTableView(tableView, contextMenuConfigurationForRowAt: indexPath, point: point)
// }
//
// func tableView(_ tableView: UITableView, previewForHighlightingContextMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? {
// aspectTableView(tableView, previewForHighlightingContextMenuWithConfiguration: configuration)
// }
//
// func tableView(_ tableView: UITableView, previewForDismissingContextMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? {
// aspectTableView(tableView, previewForDismissingContextMenuWithConfiguration: configuration)
// }
//
// func tableView(_ tableView: UITableView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
// aspectTableView(tableView, willPerformPreviewActionForMenuWith: configuration, animator: animator)
// }
}
// MARK: - UITableViewDataSourcePrefetching
//extension SearchResultViewController: UITableViewDataSourcePrefetching {
// func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) {
// aspectTableView(tableView, cancelPrefetchingForRowsAt: indexPaths)
// }
//
// func tableView(_ tableView: UITableView, cancelPrefetchingForRowsAt indexPaths: [IndexPath]) {
// aspectTableView(tableView, cancelPrefetchingForRowsAt: indexPaths)
// }
//}
// MARK: - AVPlayerViewControllerDelegate
//extension SearchResultViewController: AVPlayerViewControllerDelegate {
// func playerViewController(_ playerViewController: AVPlayerViewController, willBeginFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator) {
// handlePlayerViewController(playerViewController, willBeginFullScreenPresentationWithAnimationCoordinator: coordinator)
// }
//
// func playerViewController(_ playerViewController: AVPlayerViewController, willEndFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator) {
// handlePlayerViewController(playerViewController, willEndFullScreenPresentationWithAnimationCoordinator: coordinator)
// }
//}
// MARK: - StatusTableViewCellDelegate
extension SearchResultViewController: StatusTableViewCellDelegate { }

View File

@ -62,139 +62,6 @@ final class SearchResultViewModel {
domain: authContext.mastodonAuthenticationBox.domain,
additionalTweetPredicate: nil
)
// Publishers.CombineLatest(
// items,
// statusFetchedResultsController.objectIDs.removeDuplicates()
// )
// .receive(on: DispatchQueue.main)
// .sink { [weak self] items, statusObjectIDs in
// guard let self = self else { return }
// guard let diffableDataSource = self.diffableDataSource else { return }
//
// var snapshot = NSDiffableDataSourceSnapshot<SearchResultSection, SearchResultItem>()
// snapshot.appendSections([.main])
//
// // append account & hashtag items
//
// var items = items
// if self.searchScope == .all {
// // all search scope not paging. it's safe sort on whole dataset
// items.sort(by: { ($0.sortKey ?? "") < ($1.sortKey ?? "")})
// }
// snapshot.appendItems(items, toSection: .main)
//
// var oldSnapshotAttributeDict: [NSManagedObjectID : Item.StatusAttribute] = [:]
// let oldSnapshot = diffableDataSource.snapshot()
// for item in oldSnapshot.itemIdentifiers {
// guard case let .status(objectID, attribute) = item else { continue }
// oldSnapshotAttributeDict[objectID] = attribute
// }
//
// // append statuses
// var statusItems: [SearchResultItem] = []
// for objectID in statusObjectIDs {
// let attribute = oldSnapshotAttributeDict[objectID] ?? Item.StatusAttribute()
// statusItems.append(.status(statusObjectID: objectID, attribute: attribute))
// }
// snapshot.appendItems(statusItems, toSection: .main)
//
// if let currentState = self.stateMachine.currentState {
// switch currentState {
// case is State.Loading, is State.Fail, is State.Idle:
// let attribute = SearchResultItem.BottomLoaderAttribute(isEmptyResult: false)
// snapshot.appendItems([.bottomLoader(attribute: attribute)], toSection: .main)
// case is State.Fail:
// break
// case is State.NoMore:
// if snapshot.itemIdentifiers.isEmpty {
// let attribute = SearchResultItem.BottomLoaderAttribute(isEmptyResult: true)
// snapshot.appendItems([.bottomLoader(attribute: attribute)], toSection: .main)
// }
// default:
// break
// }
// }
//
// diffableDataSource.defaultRowAnimation = .fade
// diffableDataSource.apply(snapshot, animatingDifferences: true) { [weak self] in
// guard let self = self else { return }
// self.didDataSourceUpdate.send()
// }
//
// }
// .store(in: &disposeBag)
}
}
extension SearchResultViewModel {
func persistSearchHistory(for item: SearchResultItem) {
fatalError()
// guard let box = context.authenticationService.activeMastodonAuthenticationBox.value else { return }
// let property = SearchHistory.Property(domain: box.domain, userID: box.userID)
// let domain = box.domain
//
// switch item {
// case .account(let entity):
// let managedObjectContext = context.backgroundManagedObjectContext
// managedObjectContext.performChanges {
// let (user, _) = APIService.CoreData.createOrMergeMastodonUser(
// into: managedObjectContext,
// for: nil,
// in: domain,
// entity: entity,
// userCache: nil,
// networkDate: Date(),
// log: OSLog.api
// )
// if let searchHistory = user.findSearchHistory(domain: box.domain, userID: box.userID) {
// searchHistory.update(updatedAt: Date())
// } else {
// SearchHistory.insert(into: managedObjectContext, property: property, account: user)
// }
// }
// .sink { result in
// switch result {
// case .failure(let error):
// assertionFailure(error.localizedDescription)
// case .success:
// break
// }
// }
// .store(in: &context.disposeBag)
//
// case .hashtag(let entity):
// let managedObjectContext = context.backgroundManagedObjectContext
// var tag: Tag?
// managedObjectContext.performChanges {
// let (hashtag, _) = APIService.CoreData.createOrMergeTag(
// into: managedObjectContext,
// entity: entity
// )
// tag = hashtag
// if let searchHistory = hashtag.findSearchHistory(domain: box.domain, userID: box.userID) {
// searchHistory.update(updatedAt: Date())
// } else {
// _ = SearchHistory.insert(into: managedObjectContext, property: property, hashtag: hashtag)
// }
// }
// .sink { result in
// switch result {
// case .failure(let error):
// assertionFailure(error.localizedDescription)
// case .success:
// print(tag?.searchHistories)
// break
// }
// }
// .store(in: &context.disposeBag)
//
// case .status:
// // FIXME:
// break
// case .bottomLoader:
// break
// }
}
}