From 3e70cfc996b6e5ae8f02795fd0b5381c7285c395 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 | 169 +----------------- ...wift => AppBannerCollectionViewCell.swift} | 33 +++- AltStore/Sources/Sources.storyboard | 142 +++++++++++++++ AltStore/Sources/SourcesViewController.swift | 16 +- 6 files changed, 200 insertions(+), 174 deletions(-) rename AltStore/Components/{BannerCollectionViewCell.swift => AppBannerCollectionViewCell.swift} (63%) create mode 100644 AltStore/Sources/Sources.storyboard diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index 5880c61e..22e3c972 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -174,7 +174,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 */; }; BF718BD123C91BD300A89F2D /* ALTWiredConnection.mm in Sources */ = {isa = PBXBuildFile; fileRef = BF718BD023C91BD300A89F2D /* ALTWiredConnection.mm */; }; @@ -368,6 +368,7 @@ 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 */; }; @@ -692,7 +693,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 = ""; }; @@ -873,6 +874,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 = ""; }; @@ -1549,6 +1551,7 @@ BFC84A4B2421A13000853474 /* Sources */ = { isa = PBXGroup; children = ( + D5935AEE29C3B23600C157EF /* Sources.storyboard */, BFC84A4C2421A19100853474 /* SourcesViewController.swift */, ); path = Sources; @@ -1668,7 +1671,7 @@ BF3D649E22E7B24C00E9056B /* CollapsingTextView.swift */, BF2901302318F7A800D88A45 /* AppBannerView.swift */, BF29012E2318F6B100D88A45 /* AppBannerView.xib */, - BF6C8FAD2429597900125131 /* BannerCollectionViewCell.swift */, + BF6C8FAD2429597900125131 /* AppBannerCollectionViewCell.swift */, BF6C8FAF2429599900125131 /* TextCollectionReusableView.swift */, ); path = Components; @@ -2317,6 +2320,7 @@ BFE6073C231AE1E7002B0E8E /* SettingsHeaderFooterView.xib in Resources */, BF29012F2318F6B100D88A45 /* AppBannerView.xib in Resources */, BFE6325A22A83BEB00F30809 /* Authentication.storyboard in Resources */, + D5935AEF29C3B23600C157EF /* Sources.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2734,7 +2738,7 @@ BF3D64B022E8D4B800E9056B /* AppContentViewControllerCells.swift in Sources */, BFC57A6E2416FC5D00EB891E /* InstalledAppsCollectionHeaderView.swift in Sources */, BF88F97224F8727D00BB75DF /* AppManagerErrors.swift in Sources */, - BF6C8FAE2429597900125131 /* BannerCollectionViewCell.swift in Sources */, + BF6C8FAE2429597900125131 /* AppBannerCollectionViewCell.swift in Sources */, BF6F439223644C6E00A0B879 /* RefreshAltStoreViewController.swift in Sources */, BFE60742231B07E6002B0E8E /* SettingsHeaderFooterView.swift in Sources */, BFE338E822F10E56002E24B9 /* LaunchViewController.swift in Sources */, diff --git a/AltStore/App IDs/AppIDsViewController.swift b/AltStore/App IDs/AppIDsViewController.swift index 0d552739..c4aa6f0b 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 6689ab1f..1f45006c 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 - + @@ -818,30 +818,13 @@ World - + - - - - - - - - - - - - - - - - - @@ -950,150 +933,16 @@ World - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - + - + diff --git a/AltStore/Components/BannerCollectionViewCell.swift b/AltStore/Components/AppBannerCollectionViewCell.swift similarity index 63% rename from AltStore/Components/BannerCollectionViewCell.swift rename to AltStore/Components/AppBannerCollectionViewCell.swift index d50c6c13..93a2a919 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. @@ -8,18 +8,34 @@ import UIKit -class BannerCollectionViewCell: UICollectionViewCell +class AppBannerCollectionViewCell: 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 @@ 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 016c26fa..1c612a15 100644 --- a/AltStore/Sources/SourcesViewController.swift +++ b/AltStore/Sources/SourcesViewController.swift @@ -49,6 +49,16 @@ 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 @@ -92,7 +102,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 @@ -602,7 +612,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) } @@ -618,7 +628,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