Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/delete #91

Merged
merged 3 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 103 additions & 64 deletions ownCloud/Client/ClientQueryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
//

/*
* Copyright (C) 2018, 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 <http://www.gnu.org/licenses/gpl-3.0.en.html>.
*
*/
* Copyright (C) 2018, 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 <http://www.gnu.org/licenses/gpl-3.0.en.html>.
*
*/

import UIKit
import ownCloudSDK
Expand Down Expand Up @@ -167,47 +167,47 @@ class ClientQueryViewController: UITableViewController, Themeable {
var summary : ProgressSummary = ProgressSummary(indeterminate: true, progress: 1.0, message: nil, progressCount: 1)

switch query?.state {
case .stopped?:
summary.message = "Stopped".localized
case .stopped?:
summary.message = "Stopped".localized

case .started?:
summary.message = "Started…".localized
case .started?:
summary.message = "Started…".localized

case .contentsFromCache?:
if core?.reachabilityMonitor?.available == true {
summary.message = "Contents from cache.".localized
} else {
summary.message = "Offline. Contents from cache.".localized
}
case .contentsFromCache?:
if core?.reachabilityMonitor?.available == true {
summary.message = "Contents from cache.".localized
} else {
summary.message = "Offline. Contents from cache.".localized
}

case .waitingForServerReply?:
summary.message = "Waiting for server response…".localized
case .waitingForServerReply?:
summary.message = "Waiting for server response…".localized

case .targetRemoved?:
summary.message = "This folder no longer exists.".localized
case .targetRemoved?:
summary.message = "This folder no longer exists.".localized

case .idle?:
summary.message = "Everything up-to-date.".localized
summary.progressCount = 0
case .idle?:
summary.message = "Everything up-to-date.".localized
summary.progressCount = 0

case .none:
summary.message = "Please wait…".localized
case .none:
summary.message = "Please wait…".localized
}

switch query?.state {
case .idle?:
DispatchQueue.main.async {
if !self.refreshController!.isRefreshing {
self.refreshController?.beginRefreshing()
}
case .idle?:
DispatchQueue.main.async {
if !self.refreshController!.isRefreshing {
self.refreshController?.beginRefreshing()
}
}

case .contentsFromCache?, .stopped?:
DispatchQueue.main.async {
self.tableView.refreshControl = nil
}
case .contentsFromCache?, .stopped?:
DispatchQueue.main.async {
self.tableView.refreshControl = nil
}

default:
default:
break
}

Expand Down Expand Up @@ -256,39 +256,78 @@ class ClientQueryViewController: UITableViewController, Themeable {
}

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

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

case .file:
let fallbackSummary = ProgressSummary(indeterminate: true, progress: 1.0, message: "Downloading \(rowItem.name)", progressCount: 1)
switch rowItem.type {
case .collection:
self.navigationController?.pushViewController(ClientQueryViewController(core: self.core!, query: OCQuery(forPath: rowItem.path)), animated: true)

if let downloadProgress = self.core?.downloadItem(rowItem, options: nil, resultHandler: { (error, _, item, file) in
OnMainThread {
if error != nil {
// TODO: Handle error
} else {
let itemViewController : ClientItemViewController = ClientItemViewController()
case .file:
let fallbackSummary = ProgressSummary(indeterminate: true, progress: 1.0, message: "Downloading \(rowItem.name!)", progressCount: 1)

itemViewController.file = file
itemViewController.item = item
if let downloadProgress = self.core?.downloadItem(rowItem, options: nil, resultHandler: { (error, _, item, file) in
OnMainThread {
if error != nil {
// TODO: Handle error
} else {
let itemViewController : ClientItemViewController = ClientItemViewController()

self.navigationController?.pushViewController(itemViewController, animated: true)
}
itemViewController.file = file
itemViewController.item = item

self.progressSummarizer?.popFallbackSummary(summary: fallbackSummary)
self.navigationController?.pushViewController(itemViewController, animated: true)
}
}) {
Log.log("Downloading \(rowItem.name): \(downloadProgress)")

progressSummarizer?.pushFallbackSummary(summary: fallbackSummary)

// TODO: Use progress as soon as it works SDK-wise
// progressSummarizer?.startTracking(progress: downloadProgress)
self.progressSummarizer?.popFallbackSummary(summary: fallbackSummary)
}
}) {
Log.log("Downloading \(rowItem.name!): \(downloadProgress)")

progressSummarizer?.pushFallbackSummary(summary: fallbackSummary)

// TODO: Use progress as soon as it works SDK-wise
// progressSummarizer?.startTracking(progress: downloadProgress)
}
}
}

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

guard let item: OCItem = items?[indexPath.row], core != nil else {
return nil
}

let presentationStyle: UIAlertControllerStyle = UIDevice.current.isIpad() ? UIAlertControllerStyle.alert : UIAlertControllerStyle.actionSheet

let deleteContextualAction: UIContextualAction = UIContextualAction(style: .destructive, title: "Delete".localized) { (_, _, actionPerformed) in

let alertController =
UIAlertController(with: item.name!,
message: "Are you sure you want to delete this file from the server?".localized,
destructiveLabel: "Delete".localized,
preferredStyle: presentationStyle,
destructiveAction: {
if let progress = self.core?.delete(item, requireMatch: true, resultHandler: { (error, _, _, _) in
if error != nil {
Log.log("Error \(String(describing: error)) deleting \(String(describing: item.path))")
}
}) {
self.progressSummarizer?.startTracking(progress: progress)
}
}
)

self.present(alertController, animated: true, completion: {
actionPerformed(false)
})
}
let actions: [UIContextualAction] = [deleteContextualAction]
let actionsConfigurator: UISwipeActionsConfiguration = UISwipeActionsConfiguration(actions: actions)

return actionsConfigurator
}

// MARK: - Message
Expand Down Expand Up @@ -336,10 +375,10 @@ class ClientQueryViewController: UITableViewController, Themeable {
containerView.addSubview(messageLabel)

containerView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[imageView]-(20)-[titleLabel]-[messageLabel]|",
options: NSLayoutFormatOptions(rawValue: 0),
metrics: nil,
views: ["imageView" : imageView, "titleLabel" : titleLabel, "messageLabel" : messageLabel])
)
options: NSLayoutFormatOptions(rawValue: 0),
metrics: nil,
views: ["imageView" : imageView, "titleLabel" : titleLabel, "messageLabel" : messageLabel])
)

imageView.centerXAnchor.constraint(equalTo: containerView.centerXAnchor).isActive = true
imageView.widthAnchor.constraint(equalToConstant: 96).isActive = true
Expand Down
2 changes: 2 additions & 0 deletions ownCloud/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@

"Folder removed" = "Folder removed";
"This folder no longer exists on the server." = "This folder no longer exists on 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 '%@'";

/* Server List*/
"Cancel" = "Cancel";
Expand Down
20 changes: 9 additions & 11 deletions ownCloud/Theming/TVG/TVGImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
//

/*
* Copyright (C) 2018, 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 <http://www.gnu.org/licenses/gpl-3.0.en.html>.
*
*/
* Copyright (C) 2018, 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 <http://www.gnu.org/licenses/gpl-3.0.en.html>.
*
*/

import UIKit
import PocketSVG
Expand Down Expand Up @@ -103,9 +103,7 @@ class TVGImage: NSObject {
return nil
}

guard let bezierPaths : [SVGBezierPath] = SVGBezierPath.paths(fromSVGString: svgString) as? [SVGBezierPath] else {
return nil
}
let bezierPaths : [SVGBezierPath] = SVGBezierPath.paths(fromSVGString: svgString)

svgBezierPaths = bezierPaths

Expand Down
18 changes: 9 additions & 9 deletions ownCloud/Tools/Log.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
//

/*
* Copyright (C) 2018, 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 <http://www.gnu.org/licenses/gpl-3.0.en.html>.
*
*/
* Copyright (C) 2018, 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 <http://www.gnu.org/licenses/gpl-3.0.en.html>.
*
*/

import UIKit

Expand Down Expand Up @@ -46,6 +46,6 @@ class Log {
}

static func mask(_ obj: Any?) -> Any {
return (OCLogger.shared.applyPrivacyMask(obj))
return (OCLogger.shared.applyPrivacyMask(obj))!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import ownCloudSDK
extension OCConnectionIssueChoice {
var alertActionStyle : UIAlertActionStyle {
switch type {
case .cancel:
return .cancel

case .regular, .default:
return .default

case .destructive:
return .destructive
case .cancel:
return .cancel
case .regular, .default:
return .default
case .destructive:
return .destructive
}
}
}
Expand All @@ -35,4 +33,17 @@ extension UIAlertController {
}))
}
}

convenience init(with title: String, message: String, cancelLabel: String = "Cancel".localized, destructiveLabel: String, preferredStyle: UIAlertControllerStyle, destructiveAction action: @escaping () -> Void) {

self.init(title: title, message: message, preferredStyle: preferredStyle)

let cancelAction = UIAlertAction(title: cancelLabel, style: .cancel, handler: nil)
let destructiveAction = UIAlertAction(title: destructiveLabel, style: .destructive) { (_) in
action()
}

self.addAction(destructiveAction)
self.addAction(cancelAction)
}
}