From 5145e355ce752b5bd27f3269f4a9127a3af96454 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Tue, 4 Apr 2023 14:37:11 -0500 Subject: [PATCH] Refactors SourcesViewController from Main.storyboard to new Sources.storyboard Also refactors BannerCollectionViewCell to AppBannerCollectionViewCell to support initializing from code. --- AltStore.xcodeproj/project.pbxproj | 12 +- AltStore/App IDs/AppIDsViewController.swift | 2 +- AltStore/Base.lproj/Main.storyboard | 159 +----------------- ...wift => AppBannerCollectionViewCell.swift} | 31 +++- AltStore/Sources/Sources.storyboard | 142 ++++++++++++++++ AltStore/Sources/SourcesViewController.swift | 16 +- 6 files changed, 199 insertions(+), 163 deletions(-) rename AltStore/Components/{BannerCollectionViewCell.swift => AppBannerCollectionViewCell.swift} (65%) create mode 100644 AltStore/Sources/Sources.storyboard diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index a66964c4..ae118dd8 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -220,7 +220,7 @@ BF66EEEA2501AED0007EE018 /* UIColor+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF66EEE62501AED0007EE018 /* UIColor+Hex.swift */; }; BF66EEEB2501AED0007EE018 /* UIApplication+AppExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF66EEE72501AED0007EE018 /* UIApplication+AppExtension.swift */; }; BF6C8FAC242935ED00125131 /* NSAttributedString+Markdown.m in Sources */ = {isa = PBXBuildFile; fileRef = BF6C8FAA242935ED00125131 /* NSAttributedString+Markdown.m */; }; - BF6C8FAE2429597900125131 /* BannerCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF6C8FAD2429597900125131 /* BannerCollectionViewCell.swift */; }; + BF6C8FAE2429597900125131 /* AppBannerCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF6C8FAD2429597900125131 /* AppBannerCollectionViewCell.swift */; }; BF6C8FB02429599900125131 /* TextCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF6C8FAF2429599900125131 /* TextCollectionReusableView.swift */; }; BF6F439223644C6E00A0B879 /* RefreshAltStoreViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF6F439123644C6E00A0B879 /* RefreshAltStoreViewController.swift */; }; BF74989B23621C0700CED65F /* ForwardingNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF74989A23621C0700CED65F /* ForwardingNavigationController.swift */; }; @@ -362,6 +362,8 @@ D57FE84428C7DB7100216002 /* ErrorLogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57FE84328C7DB7100216002 /* ErrorLogViewController.swift */; }; D586D39B28EF58B0000E101F /* AltTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D586D39A28EF58B0000E101F /* AltTests.swift */; }; D58916FE28C7C55C00E39C8B /* LoggedError.swift in Sources */ = {isa = PBXBuildFile; fileRef = D58916FD28C7C55C00E39C8B /* LoggedError.swift */; }; + D58D5F2E26DFE68E00E55E38 /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = D58D5F2D26DFE68E00E55E38 /* LaunchAtLogin */; }; + D5935AEF29C3B23600C157EF /* Sources.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D5935AEE29C3B23600C157EF /* Sources.storyboard */; }; D593F1942717749A006E82DE /* PatchAppOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D593F1932717749A006E82DE /* PatchAppOperation.swift */; }; D5A2193429B14F94002229FC /* DeprecatedAPIs.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5A2193329B14F94002229FC /* DeprecatedAPIs.swift */; }; D5ACE84528E3B8450021CAB9 /* ClearAppCacheOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5ACE84428E3B8450021CAB9 /* ClearAppCacheOperation.swift */; }; @@ -784,7 +786,7 @@ BF6C336124197D700034FD24 /* NSError+AltStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSError+AltStore.swift"; sourceTree = ""; }; BF6C8FAA242935ED00125131 /* NSAttributedString+Markdown.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSAttributedString+Markdown.m"; path = "Dependencies/MarkdownAttributedString/NSAttributedString+Markdown.m"; sourceTree = SOURCE_ROOT; }; BF6C8FAB242935ED00125131 /* NSAttributedString+Markdown.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSAttributedString+Markdown.h"; path = "Dependencies/MarkdownAttributedString/NSAttributedString+Markdown.h"; sourceTree = SOURCE_ROOT; }; - BF6C8FAD2429597900125131 /* BannerCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BannerCollectionViewCell.swift; sourceTree = ""; }; + BF6C8FAD2429597900125131 /* AppBannerCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppBannerCollectionViewCell.swift; sourceTree = ""; }; BF6C8FAF2429599900125131 /* TextCollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextCollectionReusableView.swift; sourceTree = ""; }; BF6F439123644C6E00A0B879 /* RefreshAltStoreViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshAltStoreViewController.swift; sourceTree = ""; }; BF718BC723C919CC00A89F2D /* CFNotificationName+AltStore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CFNotificationName+AltStore.h"; sourceTree = ""; }; @@ -907,6 +909,7 @@ D586D39828EF58B0000E101F /* AltTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AltTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; D586D39A28EF58B0000E101F /* AltTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AltTests.swift; sourceTree = ""; }; D58916FD28C7C55C00E39C8B /* LoggedError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggedError.swift; sourceTree = ""; }; + D5935AEE29C3B23600C157EF /* Sources.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Sources.storyboard; sourceTree = ""; }; D593F1932717749A006E82DE /* PatchAppOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PatchAppOperation.swift; sourceTree = ""; }; D5A2193329B14F94002229FC /* DeprecatedAPIs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeprecatedAPIs.swift; sourceTree = ""; }; D5ACE84428E3B8450021CAB9 /* ClearAppCacheOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClearAppCacheOperation.swift; sourceTree = ""; }; @@ -1600,6 +1603,7 @@ BFC84A4B2421A13000853474 /* Sources */ = { isa = PBXGroup; children = ( + D5935AEE29C3B23600C157EF /* Sources.storyboard */, BFC84A4C2421A19100853474 /* SourcesViewController.swift */, ); path = Sources; @@ -1723,7 +1727,7 @@ BF3D649E22E7B24C00E9056B /* CollapsingTextView.swift */, BF2901302318F7A800D88A45 /* AppBannerView.swift */, BF29012E2318F6B100D88A45 /* AppBannerView.xib */, - BF6C8FAD2429597900125131 /* BannerCollectionViewCell.swift */, + BF6C8FAD2429597900125131 /* AppBannerCollectionViewCell.swift */, BF6C8FAF2429599900125131 /* TextCollectionReusableView.swift */, ); path = Components; @@ -2352,6 +2356,7 @@ BFE6073C231AE1E7002B0E8E /* SettingsHeaderFooterView.xib in Resources */, BF29012F2318F6B100D88A45 /* AppBannerView.xib in Resources */, BFE6325A22A83BEB00F30809 /* Authentication.storyboard in Resources */, + D5935AEF29C3B23600C157EF /* Sources.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2686,6 +2691,7 @@ BF88F97224F8727D00BB75DF /* AppManagerErrors.swift in Sources */, B39F16152918D7DA002E9404 /* Consts+Proxy.swift in Sources */, BF6C8FAE2429597900125131 /* BannerCollectionViewCell.swift in Sources */, + BF6C8FAE2429597900125131 /* AppBannerCollectionViewCell.swift in Sources */, BF6F439223644C6E00A0B879 /* RefreshAltStoreViewController.swift in Sources */, BFE60742231B07E6002B0E8E /* SettingsHeaderFooterView.swift in Sources */, BD4513AB2C6FA98C0052BCC0 /* AppExtensionView.swift in Sources */, diff --git a/AltStore/App IDs/AppIDsViewController.swift b/AltStore/App IDs/AppIDsViewController.swift index 8aa86f04..c4d9c876 100644 --- a/AltStore/App IDs/AppIDsViewController.swift +++ b/AltStore/App IDs/AppIDsViewController.swift @@ -72,7 +72,7 @@ private extension AppIDsViewController dataSource.cellConfigurationHandler = { (cell, appID, indexPath) in let tintColor = UIColor.altPrimary - let cell = cell as! BannerCollectionViewCell + let cell = cell as! AppBannerCollectionViewCell cell.layoutMargins.left = self.view.layoutMargins.left cell.layoutMargins.right = self.view.layoutMargins.right cell.tintColor = tintColor diff --git a/AltStore/Base.lproj/Main.storyboard b/AltStore/Base.lproj/Main.storyboard index 85cfc5f9..5ac8118a 100644 --- a/AltStore/Base.lproj/Main.storyboard +++ b/AltStore/Base.lproj/Main.storyboard @@ -39,8 +39,8 @@ - + @@ -70,7 +70,7 @@ - + @@ -561,7 +561,7 @@ World - + @@ -833,15 +833,6 @@ World - - - - - - - - - @@ -950,150 +941,16 @@ World - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - + - + diff --git a/AltStore/Components/BannerCollectionViewCell.swift b/AltStore/Components/AppBannerCollectionViewCell.swift similarity index 65% rename from AltStore/Components/BannerCollectionViewCell.swift rename to AltStore/Components/AppBannerCollectionViewCell.swift index fd0011ff..f304cba3 100644 --- a/AltStore/Components/BannerCollectionViewCell.swift +++ b/AltStore/Components/AppBannerCollectionViewCell.swift @@ -1,5 +1,5 @@ // -// BannerCollectionViewCell.swift +// AppBannerCollectionViewCell.swift // AltStore // // Created by Riley Testut on 3/23/20. @@ -10,16 +10,32 @@ import UIKit final class BannerCollectionViewCell: UICollectionViewCell { - private(set) var errorBadge: UIView? - @IBOutlet private(set) var bannerView: AppBannerView! + let bannerView = AppBannerView(frame: .zero) - override func awakeFromNib() + private(set) var errorBadge: UIView! + + override init(frame: CGRect) { - super.awakeFromNib() + super.init(frame: frame) + self.initialize() + } + + required init?(coder: NSCoder) + { + super.init(coder: coder) + + self.initialize() + } + + private func initialize() + { self.contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.contentView.preservesSuperviewLayoutMargins = true + self.bannerView.translatesAutoresizingMaskIntoConstraints = false + self.contentView.addSubview(self.bannerView) + let errorBadge = UIView() errorBadge.translatesAutoresizingMaskIntoConstraints = false errorBadge.isHidden = true @@ -37,6 +53,11 @@ final class BannerCollectionViewCell: UICollectionViewCell errorBadge.addSubview(badgeView, pinningEdgesWith: .zero) NSLayoutConstraint.activate([ + self.bannerView.topAnchor.constraint(equalTo: self.contentView.topAnchor), + self.bannerView.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor), + self.bannerView.leadingAnchor.constraint(equalTo: self.contentView.layoutMarginsGuide.leadingAnchor), + self.bannerView.trailingAnchor.constraint(equalTo: self.contentView.layoutMarginsGuide.trailingAnchor), + errorBadge.centerXAnchor.constraint(equalTo: self.bannerView.trailingAnchor, constant: -5), errorBadge.centerYAnchor.constraint(equalTo: self.bannerView.topAnchor, constant: 5), diff --git a/AltStore/Sources/Sources.storyboard b/AltStore/Sources/Sources.storyboard new file mode 100644 index 00000000..87238e59 --- /dev/null +++ b/AltStore/Sources/Sources.storyboard @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AltStore/Sources/SourcesViewController.swift b/AltStore/Sources/SourcesViewController.swift index ea785a9b..2dd28018 100644 --- a/AltStore/Sources/SourcesViewController.swift +++ b/AltStore/Sources/SourcesViewController.swift @@ -70,6 +70,16 @@ final class SourcesViewController: UICollectionViewController { super.viewDidLoad() + self.view.tintColor = .altPrimary + self.navigationController?.view.tintColor = .altPrimary + + if let navigationBar = self.navigationController?.navigationBar as? NavigationBar + { + // Don't automatically adjust item positions when being presented non-full screen, + // or else the navigation bar content won't be vertically centered. + navigationBar.automaticallyAdjustsItemPositions = false + } + self.collectionView.dataSource = self.dataSource #if !BETA @@ -113,7 +123,7 @@ private extension SourcesViewController dataSource.cellConfigurationHandler = { (cell, source, indexPath) in let tintColor = UIColor.altPrimary - let cell = cell as! BannerCollectionViewCell + let cell = cell as! AppBannerCollectionViewCell cell.layoutMargins.left = self.view.layoutMargins.left cell.layoutMargins.right = self.view.layoutMargins.right cell.tintColor = tintColor @@ -622,7 +632,7 @@ extension SourcesViewController } case .trusted: - if let cell = collectionView.cellForItem(at: indexPath) as? BannerCollectionViewCell, !cell.bannerView.button.isHidden + if let cell = collectionView.cellForItem(at: indexPath) as? AppBannerCollectionViewCell, !cell.bannerView.button.isHidden { actions.append(addAction) } @@ -638,7 +648,7 @@ extension SourcesViewController override func collectionView(_ collectionView: UICollectionView, previewForHighlightingContextMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? { guard let indexPath = configuration.identifier as? NSIndexPath else { return nil } - guard let cell = collectionView.cellForItem(at: indexPath as IndexPath) as? BannerCollectionViewCell else { return nil } + guard let cell = collectionView.cellForItem(at: indexPath as IndexPath) as? AppBannerCollectionViewCell else { return nil } let parameters = UIPreviewParameters() parameters.backgroundColor = .clear