Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix/quick-access] Fix quick access issue #1044

Merged
merged 1 commit into from
Oct 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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