HistoryView: Compact UI for phones
This commit is contained in:
@@ -86,7 +86,7 @@ class BrowserHistory
|
||||
}
|
||||
}
|
||||
|
||||
public func viewModel(forFilterString filterString: String? = nil, limit: Int? = nil) -> ViewModel {
|
||||
public func viewModel(forFilterString filterString: String? = nil, limit: Int = 500) -> ViewModel {
|
||||
let resultsController = fetchRequestController(forQuery: filterString, limit: limit)
|
||||
return ViewModel(fetchedResultsController: resultsController, historyController: self)
|
||||
}
|
||||
@@ -107,7 +107,7 @@ class BrowserHistory
|
||||
}
|
||||
}
|
||||
|
||||
public func allHistory(filteredBy filterString: String? = nil, limit: Int? = nil) -> [HistoryItem] {
|
||||
public func allHistory(filteredBy filterString: String? = nil, limit: Int = 500) -> [HistoryItem] {
|
||||
let dataContext = persistentContainer.viewContext
|
||||
let fetchRequest = fetchRequest(forStringContaining: filterString, limit: limit)
|
||||
let entities: [HistoryItemEntity] = (try? dataContext.fetch(fetchRequest)) ?? []
|
||||
@@ -160,24 +160,21 @@ class BrowserHistory
|
||||
|
||||
extension BrowserHistory
|
||||
{
|
||||
fileprivate func fetchRequestController(forQuery query: String? = nil, limit: Int? = nil) -> NSFetchedResultsController<HistoryItemEntity> {
|
||||
fileprivate func fetchRequestController(forQuery query: String? = nil, limit: Int = 500) -> NSFetchedResultsController<HistoryItemEntity> {
|
||||
let fetchRequest = fetchRequest(forStringContaining: query, limit: limit)
|
||||
return NSFetchedResultsController(fetchRequest: fetchRequest,
|
||||
managedObjectContext: persistentContainer.viewContext,
|
||||
sectionNameKeyPath: nil, cacheName: nil)
|
||||
}
|
||||
|
||||
fileprivate func fetchRequest(forStringContaining filterString: String? = nil, limit: Int? = nil) -> NSFetchRequest<HistoryItemEntity> {
|
||||
fileprivate func fetchRequest(forStringContaining filterString: String? = nil, limit: Int = 500) -> NSFetchRequest<HistoryItemEntity> {
|
||||
let fetchRequest: NSFetchRequest<HistoryItemEntity> = HistoryItemEntity.fetchRequest()
|
||||
fetchRequest.fetchLimit = limit
|
||||
fetchRequest.sortDescriptors = [
|
||||
// Sort by date
|
||||
NSSortDescriptor(keyPath: \HistoryItemEntity.lastVisited, ascending: false)
|
||||
]
|
||||
|
||||
if let limit {
|
||||
fetchRequest.fetchLimit = limit
|
||||
}
|
||||
|
||||
if let filterString, filterString.count > 0 {
|
||||
fetchRequest.predicate = NSPredicate(format: """
|
||||
host CONTAINS[cd] %@
|
||||
|
||||
Reference in New Issue
Block a user