Better file caching and update management
This commit is contained in:
@@ -25,6 +25,13 @@ struct Recipe: Codable {
|
||||
let imageUrl: String
|
||||
let imagePlaceholderUrl: String
|
||||
let recipe_id: Int
|
||||
|
||||
// Properties excluded from Codable
|
||||
var storedLocally: Bool? = nil
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case name, keywords, dateCreated, dateModified, imageUrl, imagePlaceholderUrl, recipe_id
|
||||
}
|
||||
}
|
||||
|
||||
extension Recipe: Identifiable, Hashable {
|
||||
@@ -91,16 +98,6 @@ struct RecipeDetail: Codable {
|
||||
recipeInstructions = []
|
||||
nutrition = [:]
|
||||
}
|
||||
|
||||
func getKeywordsArray() -> [String] {
|
||||
return keywords.components(separatedBy: ",")
|
||||
}
|
||||
|
||||
mutating func setKeywordsFromArray(_ keywordsArray: [String]) {
|
||||
if !self.keywords.isEmpty {
|
||||
self.keywords = keywordsArray.joined(separator: ",")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension RecipeDetail {
|
||||
@@ -124,7 +121,18 @@ extension RecipeDetail {
|
||||
recipeInstructions: [],
|
||||
nutrition: [:]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func getKeywordsArray() -> [String] {
|
||||
if keywords == "" { return [] }
|
||||
return keywords.components(separatedBy: ",")
|
||||
}
|
||||
|
||||
mutating func setKeywordsFromArray(_ keywordsArray: [String]) {
|
||||
if !keywordsArray.isEmpty {
|
||||
self.keywords = keywordsArray.joined(separator: ",")
|
||||
}
|
||||
}
|
||||
|
||||
func getNutritionList() -> [String]? {
|
||||
var stringList: [String] = []
|
||||
@@ -146,8 +154,8 @@ extension RecipeDetail {
|
||||
|
||||
|
||||
struct RecipeImage {
|
||||
enum RecipeImageSize {
|
||||
case THUMB, FULL
|
||||
enum RecipeImageSize: String {
|
||||
case THUMB="thumb", FULL="full"
|
||||
}
|
||||
var imageExists: Bool = true
|
||||
var thumb: UIImage?
|
||||
|
||||
@@ -10,6 +10,9 @@ import Foundation
|
||||
import Combine
|
||||
|
||||
class UserSettings: ObservableObject {
|
||||
|
||||
static let shared = UserSettings()
|
||||
|
||||
@Published var username: String {
|
||||
didSet {
|
||||
UserDefaults.standard.set(username, forKey: "username")
|
||||
@@ -52,9 +55,27 @@ class UserSettings: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
@Published var downloadRecipes: Bool {
|
||||
@Published var storeRecipes: Bool {
|
||||
didSet {
|
||||
UserDefaults.standard.set(downloadRecipes, forKey: "downloadRecipes")
|
||||
UserDefaults.standard.set(storeRecipes, forKey: "storeRecipes")
|
||||
}
|
||||
}
|
||||
|
||||
@Published var storeImages: Bool {
|
||||
didSet {
|
||||
UserDefaults.standard.set(storeImages, forKey: "storeImages")
|
||||
}
|
||||
}
|
||||
|
||||
@Published var storeThumb: Bool {
|
||||
didSet {
|
||||
UserDefaults.standard.set(storeThumb, forKey: "storeThumb")
|
||||
}
|
||||
}
|
||||
|
||||
@Published var lastUpdate: Date {
|
||||
didSet {
|
||||
UserDefaults.standard.set(lastUpdate, forKey: "lastUpdate")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +87,10 @@ class UserSettings: ObservableObject {
|
||||
self.onboarding = UserDefaults.standard.object(forKey: "onboarding") as? Bool ?? true
|
||||
self.defaultCategory = UserDefaults.standard.object(forKey: "defaultCategory") as? String ?? ""
|
||||
self.language = UserDefaults.standard.object(forKey: "language") as? String ?? SupportedLanguage.DEVICE.rawValue
|
||||
self.downloadRecipes = UserDefaults.standard.object(forKey: "downloadRecipes") as? Bool ?? false
|
||||
self.storeRecipes = UserDefaults.standard.object(forKey: "storeRecipes") as? Bool ?? true
|
||||
self.storeImages = UserDefaults.standard.object(forKey: "storeImages") as? Bool ?? true
|
||||
self.storeThumb = UserDefaults.standard.object(forKey: "storeThumb") as? Bool ?? true
|
||||
self.lastUpdate = UserDefaults.standard.object(forKey: "lastUpdate") as? Date ?? Date.distantPast
|
||||
|
||||
if authString == "" {
|
||||
if token != "" && username != "" {
|
||||
|
||||
Reference in New Issue
Block a user