From 1252ad986470f2651a759f1a7566a67c5a1e3ada Mon Sep 17 00:00:00 2001 From: Femi Lamptey Date: Mon, 7 May 2018 12:51:41 +0000 Subject: [PATCH 1/2] Removed files in .trash from visualizations Checks if the filePath contains .Trash/ , and if it does, the FileInfo is not appended to the fileInfos array --- LocalStorage/Local Storage/Common.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/LocalStorage/Local Storage/Common.swift b/LocalStorage/Local Storage/Common.swift index 26320f5..b18a187 100644 --- a/LocalStorage/Local Storage/Common.swift +++ b/LocalStorage/Local Storage/Common.swift @@ -254,15 +254,17 @@ func addToType(name: String, size: Int64, path: String) { let documentsPathEndIndex = path.index(AppState.documentsPath.endIndex, offsetBy: 1) let filePath = String(path[documentsPathEndIndex...]) - AppState.types[n].size += size - AppState.types[n].number += 1 - AppState.types[n].paths.append(filePath) - AppState.types[n].sizes.append(size) + if filePath.name.range(of: ".Trash/") { + AppState.types[n].size += size + AppState.types[n].number += 1 + AppState.types[n].paths.append(filePath) + AppState.types[n].sizes.append(size) - AppState.files.allValues.append(Double(size)) - AppState.files.fileInfos.append(FileInfo(name: filePath, type: type_info.name)) + AppState.files.allValues.append(Double(size)) + AppState.files.fileInfos.append(FileInfo(name: filePath, type: type_info.name)) - break + break + } } } } From 106e2f5b1d4175e07ef583fd769cbfb83c6ca29f Mon Sep 17 00:00:00 2001 From: Femi Lamptey Date: Sat, 12 May 2018 21:17:27 +0000 Subject: [PATCH 2/2] Further improvements to removing files in ".Trash/" from visualizations Added a category for trash in the Types screen, and removed Types from visualizations. Also added scrolling for the FilesCollectionViewLayout. --- LocalStorage/Local Storage/AppDelegate.swift | 4 +- LocalStorage/Local Storage/Common.swift | 25 +++++--- .../Main/Base.lproj/Main.storyboard | 58 +++++++++---------- .../Main/Files/FilesViewController.swift | 3 +- 4 files changed, 51 insertions(+), 39 deletions(-) diff --git a/LocalStorage/Local Storage/AppDelegate.swift b/LocalStorage/Local Storage/AppDelegate.swift index aae75af..7ce27f9 100644 --- a/LocalStorage/Local Storage/AppDelegate.swift +++ b/LocalStorage/Local Storage/AppDelegate.swift @@ -207,6 +207,7 @@ struct LocalizedTypeNames { static var code = NSLocalizedString("type-code", value: "Code", comment: "Name of type") static var archives = NSLocalizedString("type-archives", value: "Archives", comment: "Name of type") static var other = NSLocalizedString("type-other", value: "Other", comment: "Name of type") + static var trash = NSLocalizedString("type-trash", value: "Trash", comment: "Name of type") } @@ -229,7 +230,8 @@ struct AppState { TypeInfo(name: LocalizedTypeNames.images, color: UIColor(named: "ColorTypeImages")!, size: 0, number: 0, paths: [], sizes: []), TypeInfo(name: LocalizedTypeNames.code, color: UIColor(named: "ColorTypeCode")!, size: 0, number: 0, paths: [], sizes: []), TypeInfo(name: LocalizedTypeNames.archives, color: UIColor(named: "ColorTypeArchives")!, size: 0, number: 0, paths: [], sizes: []), - TypeInfo(name: LocalizedTypeNames.other, color: UIColor(named: "ColorTypeOther")!, size: 0, number: 0, paths: [], sizes: []) + TypeInfo(name: LocalizedTypeNames.other, color: UIColor(named: "ColorTypeOther")!, size: 0, number: 0, paths: [], sizes: []), + TypeInfo(name: LocalizedTypeNames.trash, color: UIColor.magenta, size: 0, number: 0, paths: [], sizes: []) ] struct files { diff --git a/LocalStorage/Local Storage/Common.swift b/LocalStorage/Local Storage/Common.swift index b18a187..24138b9 100644 --- a/LocalStorage/Local Storage/Common.swift +++ b/LocalStorage/Local Storage/Common.swift @@ -229,7 +229,9 @@ func resetStats() { TypeInfo(name: LocalizedTypeNames.images, color: UIColor(named: "ColorTypeImages")!, size: 0, number: 0, paths: [], sizes: []), TypeInfo(name: LocalizedTypeNames.code, color: UIColor(named: "ColorTypeCode")!, size: 0, number: 0, paths: [], sizes: []), TypeInfo(name: LocalizedTypeNames.archives, color: UIColor(named: "ColorTypeArchives")!, size: 0, number: 0, paths: [], sizes: []), - TypeInfo(name: LocalizedTypeNames.other, color: UIColor(named: "ColorTypeOther")!, size: 0, number: 0, paths: [], sizes: [])] + TypeInfo(name: LocalizedTypeNames.other, color: UIColor(named: "ColorTypeOther")!, size: 0, number: 0, paths: [], sizes: []), + TypeInfo(name: LocalizedTypeNames.trash, color: UIColor.magenta, size: 0, number: 0, paths: [], sizes: []) + ] AppState.files.allValues = [] AppState.files.fileInfos = [] @@ -254,17 +256,22 @@ func addToType(name: String, size: Int64, path: String) { let documentsPathEndIndex = path.index(AppState.documentsPath.endIndex, offsetBy: 1) let filePath = String(path[documentsPathEndIndex...]) - if filePath.name.range(of: ".Trash/") { + if !filePath.contains(".Trash/") { AppState.types[n].size += size AppState.types[n].number += 1 AppState.types[n].paths.append(filePath) AppState.types[n].sizes.append(size) - + AppState.files.allValues.append(Double(size)) AppState.files.fileInfos.append(FileInfo(name: filePath, type: type_info.name)) - - break + } else { + AppState.types[n].size += size + AppState.types[n].number += 1 + AppState.types[n].paths.append(filePath) + AppState.types[n].sizes.append(size) } + + break } } } @@ -370,7 +377,9 @@ func getStats() { } if let fileType: String = elementURL.typeIdentifier { - if UtiLookup.audio.contains(fileType) { + if elementURL.absoluteString.contains(".Trash/") { + addToType(name: LocalizedTypeNames.trash, size: fileSize, path: elementURL.path) + } else if UtiLookup.audio.contains(fileType) { addToType(name: LocalizedTypeNames.audio, size: fileSize, path: elementURL.path) } else if UtiLookup.videos.contains(fileType) { addToType(name: LocalizedTypeNames.videos, size: fileSize, path: elementURL.path) @@ -384,7 +393,7 @@ func getStats() { addToType(name: LocalizedTypeNames.archives, size: fileSize, path: elementURL.path) } else if UtiLookup.other.contains(fileType) { addToType(name: LocalizedTypeNames.other, size: fileSize, path: elementURL.path) - } else { + } else { if fileType.starts(with: "dyn.") { // No UTI available for this file, use extension based lookup. Less stable but whatever. @@ -402,7 +411,7 @@ func getStats() { addToType(name: LocalizedTypeNames.code, size: fileSize, path: elementURL.path) } else if FileExtensionLookup.archives.contains(fileExtension) { addToType(name: LocalizedTypeNames.archives, size: fileSize, path: elementURL.path) - } else { + } else if elementURL.absoluteString.contains(".Trash/") { addToType(name: LocalizedTypeNames.other, size: fileSize, path: elementURL.path) } } else { diff --git a/LocalStorage/Local Storage/Main/Base.lproj/Main.storyboard b/LocalStorage/Local Storage/Main/Base.lproj/Main.storyboard index ac248bb..252bd07 100644 --- a/LocalStorage/Local Storage/Main/Base.lproj/Main.storyboard +++ b/LocalStorage/Local Storage/Main/Base.lproj/Main.storyboard @@ -1,6 +1,6 @@ - + @@ -16,7 +16,7 @@ - + @@ -33,7 +33,7 @@ - + @@ -49,11 +49,11 @@ - + - + @@ -392,7 +392,7 @@ - + - + - - + + - +