Shows app’s source icon on AppBannerView

Excluding contexts where it is redundant (e.g. source detail page).
This commit is contained in:
Riley Testut
2023-12-07 18:19:42 -06:00
committed by Magesh K
parent 20b424c97c
commit 5c808ec59e
5 changed files with 68 additions and 18 deletions

View File

@@ -219,12 +219,16 @@ private extension BrowseViewController
let context = self.source?.managedObjectContext ?? DatabaseManager.shared.viewContext
let dataSource = RSTFetchedResultsCollectionViewPrefetchingDataSource<StoreApp, UIImage>(fetchRequest: fetchRequest, managedObjectContext: context)
dataSource.cellConfigurationHandler = { (cell, app, indexPath) in
dataSource.placeholderView = self.placeholderView
dataSource.cellConfigurationHandler = { [weak self] (cell, app, indexPath) in
guard let self else { return }
let cell = cell as! AppCardCollectionViewCell
cell.layoutMargins.left = self.view.layoutMargins.left
cell.layoutMargins.right = self.view.layoutMargins.right
cell.configure(for: app)
let showSourceIcon = (self.source == nil) // Hide source icon if redundant
cell.configure(for: app, showSourceIcon: showSourceIcon)
cell.bannerView.iconImageView.image = nil
cell.bannerView.iconImageView.isIndicatingActivity = true
@@ -251,19 +255,18 @@ private extension BrowseViewController
}
}
}
dataSource.prefetchCompletionHandler = { (cell, image, indexPath, error) in
dataSource.prefetchCompletionHandler = { [weak dataSource] (cell, image, indexPath, error) in
let cell = cell as! AppCardCollectionViewCell
cell.bannerView.iconImageView.isIndicatingActivity = false
cell.bannerView.iconImageView.image = image
if let error = error
if let error = error, let dataSource
{
print("Error loading image:", error)
let app = dataSource.item(at: indexPath)
Logger.main.debug("Failed to load app icon from \(app.iconURL, privacy: .public). \(error.localizedDescription, privacy: .public)")
}
}
dataSource.placeholderView = self.placeholderView
return dataSource
}