Skip to content

Commit

Permalink
Show the used quota inside the app (#337)
Browse files Browse the repository at this point in the history
* First implementation of quota displaying

* Showing quota as table view footer for root folder

For sub-folders total space occupied by it’s items is shown

* Changed SDK version and setting quota label only once

* Updated SDK version

* Quota information is retrieved through KVO from OCCore properties

* Updated to SDK with merged master changes

* Fix for negative </d:quota-available-bytes>

* Fixed total quota calculation

* Removed a hack to keep navigation bar prompt in the same color as title

* - Update ios-sdk
- Update ClientQueryViewController to updated OCCore.rootQuota property layout
- Make the footer show always (fixes issues where new accounts would first show separator lines - and then suddenly get replaced with the quota)
- Make quota label use correct color (the previous was unreadable with the Classic theme)

* link against newest ios sdk
  • Loading branch information
mneuwert authored and hosy committed Apr 4, 2019
1 parent 82c42ec commit 6583d9f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 10 deletions.
70 changes: 61 additions & 9 deletions ownCloud/Client/ClientQueryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ class ClientQueryViewController: UITableViewController, Themeable, UIDropInterac

var selectBarButton: UIBarButtonItem?
var uploadBarButton: UIBarButtonItem?

var selectDeselectAllButtonItem: UIBarButtonItem?
var exitMultipleSelectionBarButtonItem: UIBarButtonItem?

var quotaLabel = UILabel()
var quotaObservation : NSKeyValueObservation?

// MARK: - Init & Deinit
public init(core inCore: OCCore, query inQuery: OCQuery) {

Expand All @@ -76,18 +78,41 @@ class ClientQueryViewController: UITableViewController, Themeable, UIDropInterac
query.addObserver(self, forKeyPath: "state", options: .initial, context: nil)
core?.start(query)

var title : String?
let lastPathComponent = (query.queryPath as NSString?)!.lastPathComponent

if lastPathComponent == "/", let shortName = core?.bookmark.shortName {
self.navigationItem.title = shortName
} else {
self.navigationItem.title = lastPathComponent
}

if lastPathComponent == "/" {
quotaObservation = core?.observe(\OCCore.rootQuotaBytesUsed, options: [.initial], changeHandler: { [weak self, core] (_, _) in
let quotaUsed = core?.rootQuotaBytesUsed?.int64Value ?? 0

if let queryTitle = (query.queryPath as NSString?)?.lastPathComponent {
title = queryTitle
OnMainThread {
var footerText: String?

if quotaUsed > 0 {

let byteCounterFormatter = ByteCountFormatter()
byteCounterFormatter.allowsNonnumericFormatting = false

if title == "/" {
if let shortName = core?.bookmark.shortName {
title = shortName
let quotaUsedFormatted = byteCounterFormatter.string(fromByteCount: quotaUsed)

// A rootQuotaBytesRemaining value of nil indicates that no quota has been set
if core?.rootQuotaBytesRemaining != nil, let quotaTotal = core?.rootQuotaBytesTotal?.int64Value {
let quotaTotalFormatted = byteCounterFormatter.string(fromByteCount: quotaTotal )
footerText = String(format: "%@ of %@ used".localized, quotaUsedFormatted, quotaTotalFormatted)
} else {
footerText = String(format: "Total: %@".localized, quotaUsedFormatted)
}
}

self?.updateFooter(text: footerText)
}
}
})
}
self.navigationItem.title = title
}

required init?(coder aDecoder: NSCoder) {
Expand All @@ -106,6 +131,8 @@ class ClientQueryViewController: UITableViewController, Themeable, UIDropInterac
}

self.queryProgressSummary = nil

quotaObservation = nil
}

// MARK: - Actions
Expand Down Expand Up @@ -191,6 +218,10 @@ class ClientQueryViewController: UITableViewController, Themeable, UIDropInterac
openMultipleBarButtonItem?.isEnabled = false

self.addThemableBackgroundView()

quotaLabel.textAlignment = .center
quotaLabel.font = UIFont.systemFont(ofSize: UIFont.smallSystemFontSize)
quotaLabel.numberOfLines = 0
}

private var viewControllerVisible : Bool = false
Expand Down Expand Up @@ -219,6 +250,19 @@ class ClientQueryViewController: UITableViewController, Themeable, UIDropInterac
self.reloadTableData(ifNeeded: true)
}

private func updateFooter(text:String?) {
let labelText = text ?? ""

// Resize quota label
self.quotaLabel.text = labelText
self.quotaLabel.sizeToFit()
var frame = self.quotaLabel.frame
// Width is ignored and set by the UITableView when assigning to tableFooterView property
frame.size.height = floor(self.quotaLabel.frame.size.height * 2.0)
quotaLabel.frame = frame
self.tableView.tableFooterView = quotaLabel
}

func updateQueryProgressSummary() {
var summary : ProgressSummary = ProgressSummary(indeterminate: true, progress: 1.0, message: nil, progressCount: 1)

Expand Down Expand Up @@ -270,6 +314,7 @@ class ClientQueryViewController: UITableViewController, Themeable, UIDropInterac

func applyThemeCollection(theme: Theme, collection: ThemeCollection, event: ThemeEvent) {
self.tableView.applyThemeCollection(collection)
self.quotaLabel.textColor = collection.tableRowColors.secondaryLabelColor
self.searchController?.searchBar.applyThemeCollection(collection)
if event == .update {
self.reloadTableData()
Expand Down Expand Up @@ -958,6 +1003,13 @@ extension ClientQueryViewController : OCQueryDelegate {
default:
self.message(show: false)
}

if let rootItem = self.query.rootItem {
if query.queryPath != "/" {
let totalSize = String(format: "Total: %@".localized, rootItem.sizeLocalized)
self.updateFooter(text: totalSize)
}
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions ownCloud/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
"Search this folder" = "Search this folder";
"Pending" = "Pending";

"%@ of %@ used" = "%@ of %@ used";
"Total: %@" = "Total: %@";

/* Client Messages */
"Empty folder" = "Empty folder";
"This folder contains no files or folders." = "This folder contains no files or folders.";
Expand Down

0 comments on commit 6583d9f

Please sign in to comment.