[AltStore] Loads images remotely rather than including them in app bundle

This commit is contained in:
Riley Testut
2019-08-20 19:06:03 -05:00
parent a1c9049b4b
commit 7d48b831ed
58 changed files with 5168 additions and 334 deletions

View File

@@ -10,11 +10,13 @@ import UIKit
import Roxas
import Nuke
@objc class BrowseCollectionViewCell: UICollectionViewCell
{
var imageNames: [String] = [] {
var imageURLs: [URL] = [] {
didSet {
self.dataSource.items = self.imageNames.map { $0 as NSString }
self.dataSource.items = self.imageURLs as [NSURL]
}
}
private lazy var dataSource = self.makeDataSource()
@@ -56,24 +58,39 @@ import Roxas
private extension BrowseCollectionViewCell
{
func makeDataSource() -> RSTArrayCollectionViewPrefetchingDataSource<NSString, UIImage>
func makeDataSource() -> RSTArrayCollectionViewPrefetchingDataSource<NSURL, UIImage>
{
let dataSource = RSTArrayCollectionViewPrefetchingDataSource<NSString, UIImage>(items: [])
let dataSource = RSTArrayCollectionViewPrefetchingDataSource<NSURL, UIImage>(items: [])
dataSource.cellConfigurationHandler = { (cell, screenshot, indexPath) in
let cell = cell as! ScreenshotCollectionViewCell
cell.imageView.image = nil
cell.imageView.isIndicatingActivity = true
}
dataSource.prefetchHandler = { (imageName, indexPath, completion) in
return BlockOperation {
let image = UIImage(named: imageName as String)
completion(image, nil)
dataSource.prefetchHandler = { (imageURL, indexPath, completionHandler) in
return RSTAsyncBlockOperation() { (operation) in
ImagePipeline.shared.loadImage(with: imageURL as URL, progress: nil, completion: { (response, error) in
guard !operation.isCancelled else { return }
if let image = response?.image
{
completionHandler(image, nil)
}
else
{
completionHandler(nil, error)
}
})
}
}
dataSource.prefetchCompletionHandler = { (cell, image, indexPath, error) in
let cell = cell as! ScreenshotCollectionViewCell
cell.imageView.isIndicatingActivity = false
cell.imageView.image = image
if let error = error
{
print("Error loading image:", error)
}
}
return dataSource

View File

@@ -10,6 +10,8 @@ import UIKit
import Roxas
import Nuke
class BrowseViewController: UICollectionViewController
{
private lazy var dataSource = self.makeDataSource()
@@ -75,8 +77,9 @@ private extension BrowseViewController
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.imageURLs = Array(app.screenshotURLs.prefix(2))
cell.appIconImageView.image = nil
cell.appIconImageView.isIndicatingActivity = true
cell.actionButton.addTarget(self, action: #selector(BrowseViewController.performAppAction(_:)), for: .primaryActionTriggered)
cell.actionButton.activityIndicatorView.style = .white
@@ -103,6 +106,34 @@ private extension BrowseViewController
cell.actionButton.isInverted = true
}
}
dataSource.prefetchHandler = { (storeApp, indexPath, completionHandler) -> Foundation.Operation? in
let iconURL = storeApp.iconURL
return RSTAsyncBlockOperation() { (operation) in
ImagePipeline.shared.loadImage(with: iconURL, progress: nil, completion: { (response, error) in
guard !operation.isCancelled else { return }
if let image = response?.image
{
completionHandler(image, nil)
}
else
{
completionHandler(nil, error)
}
})
}
}
dataSource.prefetchCompletionHandler = { (cell, image, indexPath, error) in
let cell = cell as! BrowseCollectionViewCell
cell.appIconImageView.isIndicatingActivity = false
cell.appIconImageView.image = image
if let error = error
{
print("Error loading image:", error)
}
}
return dataSource
}