-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into feature/filePreviewing
- Loading branch information
Showing
9 changed files
with
303 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule ios-sdk
updated
26 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
ownCloud/Client/Actions/ClientDirectoryPickerViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// ClientDirectoryPickerViewController.swift | ||
// ownCloud | ||
// | ||
// Created by Pablo Carrascal on 22/08/2018. | ||
// Copyright © 2018 ownCloud GmbH. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import ownCloudSDK | ||
|
||
class ClientDirectoryPickerViewController: ClientQueryViewController { | ||
|
||
private let SELECT_BUTTON_HEIGHT: CGFloat = 44.0 | ||
|
||
// MARK: - Query directory filter | ||
private static let DIRECTORY_FILTER_IDENTIFIER: String = "directory-filter" | ||
private static var directoryFilterHandler: OCQueryFilterHandler = { (_, _, item) -> Bool in | ||
if let item = item { | ||
if item.type == .collection {return true} | ||
} | ||
return false | ||
} | ||
private static var directoryFilter: OCQueryFilter { | ||
return OCQueryFilter(handler: ClientDirectoryPickerViewController.directoryFilterHandler) | ||
} | ||
|
||
// MARK: - Instance Properties | ||
private var selectButton: UIBarButtonItem! | ||
private var selectButtonTitle: String | ||
private var cancelBarButton: UIBarButtonItem! | ||
private var completion: (OCItem) -> Void | ||
|
||
// MARK: - Init & deinit | ||
init(core inCore: OCCore, path: String, selectButtonTitle: String = "Move here".localized, completion: @escaping (OCItem) -> Void) { | ||
self.selectButtonTitle = selectButtonTitle | ||
self.completion = completion | ||
|
||
super.init(core: inCore, query: OCQuery(forPath: path)!) | ||
|
||
self.query?.addFilter(ClientDirectoryPickerViewController.directoryFilter, withIdentifier: ClientDirectoryPickerViewController.DIRECTORY_FILTER_IDENTIFIER) | ||
|
||
Theme.shared.register(client: self) | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
deinit { | ||
Theme.shared.unregister(client: self) | ||
} | ||
|
||
// MARK: - ViewController lifecycle | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
// Select button creation | ||
selectButton = UIBarButtonItem(title: selectButtonTitle, style: .plain, target: self, action: #selector(selectButtonPressed)) | ||
selectButton.title = selectButtonTitle | ||
|
||
// Cancel button creation | ||
cancelBarButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelBarButtonPressed)) | ||
navigationItem.rightBarButtonItem = cancelBarButton | ||
} | ||
|
||
override func viewWillAppear(_ animated: Bool) { | ||
super.viewWillAppear(true) | ||
|
||
if let navController = self.navigationController { | ||
navController.isToolbarHidden = false | ||
let flexibleSpaceBarButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) | ||
self.setToolbarItems([flexibleSpaceBarButton, selectButton, flexibleSpaceBarButton], animated: false) | ||
} | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
guard let items = items else { | ||
return | ||
} | ||
|
||
let item = items[indexPath.row] | ||
|
||
guard item.type == OCItemType.collection else { | ||
return | ||
} | ||
|
||
self.navigationController?.pushViewController(ClientDirectoryPickerViewController(core: core!, path: item.path, completion: completion), animated: true) | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { | ||
return nil | ||
} | ||
|
||
// MARK: - Actions | ||
@objc private func cancelBarButtonPressed() { | ||
self.dismiss(animated: true) | ||
} | ||
|
||
@objc private func selectButtonPressed() { | ||
guard let query = query else { | ||
return | ||
} | ||
|
||
self.dismiss(animated: true, completion: { | ||
self.completion(query.rootItem) | ||
}) | ||
} | ||
} |
Oops, something went wrong.