diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index f36df688..e5b8b93f 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -100,9 +100,15 @@ BF770E6722BD57C4002A40FE /* BackgroundTaskManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF770E6622BD57C3002A40FE /* BackgroundTaskManager.swift */; }; BF770E6922BD57DD002A40FE /* Silence.m4a in Resources */ = {isa = PBXBuildFile; fileRef = BF770E6822BD57DD002A40FE /* Silence.m4a */; }; BF7B9EF322B82B1F0042C873 /* FetchAppsOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF7B9EF222B82B1F0042C873 /* FetchAppsOperation.swift */; }; + BF9ABA4522DCFF43008935CF /* BrowseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF9ABA4422DCFF43008935CF /* BrowseViewController.swift */; }; + BF9ABA4722DD0638008935CF /* BrowseCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF9ABA4622DD0638008935CF /* BrowseCollectionViewCell.swift */; }; + BF9ABA4922DD0742008935CF /* ScreenshotCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF9ABA4822DD0742008935CF /* ScreenshotCollectionViewCell.swift */; }; + BF9ABA4B22DD1380008935CF /* NavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF9ABA4A22DD137F008935CF /* NavigationBar.swift */; }; + BF9ABA4D22DD16DE008935CF /* ProgressButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF9ABA4C22DD16DE008935CF /* ProgressButton.swift */; }; + BF9ABA4F22DD41A9008935CF /* UIColor+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF9ABA4E22DD41A9008935CF /* UIColor+Hex.swift */; }; BFB11692229322E400BB457C /* DatabaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFB11691229322E400BB457C /* DatabaseManager.swift */; }; BFB1169B2293274D00BB457C /* JSONDecoder+ManagedObjectContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFB1169A2293274D00BB457C /* JSONDecoder+ManagedObjectContext.swift */; }; - BFB1169D22932DB100BB457C /* Apps.json in Resources */ = {isa = PBXBuildFile; fileRef = BFB1169C22932DB100BB457C /* Apps.json */; }; + BFB1169D22932DB100BB457C /* Apps-Dev.json in Resources */ = {isa = PBXBuildFile; fileRef = BFB1169C22932DB100BB457C /* Apps-Dev.json */; }; BFB116A022933DEB00BB457C /* UpdatesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFB1169F22933DEB00BB457C /* UpdatesViewController.swift */; }; BFBBE2DD22931B20002097FA /* AltStore.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = BFBBE2DB22931B20002097FA /* AltStore.xcdatamodeld */; }; BFBBE2DF22931F73002097FA /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBE2DE22931F73002097FA /* App.swift */; }; @@ -328,10 +334,16 @@ BF770E6622BD57C3002A40FE /* BackgroundTaskManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackgroundTaskManager.swift; sourceTree = ""; }; BF770E6822BD57DD002A40FE /* Silence.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = Silence.m4a; sourceTree = ""; }; BF7B9EF222B82B1F0042C873 /* FetchAppsOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchAppsOperation.swift; sourceTree = ""; }; + BF9ABA4422DCFF43008935CF /* BrowseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowseViewController.swift; sourceTree = ""; }; + BF9ABA4622DD0638008935CF /* BrowseCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowseCollectionViewCell.swift; sourceTree = ""; }; + BF9ABA4822DD0742008935CF /* ScreenshotCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenshotCollectionViewCell.swift; sourceTree = ""; }; + BF9ABA4A22DD137F008935CF /* NavigationBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationBar.swift; sourceTree = ""; }; + BF9ABA4C22DD16DE008935CF /* ProgressButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressButton.swift; sourceTree = ""; }; + BF9ABA4E22DD41A9008935CF /* UIColor+Hex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Hex.swift"; sourceTree = ""; }; BF9B63C5229DD44D002F0A62 /* AltSign.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AltSign.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BFB11691229322E400BB457C /* DatabaseManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseManager.swift; sourceTree = ""; }; BFB1169A2293274D00BB457C /* JSONDecoder+ManagedObjectContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "JSONDecoder+ManagedObjectContext.swift"; sourceTree = ""; }; - BFB1169C22932DB100BB457C /* Apps.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Apps.json; sourceTree = ""; }; + BFB1169C22932DB100BB457C /* Apps-Dev.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "Apps-Dev.json"; sourceTree = ""; }; BFB1169F22933DEB00BB457C /* UpdatesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdatesViewController.swift; sourceTree = ""; }; BFBAC8852295C90300587369 /* Result+Conveniences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Result+Conveniences.swift"; sourceTree = ""; }; BFBBE2DC22931B20002097FA /* AltStore.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = AltStore.xcdatamodel; sourceTree = ""; }; @@ -645,6 +657,16 @@ name = "Supporting Files"; sourceTree = ""; }; + BF9ABA4322DCFF33008935CF /* Browse */ = { + isa = PBXGroup; + children = ( + BF9ABA4422DCFF43008935CF /* BrowseViewController.swift */, + BF9ABA4622DD0638008935CF /* BrowseCollectionViewCell.swift */, + BF9ABA4822DD0742008935CF /* ScreenshotCollectionViewCell.swift */, + ); + path = Browse; + sourceTree = ""; + }; BFB1169E22933DDC00BB457C /* Updates */ = { isa = PBXGroup; children = ( @@ -701,6 +723,7 @@ BFD2476D2284B9A500981D42 /* AppDelegate.swift */, BFD247732284B9A500981D42 /* Main.storyboard */, BFE6325822A83BA800F30809 /* Authentication */, + BF9ABA4322DCFF33008935CF /* Browse */, BFD2478A2284C49000981D42 /* Apps */, BFBBE2E2229320A2002097FA /* My Apps */, BFB1169E22933DDC00BB457C /* Updates */, @@ -750,6 +773,8 @@ BFD2478E2284C8F900981D42 /* Button.swift */, BF43002D22A714AF0051E2BC /* Keychain.swift */, BF770E6622BD57C3002A40FE /* BackgroundTaskManager.swift */, + BF9ABA4A22DD137F008935CF /* NavigationBar.swift */, + BF9ABA4C22DD16DE008935CF /* ProgressButton.swift */, ); path = Components; sourceTree = ""; @@ -757,7 +782,7 @@ BFD247962284D7C100981D42 /* Resources */ = { isa = PBXGroup; children = ( - BFB1169C22932DB100BB457C /* Apps.json */, + BFB1169C22932DB100BB457C /* Apps-Dev.json */, BFD247762284B9A700981D42 /* Assets.xcassets */, BF770E6822BD57DD002A40FE /* Silence.m4a */, ); @@ -793,6 +818,7 @@ BFD2479E2284FBD000981D42 /* UIColor+AltStore.swift */, BFB1169A2293274D00BB457C /* JSONDecoder+ManagedObjectContext.swift */, BF43002F22A71C960051E2BC /* UserDefaults+AltStore.swift */, + BF9ABA4E22DD41A9008935CF /* UIColor+Hex.swift */, ); path = Extensions; sourceTree = ""; @@ -1052,7 +1078,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - BFB1169D22932DB100BB457C /* Apps.json in Resources */, + BFB1169D22932DB100BB457C /* Apps-Dev.json in Resources */, BFD2477A2284B9A700981D42 /* LaunchScreen.storyboard in Resources */, BF770E6922BD57DD002A40FE /* Silence.m4a in Resources */, BFD247772284B9A700981D42 /* Assets.xcassets in Resources */, @@ -1210,6 +1236,7 @@ BFC1F38D22AEE3A4003AC21A /* DownloadAppOperation.swift in Sources */, BFBBE2E122931F81002097FA /* InstalledApp.swift in Sources */, BFBBE2DF22931F73002097FA /* App.swift in Sources */, + BF9ABA4522DCFF43008935CF /* BrowseViewController.swift in Sources */, BF43002E22A714AF0051E2BC /* Keychain.swift in Sources */, BF770E5422BC044E002A40FE /* AppOperationContext.swift in Sources */, BFD2478C2284C4C300981D42 /* AppIconImageView.swift in Sources */, @@ -1224,12 +1251,17 @@ BFBBE2DD22931B20002097FA /* AltStore.xcdatamodeld in Sources */, BFE6325C22A83C0100F30809 /* AuthenticationViewController.swift in Sources */, BFB1169B2293274D00BB457C /* JSONDecoder+ManagedObjectContext.swift in Sources */, + BF9ABA4722DD0638008935CF /* BrowseCollectionViewCell.swift in Sources */, BFD247932284D4B700981D42 /* AppTableViewCell.swift in Sources */, BF770E5822BC3D0F002A40FE /* OperationGroup.swift in Sources */, + BF9ABA4F22DD41A9008935CF /* UIColor+Hex.swift in Sources */, BFD52BD422A0800A000B7ED1 /* ServerManager.swift in Sources */, BFDB6A0822AAED73007EA6D6 /* ResignAppOperation.swift in Sources */, BF770E5122BB1CF6002A40FE /* InstallAppOperation.swift in Sources */, + BF9ABA4B22DD1380008935CF /* NavigationBar.swift in Sources */, BF0C4EBD22A1BD8B009A2DD7 /* AppManager.swift in Sources */, + BF9ABA4922DD0742008935CF /* ScreenshotCollectionViewCell.swift in Sources */, + BF9ABA4D22DD16DE008935CF /* ProgressButton.swift in Sources */, BFE6326C22A86FF300F30809 /* AuthenticationOperation.swift in Sources */, BFDB6A0522A9AFB2007EA6D6 /* Fetchable.swift in Sources */, BFD2479F2284FBD000981D42 /* UIColor+AltStore.swift in Sources */, diff --git a/AltStore/Apps/AppDetailViewController.swift b/AltStore/Apps/AppDetailViewController.swift index 7b6cebf8..6d423240 100644 --- a/AltStore/Apps/AppDetailViewController.swift +++ b/AltStore/Apps/AppDetailViewController.swift @@ -9,12 +9,6 @@ import UIKit import Roxas -@objc(ScreenshotCollectionViewCell) -private class ScreenshotCollectionViewCell: UICollectionViewCell -{ - @IBOutlet var imageView: UIImageView! -} - extension AppDetailViewController { private enum Row: Int diff --git a/AltStore/Base.lproj/Main.storyboard b/AltStore/Base.lproj/Main.storyboard index d07ebf61..be2890f7 100644 --- a/AltStore/Base.lproj/Main.storyboard +++ b/AltStore/Base.lproj/Main.storyboard @@ -4,7 +4,9 @@ + + @@ -18,10 +20,11 @@ - - - - + + + + + @@ -86,12 +89,156 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -477,7 +624,7 @@ - + @@ -636,14 +783,37 @@ + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/AltStore/Browse/BrowseCollectionViewCell.swift b/AltStore/Browse/BrowseCollectionViewCell.swift new file mode 100644 index 00000000..c358324a --- /dev/null +++ b/AltStore/Browse/BrowseCollectionViewCell.swift @@ -0,0 +1,101 @@ +// +// BrowseCollectionViewCell.swift +// AltStore +// +// Created by Riley Testut on 7/15/19. +// Copyright © 2019 Riley Testut. All rights reserved. +// + +import UIKit + +import Roxas + +@objc class BrowseCollectionViewCell: UICollectionViewCell +{ + var imageNames: [String] = [] { + didSet { + self.dataSource.items = self.imageNames.map { $0 as NSString } + } + } + private lazy var dataSource = self.makeDataSource() + + private lazy var imageSizes = [NSString: CGSize]() + + @IBOutlet var nameLabel: UILabel! + @IBOutlet var developerLabel: UILabel! + @IBOutlet var appIconImageView: UIImageView! + @IBOutlet var actionButton: ProgressButton! + @IBOutlet var subtitleLabel: UILabel! + + @IBOutlet private var screenshotsContentView: UIView! + @IBOutlet private var screenshotsCollectionView: UICollectionView! + + override func awakeFromNib() + { + super.awakeFromNib() + + self.screenshotsCollectionView.delegate = self + self.screenshotsCollectionView.dataSource = self.dataSource + self.screenshotsCollectionView.prefetchDataSource = self.dataSource + + self.screenshotsContentView.layer.cornerRadius = 20 + self.screenshotsContentView.layer.masksToBounds = true + + self.update() + } + + override func tintColorDidChange() + { + super.tintColorDidChange() + + self.update() + } +} + +private extension BrowseCollectionViewCell +{ + func makeDataSource() -> RSTArrayCollectionViewPrefetchingDataSource + { + let dataSource = RSTArrayCollectionViewPrefetchingDataSource(items: []) + dataSource.cellConfigurationHandler = { (cell, screenshot, indexPath) in + let cell = cell as! ScreenshotCollectionViewCell + cell.imageView.isIndicatingActivity = true + } + dataSource.prefetchHandler = { (imageName, indexPath, completion) in + return BlockOperation { + let image = UIImage(named: imageName as String) + completion(image, nil) + } + } + dataSource.prefetchCompletionHandler = { (cell, image, indexPath, error) in + let cell = cell as! ScreenshotCollectionViewCell + cell.imageView.isIndicatingActivity = false + cell.imageView.image = image + } + + return dataSource + } + + private func update() + { + self.subtitleLabel.textColor = self.tintColor + self.screenshotsContentView.backgroundColor = self.tintColor.withAlphaComponent(0.1) + } +} + +extension BrowseCollectionViewCell: UICollectionViewDelegateFlowLayout +{ + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize + { + let imageURL = self.dataSource.item(at: indexPath) + let dimensions = self.imageSizes[imageURL] ?? UIScreen.main.nativeBounds.size + + let aspectRatio = dimensions.width / dimensions.height + + let height = self.screenshotsCollectionView.bounds.height + let width = (self.screenshotsCollectionView.bounds.height * aspectRatio).rounded(.down) + + let size = CGSize(width: width, height: height) + return size + } +} diff --git a/AltStore/Browse/BrowseViewController.swift b/AltStore/Browse/BrowseViewController.swift new file mode 100644 index 00000000..f38c1dc7 --- /dev/null +++ b/AltStore/Browse/BrowseViewController.swift @@ -0,0 +1,172 @@ +// +// BrowseViewController.swift +// AltStore +// +// Created by Riley Testut on 7/15/19. +// Copyright © 2019 Riley Testut. All rights reserved. +// + +import UIKit + +import Roxas + +class BrowseViewController: UICollectionViewController +{ + private lazy var dataSource = self.makeDataSource() + + override func viewDidLoad() + { + super.viewDidLoad() + + self.collectionView.dataSource = self.dataSource + self.collectionView.prefetchDataSource = self.dataSource + } + + override func viewWillAppear(_ animated: Bool) + { + super.viewWillAppear(animated) + + self.fetchApps() + } + + override func viewDidLayoutSubviews() + { + super.viewDidLayoutSubviews() + + let collectionViewLayout = self.collectionViewLayout as! UICollectionViewFlowLayout + collectionViewLayout.itemSize.width = self.view.bounds.width + } +} + +private extension BrowseViewController +{ + func makeDataSource() -> RSTFetchedResultsCollectionViewPrefetchingDataSource + { + let fetchRequest = App.fetchRequest() as NSFetchRequest + fetchRequest.relationshipKeyPathsForPrefetching = [#keyPath(InstalledApp.app)] + fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \App.name, ascending: false)] + fetchRequest.predicate = NSPredicate(format: "%K != %@", #keyPath(App.identifier), App.altstoreAppID) + fetchRequest.returnsObjectsAsFaults = false + + let dataSource = RSTFetchedResultsCollectionViewPrefetchingDataSource(fetchRequest: fetchRequest, managedObjectContext: DatabaseManager.shared.viewContext) + dataSource.cellConfigurationHandler = { [weak self] (cell, app, indexPath) in + guard let `self` = self else { return } + + let cell = cell as! BrowseCollectionViewCell + cell.nameLabel.text = app.name + cell.developerLabel.text = app.developerName + cell.subtitleLabel.text = app.subtitle + cell.imageNames = Array(app.screenshotNames.prefix(3)) + cell.appIconImageView.image = UIImage(named: app.iconName) + + cell.actionButton.tag = indexPath.item + cell.actionButton.activityIndicatorView.style = .white + + // Explicitly set to false to ensure we're starting from a non-activity indicating state. + // Otherwise, cell reuse can mess up some cached values. + cell.actionButton.isIndicatingActivity = false + + let tintColor = app.tintColor ?? self.collectionView.tintColor! + cell.tintColor = tintColor + cell.actionButton.progressTintColor = tintColor + + if app.installedApp == nil + { + cell.actionButton.setTitle(NSLocalizedString("FREE", comment: ""), for: .normal) + cell.actionButton.setTitleColor(.altGreen, for: .normal) + cell.actionButton.backgroundColor = UIColor.altGreen.withAlphaComponent(0.1) + + if let progress = AppManager.shared.installationProgress(for: app) + { + cell.actionButton.progress = progress + cell.actionButton.isIndicatingActivity = true + cell.actionButton.activityIndicatorView.isUserInteractionEnabled = false + cell.actionButton.isUserInteractionEnabled = true + } + else + { + cell.actionButton.progress = nil + cell.actionButton.isIndicatingActivity = false + } + } + else + { + cell.actionButton.setTitle(NSLocalizedString("OPEN", comment: ""), for: .normal) + cell.actionButton.setTitleColor(.white, for: .normal) + cell.actionButton.backgroundColor = .altGreen + } + } + + return dataSource + } + + func fetchApps() + { + AppManager.shared.fetchApps() { (result) in + do + { + let apps = try result.get() + try apps.first?.managedObjectContext?.save() + } + catch + { + DispatchQueue.main.async { + let toastView = RSTToastView(text: NSLocalizedString("Failed to Fetch Apps", comment: ""), detailText: error.localizedDescription) + toastView.tintColor = .altGreen + toastView.show(in: self.navigationController?.view ?? self.view, duration: 2.0) + } + } + } + } +} + +private extension BrowseViewController +{ + @IBAction func performAppAction(_ sender: ProgressButton) + { + let indexPath = IndexPath(item: sender.tag, section: 0) + let app = self.dataSource.item(at: indexPath) + + if let installedApp = app.installedApp + { + self.open(installedApp) + } + else + { + self.install(app, at: indexPath) + } + } + + func install(_ app: App, at indexPath: IndexPath) + { + let previousProgress = AppManager.shared.installationProgress(for: app) + guard previousProgress == nil else { + previousProgress?.cancel() + return + } + + _ = AppManager.shared.install(app, presentingViewController: self) { (result) in + DispatchQueue.main.async { + switch result + { + case .failure(OperationError.cancelled): break // Ignore + case .failure(let error): + let toastView = RSTToastView(text: "Failed to install \(app.name)", detailText: error.localizedDescription) + toastView.tintColor = .altGreen + toastView.show(in: self.navigationController!.view, duration: 2) + + case .success(let installedApp): print("Installed app:", installedApp.app.identifier) + } + + self.collectionView.reloadItems(at: [indexPath]) + } + } + + self.collectionView.reloadItems(at: [indexPath]) + } + + func open(_ installedApp: InstalledApp) + { + UIApplication.shared.open(installedApp.openAppURL) + } +} diff --git a/AltStore/Browse/ScreenshotCollectionViewCell.swift b/AltStore/Browse/ScreenshotCollectionViewCell.swift new file mode 100644 index 00000000..bc329a5a --- /dev/null +++ b/AltStore/Browse/ScreenshotCollectionViewCell.swift @@ -0,0 +1,28 @@ +// +// ScreenshotCollectionViewCell.swift +// AltStore +// +// Created by Riley Testut on 7/15/19. +// Copyright © 2019 Riley Testut. All rights reserved. +// + +import UIKit + +import Roxas + +@objc(ScreenshotCollectionViewCell) +class ScreenshotCollectionViewCell: UICollectionViewCell +{ + let imageView: UIImageView + + required init?(coder aDecoder: NSCoder) + { + self.imageView = UIImageView(image: nil) + self.imageView.layer.cornerRadius = 8 + self.imageView.layer.masksToBounds = true + + super.init(coder: aDecoder) + + self.addSubview(self.imageView, pinningEdgesWith: .zero) + } +} diff --git a/AltStore/Components/NavigationBar.swift b/AltStore/Components/NavigationBar.swift new file mode 100644 index 00000000..ed020d62 --- /dev/null +++ b/AltStore/Components/NavigationBar.swift @@ -0,0 +1,34 @@ +// +// NavigationBar.swift +// AltStore +// +// Created by Riley Testut on 7/15/19. +// Copyright © 2019 Riley Testut. All rights reserved. +// + +import UIKit + +import Roxas + +class NavigationBar: UINavigationBar +{ + override init(frame: CGRect) + { + super.init(frame: frame) + + self.initialize() + } + + required init?(coder aDecoder: NSCoder) + { + super.init(coder: aDecoder) + + self.initialize() + } + + private func initialize() + { + self.barTintColor = .white + self.shadowImage = UIImage() + } +} diff --git a/AltStore/Components/ProgressButton.swift b/AltStore/Components/ProgressButton.swift new file mode 100644 index 00000000..b406f651 --- /dev/null +++ b/AltStore/Components/ProgressButton.swift @@ -0,0 +1,63 @@ +// +// ProgressButton.swift +// AltStore +// +// Created by Riley Testut on 7/15/19. +// Copyright © 2019 Riley Testut. All rights reserved. +// + +import UIKit + +class ProgressButton: UIButton +{ + var progress: Progress? { + didSet { + self.progressView.progress = Float(self.progress?.fractionCompleted ?? 0) + self.progressView.observedProgress = self.progress + } + } + + var progressTintColor: UIColor? { + get { + return self.progressView.progressTintColor + } + set { + self.progressView.progressTintColor = newValue + } + } + + private let progressView = UIProgressView(progressViewStyle: .default) + + override var intrinsicContentSize: CGSize { + var size = super.intrinsicContentSize + size.width += 32 + size.height += 4 + return size + } + + override func awakeFromNib() + { + super.awakeFromNib() + + self.layer.masksToBounds = true + + self.progressView.progress = 0 + self.progressView.trackImage = UIImage() + self.progressView.isUserInteractionEnabled = false + self.addSubview(self.progressView) + } + + override func layoutSubviews() + { + super.layoutSubviews() + + self.progressView.bounds.size.width = self.bounds.width + + let scale = self.bounds.height / self.progressView.bounds.height + + self.progressView.transform = CGAffineTransform.identity.scaledBy(x: 1, y: scale) + self.progressView.center = CGPoint(x: self.bounds.midX, y: self.bounds.midY) + + self.layer.cornerRadius = self.bounds.midY + } +} diff --git a/AltStore/Extensions/UIColor+AltStore.swift b/AltStore/Extensions/UIColor+AltStore.swift index df1dd941..51d1a33c 100644 --- a/AltStore/Extensions/UIColor+AltStore.swift +++ b/AltStore/Extensions/UIColor+AltStore.swift @@ -11,4 +11,5 @@ import UIKit extension UIColor { static let altPurple = UIColor(named: "Purple")! + static let altGreen = UIColor(named: "Green")! } diff --git a/AltStore/Extensions/UIColor+Hex.swift b/AltStore/Extensions/UIColor+Hex.swift new file mode 100644 index 00000000..6f4b4d63 --- /dev/null +++ b/AltStore/Extensions/UIColor+Hex.swift @@ -0,0 +1,32 @@ +// +// UIColor+Hex.swift +// AltStore +// +// Created by Riley Testut on 7/15/19. +// Copyright © 2019 Riley Testut. All rights reserved. +// + +import UIKit + +extension UIColor +{ + // Borrowed from https://stackoverflow.com/a/33397427 + convenience init?(hexString: String) + { + let hex = hexString.trimmingCharacters(in: CharacterSet.alphanumerics.inverted) + var int = UInt32() + Scanner(string: hex).scanHexInt32(&int) + let a, r, g, b: UInt32 + switch hex.count { + case 3: // RGB (12-bit) + (a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17) + case 6: // RGB (24-bit) + (a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF) + case 8: // ARGB (32-bit) + (a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF) + default: + return nil + } + self.init(red: CGFloat(r) / 255, green: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: CGFloat(a) / 255) + } +} diff --git a/AltStore/Model/AltStore.xcdatamodeld/AltStore.xcdatamodel/contents b/AltStore/Model/AltStore.xcdatamodeld/AltStore.xcdatamodel/contents index e150807c..595ff761 100644 --- a/AltStore/Model/AltStore.xcdatamodeld/AltStore.xcdatamodel/contents +++ b/AltStore/Model/AltStore.xcdatamodeld/AltStore.xcdatamodel/contents @@ -21,6 +21,8 @@ + + @@ -57,7 +59,7 @@ - + diff --git a/AltStore/Model/App.swift b/AltStore/Model/App.swift index 898c98af..14094d52 100644 --- a/AltStore/Model/App.swift +++ b/AltStore/Model/App.swift @@ -22,6 +22,7 @@ class App: NSManagedObject, Decodable, Fetchable /* Properties */ @NSManaged private(set) var name: String @NSManaged private(set) var identifier: String + @NSManaged private(set) var subtitle: String? @NSManaged private(set) var developerName: String @NSManaged private(set) var localizedDescription: String @@ -34,6 +35,7 @@ class App: NSManagedObject, Decodable, Fetchable @NSManaged private(set) var versionDescription: String? @NSManaged private(set) var downloadURL: URL + @NSManaged private(set) var tintColor: UIColor? /* Relationships */ @NSManaged private(set) var installedApp: InstalledApp? @@ -55,6 +57,8 @@ class App: NSManagedObject, Decodable, Fetchable case iconName case screenshotNames case downloadURL + case tintColor + case subtitle } required init(from decoder: Decoder) throws @@ -69,6 +73,8 @@ class App: NSManagedObject, Decodable, Fetchable self.developerName = try container.decode(String.self, forKey: .developerName) self.localizedDescription = try container.decode(String.self, forKey: .localizedDescription) + self.subtitle = try container.decodeIfPresent(String.self, forKey: .subtitle) + self.version = try container.decode(String.self, forKey: .version) self.versionDate = try container.decode(Date.self, forKey: .versionDate) self.versionDescription = try container.decodeIfPresent(String.self, forKey: .versionDescription) @@ -78,6 +84,15 @@ class App: NSManagedObject, Decodable, Fetchable self.downloadURL = try container.decode(URL.self, forKey: .downloadURL) + if let tintColorHex = try container.decodeIfPresent(String.self, forKey: .tintColor) + { + guard let tintColor = UIColor(hexString: tintColorHex) else { + throw DecodingError.dataCorruptedError(forKey: .tintColor, in: container, debugDescription: "Hex code is invalid.") + } + + self.tintColor = tintColor + } + context.insert(self) } } diff --git a/AltStore/Operations/FetchAppsOperation.swift b/AltStore/Operations/FetchAppsOperation.swift index 70d21b84..eb3ead59 100644 --- a/AltStore/Operations/FetchAppsOperation.swift +++ b/AltStore/Operations/FetchAppsOperation.swift @@ -24,7 +24,7 @@ class FetchAppsOperation: ResultOperation<[App]> { super.main() - let appsURL = URL(string: "https://www.dropbox.com/s/z5tj1tx8zgeqbms/Apps.json?dl=1")! + let appsURL = URL(string: "https://www.dropbox.com/s/6qi1vt6hsi88lv6/Apps-Dev.json?dl=1")! let dataTask = self.session.dataTask(with: appsURL) { (data, response, error) in DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in diff --git a/AltStore/Resources/Apps.json b/AltStore/Resources/Apps-Dev.json similarity index 98% rename from AltStore/Resources/Apps.json rename to AltStore/Resources/Apps-Dev.json index f083ccda..0b7ef4ae 100644 --- a/AltStore/Resources/Apps.json +++ b/AltStore/Resources/Apps-Dev.json @@ -14,12 +14,14 @@ "name": "Delta", "identifier": "com.rileytestut.Delta", "developerName": "Riley Testut", + "subtitle": "Classic Nintendo games in your pocket.", "version": "1.0", "versionDate": "2019-05-20", "versionDescription": "Finally, after over five years of waiting, Delta is out of beta and ready for everyone to enjoy!\n\nCurrently supports NES, SNES, N64, GB(C), and GBA games, with more to come in the future.", "downloadURL": "https://www.dropbox.com/s/31i4hcqnorucrxi/Delta.ipa?dl=1", "localizedDescription": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Sed enim ut sem viverra aliquet eget sit amet. Viverra mauris in aliquam sem fringilla ut. Egestas erat imperdiet sed euismod nisi porta. Sit amet dictum sit amet justo donec enim diam vulputate. Phasellus vestibulum lorem sed risus ultricies tristique nulla. Elit pellentesque habitant morbi tristique. Ut lectus arcu bibendum at. Ullamcorper a lacus vestibulum sed. Mi tempus imperdiet nulla malesuada pellentesque elit eget gravida. Nec feugiat nisl pretium fusce id velit ut. Amet nulla facilisi morbi tempus. Ut sem nulla pharetra diam sit amet nisl.\n\nTortor at auctor urna nunc id cursus metus. Commodo ullamcorper a lacus vestibulum sed arcu non odio. Faucibus turpis in eu mi bibendum neque egestas. Auctor augue mauris augue neque gravida in fermentum et sollicitudin. Aliquam vestibulum morbi blandit cursus risus at ultrices mi tempus. Placerat in egestas erat imperdiet sed euismod nisi. Aliquam id diam maecenas ultricies mi eget mauris. Nunc faucibus a pellentesque sit amet porttitor eget dolor. Sed faucibus turpis in eu mi. Tortor vitae purus faucibus ornare suspendisse sed nisi lacus sed. Id semper risus in hendrerit gravida rutrum quisque. At lectus urna duis convallis convallis. Egestas maecenas pharetra convallis posuere. Id velit ut tortor pretium viverra. Quam pellentesque nec nam aliquam sem et tortor consequat. Risus pretium quam vulputate dignissim. Urna nec tincidunt praesent semper feugiat nibh sed pulvinar.\n\nTempor orci eu lobortis elementum nibh tellus. Mattis rhoncus urna neque viverra justo nec. Maecenas pharetra convallis posuere morbi leo. Rhoncus mattis rhoncus urna neque viverra justo nec. Gravida dictum fusce ut placerat orci nulla pellentesque dignissim enim. At imperdiet dui accumsan sit amet. Elit sed vulputate mi sit amet mauris commodo. Pellentesque habitant morbi tristique senectus. Tortor id aliquet lectus proin nibh. Magna etiam tempor orci eu lobortis elementum. Est pellentesque elit ullamcorper dignissim. Dapibus ultrices in iaculis nunc. Commodo quis imperdiet massa tincidunt nunc pulvinar sapien et ligula. Diam vel quam elementum pulvinar. Vel turpis nunc eget lorem dolor sed viverra. Tortor pretium viverra suspendisse potenti nullam ac tortor vitae. Euismod nisi porta lorem mollis. Massa id neque aliquam vestibulum morbi blandit.\n\nMassa massa ultricies mi quis hendrerit dolor magna eget est. Augue interdum velit euismod in pellentesque massa. Sed risus ultricies tristique nulla aliquet enim. Risus viverra adipiscing at in tellus. Donec adipiscing tristique risus nec feugiat. Eget sit amet tellus cras adipiscing enim eu turpis. Auctor neque vitae tempus quam pellentesque nec. Sit amet tellus cras adipiscing enim eu turpis egestas. Dui faucibus in ornare quam viverra. Fermentum iaculis eu non diam phasellus vestibulum lorem. Odio ut enim blandit volutpat maecenas. Dolor sit amet consectetur adipiscing elit pellentesque habitant morbi tristique. Pellentesque diam volutpat commodo sed egestas egestas. Aliquam purus sit amet luctus venenatis lectus magna fringilla. Viverra mauris in aliquam sem fringilla ut morbi tincidunt. Elit duis tristique sollicitudin nibh sit. Fermentum dui faucibus in ornare quam viverra orci sagittis. Aliquet eget sit amet tellus cras adipiscing.", "iconName": "DeltaIcon", + "tintColor": "8A28F7", "screenshotNames": [ "Delta1", "Delta2", @@ -30,6 +32,7 @@ { "name": "Clipboard Manager", "identifier": "com.rileytestut.ClipboardManager", + "subtitle": "Manage your clipboard history with ease.", "developerName": "Riley Testut", "version": "1.0", "versionDate": "2019-06-20", diff --git a/AltStore/Resources/Assets.xcassets/Colors/Green.colorset/Contents.json b/AltStore/Resources/Assets.xcassets/Colors/Green.colorset/Contents.json new file mode 100644 index 00000000..d3d6625b --- /dev/null +++ b/AltStore/Resources/Assets.xcassets/Colors/Green.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + }, + "colors" : [ + { + "idiom" : "universal", + "color" : { + "color-space" : "srgb", + "components" : { + "red" : "57", + "alpha" : "1.000", + "blue" : "101", + "green" : "126" + } + } + } + ] +} \ No newline at end of file diff --git a/AltStore/Resources/Assets.xcassets/Colors/Purple.colorset/Contents.json b/AltStore/Resources/Assets.xcassets/Colors/Purple.colorset/Contents.json index 7286a22d..fb2e176c 100644 --- a/AltStore/Resources/Assets.xcassets/Colors/Purple.colorset/Contents.json +++ b/AltStore/Resources/Assets.xcassets/Colors/Purple.colorset/Contents.json @@ -9,10 +9,10 @@ "color" : { "color-space" : "srgb", "components" : { - "red" : "0.545", + "red" : "0x8A", "alpha" : "1.000", - "blue" : "0.969", - "green" : "0.157" + "blue" : "0xF7", + "green" : "0x28" } } }