-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from worthbak/wb/store-json-fetch
v0.2.0: async/await model overhaul; iPad support
- Loading branch information
Showing
30 changed files
with
9,940 additions
and
3,483 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// | ||
// DefaultsVendor.swift | ||
// InventoryWatch | ||
// | ||
// Created by Worth Baker on 10/25/22. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
extension UserDefaults { | ||
|
||
@objc dynamic var preferredStoreNumber: String { | ||
get { string(forKey: "preferredStoreNumber") ?? "R032" } | ||
set { setValue(newValue, forKey: "preferredStoreNumber") } | ||
} | ||
|
||
@objc dynamic var lastUpdateDate: String? { | ||
get { string(forKey: "lastUpdateDate") } | ||
set { setValue(newValue, forKey: "lastUpdateDate") } | ||
} | ||
|
||
@objc dynamic var preferredUpdateInterval: Int { | ||
get { | ||
if let currentValue = object(forKey: "preferredUpdateInterval") as? Int { | ||
return currentValue | ||
} else { | ||
// WB 10/28/22: Changing default update interval from 1min to 5min | ||
let presetValue = 5 | ||
set(presetValue, forKey: "preferredUpdateInterval") | ||
|
||
return presetValue | ||
} | ||
} | ||
set { setValue(newValue, forKey: "preferredUpdateInterval") } | ||
} | ||
} | ||
|
||
struct DefaultsVendor { | ||
|
||
var preferredCountry: Country { | ||
let value = UserDefaults.standard.string(forKey: "preferredCountry") ?? "US" | ||
|
||
return Countries[value] ?? USData | ||
} | ||
|
||
var preferredProductType: ProductType { | ||
let value = UserDefaults.standard.string(forKey: "preferredProductType") ?? "MacBookPro" | ||
|
||
return ProductType(rawValue: value) ?? .MacBookPro | ||
} | ||
|
||
var countryPathElement: String { | ||
let country = preferredCountry | ||
if country.shortcode == "US" { | ||
return "" | ||
} else { | ||
return country.shortcode + "/" | ||
} | ||
} | ||
|
||
var preferredStoreNumber: String { | ||
get { return UserDefaults.standard.preferredStoreNumber } | ||
set { UserDefaults.standard.preferredStoreNumber = newValue } | ||
} | ||
|
||
var lastUpdateDate: String? { | ||
get { return UserDefaults.standard.lastUpdateDate } | ||
set { UserDefaults.standard.lastUpdateDate = newValue } | ||
} | ||
|
||
// unused - keeping this around as an example implementation | ||
private var preferredStoreNumberStream: AnyPublisher<String, Never> { | ||
return UserDefaults.standard | ||
.publisher(for: \.preferredStoreNumber) | ||
.eraseToAnyPublisher() | ||
} | ||
|
||
var preferredUpdateInterval: Int { | ||
return UserDefaults.standard.preferredUpdateInterval | ||
} | ||
|
||
var shouldIncludeNearbyStores: Bool { | ||
let value = UserDefaults.standard.object(forKey: "shouldIncludeNearbyStores") as? Bool | ||
|
||
return value ?? true | ||
} | ||
|
||
var preferredSKUs: Set<String> { | ||
guard let defaults = UserDefaults.standard.string(forKey: "preferredSKUs") else { | ||
return [] | ||
} | ||
|
||
return defaults.components(separatedBy: ",").reduce(into: Set<String>()) { partialResult, next in | ||
partialResult.insert(next) | ||
} | ||
} | ||
|
||
var customSkuData: (sku: String, nickname: String)? { | ||
guard | ||
let sku = UserDefaults.standard.string(forKey: "customSku"), | ||
let name = UserDefaults.standard.string(forKey: "customSkuNickname") | ||
else { | ||
return nil | ||
} | ||
|
||
return (sku, name) | ||
} | ||
|
||
var showResultsOnlyForPreferredModels: Bool { | ||
UserDefaults.standard.bool(forKey: "showResultsOnlyForPreferredModels") | ||
} | ||
|
||
var notifyOnlyForPreferredModels: Bool { | ||
UserDefaults.standard.bool(forKey: "notifyOnlyForPreferredModels") | ||
} | ||
} |
Oops, something went wrong.