mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-18 11:13:28 +01:00
Supports searching all apps from FeaturedViewController
This commit is contained in:
@@ -27,6 +27,12 @@ class BrowseViewController: UICollectionViewController, PeekPopPreviewing
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var searchPredicate: NSPredicate? {
|
||||||
|
didSet {
|
||||||
|
self.updateDataSource()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private lazy var dataSource = self.makeDataSource()
|
private lazy var dataSource = self.makeDataSource()
|
||||||
private lazy var placeholderView = RSTPlaceholderView(frame: .zero)
|
private lazy var placeholderView = RSTPlaceholderView(frame: .zero)
|
||||||
|
|
||||||
@@ -278,6 +284,8 @@ private extension BrowseViewController
|
|||||||
let context = self.source?.managedObjectContext ?? DatabaseManager.shared.viewContext
|
let context = self.source?.managedObjectContext ?? DatabaseManager.shared.viewContext
|
||||||
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
|
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
|
||||||
self.dataSource.fetchedResultsController = fetchedResultsController
|
self.dataSource.fetchedResultsController = fetchedResultsController
|
||||||
|
|
||||||
|
self.dataSource.predicate = self.searchPredicate
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateSources()
|
func updateSources()
|
||||||
@@ -298,32 +306,45 @@ private extension BrowseViewController
|
|||||||
|
|
||||||
func update()
|
func update()
|
||||||
{
|
{
|
||||||
switch AppManager.shared.updateSourcesResult
|
if self.searchPredicate != nil
|
||||||
{
|
{
|
||||||
case nil:
|
|
||||||
self.placeholderView.textLabel.isHidden = true
|
|
||||||
self.placeholderView.detailTextLabel.isHidden = false
|
|
||||||
|
|
||||||
self.placeholderView.detailTextLabel.text = NSLocalizedString("Loading...", comment: "")
|
|
||||||
|
|
||||||
self.placeholderView.activityIndicatorView.startAnimating()
|
|
||||||
|
|
||||||
case .failure(let error):
|
|
||||||
self.placeholderView.textLabel.isHidden = false
|
|
||||||
self.placeholderView.detailTextLabel.isHidden = false
|
|
||||||
|
|
||||||
self.placeholderView.textLabel.text = NSLocalizedString("Unable to Fetch Apps", comment: "")
|
|
||||||
self.placeholderView.detailTextLabel.text = error.localizedDescription
|
|
||||||
|
|
||||||
self.placeholderView.activityIndicatorView.stopAnimating()
|
|
||||||
|
|
||||||
case .success:
|
|
||||||
self.placeholderView.textLabel.text = NSLocalizedString("No Apps", comment: "")
|
self.placeholderView.textLabel.text = NSLocalizedString("No Apps", comment: "")
|
||||||
self.placeholderView.textLabel.isHidden = false
|
self.placeholderView.textLabel.isHidden = false
|
||||||
self.placeholderView.detailTextLabel.isHidden = true
|
|
||||||
|
self.placeholderView.detailTextLabel.text = NSLocalizedString("Please make sure your spelling is correct, or try searching for another app.", comment: "")
|
||||||
|
self.placeholderView.detailTextLabel.isHidden = false
|
||||||
|
|
||||||
self.placeholderView.activityIndicatorView.stopAnimating()
|
self.placeholderView.activityIndicatorView.stopAnimating()
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch AppManager.shared.updateSourcesResult
|
||||||
|
{
|
||||||
|
case nil:
|
||||||
|
self.placeholderView.textLabel.isHidden = true
|
||||||
|
self.placeholderView.detailTextLabel.isHidden = false
|
||||||
|
|
||||||
|
self.placeholderView.detailTextLabel.text = NSLocalizedString("Loading...", comment: "")
|
||||||
|
|
||||||
|
self.placeholderView.activityIndicatorView.startAnimating()
|
||||||
|
|
||||||
|
case .failure(let error):
|
||||||
|
self.placeholderView.textLabel.isHidden = false
|
||||||
|
self.placeholderView.detailTextLabel.isHidden = false
|
||||||
|
|
||||||
|
self.placeholderView.textLabel.text = NSLocalizedString("Unable to Fetch Apps", comment: "")
|
||||||
|
self.placeholderView.detailTextLabel.text = error.localizedDescription
|
||||||
|
|
||||||
|
self.placeholderView.activityIndicatorView.stopAnimating()
|
||||||
|
|
||||||
|
case .success:
|
||||||
|
self.placeholderView.textLabel.text = NSLocalizedString("No Apps", comment: "")
|
||||||
|
self.placeholderView.textLabel.isHidden = false
|
||||||
|
self.placeholderView.detailTextLabel.isHidden = true
|
||||||
|
|
||||||
|
self.placeholderView.activityIndicatorView.stopAnimating()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let category = self.category
|
if let category = self.category
|
||||||
{
|
{
|
||||||
@@ -535,9 +556,11 @@ extension BrowseViewController: UICollectionViewDelegateFlowLayout
|
|||||||
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
|
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
|
||||||
{
|
{
|
||||||
let app = self.dataSource.item(at: indexPath)
|
let app = self.dataSource.item(at: indexPath)
|
||||||
|
|
||||||
let appViewController = AppViewController.makeAppViewController(app: app)
|
let appViewController = AppViewController.makeAppViewController(app: app)
|
||||||
self.navigationController?.pushViewController(appViewController, animated: true)
|
|
||||||
|
// Fall back to presentingViewController.navigationController in case we're being used for search results.
|
||||||
|
let navigationController = self.navigationController ?? self.presentingViewController?.navigationController
|
||||||
|
navigationController?.pushViewController(appViewController, animated: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,9 @@ class FeaturedViewController: UICollectionViewController
|
|||||||
private lazy var categoriesDataSource = self.makeCategoriesDataSource()
|
private lazy var categoriesDataSource = self.makeCategoriesDataSource()
|
||||||
private lazy var featuredAppsDataSource = self.makeFeaturedAppsDataSource()
|
private lazy var featuredAppsDataSource = self.makeFeaturedAppsDataSource()
|
||||||
|
|
||||||
|
private var searchController: RSTSearchController!
|
||||||
|
private var searchBrowseViewController: BrowseViewController!
|
||||||
|
|
||||||
override func viewDidLoad()
|
override func viewDidLoad()
|
||||||
{
|
{
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
@@ -87,6 +90,25 @@ class FeaturedViewController: UICollectionViewController
|
|||||||
self.collectionView.directionalLayoutMargins.leading = 20
|
self.collectionView.directionalLayoutMargins.leading = 20
|
||||||
self.collectionView.directionalLayoutMargins.trailing = 20
|
self.collectionView.directionalLayoutMargins.trailing = 20
|
||||||
|
|
||||||
|
let storyboard = UIStoryboard(name: "Main", bundle: nil)
|
||||||
|
self.searchBrowseViewController = storyboard.instantiateViewController(identifier: "browseViewController") { coder in
|
||||||
|
let browseViewController = BrowseViewController(coder: coder)
|
||||||
|
return browseViewController
|
||||||
|
}
|
||||||
|
|
||||||
|
self.searchController = RSTSearchController(searchResultsController: self.searchBrowseViewController)
|
||||||
|
self.searchController.searchableKeyPaths = [#keyPath(StoreApp.name),
|
||||||
|
#keyPath(StoreApp.developerName),
|
||||||
|
#keyPath(StoreApp.subtitle),
|
||||||
|
#keyPath(StoreApp.bundleIdentifier)]
|
||||||
|
self.searchController.searchHandler = { [weak searchBrowseViewController] (searchValue, _) in
|
||||||
|
searchBrowseViewController?.searchPredicate = searchValue.predicate
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
self.navigationItem.searchController = self.searchController
|
||||||
|
self.navigationItem.hidesSearchBarWhenScrolling = true
|
||||||
|
|
||||||
self.navigationItem.largeTitleDisplayMode = .always
|
self.navigationItem.largeTitleDisplayMode = .always
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user