From 7bb5c4f0c7b16f001f63f1988a3abd17d5441348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20H=C3=BChne?= Date: Fri, 9 Aug 2019 14:23:31 +0200 Subject: [PATCH] [fix/index-bar] Make Index Bar available in general file list (#469) * #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 --- ownCloud.xcodeproj/project.pbxproj | 4 -- .../LibraryFilesTableViewController.swift | 53 ------------------- .../Library/LibraryTableViewController.swift | 2 +- .../QueryFileListTableViewController.swift | 37 +++++++++++++ 4 files changed, 38 insertions(+), 58 deletions(-) delete mode 100644 ownCloud/Client/Library/LibraryFilesTableViewController.swift diff --git a/ownCloud.xcodeproj/project.pbxproj b/ownCloud.xcodeproj/project.pbxproj index 296a41f9a..61dc69f11 100644 --- a/ownCloud.xcodeproj/project.pbxproj +++ b/ownCloud.xcodeproj/project.pbxproj @@ -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 */; }; @@ -749,7 +748,6 @@ DC297968226E52E600E01BC7 /* PushTransition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushTransition.swift; sourceTree = ""; }; DC29F08F22974AEA00F77349 /* QueryFileListTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueryFileListTableViewController.swift; sourceTree = ""; }; 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 = ""; }; DC3317CD2084966700E36C8F /* ThemeTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeTableViewCell.swift; sourceTree = ""; }; DC3BE0DC2077CC13002A0AC0 /* ClientQueryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClientQueryViewController.swift; sourceTree = ""; }; @@ -1135,7 +1133,6 @@ children = ( 3913214A22956D5700EF88F4 /* LibraryTableViewController.swift */, DC29F09222976B9200F77349 /* LibrarySharesTableViewController.swift */, - DC29F09322976B9200F77349 /* LibraryFilesTableViewController.swift */, ); path = Library; sourceTree = ""; @@ -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 */, diff --git a/ownCloud/Client/Library/LibraryFilesTableViewController.swift b/ownCloud/Client/Library/LibraryFilesTableViewController.swift deleted file mode 100644 index 626a96c1b..000000000 --- a/ownCloud/Client/Library/LibraryFilesTableViewController.swift +++ /dev/null @@ -1,53 +0,0 @@ -// -// LibraryFilesTableViewController -// ownCloud -// -// Created by Matthias Hühne on 13.05.19. -// Copyright © 2019 ownCloud GmbH. All rights reserved. -// - -/* -* Copyright (C) 2019, ownCloud GmbH. -* -* This code is covered by the GNU Public License Version 3. -* -* For distribution utilizing Apple mechanisms please see https://owncloud.org/contribute/iOS-license-exception/ -* You should have received a copy of this license along with this program. If not, see . -* -*/ - -import UIKit -import ownCloudSDK - -class LibraryFilesTableViewController: QueryFileListTableViewController { - - // MARK: - Theme support - override func applyThemeCollection(theme: Theme, collection: ThemeCollection, event: ThemeEvent) { - super.applyThemeCollection(theme: theme, collection: collection, event: event) - - tableView.sectionIndexColor = collection.tintColor - } - - override func sectionIndexTitles(for tableView: UITableView) -> [String]? { - if sortMethod == .alphabetically { - return Array( Set( self.items.map { String(( $0.name?.first!.uppercased())!) })).sorted() - } - - 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 - } - -} diff --git a/ownCloud/Client/Library/LibraryTableViewController.swift b/ownCloud/Client/Library/LibraryTableViewController.swift index 802bb21ae..570384712 100644 --- a/ownCloud/Client/Library/LibraryTableViewController.swift +++ b/ownCloud/Client/Library/LibraryTableViewController.swift @@ -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) diff --git a/ownCloud/FileLists/QueryFileListTableViewController.swift b/ownCloud/FileLists/QueryFileListTableViewController.swift index 6e9e81897..7d84fb487 100644 --- a/ownCloud/FileLists/QueryFileListTableViewController.swift +++ b/ownCloud/FileLists/QueryFileListTableViewController.swift @@ -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 @@ -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 + } }