Skip to content

Commit b7c87cf

Browse files
committed
Refactor AppIcon utility variables
1 parent c98be2b commit b7c87cf

7 files changed

Lines changed: 41 additions & 55 deletions

File tree

WordPress/Classes/Stores/UserPersistentRepositoryUtility.swift

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ private enum UPRUConstants {
77
static let notificationsTabAccessCount = "NotificationsTabAccessCount"
88
static let notificationPrimerInlineWasAcknowledged = "notificationPrimerInlineWasAcknowledged"
99
static let secondNotificationsAlertCount = "secondNotificationsAlertCount"
10+
static let hasShownCustomAppIconUpgradeAlert = "custom-app-icon-upgrade-alert-shown"
11+
static let createButtonTooltipWasDisplayed = "CreateButtonTooltipWasDisplayed"
12+
static let createButtonTooltipDisplayCount = "CreateButtonTooltipDisplayCount"
1013
}
1114

1215
protocol UserPersistentRepositoryUtility: AnyObject {
@@ -63,7 +66,7 @@ extension UserPersistentRepositoryUtility {
6366

6467
var notificationPrimerInlineWasAcknowledged: Bool {
6568
get {
66-
return UserPersistentStoreFactory.instance().bool(forKey: UPRUConstants.notificationPrimerInlineWasAcknowledged)
69+
UserPersistentStoreFactory.instance().bool(forKey: UPRUConstants.notificationPrimerInlineWasAcknowledged)
6770
}
6871
set {
6972
UserPersistentStoreFactory.instance().set(newValue, forKey: UPRUConstants.notificationPrimerInlineWasAcknowledged)
@@ -78,4 +81,31 @@ extension UserPersistentRepositoryUtility {
7881
UserPersistentStoreFactory.instance().set(newValue, forKey: UPRUConstants.secondNotificationsAlertCount)
7982
}
8083
}
84+
85+
var hasShownCustomAppIconUpgradeAlert: Bool {
86+
get {
87+
UserPersistentStoreFactory.instance().bool(forKey: UPRUConstants.hasShownCustomAppIconUpgradeAlert)
88+
}
89+
set {
90+
UserPersistentStoreFactory.instance().set(newValue, forKey: UPRUConstants.hasShownCustomAppIconUpgradeAlert)
91+
}
92+
}
93+
94+
var createButtonTooltipDisplayCount: Int {
95+
get {
96+
UserPersistentStoreFactory.instance().integer(forKey: UPRUConstants.createButtonTooltipDisplayCount)
97+
}
98+
set {
99+
UserPersistentStoreFactory.instance().set(newValue, forKey: UPRUConstants.createButtonTooltipDisplayCount)
100+
}
101+
}
102+
103+
var createButtonTooltipWasDisplayed: Bool {
104+
get {
105+
UserPersistentStoreFactory.instance().bool(forKey: UPRUConstants.createButtonTooltipWasDisplayed)
106+
}
107+
set {
108+
UserPersistentStoreFactory.instance().set(newValue, forKey: UPRUConstants.createButtonTooltipWasDisplayed)
109+
}
110+
}
81111
}

WordPress/Classes/ViewRelated/Me/App Settings/AppIconViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ open class AppIconViewController: UITableViewController {
110110
// Prevent showing the custom icon upgrade alert to a user
111111
// who's just set an icon for the first time.
112112
// We'll remove this alert after a couple of releases.
113-
UserDefaults.standard.hasShownCustomAppIconUpgradeAlert = true
113+
UserPersistentStoreFactory.instance().hasShownCustomAppIconUpgradeAlert = true
114114

115115
UIApplication.shared.setAlternateIconName(iconName, completionHandler: { [weak self] error in
116116
if error == nil {

WordPress/Classes/ViewRelated/NUX/WordPressAuthenticationManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ extension WordPressAuthenticationManager: WordPressAuthenticatorDelegate {
406406
}
407407
}
408408

409-
UserPersistentStoreFactory.instance().set(false, forKey: UserDefaults.standard.welcomeNotificationSeenKey)
409+
UserPersistentStoreFactory.instance().set(false, forKey: UserPersistentStoreFactory.instance().welcomeNotificationSeenKey)
410410
}
411411

412412
navigationController.pushViewController(epilogueViewController, animated: true)

WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationsViewController+PushPrimer.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extension NotificationsViewController {
88

99
var shouldShowPrimeForPush: Bool {
1010
get {
11-
return !UserDefaults.standard.notificationPrimerInlineWasAcknowledged
11+
return !UserPersistentStoreFactory.instance().notificationPrimerInlineWasAcknowledged
1212
}
1313
}
1414

@@ -44,7 +44,7 @@ extension NotificationsViewController {
4444
InteractiveNotificationsManager.shared.requestAuthorization { _ in
4545
DispatchQueue.main.async {
4646
self?.hideInlinePrompt(delay: 0.0)
47-
UserDefaults.standard.notificationPrimerInlineWasAcknowledged = true
47+
UserPersistentStoreFactory.instance().notificationPrimerInlineWasAcknowledged = true
4848
}
4949
}
5050
}
@@ -54,7 +54,7 @@ extension NotificationsViewController {
5454
WPAnalytics.track(.pushNotificationPrimerNoTapped, withProperties: [Analytics.locationKey: Analytics.inlineKey])
5555
}
5656
self?.hideInlinePrompt(delay: 0.0)
57-
UserDefaults.standard.notificationPrimerInlineWasAcknowledged = true
57+
UserPersistentStoreFactory.instance().notificationPrimerInlineWasAcknowledged = true
5858
}
5959

6060
// We _seriously_ need to call the following method at last.
@@ -65,9 +65,9 @@ extension NotificationsViewController {
6565

6666
private func setupWinback() {
6767
// only show the winback for folks that denied without seeing the post-login primer: aka users of a previous version
68-
guard !UserDefaults.standard.notificationPrimerAlertWasDisplayed else {
68+
guard !UserPersistentStoreFactory.instance().notificationPrimerAlertWasDisplayed else {
6969
// they saw the primer, and denied us. they aren't coming back, we aren't bothering them anymore.
70-
UserDefaults.standard.notificationPrimerInlineWasAcknowledged = true
70+
UserPersistentStoreFactory.instance().notificationPrimerInlineWasAcknowledged = true
7171
return
7272
}
7373

@@ -91,15 +91,15 @@ extension NotificationsViewController {
9191
self?.hideInlinePrompt(delay: 0.0)
9292
let targetURL = URL(string: UIApplication.openSettingsURLString)
9393
UIApplication.shared.open(targetURL!)
94-
UserDefaults.standard.notificationPrimerInlineWasAcknowledged = true
94+
UserPersistentStoreFactory.instance().notificationPrimerInlineWasAcknowledged = true
9595
}
9696

9797
inlinePromptView.setupNoButton(title: noTitle) { [weak self] button in
9898
defer {
9999
WPAnalytics.track(.pushNotificationWinbackNoTapped, withProperties: [Analytics.locationKey: Analytics.inlineKey])
100100
}
101101
self?.hideInlinePrompt(delay: 0.0)
102-
UserDefaults.standard.notificationPrimerInlineWasAcknowledged = true
102+
UserPersistentStoreFactory.instance().notificationPrimerInlineWasAcknowledged = true
103103
}
104104
}
105105
}

WordPress/Classes/ViewRelated/Post/PostListFilterSettings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class PostListFilterSettings: NSObject {
104104
/// currentPostListFilter: returns the index of the last active PostListFilter
105105
@objc func currentFilterIndex() -> Int {
106106

107-
let userDefaults = UserDefaults.standard
107+
let userDefaults = UserPersistentStoreFactory.instance()
108108

109109
if let filter = userDefaults.object(forKey: keyForCurrentListStatusFilter()) as? Int, filter < availablePostListFilters().count {
110110

WordPress/Classes/ViewRelated/System/FancyAlertViewController+AppIcons.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,3 @@ extension FancyAlertViewController {
5454
return controller
5555
}
5656
}
57-
58-
// MARK: - User Defaults
59-
60-
extension UserDefaults {
61-
private enum Keys: String {
62-
case hasShownCustomAppIconUpgradeAlert = "custom-app-icon-upgrade-alert-shown"
63-
}
64-
65-
var hasShownCustomAppIconUpgradeAlert: Bool {
66-
get {
67-
return bool(forKey: Keys.hasShownCustomAppIconUpgradeAlert.rawValue)
68-
}
69-
set {
70-
set(newValue, forKey: Keys.hasShownCustomAppIconUpgradeAlert.rawValue)
71-
}
72-
}
73-
}

WordPress/Classes/ViewRelated/System/Floating Create Button/CreateButtonCoordinator.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -273,33 +273,6 @@ extension CreateButtonCoordinator: UIViewControllerTransitioningDelegate {
273273
}
274274
}
275275

276-
@objc
277-
extension UserDefaults {
278-
private enum Keys: String {
279-
case createButtonTooltipWasDisplayed = "CreateButtonTooltipWasDisplayed"
280-
case createButtonTooltipDisplayCount = "CreateButtonTooltipDisplayCount"
281-
}
282-
283-
var createButtonTooltipDisplayCount: Int {
284-
get {
285-
return integer(forKey: Keys.createButtonTooltipDisplayCount.rawValue)
286-
}
287-
set {
288-
set(newValue, forKey: Keys.createButtonTooltipDisplayCount.rawValue)
289-
}
290-
}
291-
292-
var createButtonTooltipWasDisplayed: Bool {
293-
get {
294-
return bool(forKey: Keys.createButtonTooltipWasDisplayed.rawValue)
295-
}
296-
set {
297-
set(newValue, forKey: Keys.createButtonTooltipWasDisplayed.rawValue)
298-
}
299-
}
300-
}
301-
302-
303276
// MARK: - Blogging Prompts Methods
304277

305278
private extension CreateButtonCoordinator {

0 commit comments

Comments
 (0)