Skip to content

Commit

Permalink
Merge pull request wordpress-mobile#18636 from wordpress-mobile/featu…
Browse files Browse the repository at this point in the history
…re/11925

App Settings Cleanup i
  • Loading branch information
mindgraffiti authored May 26, 2022
2 parents 00fb843 + 0a021c0 commit 32af0f3
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 24 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
20.0
-----
* [*] Quick Start: The "Get to know the WordPress app" card has a fresh new look [#18688]
* [*] App Settings: refreshed the UI with updated colors for Media Cache Size controls, Clear Spot Index row button, and Clear Siri Shortcut Suggestions row button. From destructive (red color) to standard and brand colors. [#18636]
* [*] [internal] Quick Start: Fixed an issue where the Quick Start modal was not displayed after login if the user's default tab is Home. [#18721]
* [*] Quick Start: The Next Steps modal has a fresh new look [#18711]

Expand Down
31 changes: 31 additions & 0 deletions WordPress/Classes/Utility/WPImmuTableRows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,37 @@ struct LinkWithValueRow: ImmuTableRow {
}
}

/// Create a row that navigates to a new ViewController.
/// Uses the WordPress branded blue and is left aligned.
///
struct BrandedNavigationRow: ImmuTableRow {
static let cell = ImmuTableCell.class(WPTableViewCellIndicator.self)

let title: String
let showIndicator: Bool
let action: ImmuTableAction?
let accessibilityIdentifier: String?

init(title: String, action: @escaping ImmuTableAction, showIndicator: Bool = false, accessibilityIdentifier: String? = nil) {
self.title = title
self.showIndicator = showIndicator
self.action = action
self.accessibilityIdentifier = accessibilityIdentifier
}

func configureCell(_ cell: UITableViewCell) {
guard let cell = cell as? WPTableViewCellIndicator else {
return
}
cell.textLabel?.text = title
WPStyleGuide.configureTableViewCell(cell)
cell.textLabel?.textColor = .primary
cell.showIndicator = showIndicator
cell.accessibilityTraits = .button
cell.accessibilityIdentifier = accessibilityIdentifier
}
}

struct ButtonRow: ImmuTableRow {
static let cell = ImmuTableCell.class(WPTableViewCellDefault.self)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class AppSettingsViewController: UITableViewController {
super.viewDidLoad()

ImmuTable.registerRows([
BrandedNavigationRow.self,
DestructiveButtonRow.self,
TextRow.self,
ImageSizingRow.self,
Expand Down Expand Up @@ -132,17 +133,6 @@ class AppSettingsViewController: UITableViewController {
}
}

fileprivate func clearMediaCache() {
WPAnalytics.track(.appSettingsClearMediaCacheTapped)

setMediaCacheRowDescription(status: .clearingCache)
MediaFileManager.clearAllMediaCacheFiles(onCompletion: { [weak self] in
self?.updateMediaCacheSize()
}, onError: { [weak self] (error) in
self?.updateMediaCacheSize()
})
}

// MARK: - Actions

@objc func imageSizeChanged() -> (Int) -> Void {
Expand Down Expand Up @@ -199,6 +189,13 @@ class AppSettingsViewController: UITableViewController {
}
}

func openMediaCacheSettings() -> ImmuTableAction {
return { [weak self] _ in
let controller = MediaCacheSettingsViewController(style: .insetGrouped)
self?.navigationController?.pushViewController(controller, animated: true)
}
}

@objc func mediaRemoveLocationChanged() -> (Bool) -> Void {
return { value in
MediaSettings().removeLocationSetting = value
Expand Down Expand Up @@ -427,23 +424,17 @@ private extension AppSettingsViewController {
detail: MediaSettings().maxVideoSizeSetting.description,
action: pushVideoResolutionSettings())

let mediaCacheRow = TextRow(title: NSLocalizedString("Media Cache Size", comment: "Label for size of media cache in the app."),
value: mediaCacheRowDescription)

let mediaClearCacheRow = DestructiveButtonRow(
title: NSLocalizedString("Clear Device Media Cache", comment: "Label for button that clears all media cache."),
action: { [weak self] row in
self?.clearMediaCache()
},
accessibilityIdentifier: "mediaClearCacheButton")
let mediaCacheRow = NavigationItemRow(
title: NSLocalizedString("Media Cache", comment: "Label for the media cache navigation row in the app."),
detail: mediaCacheRowDescription,
action: openMediaCacheSettings())

return ImmuTableSection(
headerText: mediaHeader,
rows: [
imageSizingRow,
videoSizingRow,
mediaCacheRow,
mediaClearCacheRow
mediaCacheRow
],
footerText: NSLocalizedString("Free up storage space on this device by deleting temporary media files. This will not affect the media on your site.",
comment: "Explanatory text for clearing device media cache.")
Expand All @@ -464,7 +455,7 @@ private extension AppSettingsViewController {
action: openPrivacySettings()
)

let spotlightClearCacheRow = DestructiveButtonRow(
let spotlightClearCacheRow = BrandedNavigationRow(
title: NSLocalizedString("Clear Spotlight Index", comment: "Label for button that clears the spotlight index on device."),
action: clearSpotlightCache(),
accessibilityIdentifier: "spotlightClearCacheButton")
Expand All @@ -475,7 +466,7 @@ private extension AppSettingsViewController {
]

if #available(iOS 12.0, *) {
let siriClearCacheRow = DestructiveButtonRow(
let siriClearCacheRow = BrandedNavigationRow(
title: NSLocalizedString("Siri Reset Prompt", value: "Clear Siri Shortcut Suggestions", comment: "Label for button that clears user activities donated to Siri."),
action: clearSiriActivityDonations(),
accessibilityIdentifier: "spotlightClearCacheButton")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import Foundation

class MediaCacheSettingsViewController: UITableViewController {
fileprivate var handler: ImmuTableViewHandler?

override init(style: UITableView.Style) {
super.init(style: .insetGrouped)
handler = ImmuTableViewHandler(takeOver: self)
navigationItem.title = NSLocalizedString("Media Cache", comment: "Media Cache title")
}

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

required convenience init() {
self.init(style: .plain)
}

override func viewDidLoad() {
super.viewDidLoad()

ImmuTable.registerRows([
TextRow.self,
BrandedNavigationRow.self
], tableView: self.tableView)

reloadViewModel()

WPStyleGuide.configureColors(view: view, tableView: tableView)
WPStyleGuide.configureAutomaticHeightRows(for: tableView)
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateMediaCacheSize()
}

// MARK: - Model mapping

fileprivate func reloadViewModel() {
handler?.viewModel = tableViewModel()
}

func tableViewModel() -> ImmuTable {
let mediaCacheRow = TextRow(
title: NSLocalizedString("Media Cache Size",
comment: "Label for size of media cache in the app."),
value: mediaCacheRowDescription)

let mediaClearCacheRow = BrandedNavigationRow(
title: NSLocalizedString("Clear Device Media Cache",
comment: "Label for button that clears all media cache."),
action: { [weak self] row in
self?.clearMediaCache()
},
accessibilityIdentifier: "mediaClearCacheButton")

return ImmuTable(sections: [
ImmuTableSection(rows: [
mediaCacheRow
]),
ImmuTableSection(rows: [
mediaClearCacheRow
]),
])
}

// MARK: - Media cache methods

fileprivate enum MediaCacheSettingsStatus {
case calculatingSize
case clearingCache
case unknown
case empty
}

fileprivate var mediaCacheRowDescription = "" {
didSet {
reloadViewModel()
}
}

fileprivate func setMediaCacheRowDescription(allocatedSize: Int64?) {
guard let allocatedSize = allocatedSize else {
setMediaCacheRowDescription(status: .unknown)
return
}
if allocatedSize == 0 {
setMediaCacheRowDescription(status: .empty)
return
}
mediaCacheRowDescription = ByteCountFormatter.string(fromByteCount: allocatedSize, countStyle: ByteCountFormatter.CountStyle.file)
}

fileprivate func setMediaCacheRowDescription(status: MediaCacheSettingsStatus) {
switch status {
case .clearingCache:
mediaCacheRowDescription = NSLocalizedString("Clearing...", comment: "Label for size of media while it's being cleared.")
case .calculatingSize:
mediaCacheRowDescription = NSLocalizedString("Calculating...", comment: "Label for size of media while it's being calculated.")
case .unknown:
mediaCacheRowDescription = NSLocalizedString("Unknown", comment: "Label for size of media when it's not possible to calculate it.")
case .empty:
mediaCacheRowDescription = NSLocalizedString("Empty", comment: "Label for size of media when the cache is empty.")
}
}

fileprivate func updateMediaCacheSize() {
setMediaCacheRowDescription(status: .calculatingSize)
MediaFileManager.calculateSizeOfMediaDirectories { [weak self] (allocatedSize) in
self?.setMediaCacheRowDescription(allocatedSize: allocatedSize)
}
}

fileprivate func clearMediaCache() {
WPAnalytics.track(.appSettingsClearMediaCacheTapped)

setMediaCacheRowDescription(status: .clearingCache)
MediaFileManager.clearAllMediaCacheFiles(onCompletion: { [weak self] in
self?.updateMediaCacheSize()
}, onError: { [weak self] (error) in
self?.updateMediaCacheSize()
})
}
}
6 changes: 6 additions & 0 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,8 @@
CE39E17320CB117B00CABA05 /* RemoteBlog+Capabilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE39E17120CB117B00CABA05 /* RemoteBlog+Capabilities.swift */; };
CE46018B21139E8300F242B6 /* FooterTextContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE46018A21139E8300F242B6 /* FooterTextContent.swift */; };
CEBD3EAB0FF1BA3B00C1396E /* Blog.m in Sources */ = {isa = PBXBuildFile; fileRef = CEBD3EAA0FF1BA3B00C1396E /* Blog.m */; };
CECEEB552823164800A28ADE /* MediaCacheSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CECEEB542823164800A28ADE /* MediaCacheSettingsViewController.swift */; };
CECEEB562823164800A28ADE /* MediaCacheSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CECEEB542823164800A28ADE /* MediaCacheSettingsViewController.swift */; };
D8071631203DA23700B32FD9 /* Accessible.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8071630203DA23700B32FD9 /* Accessible.swift */; };
D809E686203F0215001AA0DE /* ReaderPostCardCellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D809E685203F0215001AA0DE /* ReaderPostCardCellTests.swift */; };
D80BC79C207464D200614A59 /* MediaLibraryMediaPickingCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D80BC79B207464D200614A59 /* MediaLibraryMediaPickingCoordinator.swift */; };
Expand Down Expand Up @@ -7167,6 +7169,7 @@
CE907AFD25F97D2A007E7654 /* WordPress 115.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 115.xcdatamodel"; sourceTree = "<group>"; };
CEBD3EA90FF1BA3B00C1396E /* Blog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Blog.h; sourceTree = "<group>"; };
CEBD3EAA0FF1BA3B00C1396E /* Blog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Blog.m; sourceTree = "<group>"; };
CECEEB542823164800A28ADE /* MediaCacheSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaCacheSettingsViewController.swift; sourceTree = "<group>"; };
CF343E897B9953453334768C /* Pods-WordPressHomeWidgetToday.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressHomeWidgetToday.release.xcconfig"; path = "../Pods/Target Support Files/Pods-WordPressHomeWidgetToday/Pods-WordPressHomeWidgetToday.release.xcconfig"; sourceTree = "<group>"; };
D1216A69ECC61E7772AB8C41 /* Pods-WordPressThisWeekWidget.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressThisWeekWidget.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-WordPressThisWeekWidget/Pods-WordPressThisWeekWidget.debug.xcconfig"; sourceTree = "<group>"; };
D61CEAC1CB25AE65B26BDC68 /* Pods-WordPressShareExtension.release-alpha.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressShareExtension.release-alpha.xcconfig"; path = "../Pods/Target Support Files/Pods-WordPressShareExtension/Pods-WordPressShareExtension.release-alpha.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9461,6 +9464,7 @@
17E4CD0B238C33F300C56916 /* DebugMenuViewController.swift */,
E1ADE0EA20A9EF6200D6AADC /* PrivacySettingsViewController.swift */,
F9B862C82478170A008B093C /* EncryptedLogTableViewController.swift */,
CECEEB542823164800A28ADE /* MediaCacheSettingsViewController.swift */,
);
path = "App Settings";
sourceTree = "<group>";
Expand Down Expand Up @@ -18063,6 +18067,7 @@
E66969E41B9E68B200EC9C00 /* ReaderPostToReaderPost37to38.swift in Sources */,
FA6FAB3525EF7C5700666CED /* ReaderRelatedPostsSectionHeaderView.swift in Sources */,
98712D1B23DA1C7E00555316 /* WidgetNoConnectionCell.swift in Sources */,
CECEEB552823164800A28ADE /* MediaCacheSettingsViewController.swift in Sources */,
7E5887A020FE956100DB6F80 /* AppRatingUtilityType.swift in Sources */,
08216FD01CDBF96000304BA7 /* MenuItemSourceFooterView.m in Sources */,
FAD951A425B6CB3600F011B5 /* JetpackRestoreFailedViewController.swift in Sources */,
Expand Down Expand Up @@ -21417,6 +21422,7 @@
FABB24E72602FC2C00C8785C /* TopViewedVideoStatsRecordValue+CoreDataClass.swift in Sources */,
FABB24E82602FC2C00C8785C /* ReaderPost.m in Sources */,
FABB24E92602FC2C00C8785C /* MediaLibraryMediaPickingCoordinator.swift in Sources */,
CECEEB562823164800A28ADE /* MediaCacheSettingsViewController.swift in Sources */,
FABB24EA2602FC2C00C8785C /* PageTemplateLayout+CoreDataClass.swift in Sources */,
FABB24EB2602FC2C00C8785C /* NoResultsViewController.swift in Sources */,
FABB24EC2602FC2C00C8785C /* ActionDispatcherFacade.swift in Sources */,
Expand Down

0 comments on commit 32af0f3

Please sign in to comment.