From d8c7eb5cf5c783f14274f63c7c82f725a701ab6a Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 10 Feb 2023 18:19:00 -0500 Subject: [PATCH] Add buttons to Explore screen --- Tusker.xcodeproj/project.pbxproj | 4 + .../MoreTrendsFooterCollectionViewCell.swift | 84 +++++++++++++++++++ .../Explore/TrendsViewController.swift | 26 +++++- 3 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 Tusker/Screens/Explore/MoreTrendsFooterCollectionViewCell.swift diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 21cebcd1..05733ac1 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -200,6 +200,7 @@ D681E4D7246E32290053414F /* StatusActivityItemSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D681E4D6246E32290053414F /* StatusActivityItemSource.swift */; }; D681E4D9246E346E0053414F /* AccountActivityItemSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D681E4D8246E346E0053414F /* AccountActivityItemSource.swift */; }; D68232F72464F4FD00325FB8 /* ComposeDrawingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D68232F62464F4FD00325FB8 /* ComposeDrawingViewController.swift */; }; + D68329EF299540050026EB24 /* MoreTrendsFooterCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D68329EE299540050026EB24 /* MoreTrendsFooterCollectionViewCell.swift */; }; D686BBE324FBF8110068E6AA /* WrappedProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D686BBE224FBF8110068E6AA /* WrappedProgressView.swift */; }; D6895DC228D65274006341DA /* CustomAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6895DC128D65274006341DA /* CustomAlertController.swift */; }; D6895DC428D65342006341DA /* ConfirmReblogStatusPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6895DC328D65342006341DA /* ConfirmReblogStatusPreviewView.swift */; }; @@ -612,6 +613,7 @@ D681E4D6246E32290053414F /* StatusActivityItemSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusActivityItemSource.swift; sourceTree = ""; }; D681E4D8246E346E0053414F /* AccountActivityItemSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountActivityItemSource.swift; sourceTree = ""; }; D68232F62464F4FD00325FB8 /* ComposeDrawingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeDrawingViewController.swift; sourceTree = ""; }; + D68329EE299540050026EB24 /* MoreTrendsFooterCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoreTrendsFooterCollectionViewCell.swift; sourceTree = ""; }; D686BBE224FBF8110068E6AA /* WrappedProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrappedProgressView.swift; sourceTree = ""; }; D6895DC128D65274006341DA /* CustomAlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomAlertController.swift; sourceTree = ""; }; D6895DC328D65342006341DA /* ConfirmReblogStatusPreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfirmReblogStatusPreviewView.swift; sourceTree = ""; }; @@ -945,6 +947,7 @@ D693A72D25CF91C6003A14E2 /* FeaturedProfileCollectionViewCell.swift */, D693A72E25CF91C6003A14E2 /* FeaturedProfileCollectionViewCell.xib */, D6C3F4FA299035650009FCFF /* TrendsViewController.swift */, + D68329EE299540050026EB24 /* MoreTrendsFooterCollectionViewCell.swift */, ); path = Explore; sourceTree = ""; @@ -2072,6 +2075,7 @@ D6A00B1D26379FC900316AD4 /* PollOptionsView.swift in Sources */, D6DF95C12533F5DE0027A9B6 /* RelationshipMO.swift in Sources */, D6ADB6EE28EA74E8009924AB /* UIView+Configure.swift in Sources */, + D68329EF299540050026EB24 /* MoreTrendsFooterCollectionViewCell.swift in Sources */, D623A5412635FB3C0095BD04 /* PollOptionView.swift in Sources */, D61F75B1293BD85300C0B37F /* CreateFilterService.swift in Sources */, D65C6BF525478A9C00A6E89C /* BackgroundableViewController.swift in Sources */, diff --git a/Tusker/Screens/Explore/MoreTrendsFooterCollectionViewCell.swift b/Tusker/Screens/Explore/MoreTrendsFooterCollectionViewCell.swift new file mode 100644 index 00000000..73683bfe --- /dev/null +++ b/Tusker/Screens/Explore/MoreTrendsFooterCollectionViewCell.swift @@ -0,0 +1,84 @@ +// +// MoreTrendsFooterCollectionViewCell.swift +// Tusker +// +// Created by Shadowfacts on 2/9/23. +// Copyright © 2023 Shadowfacts. All rights reserved. +// + +import UIKit + +class MoreTrendsFooterCollectionViewCell: UICollectionViewCell { + + weak var delegate: TuskerNavigationDelegate? + + private var button = UIButton() + + private var kind: Kind! + + override init(frame: CGRect) { + super.init(frame: frame) + + button.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside) + button.translatesAutoresizingMaskIntoConstraints = false + contentView.addSubview(button) + NSLayoutConstraint.activate([ + button.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), + button.topAnchor.constraint(equalTo: contentView.topAnchor), + button.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), + ]) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func updateUI(_ kind: Kind) { + guard self.kind != kind else { + return + } + self.kind = kind + + var config = UIButton.Configuration.plain() + var title: AttributedString + switch kind { + case .hashtags: + title = "More Trending Hashtags" + case .links: + title = "More Trending Links" + case .profileSuggestions: + title = "More Suggested Accounts" + } + title.font = .preferredFont(forTextStyle: .body).withTraits(.traitBold)! + config.attributedTitle = title + config.image = UIImage(systemName: "chevron.right") + config.imagePlacement = .trailing + config.buttonSize = .mini + button.configuration = config + } + + @objc private func buttonPressed() { + guard let delegate else { + return + } + switch kind { + case nil: + return + case .hashtags: + delegate.show(TrendingHashtagsViewController(mastodonController: delegate.apiController)) + case .links: + delegate.show(TrendingLinksViewController(mastodonController: delegate.apiController)) + case .profileSuggestions: + delegate.show(ProfileDirectoryViewController(mastodonController: delegate.apiController)) + } + } + +} + +extension MoreTrendsFooterCollectionViewCell { + enum Kind { + case hashtags + case links + case profileSuggestions + } +} diff --git a/Tusker/Screens/Explore/TrendsViewController.swift b/Tusker/Screens/Explore/TrendsViewController.swift index df524702..4380fbff 100644 --- a/Tusker/Screens/Explore/TrendsViewController.swift +++ b/Tusker/Screens/Explore/TrendsViewController.swift @@ -45,6 +45,7 @@ class TrendsViewController: UIViewController, CollectionViewController { case .trendingHashtags: var listConfig = UICollectionLayoutListConfiguration(appearance: .grouped) listConfig.headerMode = .supplementary + listConfig.footerMode = .supplementary listConfig.backgroundColor = .appGroupedBackground return .list(using: listConfig, layoutEnvironment: environment) @@ -57,9 +58,10 @@ class TrendsViewController: UIViewController, CollectionViewController { let section = NSCollectionLayoutSection(group: group) section.orthogonalScrollingBehavior = .groupPaging section.boundarySupplementaryItems = [ - NSCollectionLayoutBoundarySupplementaryItem(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(12)), elementKind: UICollectionView.elementKindSectionHeader, alignment: .topLeading) + NSCollectionLayoutBoundarySupplementaryItem(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(12)), elementKind: UICollectionView.elementKindSectionHeader, alignment: .topLeading), + NSCollectionLayoutBoundarySupplementaryItem(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(30)), elementKind: UICollectionView.elementKindSectionFooter, alignment: .bottomLeading), ] - section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 16, trailing: 0) + section.contentInsets = .zero return section case .profileSuggestions: @@ -71,9 +73,10 @@ class TrendsViewController: UIViewController, CollectionViewController { let section = NSCollectionLayoutSection(group: group) section.orthogonalScrollingBehavior = .groupPaging section.boundarySupplementaryItems = [ - NSCollectionLayoutBoundarySupplementaryItem(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(12)), elementKind: UICollectionView.elementKindSectionHeader, alignment: .topLeading) + NSCollectionLayoutBoundarySupplementaryItem(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(12)), elementKind: UICollectionView.elementKindSectionHeader, alignment: .topLeading), + NSCollectionLayoutBoundarySupplementaryItem(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(30)), elementKind: UICollectionView.elementKindSectionFooter, alignment: .bottomLeading), ] - section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 16, trailing: 0) + section.contentInsets = .zero return section case .trendingStatuses: @@ -119,6 +122,19 @@ class TrendsViewController: UIViewController, CollectionViewController { cell.delegate = self cell.updateUI(accountID: item.0, source: item.1) } + let moreCell = UICollectionView.SupplementaryRegistration(elementKind: UICollectionView.elementKindSectionFooter) { [unowned self] supplementaryView, elementKind, indexPath in + supplementaryView.delegate = self + switch self.dataSource.sectionIdentifier(for: indexPath.section) { + case nil, .trendingStatuses: + fatalError() + case .trendingHashtags: + supplementaryView.updateUI(.hashtags) + case .trendingLinks: + supplementaryView.updateUI(.links) + case .profileSuggestions: + supplementaryView.updateUI(.profileSuggestions) + } + } let dataSource = UICollectionViewDiffableDataSource(collectionView: collectionView) { collectionView, indexPath, item in switch item { @@ -138,6 +154,8 @@ class TrendsViewController: UIViewController, CollectionViewController { dataSource.supplementaryViewProvider = { (collectionView, elementKind, indexPath) in if elementKind == UICollectionView.elementKindSectionHeader { return collectionView.dequeueConfiguredReusableSupplementary(using: sectionHeaderCell, for: indexPath) + } else if elementKind == UICollectionView.elementKindSectionFooter { + return collectionView.dequeueConfiguredReusableSupplementary(using: moreCell, for: indexPath) } else { return nil }