Skip to content

Commit 7a5cc70

Browse files
committed
Add all of remaining utility variables
1 parent b7c87cf commit 7a5cc70

13 files changed

Lines changed: 75 additions & 95 deletions

WordPress/Classes/Stores/UserPersistentRepositoryUtility.swift

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ private enum UPRUConstants {
1010
static let hasShownCustomAppIconUpgradeAlert = "custom-app-icon-upgrade-alert-shown"
1111
static let createButtonTooltipWasDisplayed = "CreateButtonTooltipWasDisplayed"
1212
static let createButtonTooltipDisplayCount = "CreateButtonTooltipDisplayCount"
13+
static let savedPostsPromoWasDisplayed = "SavedPostsV1PromoWasDisplayed"
14+
static let storiesIntroWasAcknowledged = "storiesIntroWasAcknowledged"
15+
static let currentAnnouncementsKey = "currentAnnouncements"
16+
static let currentAnnouncementsDateKey = "currentAnnouncementsDate"
17+
static let announcementsVersionDisplayedKey = "announcementsVersionDisplayed"
1318
}
1419

1520
protocol UserPersistentRepositoryUtility: AnyObject {
@@ -108,4 +113,55 @@ extension UserPersistentRepositoryUtility {
108113
UserPersistentStoreFactory.instance().set(newValue, forKey: UPRUConstants.createButtonTooltipWasDisplayed)
109114
}
110115
}
116+
117+
var savedPostsPromoWasDisplayed: Bool {
118+
get {
119+
return UserPersistentStoreFactory.instance().bool(forKey: UPRUConstants.savedPostsPromoWasDisplayed)
120+
}
121+
set {
122+
UserPersistentStoreFactory.instance().set(newValue, forKey: UPRUConstants.savedPostsPromoWasDisplayed)
123+
}
124+
}
125+
126+
var storiesIntroWasAcknowledged: Bool {
127+
get {
128+
return UserPersistentStoreFactory.instance().bool(forKey: UPRUConstants.storiesIntroWasAcknowledged)
129+
}
130+
set {
131+
UserPersistentStoreFactory.instance().set(newValue, forKey: UPRUConstants.storiesIntroWasAcknowledged)
132+
}
133+
}
134+
135+
var announcements: [Announcement]? {
136+
get {
137+
guard let encodedAnnouncements = UserPersistentStoreFactory.instance().object(forKey: UPRUConstants.currentAnnouncementsKey) as? Data,
138+
let announcements = try? PropertyListDecoder().decode([Announcement].self, from: encodedAnnouncements) else {
139+
return nil
140+
}
141+
return announcements
142+
}
143+
144+
set {
145+
guard let announcements = newValue, let encodedAnnouncements = try? PropertyListEncoder().encode(announcements) else {
146+
UserPersistentStoreFactory.instance().removeObject(forKey: UPRUConstants.currentAnnouncementsKey)
147+
UserPersistentStoreFactory.instance().removeObject(forKey: UPRUConstants.currentAnnouncementsDateKey)
148+
return
149+
}
150+
UserPersistentStoreFactory.instance().set(encodedAnnouncements, forKey: UPRUConstants.currentAnnouncementsKey)
151+
UserPersistentStoreFactory.instance().set(Date(), forKey: UPRUConstants.currentAnnouncementsDateKey)
152+
}
153+
}
154+
155+
var announcementsDate: Date? {
156+
UserPersistentStoreFactory.instance().object(forKey: UPRUConstants.currentAnnouncementsDateKey) as? Date
157+
}
158+
159+
var announcementsVersionDisplayed: String? {
160+
get {
161+
UserPersistentStoreFactory.instance().string(forKey: UPRUConstants.announcementsVersionDisplayedKey)
162+
}
163+
set {
164+
UserPersistentStoreFactory.instance().set(newValue, forKey: UPRUConstants.announcementsVersionDisplayedKey)
165+
}
166+
}
111167
}

WordPress/Classes/ViewRelated/Reader/Detail/WebView/ReaderCSS.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct ReaderCSS {
5050
}
5151

5252
init(now: Int = Int(Date().timeIntervalSince1970),
53-
store: KeyValueDatabase = UserDefaults.standard,
53+
store: KeyValueDatabase = UserPersistentStoreFactory.instance(),
5454
isInternetReachable: @escaping () -> Bool = ReachabilityUtils.isInternetReachable) {
5555
self.store = store
5656
self.now = now

WordPress/Classes/ViewRelated/Reader/ReaderInterestsCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ReaderSelectInterestsCoordinator {
99
/// - store: An optional backing store to keep track of if the user has seen the select interests view or not
1010
/// - userId: The logged in user account, this makes sure the tracking is a per-user basis
1111
init(service: ReaderFollowedInterestsService? = nil,
12-
store: KeyValueDatabase = UserDefaults.standard,
12+
store: KeyValueDatabase = UserPersistentStoreFactory.instance(),
1313
userId: NSNumber? = nil,
1414
context: NSManagedObjectContext = ContextManager.sharedInstance().mainContext) {
1515

WordPress/Classes/ViewRelated/Reader/ReaderWelcomeBanner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ReaderWelcomeBanner: UIView, NibLoadable {
2020

2121
/// Present the Welcome banner just one time
2222
class func displayIfNeeded(in tableView: UITableView,
23-
database: KeyValueDatabase = UserDefaults.standard) {
23+
database: KeyValueDatabase = UserPersistentStoreFactory.instance()) {
2424
guard !database.bool(forKey: ReaderWelcomeBanner.bannerPresentedKey) else {
2525
return
2626
}

WordPress/Classes/ViewRelated/Stats/Helpers/SiteStatsInformation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import Foundation
3232

3333
extension SiteStatsInformation {
3434

35-
func getCurrentSiteInsights(_ userDefaults: UserDefaults = UserDefaults.standard) -> [InsightType] {
35+
func getCurrentSiteInsights(_ userDefaults: UserPersistentRepository = UserPersistentStoreFactory.instance()) -> [InsightType] {
3636

3737
guard let siteID = siteID?.stringValue else {
3838
return InsightType.defaultInsights
@@ -44,7 +44,7 @@ extension SiteStatsInformation {
4444
return InsightType.typesForValues(values ?? InsightType.defaultInsightsValues)
4545
}
4646

47-
func saveCurrentSiteInsights(_ insightsCards: [InsightType], _ userDefaults: UserDefaults = UserDefaults.standard) {
47+
func saveCurrentSiteInsights(_ insightsCards: [InsightType], _ userDefaults: UserPersistentRepository = UserPersistentStoreFactory.instance()) {
4848

4949
guard let siteID = siteID?.stringValue else {
5050
return

WordPress/Classes/ViewRelated/Support/SupportTableViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SupportTableViewController: UITableViewController {
1212
var showHelpFromViewController: UIViewController?
1313

1414
private var tableHandler: ImmuTableViewHandler?
15-
private let userDefaults = UserDefaults.standard
15+
private let userDefaults = UserPersistentStoreFactory.instance()
1616

1717
/// This closure is called when this VC is about to be dismissed due to the user
1818
/// tapping the dismiss button.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ extension FancyAlertViewController {
1212
guard AppConfiguration.allowsCustomAppIcons,
1313
AppIcon.isUsingCustomIcon,
1414
origin.presentedViewController == nil,
15-
UserDefaults.standard.hasShownCustomAppIconUpgradeAlert == false else {
15+
UserPersistentStoreFactory.instance().hasShownCustomAppIconUpgradeAlert == false else {
1616
return
1717
}
1818

19-
UserDefaults.standard.hasShownCustomAppIconUpgradeAlert = true
19+
UserPersistentStoreFactory.instance().hasShownCustomAppIconUpgradeAlert = true
2020

2121
let controller = FancyAlertViewController.makeCustomAppIconUpgradeAlertController(with: origin)
2222
controller.modalPresentationStyle = .custom

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ extension FancyAlertViewController {
1111
}
1212

1313
static func presentReaderSavedPostsAlertControllerIfNecessary(from origin: UIViewController & UIViewControllerTransitioningDelegate) {
14-
if !UserDefaults.standard.savedPostsPromoWasDisplayed {
15-
UserDefaults.standard.savedPostsPromoWasDisplayed = true
14+
if !UserPersistentStoreFactory.instance().savedPostsPromoWasDisplayed {
15+
UserPersistentStoreFactory.instance().savedPostsPromoWasDisplayed = true
1616

1717
let controller = FancyAlertViewController.makeReaderSavedPostsAlertController()
1818
controller.modalPresentationStyle = .custom
@@ -41,20 +41,3 @@ extension FancyAlertViewController {
4141
return controller
4242
}
4343
}
44-
45-
// MARK: - User Defaults
46-
47-
extension UserDefaults {
48-
private enum Keys: String {
49-
case savedPostsPromoWasDisplayed = "SavedPostsV1PromoWasDisplayed"
50-
}
51-
52-
var savedPostsPromoWasDisplayed: Bool {
53-
get {
54-
return bool(forKey: Keys.savedPostsPromoWasDisplayed.rawValue)
55-
}
56-
set {
57-
set(newValue, forKey: Keys.savedPostsPromoWasDisplayed.rawValue)
58-
}
59-
}
60-
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ import WordPressFlux
3939
if newValue >= Constants.maximumTooltipViews {
4040
didDismissTooltip = true
4141
} else {
42-
UserDefaults.standard.createButtonTooltipDisplayCount = newValue
42+
UserPersistentStoreFactory.instance().createButtonTooltipDisplayCount = newValue
4343
}
4444
}
4545
get {
46-
return UserDefaults.standard.createButtonTooltipDisplayCount
46+
return UserPersistentStoreFactory.instance().createButtonTooltipDisplayCount
4747
}
4848
}
4949

5050
private var didDismissTooltip: Bool {
5151
set {
52-
UserDefaults.standard.createButtonTooltipWasDisplayed = newValue
52+
UserPersistentStoreFactory.instance().createButtonTooltipWasDisplayed = newValue
5353
}
5454
get {
55-
return UserDefaults.standard.createButtonTooltipWasDisplayed
55+
return UserPersistentStoreFactory.instance().createButtonTooltipWasDisplayed
5656
}
5757
}
5858

WordPress/Classes/ViewRelated/System/WPTabBarController+ShowTab.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ extension WPTabBarController {
5353
return
5454
}
5555

56-
if UserDefaults.standard.storiesIntroWasAcknowledged == false {
56+
if UserPersistentStoreFactory.instance().storiesIntroWasAcknowledged == false {
5757
// Show Intro screen
5858
let intro = StoriesIntroViewController(continueTapped: { [weak self] in
59-
UserDefaults.standard.storiesIntroWasAcknowledged = true
59+
UserPersistentStoreFactory.instance().storiesIntroWasAcknowledged = true
6060
self?.showStoryEditor()
6161
}, openURL: { [weak self] url in
6262
let webViewController = WebViewControllerFactory.controller(url: url, source: "show_story_example")

0 commit comments

Comments
 (0)