[AltStore] Refactors fetch apps logic to use Source model objects

This commit is contained in:
Riley Testut
2019-07-30 17:00:04 -07:00
parent 75e398822f
commit 87ced5523e
13 changed files with 272 additions and 115 deletions

View File

@@ -36,7 +36,7 @@ class BrowseViewController: UICollectionViewController
{
super.viewWillAppear(animated)
self.fetchApps()
self.fetchSource()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
@@ -57,10 +57,18 @@ private extension BrowseViewController
func makeDataSource() -> RSTFetchedResultsCollectionViewPrefetchingDataSource<App, UIImage>
{
let fetchRequest = App.fetchRequest() as NSFetchRequest<App>
fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \App.name, ascending: false)]
fetchRequest.predicate = NSPredicate(format: "%K != %@", #keyPath(App.bundleIdentifier), App.altstoreAppID)
fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \App.sortIndex, ascending: true), NSSortDescriptor(keyPath: \App.name, ascending: true)]
fetchRequest.returnsObjectsAsFaults = false
if let source = Source.fetchAltStoreSource(in: DatabaseManager.shared.viewContext)
{
fetchRequest.predicate = NSPredicate(format: "%K != %@ AND %K == %@", #keyPath(App.bundleIdentifier), App.altstoreAppID, #keyPath(App.source), source)
}
else
{
fetchRequest.predicate = NSPredicate(format: "%K != %@", #keyPath(App.bundleIdentifier), App.altstoreAppID)
}
let dataSource = RSTFetchedResultsCollectionViewPrefetchingDataSource<App, UIImage>(fetchRequest: fetchRequest, managedObjectContext: DatabaseManager.shared.viewContext)
dataSource.cellConfigurationHandler = { (cell, app, indexPath) in
let cell = cell as! BrowseCollectionViewCell
@@ -98,13 +106,13 @@ private extension BrowseViewController
return dataSource
}
func fetchApps()
func fetchSource()
{
AppManager.shared.fetchApps() { (result) in
AppManager.shared.fetchSource() { (result) in
do
{
let apps = try result.get()
try apps.first?.managedObjectContext?.save()
let source = try result.get()
try source.managedObjectContext?.save()
}
catch
{