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

@@ -366,6 +366,7 @@
D58D5F2E26DFE68E00E55E38 /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = D58D5F2D26DFE68E00E55E38 /* LaunchAtLogin */; };
D59162AB29BA60A9005CBF47 /* SourceHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D59162AA29BA60A9005CBF47 /* SourceHeaderView.swift */; };
D59162AD29BA616A005CBF47 /* SourceHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = D59162AC29BA616A005CBF47 /* SourceHeaderView.xib */; };
D5927D6629DCC89000D6898E /* UINavigationBarAppearance+TintColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5927D6529DCC89000D6898E /* UINavigationBarAppearance+TintColor.swift */; };
D5935AED29C39DE300C157EF /* SourceDetailsComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5935AEC29C39DE300C157EF /* SourceDetailsComponents.swift */; };
D5935AEF29C3B23600C157EF /* Sources.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D5935AEE29C3B23600C157EF /* Sources.storyboard */; };
D593F1942717749A006E82DE /* PatchAppOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D593F1932717749A006E82DE /* PatchAppOperation.swift */; };
@@ -919,6 +920,7 @@
D58916FD28C7C55C00E39C8B /* LoggedError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggedError.swift; sourceTree = "<group>"; };
D59162AA29BA60A9005CBF47 /* SourceHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceHeaderView.swift; sourceTree = "<group>"; };
D59162AC29BA616A005CBF47 /* SourceHeaderView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SourceHeaderView.xib; sourceTree = "<group>"; };
D5927D6529DCC89000D6898E /* UINavigationBarAppearance+TintColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationBarAppearance+TintColor.swift"; sourceTree = "<group>"; };
D5935AEC29C39DE300C157EF /* SourceDetailsComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceDetailsComponents.swift; sourceTree = "<group>"; };
D5935AEE29C3B23600C157EF /* Sources.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Sources.storyboard; sourceTree = "<group>"; };
D593F1932717749A006E82DE /* PatchAppOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PatchAppOperation.swift; sourceTree = "<group>"; };
@@ -1784,6 +1786,7 @@
D57F2C9326E01BC700B9FA39 /* UIDevice+Vibration.swift */,
B376FE3D29258C8900E18883 /* OSLog+SideStore.swift */,
0E13E5852CC8F55900E9C0DF /* ProcessInfo+SideStore.swift */,
D5927D6529DCC89000D6898E /* UINavigationBarAppearance+TintColor.swift */,
);
path = Extensions;
sourceTree = "<group>";
@@ -2715,6 +2718,7 @@
BF3D64B022E8D4B800E9056B /* AppContentViewControllerCells.swift in Sources */,
BFC57A6E2416FC5D00EB891E /* InstalledAppsCollectionHeaderView.swift in Sources */,
B3EE16B62925E27D00B3B1F5 /* AnisetteManager.swift in Sources */,
D5927D6629DCC89000D6898E /* UINavigationBarAppearance+TintColor.swift in Sources */,
BF88F97224F8727D00BB75DF /* AppManagerErrors.swift in Sources */,
B39F16152918D7DA002E9404 /* Consts+Proxy.swift in Sources */,
BF6C8FAE2429597900125131 /* BannerCollectionViewCell.swift in Sources */,

View File

@@ -16,6 +16,9 @@ import Nuke
class BrowseViewController: UICollectionViewController, PeekPopPreviewing
{
// Nil == Show apps from all sources.
var source: Source?
private lazy var dataSource = self.makeDataSource()
private lazy var placeholderView = RSTPlaceholderView(frame: .zero)
@@ -27,6 +30,18 @@ class BrowseViewController: UICollectionViewController, PeekPopPreviewing
}
}
init?(source: Source?, coder: NSCoder)
{
self.source = source
super.init(coder: coder)
}
required init?(coder: NSCoder)
{
super.init(coder: coder)
}
private var cachedItemSizes = [String: CGSize]()
@IBOutlet private var sourcesBarButtonItem: UIBarButtonItem!
@@ -49,6 +64,22 @@ class BrowseViewController: 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()
}
@@ -78,9 +109,20 @@ private extension BrowseViewController
NSSortDescriptor(keyPath: \StoreApp.name, ascending: true),
NSSortDescriptor(keyPath: \StoreApp.bundleIdentifier, ascending: true)]
fetchRequest.returnsObjectsAsFaults = false
fetchRequest.predicate = NSPredicate(format: "%K != %@", #keyPath(StoreApp.bundleIdentifier), StoreApp.altstoreAppID)
let dataSource = RSTFetchedResultsCollectionViewPrefetchingDataSource<StoreApp, UIImage>(fetchRequest: fetchRequest, managedObjectContext: DatabaseManager.shared.viewContext)
let predicate = NSPredicate(format: "%K != %@", #keyPath(StoreApp.bundleIdentifier), StoreApp.altstoreAppID)
if let source = self.source
{
let filterPredicate = NSPredicate(format: "%K == %@", #keyPath(StoreApp._source), source)
fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [filterPredicate, predicate])
}
else
{
fetchRequest.predicate = predicate
}
let context = self.source?.managedObjectContext ?? DatabaseManager.shared.viewContext
let dataSource = RSTFetchedResultsCollectionViewPrefetchingDataSource<StoreApp, UIImage>(fetchRequest: fetchRequest, managedObjectContext: context)
dataSource.cellConfigurationHandler = { (cell, app, indexPath) in
let cell = cell as! BrowseCollectionViewCell
cell.layoutMargins.left = self.view.layoutMargins.left

View File

@@ -473,13 +473,7 @@ private extension HeaderContentViewController
barAppearance.titleTextAttributes = [.foregroundColor: UIColor.clear]
let tintColor = isHidden ? UIColor.clear : self.tintColor ?? .altPrimary
let buttonAppearance = UIBarButtonItemAppearance(style: .plain)
buttonAppearance.normal.titleTextAttributes = [.foregroundColor: tintColor]
barAppearance.buttonAppearance = buttonAppearance
let backButtonImage = UIImage(systemName: "chevron.backward")?.withTintColor(tintColor, renderingMode: .alwaysOriginal)
barAppearance.setBackIndicatorImage(backButtonImage, transitionMaskImage: backButtonImage)
barAppearance.configureWithTintColor(tintColor)
self.navigationItem.standardAppearance = barAppearance
self.navigationItem.scrollEdgeAppearance = barAppearance

View File

@@ -0,0 +1,22 @@
//
// UINavigationBarAppearance+TintColor.swift
// AltStore
//
// Created by Riley Testut on 4/4/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import UIKit
extension UINavigationBarAppearance
{
func configureWithTintColor(_ tintColor: UIColor)
{
let buttonAppearance = UIBarButtonItemAppearance(style: .plain)
buttonAppearance.normal.titleTextAttributes = [.foregroundColor: tintColor]
self.buttonAppearance = buttonAppearance
let backButtonImage = UIImage(systemName: "chevron.backward")?.withTintColor(tintColor, renderingMode: .alwaysOriginal)
self.setBackIndicatorImage(backButtonImage, transitionMaskImage: backButtonImage)
}
}

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

View File

@@ -7,6 +7,7 @@
//
import UIKit
import SafariServices
import AltStoreCore
import Roxas
@@ -304,6 +305,33 @@ private extension SourceDetailContentViewController
}
}
private extension SourceDetailContentViewController
{
@objc func viewAllNews()
{
self.performSegue(withIdentifier: "showAllNews", sender: nil)
}
@objc func viewAllApps()
{
self.performSegue(withIdentifier: "showAllApps", sender: nil)
}
@IBSegueAction
func makeNewsViewController(_ coder: NSCoder) -> UIViewController?
{
let newsViewController = NewsViewController(source: self.source, coder: coder)
return newsViewController
}
@IBSegueAction
func makeBrowseViewController(_ coder: NSCoder) -> UIViewController?
{
let browseViewController = BrowseViewController(source: self.source, coder: coder)
return browseViewController
}
}
extension SourceDetailContentViewController
{
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView
@@ -318,6 +346,9 @@ extension SourceDetailContentViewController
let buttonView = supplementaryView as! ButtonCollectionReusableView
buttonView.button.setTitle(NSLocalizedString("View All", comment: ""), for: .normal)
buttonView.button.removeTarget(self, action: nil, for: .primaryActionTriggered)
buttonView.button.addTarget(self, action: #selector(SourceDetailContentViewController.viewAllNews), for: .primaryActionTriggered)
case (.featuredApps, .title):
let titleView = supplementaryView as! TitleCollectionReusableView
titleView.label.text = NSLocalizedString("Featured Apps", comment: "")
@@ -326,6 +357,9 @@ extension SourceDetailContentViewController
let buttonView = supplementaryView as! ButtonCollectionReusableView
buttonView.button.setTitle(NSLocalizedString("View All Apps", comment: ""), for: .normal)
buttonView.button.removeTarget(self, action: nil, for: .primaryActionTriggered)
buttonView.button.addTarget(self, action: #selector(SourceDetailContentViewController.viewAllApps), for: .primaryActionTriggered)
case (.about, _):
let titleView = supplementaryView as! TitleCollectionReusableView
titleView.label.text = NSLocalizedString("About", comment: "")
@@ -333,6 +367,34 @@ extension SourceDetailContentViewController
return supplementaryView
}
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{
let section = Section(rawValue: indexPath.section)!
let item = self.dataSource.item(at: indexPath)
switch (section, item)
{
case (.news, let newsItem as NewsItem):
if let externalURL = newsItem.externalURL
{
let safariViewController = SFSafariViewController(url: externalURL)
safariViewController.preferredControlTintColor = newsItem.tintColor
self.present(safariViewController, animated: true, completion: nil)
}
else if let storeApp = newsItem.storeApp
{
let appViewController = AppViewController.makeAppViewController(app: storeApp)
self.navigationController?.pushViewController(appViewController, animated: true)
}
case (.featuredApps, let storeApp as StoreApp):
let appViewController = AppViewController.makeAppViewController(app: storeApp)
self.navigationController?.pushViewController(appViewController, animated: true)
default: break
}
}
}
extension SourceDetailContentViewController: ScrollableContentViewController

View File

@@ -138,6 +138,32 @@
</objects>
<point key="canvasLocation" x="810" y="-13"/>
</scene>
<!--All Apps-->
<scene sceneID="d8a-U8-CPc">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="ih5-9R-QX7" userLabel="First Responder" sceneMemberID="firstResponder"/>
<collectionViewController storyboardIdentifier="browseViewController" id="Nhf-Gw-Ukx" customClass="BrowseViewController" customModule="AltStore" customModuleProvider="target" sceneMemberID="viewController">
<collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" id="oBI-6P-Lm3">
<rect key="frame" x="0.0" y="0.0" width="393" height="783"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="50" minimumInteritemSpacing="10" id="pSh-Xl-aNg">
<size key="itemSize" width="375" height="400"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="8" maxX="0.0" maxY="20"/>
</collectionViewFlowLayout>
<cells/>
<connections>
<outlet property="dataSource" destination="Nhf-Gw-Ukx" id="JPE-wa-fZ5"/>
<outlet property="delegate" destination="Nhf-Gw-Ukx" id="rW6-a2-seQ"/>
</connections>
</collectionView>
<navigationItem key="navigationItem" title="All Apps" id="rUb-ON-AON"/>
</collectionViewController>
</objects>
<point key="canvasLocation" x="3404" y="-13"/>
</scene>
<!--Source Detail View Controller-->
<scene sceneID="xbN-Mz-TtU">
<objects>
@@ -192,10 +218,40 @@
<outlet property="delegate" destination="MSh-hM-32I" id="8SG-5v-iF2"/>
</connections>
</collectionView>
<connections>
<segue destination="MVH-oB-c8m" kind="show" identifier="showAllNews" destinationCreationSelector="makeNewsViewController:" id="txA-ay-P7p"/>
<segue destination="Nhf-Gw-Ukx" kind="show" identifier="showAllApps" destinationCreationSelector="makeBrowseViewController:" id="On0-GP-kaE"/>
</connections>
</collectionViewController>
</objects>
<point key="canvasLocation" x="2509" y="-13"/>
</scene>
<!--All News-->
<scene sceneID="avV-5f-uNE">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="7f5-vn-JrS" userLabel="First Responder" sceneMemberID="firstResponder"/>
<collectionViewController storyboardIdentifier="newsViewController" id="MVH-oB-c8m" customClass="NewsViewController" customModule="AltStore" customModuleProvider="target" sceneMemberID="viewController">
<collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" id="p9p-rr-fbF">
<rect key="frame" x="0.0" y="0.0" width="393" height="783"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="40" minimumInteritemSpacing="40" id="3cD-ax-3h6">
<size key="itemSize" width="375" height="300"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="40" maxX="0.0" maxY="13"/>
</collectionViewFlowLayout>
<cells/>
<connections>
<outlet property="dataSource" destination="MVH-oB-c8m" id="tji-Ko-dBy"/>
<outlet property="delegate" destination="MVH-oB-c8m" id="fcy-SK-PkD"/>
</connections>
</collectionView>
<navigationItem key="navigationItem" title="All News" id="FGB-cd-Vkd"/>
</collectionViewController>
</objects>
<point key="canvasLocation" x="3404" y="-711"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">