Skip to content

Commit

Permalink
- SDK updated.
Browse files Browse the repository at this point in the history
- Removed multilselection code.
- Blocking UI until the file was deleted.
  • Loading branch information
Pablo Carrascal committed Jul 6, 2018
1 parent d2a09a0 commit 8e5d239
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 122 deletions.
2 changes: 1 addition & 1 deletion ios-sdk
145 changes: 26 additions & 119 deletions ownCloud/Client/ClientQueryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ class ClientQueryViewController: UITableViewController, Themeable {
super.viewDidLoad()

self.tableView.register(ClientItemCell.self, forCellReuseIdentifier: "itemCell")
self.tableView.allowsMultipleSelectionDuringEditing = true
// self.tableView.allowsMultipleSelectionDuringEditing = true

// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem
// self.navigationItem.rightBarButtonItem = self.editButtonItem

searchController = UISearchController(searchResultsController: nil)
searchController?.searchResultsUpdater = self
Expand All @@ -137,8 +137,6 @@ class ClientQueryViewController: UITableViewController, Themeable {

Theme.shared.register(client: self, applyImmediately: true)

createActionsToolBar()

}

override func viewWillDisappear(_ animated: Bool) {
Expand Down Expand Up @@ -260,19 +258,13 @@ class ClientQueryViewController: UITableViewController, Themeable {
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if tableView.isEditing {
updateActionsToolBar()
} else {
let rowItem : OCItem = self.items![indexPath.row]

if rowItem.type == .collection {
self.navigationController?.pushViewController(ClientQueryViewController(core: self.core!, query: OCQuery(forPath: rowItem.path)), animated: true)
}
let rowItem : OCItem = self.items![indexPath.row]

if rowItem.type == .collection {
self.navigationController?.pushViewController(ClientQueryViewController(core: self.core!, query: OCQuery(forPath: rowItem.path)), animated: true)
}
}

override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
updateActionsToolBar()
}

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
Expand All @@ -285,14 +277,30 @@ class ClientQueryViewController: UITableViewController, Themeable {
if item.type == .collection {
message = "Are you sure you want to delete this folder from the server?".localized
}

self.deleteConfirmationActionSheet(title: item.name, message: message, completion: {
_ = self.core?.delete(item, requireMatch: true, resultHandler: { (error, _, _, _) in
let hud = ProgressHUDViewController()
let confirmationController = UIAlertController(title: item.name, message: message, preferredStyle: .actionSheet)
let deleteAction = UIAlertAction(title: "Delete".localized, style: .destructive) { (_) in
hud.present(on: self, label: "Deleting...".localized)
_ = self.core?.delete(item, requireMatch: false, resultHandler: { (error, _, _, _) in
hud.dismiss()
if error != nil {
Log.log("Error \(String(describing: error)) deleting \(String(describing: item.path))")
}
})
})
}

let cancelAction = UIAlertAction(title: "Cancel".localized, style: .cancel, handler: nil)

confirmationController.addAction(deleteAction)
confirmationController.addAction(cancelAction)

if let popoverController = confirmationController.popoverPresentationController {
popoverController.sourceView = self.view
popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
popoverController.permittedArrowDirections = []
}
self.present(confirmationController, animated: true)

actionPerformed(false)
})
])
Expand Down Expand Up @@ -436,73 +444,6 @@ class ClientQueryViewController: UITableViewController, Themeable {

// MARK: - Search
var searchController: UISearchController?

// MARK: - Edit
private var actionsToolBar: ActionsToolBar?

private func createActionsToolBar() {
actionsToolBar = ActionsToolBar(frame: .zero)
actionsToolBar?.translatesAutoresizingMaskIntoConstraints = false

self.tabBarController?.tabBar.addSubview(actionsToolBar!)

actionsToolBar?.bottomAnchor.constraint(equalTo: self.tabBarController!.tabBar.bottomAnchor).isActive = true
actionsToolBar?.rightAnchor.constraint(equalTo: self.tabBarController!.tabBar.rightAnchor).isActive = true
actionsToolBar?.leftAnchor.constraint(equalTo: self.tabBarController!.tabBar.leftAnchor).isActive = true
actionsToolBar?.topAnchor.constraint(equalTo: self.tabBarController!.tabBar.topAnchor).isActive = true

actionsToolBar?.isHidden = true
actionsToolBar?.disableAll()

actionsToolBar?.actionsDelegate = self

editButtonItem.action = #selector(editButtonItemAction)

}

@objc private func editButtonItemAction() {
if tableView.isEditing {
tableView.setEditing(false, animated: true)
actionsToolBar?.disableAll()
actionsToolBar?.hide()
editButtonItem.title = "Edit".localized
} else {
tableView.setEditing(true, animated: true)
actionsToolBar?.show()
editButtonItem.title = "Cancel".localized
}
}

private func updateActionsToolBar() {
if let selectedRows = tableView.indexPathsForSelectedRows {
if selectedRows.count > 0 {
actionsToolBar?.enableAll()
} else {
actionsToolBar?.disableAll()
}
} else {
actionsToolBar?.disableAll()
}
}

private func deleteConfirmationActionSheet(title: String?, message: String?, completion: @escaping () -> Void) {
let confirmationController = UIAlertController(title: title, message: message, preferredStyle: .actionSheet)
let deleteAction = UIAlertAction(title: "Delete".localized, style: .destructive) { (_) in
completion()
}

let cancelAction = UIAlertAction(title: "Cancel".localized, style: .cancel, handler: nil)

confirmationController.addAction(deleteAction)
confirmationController.addAction(cancelAction)

if let popoverController = confirmationController.popoverPresentationController {
popoverController.sourceView = self.view
popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
popoverController.permittedArrowDirections = []
}
self.present(confirmationController, animated: true)
}
}

// MARK: - Query Delegate
Expand Down Expand Up @@ -595,37 +536,3 @@ extension ClientQueryViewController: UISearchResultsUpdating {
self.present(presentViewController, animated: animated, completion: completionHandler)
}
}

// MARK: - ActionsToolBar Delegate
extension ClientQueryViewController : ActionsToolBarDelegate {

func actionsToolBar(_ toolbar: ActionsToolBar, copyButtonPressed: UIBarButtonItem?) {
print("Copy items pressed")
}

func actionsToolBar(_ toolbar: ActionsToolBar, shareButtonPressed: UIBarButtonItem?) {
print("Share items pressed")
}

func actionsToolBar(_ toolbar: ActionsToolBar, availableOfflineButtonPressed: UIBarButtonItem?) {
print("AvailableOffline items pressed")
}

func actionsToolBar(_ toolbar: ActionsToolBar, deleteButtonPressed: UIBarButtonItem?) {
if let selectedIndexPaths = self.tableView.indexPathsForSelectedRows {
self.deleteConfirmationActionSheet(title: "Multiple delete".localized, message: "Are you sure you want to delete the selected items from the server?".localized) {

for indexPath in selectedIndexPaths {
_ = self.core?.delete(self.items?[indexPath.row], requireMatch: true, resultHandler: { (error, _, _, _) in
if error != nil {
print("LOG ---> Error deleting some file \(error!)")
}
})
}
}
self.tableView.setEditing(false, animated: true)
self.actionsToolBar?.hide()

}
}
}
2 changes: 0 additions & 2 deletions ownCloud/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@
"Are you sure you want to delete this folder from the server?" = "Are you sure you want to delete this folder from the server?";
"Are you sure you want to delete this file from the server?" = "Are you sure you want to delete this file from the server?";
"Deleting..." = "Deleting...";
"Something wrong happened" = "Something wrong happened";
"Ok" = "Ok";

/* Server List*/
"Cancel" = "Cancel";
Expand Down

0 comments on commit 8e5d239

Please sign in to comment.