Skip to content

Commit

Permalink
Improve ItemsToolbarController code clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed Sep 11, 2023
1 parent 47faef0 commit 1891ff8
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions Zotero/Scenes/Detail/Items/ViewModels/ItemsToolbarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ final class ItemsToolbarController {
self.viewController.toolbarItems = self.createEditingToolbarItems(from: self.editingActions)
self.updateEditingToolbarItems(for: state.selectedItems, results: state.results)
} else {
let filters = self.deviceSpecificFilters(from: state.filters)
let filters = self.sizeClassSpecificFilters(from: state.filters)
self.viewController.toolbarItems = self.createNormalToolbarItems(for: filters)
self.updateNormalToolbarItems(for: filters, downloadBatchData: state.downloadBatchData, results: state.results)
}
Expand All @@ -73,24 +73,26 @@ final class ItemsToolbarController {
if state.isEditing {
self.updateEditingToolbarItems(for: state.selectedItems, results: state.results)
} else {
self.updateNormalToolbarItems(for: self.deviceSpecificFilters(from: state.filters), downloadBatchData: state.downloadBatchData, results: state.results)
self.updateNormalToolbarItems(for: self.sizeClassSpecificFilters(from: state.filters), downloadBatchData: state.downloadBatchData, results: state.results)
}
}

private func deviceSpecificFilters(from filters: [ItemsFilter]) -> [ItemsFilter] {
private func sizeClassSpecificFilters(from filters: [ItemsFilter]) -> [ItemsFilter] {
// There is different functionality based on horizontal size class. iPhone and compact iPad show tag filters in filter popup in items screen while iPad shows tag filters in master controller.
// So filter icon and description should always show up on iPhone and compact iPad, while it should not show up on regular iPad for tag filters.
// Therefore we ignore `.tag` filter on iPhone and compact iPad, and keep it on regular iPad.
if delegate?.traitCollection.horizontalSizeClass == .regular && UIDevice.current.userInterfaceIdiom == .pad {
return filters.filter({
switch $0 {
case .tags: return false
case .downloadedFiles: return true
}
})
} else {
if delegate?.traitCollection.horizontalSizeClass == .compact || UIDevice.current.userInterfaceIdiom == .phone {
return filters
}
return filters.filter({
switch $0 {
case .tags:
return false

case .downloadedFiles:
return true
}
})
}

// MARK: - Helpers
Expand Down

0 comments on commit 1891ff8

Please sign in to comment.