Skip to content

Commit

Permalink
[fix/index-bar] Make Index Bar available in general file list (#469)
Browse files Browse the repository at this point in the history
* #413 show index bar in general file list
- Index bar is only visible, if sorting is "Sort by name"
- Index bar is only visible, if more than one different letters are available
- Index bar is only visible, if more items are available as visible

* - adopt to new sort methods
- reverse index list, if sort direction is descendant
  • Loading branch information
hosy authored Aug 9, 2019
1 parent dd6b625 commit 7bb5c4f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 58 deletions.
4 changes: 0 additions & 4 deletions ownCloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
DC297967226E4D3100E01BC7 /* PushPresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC297966226E4D3100E01BC7 /* PushPresentationController.swift */; };
DC297969226E52E600E01BC7 /* PushTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC297968226E52E600E01BC7 /* PushTransition.swift */; };
DC29F09022974AEA00F77349 /* QueryFileListTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC29F08F22974AEA00F77349 /* QueryFileListTableViewController.swift */; };
DC29F09422976B9300F77349 /* LibraryFilesTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC29F09322976B9200F77349 /* LibraryFilesTableViewController.swift */; };
DC29F09522976B9300F77349 /* LibrarySharesTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC29F09222976B9200F77349 /* LibrarySharesTableViewController.swift */; };
DC321261207EB01B00DB171D /* ThemeImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC321260207EB01B00DB171D /* ThemeImage.swift */; };
DC3317CE2084966700E36C8F /* ThemeTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC3317CD2084966700E36C8F /* ThemeTableViewCell.swift */; };
Expand Down Expand Up @@ -749,7 +748,6 @@
DC297968226E52E600E01BC7 /* PushTransition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushTransition.swift; sourceTree = "<group>"; };
DC29F08F22974AEA00F77349 /* QueryFileListTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueryFileListTableViewController.swift; sourceTree = "<group>"; };
DC29F09222976B9200F77349 /* LibrarySharesTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LibrarySharesTableViewController.swift; path = ownCloud/Client/Library/LibrarySharesTableViewController.swift; sourceTree = SOURCE_ROOT; };
DC29F09322976B9200F77349 /* LibraryFilesTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LibraryFilesTableViewController.swift; path = ownCloud/Client/Library/LibraryFilesTableViewController.swift; sourceTree = SOURCE_ROOT; };
DC321260207EB01B00DB171D /* ThemeImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeImage.swift; sourceTree = "<group>"; };
DC3317CD2084966700E36C8F /* ThemeTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeTableViewCell.swift; sourceTree = "<group>"; };
DC3BE0DC2077CC13002A0AC0 /* ClientQueryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClientQueryViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1135,7 +1133,6 @@
children = (
3913214A22956D5700EF88F4 /* LibraryTableViewController.swift */,
DC29F09222976B9200F77349 /* LibrarySharesTableViewController.swift */,
DC29F09322976B9200F77349 /* LibraryFilesTableViewController.swift */,
);
path = Library;
sourceTree = "<group>";
Expand Down Expand Up @@ -2463,7 +2460,6 @@
DC27A19D20CAB602008ACB6C /* FileProviderInterfaceManager.swift in Sources */,
DCC085512293ED52008CC05C /* DisplaySettingsSection.swift in Sources */,
23EC77582137F3DD0032D4E6 /* PDFViewerViewController.swift in Sources */,
DC29F09422976B9300F77349 /* LibraryFilesTableViewController.swift in Sources */,
239F1319205A693A0029F186 /* UIColor+Extension.swift in Sources */,
23EC775B2137F3DD0032D4E6 /* OCExtensionType+Extension.swift in Sources */,
4C88041822E78D790016CBA9 /* MediaFilesSettings.swift in Sources */,
Expand Down
53 changes: 0 additions & 53 deletions ownCloud/Client/Library/LibraryFilesTableViewController.swift

This file was deleted.

2 changes: 1 addition & 1 deletion ownCloud/Client/Library/LibraryTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class LibraryTableViewController: StaticTableViewController {
let row = StaticTableViewRow(rowWithAction: { [weak self] (_, _) in

if let query = query {
let customFileListController = LibraryFilesTableViewController(core: core, query: query)
let customFileListController = QueryFileListTableViewController(core: core, query: query)
customFileListController.title = title
customFileListController.pullToRefreshAction = actionHandler
self?.navigationController?.pushViewController(customFileListController, animated: true)
Expand Down
37 changes: 37 additions & 0 deletions ownCloud/FileLists/QueryFileListTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class QueryFileListTableViewController: FileListTableViewController, SortBarDele
super.applyThemeCollection(theme: theme, collection: collection, event: event)

self.searchController?.searchBar.applyThemeCollection(collection)
tableView.sectionIndexColor = collection.tintColor
}

// MARK: - Events
Expand Down Expand Up @@ -339,4 +340,40 @@ class QueryFileListTableViewController: FileListTableViewController, SortBarDele

return cell!
}

// MARK: - Table view delegate

override func sectionIndexTitles(for tableView: UITableView) -> [String]? {
if sortMethod == .alphabetically {
var indexTitles = Array( Set( self.items.map { String(( $0.name?.first!.uppercased())!) })).sorted()
if sortDirection == .descendant {
indexTitles.reverse()
}
if #available(iOS 12.0, *) {
if Int(tableView.estimatedRowHeight) * self.items.count > Int(tableView.visibleSize.height), indexTitles.count > 1 {
return indexTitles
}
} else {
if indexTitles.count > 1 {
return indexTitles
}
}
}

return []
}

override open func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int {
let firstItem = self.items.filter { (( $0.name?.uppercased().hasPrefix(title) ?? nil)! ) }.first

if let firstItem = firstItem {
if let itemIndex = self.items.index(of: firstItem) {
OnMainThread {
tableView.scrollToRow(at: IndexPath(row: itemIndex, section: 0), at: UITableView.ScrollPosition.top, animated: false)
}
}
}

return 0
}
}

0 comments on commit 7bb5c4f

Please sign in to comment.