Supports viewing all NewsItems and StoreApps for a source

This commit is contained in:
Riley Testut
2023-04-04 16:17:38 -05:00
committed by Magesh K
parent 654f73f4ee
commit 5dfb36ca48
7 changed files with 226 additions and 14 deletions

View File

@@ -43,6 +43,9 @@ private final class AppBannerFooterView: UICollectionReusableView
class NewsViewController: UICollectionViewController, PeekPopPreviewing
{
// Nil == Show news from all sources.
var source: Source?
private lazy var dataSource = self.makeDataSource()
private lazy var placeholderView = RSTPlaceholderView(frame: .zero)
@@ -57,10 +60,24 @@ class NewsViewController: UICollectionViewController, PeekPopPreviewing
// Cache
private var cachedCellSizes = [String: CGSize]()
init?(source: Source?, coder: NSCoder)
{
self.source = source
super.init(coder: coder)
self.initialize()
}
required init?(coder: NSCoder)
{
super.init(coder: coder)
self.initialize()
}
private func initialize()
{
NotificationCenter.default.addObserver(self, selector: #selector(NewsViewController.importApp(_:)), name: AppDelegate.importAppDeepLinkNotification, object: nil)
}
@@ -79,6 +96,22 @@ class NewsViewController: UICollectionViewController, PeekPopPreviewing
(self as PeekPopPreviewing).registerForPreviewing(with: self, sourceView: self.collectionView)
if let source = self.source
{
let tintColor = source.effectiveTintColor ?? .altPrimary
self.view.tintColor = tintColor
let appearance = NavigationBarAppearance()
appearance.configureWithTintColor(tintColor)
appearance.configureWithDefaultBackground()
let edgeAppearance = appearance.copy()
edgeAppearance.configureWithTransparentBackground()
self.navigationItem.standardAppearance = appearance
self.navigationItem.scrollEdgeAppearance = edgeAppearance
}
self.update()
}
@@ -111,12 +144,11 @@ private extension NewsViewController
{
func makeDataSource() -> RSTFetchedResultsCollectionViewPrefetchingDataSource<NewsItem, UIImage>
{
let fetchRequest = NewsItem.fetchRequest() as NSFetchRequest<NewsItem>
fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \NewsItem.date, ascending: false),
NSSortDescriptor(keyPath: \NewsItem.sortIndex, ascending: true),
NSSortDescriptor(keyPath: \NewsItem.sourceIdentifier, ascending: true)]
let fetchRequest = NewsItem.sortedFetchRequest(for: self.source)
let context = self.source?.managedObjectContext ?? DatabaseManager.shared.viewContext
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: DatabaseManager.shared.viewContext, sectionNameKeyPath: #keyPath(NewsItem.objectID), cacheName: nil)
// Use fetchedResultsController to split NewsItems up into sections.
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: #keyPath(NewsItem.objectID), cacheName: nil)
let dataSource = RSTFetchedResultsCollectionViewPrefetchingDataSource<NewsItem, UIImage>(fetchedResultsController: fetchedResultsController)
dataSource.proxy = self