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

Clear storage #376

Merged
merged 9 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 8 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
10 changes: 9 additions & 1 deletion ownCloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
4C6B78102226B83300C5F3DB /* PhotoAlbumTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C6B780F2226B83300C5F3DB /* PhotoAlbumTableViewController.swift */; };
4C6B78122226B86300C5F3DB /* PhotoAlbumTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C6B78112226B86300C5F3DB /* PhotoAlbumTableViewCell.swift */; };
4C80B1E62271BBB400252901 /* PhotoUploadSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C80B1E52271BBB400252901 /* PhotoUploadSection.swift */; };
4CAF783C2282FD40000C85CF /* FileManager+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CAF783B2282FD40000C85CF /* FileManager+Extension.swift */; };
4CC46D212284C677009E938F /* BookmarkInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CC46D202284C677009E938F /* BookmarkInfoViewController.swift */; };
4CF8CAB121F9B70600B8CA67 /* UIBarButtonItem+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CF8CAB021F9B70500B8CA67 /* UIBarButtonItem+Extension.swift */; };
5917244E20D3DC2100809B38 /* BiometricalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5917244D20D3DC2100809B38 /* BiometricalTests.swift */; };
593A821120C7D4C5000E2A90 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 593A821320C7D4C5000E2A90 /* Localizable.strings */; };
Expand Down Expand Up @@ -509,6 +511,8 @@
4C6B780F2226B83300C5F3DB /* PhotoAlbumTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoAlbumTableViewController.swift; sourceTree = "<group>"; };
4C6B78112226B86300C5F3DB /* PhotoAlbumTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoAlbumTableViewCell.swift; sourceTree = "<group>"; };
4C80B1E52271BBB400252901 /* PhotoUploadSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoUploadSection.swift; sourceTree = "<group>"; };
4CAF783B2282FD40000C85CF /* FileManager+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+Extension.swift"; sourceTree = "<group>"; };
4CC46D202284C677009E938F /* BookmarkInfoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkInfoViewController.swift; sourceTree = "<group>"; };
4CF8CAB021F9B70500B8CA67 /* UIBarButtonItem+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIBarButtonItem+Extension.swift"; sourceTree = "<group>"; };
5917244D20D3DC2100809B38 /* BiometricalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BiometricalTests.swift; sourceTree = "<group>"; };
593A821220C7D4C5000E2A90 /* en */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; lineEnding = 0; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1340,6 +1344,7 @@
children = (
23031768205AA1DB006C4DAF /* Issues */,
DC1B270B209CF34B004715E1 /* BookmarkViewController.swift */,
4CC46D202284C677009E938F /* BookmarkInfoViewController.swift */,
);
path = Bookmarks;
sourceTree = "<group>";
Expand Down Expand Up @@ -1393,6 +1398,7 @@
23E22BB220C6A5C40024D11E /* UIDevice+UIUserInterfaceIdiom.swift */,
DC85493321831B0B00782BA8 /* Tools.swift */,
DCB44D86218718BA00DAA4CC /* VendorServices.swift */,
4CAF783B2282FD40000C85CF /* FileManager+Extension.swift */,
);
path = Tools;
sourceTree = "<group>";
Expand Down Expand Up @@ -1944,7 +1950,8 @@
232B01F62126B10900366FA0 /* MoreStaticTableViewController.swift in Sources */,
6E91F37E21ECA6FD009436D2 /* CopyAction.swift in Sources */,
593BAB97209F8A0500023634 /* AppLockManager.swift in Sources */,
6E5FC172221590B000F60846 /* DisplayHostViewController.swift in Sources */,
4CC46D212284C677009E938F /* BookmarkInfoViewController.swift in Sources */,
6E5FC172221590B000F60846 /* GalleryHostViewController.swift in Sources */,
DC85493421831B0B00782BA8 /* Tools.swift in Sources */,
DCFED972208095E200A2D984 /* ClientItemCell.swift in Sources */,
3998F5D522411EDF00B66713 /* BorderedLabel.swift in Sources */,
Expand All @@ -1969,6 +1976,7 @@
DC3BE0DE2077CC14002A0AC0 /* ClientQueryViewController.swift in Sources */,
4C1561EF22232357009C4EF3 /* PhotoSelectionViewCell.swift in Sources */,
23C56538212167BE00BD4B47 /* CardTransitionDelegate.swift in Sources */,
4CAF783C2282FD40000C85CF /* FileManager+Extension.swift in Sources */,
6E3A104D219D6F0100F90C96 /* DuplicateAction.swift in Sources */,
DC1B270A209CF0D3004715E1 /* ConnectionIssueViewController.swift in Sources */,
DC0B37972051681600189B9A /* ThemeButton.swift in Sources */,
Expand Down
121 changes: 121 additions & 0 deletions ownCloud/Bookmarks/BookmarkInfoViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//
// BookmarkInfoViewController
// ownCloud
//
// Created by Michael Neuwert on 09.05.19.
// Copyright © 2018 ownCloud GmbH. All rights reserved.
//

/*
* 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
import ownCloudUI

class BookmarkInfoViewController: StaticTableViewController {
var storageSection : StaticTableViewSection?
var offlineStorageInfoRow: StaticTableViewRow?
var deviceAvailableStorageInfoRow: StaticTableViewRow?
var deleteLocalFilesRow : StaticTableViewRow?

var bookmark : OCBookmark?

lazy var byteCounterFormatter: ByteCountFormatter = {
let formatter = ByteCountFormatter()
formatter.allowsNonnumericFormatting = false
return formatter
}()

// MARK: - Init & Deinit
init(_ bookmark: OCBookmark?) {
// Super init
super.init(style: .grouped)
self.bookmark = bookmark

offlineStorageInfoRow = StaticTableViewRow(valueRowWithAction: nil, title: "Offline files use".localized, value: "uknown".localized)
let deviceFreeTitle = String(format: "Free on %@".localized, UIDevice.current.name)
deviceAvailableStorageInfoRow = StaticTableViewRow(valueRowWithAction: nil, title: deviceFreeTitle, value: "uknown".localized)

deleteLocalFilesRow = StaticTableViewRow(buttonWithAction: { [weak self] (_, _) in
if let bookmark = self?.bookmark {

OCCoreManager.shared.scheduleOfflineOperation({ (bookmark, completionHandler) in
let vault : OCVault = OCVault(bookmark: bookmark)

vault.compact(completionHandler: { (_, error) in
OnMainThread {
if error != nil {
// Inform user if vault couldn't be comp acted
let alertController = UIAlertController(title: NSString(format: "Compacting of '%@' failed".localized as NSString, bookmark.shortName as NSString) as String,
message: error?.localizedDescription,
preferredStyle: .alert)

alertController.addAction(UIAlertAction(title: "OK".localized, style: .default, handler: nil))

self?.present(alertController, animated: true, completion: nil)
}

self?.updateStorageInfo()

completionHandler()
}
})
}, for: bookmark)
}
}, title: "Delete Offline Copies".localized, style: .destructive, identifier: "row-offline-copies-delete")

storageSection = StaticTableViewSection(headerTitle: "Storage".localized, footerTitle: nil, identifier: "section-credentials", rows: [ offlineStorageInfoRow!, deviceAvailableStorageInfoRow!, deleteLocalFilesRow! ])

self.insertSection(storageSection!, at: 0, animated: false)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - View controller events

override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "Manage".localized
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(BookmarkInfoViewController.userActionDone))
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
updateStorageInfo()
}

// MARK: - User actions
@objc func userActionDone() {
self.presentingViewController?.dismiss(animated: true, completion: nil)
}

// MARK: - Helper methods
private func updateStorageInfo() {
if bookmark != nil {
if let vaultURL = OCVault(bookmark: bookmark!).filesRootURL {
FileManager.default.calculateDirectorySize(at: vaultURL) { (size) in
if size != nil {
let occupiedSpace = self.byteCounterFormatter.string(fromByteCount: size!)
OnMainThread {
self.offlineStorageInfoRow?.value = occupiedSpace
}
}
}
}
}
let deviceFreeByteCount = FileManager.default.availableFreeStorageSpace()
if deviceFreeByteCount >= 0 {
deviceAvailableStorageInfoRow?.value = self.byteCounterFormatter.string(fromByteCount: deviceFreeByteCount)
}
}
}
8 changes: 8 additions & 0 deletions ownCloud/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,11 @@
"Uploading %ld of %ld files…" = "Uploading %ld of %ld files…";
"Downloading %ld of %ld files…" = "Downloading %ld of %ld files…";
"Updating %ld of %ld items…" = "Updating %ld of %ld items…";

/* Offline storage management */
"Free on %@" = "Free on %@";
"unknown" = "unknown";
"Offline files use" = "Offline files use";
"Compacting of '%@' failed" = "Compacting of '%@' failed";
"Delete Offline Copies" = "Delete Offline Copies";
"Manage" = "Manage";
122 changes: 71 additions & 51 deletions ownCloud/Server List/ServerListTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ class ServerListTableViewController: UITableViewController, Themeable {
self.present(navigationController, animated: true, completion: nil)
}

func showBookmarkInfoUI(_ bookmark: OCBookmark) {
let viewController = BookmarkInfoViewController(bookmark)
let navigationController : ThemeNavigationController = ThemeNavigationController(rootViewController: viewController)

// Prevent any in-progress connection from being shown
resetPreviousBookmarkSelection()

self.present(navigationController, animated: true, completion: nil)
}

var themeCounter : Int = 0

@IBAction func help() {
Expand Down Expand Up @@ -377,73 +387,83 @@ class ServerListTableViewController: UITableViewController, Themeable {
}

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
return [
UITableViewRowAction(style: .destructive, title: "Delete".localized, handler: { (_, indexPath) in
if let bookmark = OCBookmarkManager.shared.bookmark(at: UInt(indexPath.row)) {
var presentationStyle: UIAlertController.Style = .actionSheet
if UIDevice.current.isIpad() {
presentationStyle = .alert
}

let alertController = UIAlertController(title: NSString(format: "Really delete '%@'?".localized as NSString, bookmark.shortName) as String,
message: "This will also delete all locally stored file copies.".localized,
preferredStyle: presentationStyle)
let deleteRowAction = UITableViewRowAction(style: .destructive, title: "Delete".localized, handler: { (_, indexPath) in
if let bookmark = OCBookmarkManager.shared.bookmark(at: UInt(indexPath.row)) {
var presentationStyle: UIAlertController.Style = .actionSheet
if UIDevice.current.isIpad() {
presentationStyle = .alert
}

alertController.addAction(UIAlertAction(title: "Cancel".localized, style: .cancel, handler: nil))
let alertController = UIAlertController(title: NSString(format: "Really delete '%@'?".localized as NSString, bookmark.shortName) as String,
message: "This will also delete all locally stored file copies.".localized,
preferredStyle: presentationStyle)

alertController.addAction(UIAlertAction(title: "Delete".localized, style: .destructive, handler: { (_) in
alertController.addAction(UIAlertAction(title: "Cancel".localized, style: .cancel, handler: nil))

self.lockedBookmarks.append(bookmark)
alertController.addAction(UIAlertAction(title: "Delete".localized, style: .destructive, handler: { (_) in

OCCoreManager.shared.scheduleOfflineOperation({ (bookmark, completionHandler) in
let vault : OCVault = OCVault(bookmark: bookmark)
self.lockedBookmarks.append(bookmark)

vault.erase(completionHandler: { (_, error) in
OnMainThread {
if error != nil {
// Inform user if vault couldn't be erased
let alertController = UIAlertController(title: NSString(format: "Deletion of '%@' failed".localized as NSString, bookmark.shortName as NSString) as String,
message: error?.localizedDescription,
preferredStyle: .alert)
OCCoreManager.shared.scheduleOfflineOperation({ (bookmark, completionHandler) in
let vault : OCVault = OCVault(bookmark: bookmark)

alertController.addAction(UIAlertAction(title: "OK".localized, style: .default, handler: nil))
vault.erase(completionHandler: { (_, error) in
OnMainThread {
if error != nil {
// Inform user if vault couldn't be erased
let alertController = UIAlertController(title: NSString(format: "Deletion of '%@' failed".localized as NSString, bookmark.shortName as NSString) as String,
message: error?.localizedDescription,
preferredStyle: .alert)

self.present(alertController, animated: true, completion: nil)
} else {
// Success! We can now remove the bookmark
self.ignoreServerListChanges = true
alertController.addAction(UIAlertAction(title: "OK".localized, style: .default, handler: nil))

OCBookmarkManager.shared.removeBookmark(bookmark)
self.present(alertController, animated: true, completion: nil)
} else {
// Success! We can now remove the bookmark
self.ignoreServerListChanges = true

tableView.performBatchUpdates({
tableView.deleteRows(at: [indexPath], with: UITableView.RowAnimation.fade)
}, completion: { (_) in
self.ignoreServerListChanges = false
})
OCBookmarkManager.shared.removeBookmark(bookmark)

self.updateNoServerMessageVisibility()
}
tableView.performBatchUpdates({
tableView.deleteRows(at: [indexPath], with: UITableView.RowAnimation.fade)
}, completion: { (_) in
self.ignoreServerListChanges = false
})

if let removeIndex = self.lockedBookmarks.index(of: bookmark) {
self.lockedBookmarks.remove(at: removeIndex)
}
self.updateNoServerMessageVisibility()
}

completionHandler()
if let removeIndex = self.lockedBookmarks.index(of: bookmark) {
self.lockedBookmarks.remove(at: removeIndex)
}
})
}, for: bookmark)
}))

self.present(alertController, animated: true, completion: nil)
}
}),
completionHandler()
}
})
}, for: bookmark)
}))

UITableViewRowAction(style: .normal, title: "Edit".localized, handler: { [weak self] (_, indexPath) in
if let bookmark = OCBookmarkManager.shared.bookmark(at: UInt(indexPath.row)) {
self?.showBookmarkUI(edit: bookmark)
}
})
]
self.present(alertController, animated: true, completion: nil)
}
})

let editRowAction = UITableViewRowAction(style: .normal, title: "Edit".localized, handler: { [weak self] (_, indexPath) in
if let bookmark = OCBookmarkManager.shared.bookmark(at: UInt(indexPath.row)) {
self?.showBookmarkUI(edit: bookmark)
}
})
editRowAction.backgroundColor = .blue

let manageRowAction = UITableViewRowAction(style: .normal,
title: "Manage".localized,
handler: { [weak self] (_, indexPath) in
if let bookmark = OCBookmarkManager.shared.bookmark(at: UInt(indexPath.row)) {
self?.showBookmarkInfoUI(bookmark)
}
})

return [deleteRowAction, editRowAction, manageRowAction]
}

override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
Expand Down
2 changes: 1 addition & 1 deletion ownCloud/Settings/UserInterfaceSettingsSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class UserInterfaceSettingsSection: SettingsSection {

themeRow = StaticTableViewRow(valueRowWithAction: { [weak self] (_, _) in
self?.pushThemeStyleSelector()
}, title: "Theme".localized, value: ThemeStyle.preferredStyle.localizedName)
}, title: "Theme".localized, value: ThemeStyle.preferredStyle.localizedName, accessoryType: .disclosureIndicator)

self.add(row: themeRow!)

Expand Down
Loading