Skip to content

Commit

Permalink
- fix bug where a quick access entry showed no items when selected a …
Browse files Browse the repository at this point in the history
…second time. (#1044)
  • Loading branch information
felix-schwarz authored Oct 11, 2021
1 parent 88609b5 commit f7574f6
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions ownCloud/Client/Library/LibraryTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,26 +380,30 @@ class LibraryTableViewController: StaticTableViewController {
let section = StaticTableViewSection(headerTitle: "Collection".localized, footerTitle: nil, identifier: "collection-section")
self.addSection(section)

let lastWeekDate = Calendar.current.date(byAdding: .weekOfYear, value: -1, to: Date())!
var recentsQuery = OCQuery(condition: .require([
.where(.lastUsed, isGreaterThan: lastWeekDate),
.where(.name, isNotEqualTo: "/")
]), inputFilter:nil)

if let condition = OCQueryCondition.fromSearchTerm(":1w :file") {
recentsQuery = OCQuery(condition:condition, inputFilter: nil)
}
addCollectionRow(to: section, title: "Recents".localized, image: UIImage(named: "recents")!, queryCreator: {
let lastWeekDate = Calendar.current.date(byAdding: .weekOfYear, value: -1, to: Date())!

var recentsQuery = OCQuery(condition: .require([
.where(.lastUsed, isGreaterThan: lastWeekDate),
.where(.name, isNotEqualTo: "/")
]), inputFilter:nil)

if let condition = OCQueryCondition.fromSearchTerm(":1w :file") {
recentsQuery = OCQuery(condition:condition, inputFilter: nil)
}

addCollectionRow(to: section, title: "Recents".localized, image: UIImage(named: "recents")!, query: recentsQuery, actionHandler: nil)
return recentsQuery
}, actionHandler: nil)

let favoriteQuery = OCQuery(condition: .where(.isFavorite, isEqualTo: true), inputFilter:nil)
addCollectionRow(to: section, title: "Favorites".localized, image: UIImage(named: "star")!, query: favoriteQuery, actionHandler: { [weak self] (completion) in
addCollectionRow(to: section, title: "Favorites".localized, image: UIImage(named: "star")!, queryCreator: {
return OCQuery(condition: .where(.isFavorite, isEqualTo: true), inputFilter:nil)
}, actionHandler: { [weak self] (completion) in
self?.core?.refreshFavorites(completionHandler: { (_, _) in
completion()
})
})

addCollectionRow(to: section, title: "Available Offline".localized, image: UIImage(named: "cloud-available-offline")!, query: nil, actionHandler: { [weak self] (completion) in
addCollectionRow(to: section, title: "Available Offline".localized, image: UIImage(named: "cloud-available-offline")!, queryCreator: nil, actionHandler: { [weak self] (completion) in
if let core = self?.core {
let availableOfflineListController = ItemPolicyTableViewController(core: core, policyKind: .availableOffline)

Expand All @@ -418,22 +422,23 @@ class LibraryTableViewController: StaticTableViewController {
]

for query in queries {
let conditions = query.mimeType.map { (mimeType) -> OCQueryCondition in
return .where(.mimeType, contains: mimeType)
}
addCollectionRow(to: section, title: query.name, image: Theme.shared.image(for: query.imageName, size: CGSize(width: 25, height: 25))!, queryCreator: {
let conditions = query.mimeType.map { (mimeType) -> OCQueryCondition in
return .where(.mimeType, contains: mimeType)
}

let customQuery = OCQuery(condition: .any(of: conditions), inputFilter:nil)
addCollectionRow(to: section, title: query.name, image: Theme.shared.image(for: query.imageName, size: CGSize(width: 25, height: 25))!, query: customQuery, actionHandler: nil)
return OCQuery(condition: .any(of: conditions), inputFilter:nil)
}, actionHandler: nil)
}
}
}

func addCollectionRow(to section: StaticTableViewSection, title: String, image: UIImage? = nil, themeImageName: String? = nil, query: OCQuery?, actionHandler: ((_ completion: @escaping () -> Void) -> Void)?) {
func addCollectionRow(to section: StaticTableViewSection, title: String, image: UIImage? = nil, themeImageName: String? = nil, queryCreator: (() -> OCQuery?)?, actionHandler: ((_ completion: @escaping () -> Void) -> Void)?) {
let identifier = String(format:"%@-collection-row", title)
if section.row(withIdentifier: identifier) == nil, let core = core {
let row = StaticTableViewRow(rowWithAction: { [weak self] (_, _) in

if let query = query {
if let query = queryCreator?() {
let customFileListController = QueryFileListTableViewController(core: core, query: query)
customFileListController.title = title
customFileListController.pullToRefreshAction = actionHandler
Expand Down

0 comments on commit f7574f6

Please sign in to comment.