diff --git a/Nextcloud Cookbook iOS Client.xcodeproj/project.pbxproj b/Nextcloud Cookbook iOS Client.xcodeproj/project.pbxproj index 9b50e56..13f3f3d 100644 --- a/Nextcloud Cookbook iOS Client.xcodeproj/project.pbxproj +++ b/Nextcloud Cookbook iOS Client.xcodeproj/project.pbxproj @@ -662,7 +662,7 @@ LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 1.6; + MARKETING_VERSION = 1.6.1; PRODUCT_BUNDLE_IDENTIFIER = "VincentMeilinger.Nextcloud-Cookbook-iOS-Client"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = auto; @@ -705,7 +705,7 @@ LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 1.6; + MARKETING_VERSION = 1.6.1; PRODUCT_BUNDLE_IDENTIFIER = "VincentMeilinger.Nextcloud-Cookbook-iOS-Client"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = auto; diff --git a/Nextcloud Cookbook iOS Client.xcodeproj/project.xcworkspace/xcuserdata/vincie.xcuserdatad/UserInterfaceState.xcuserstate b/Nextcloud Cookbook iOS Client.xcodeproj/project.xcworkspace/xcuserdata/vincie.xcuserdatad/UserInterfaceState.xcuserstate index cbd1a85..365756f 100644 Binary files a/Nextcloud Cookbook iOS Client.xcodeproj/project.xcworkspace/xcuserdata/vincie.xcuserdatad/UserInterfaceState.xcuserstate and b/Nextcloud Cookbook iOS Client.xcodeproj/project.xcworkspace/xcuserdata/vincie.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Nextcloud Cookbook iOS Client/ViewModels/MainViewModel.swift b/Nextcloud Cookbook iOS Client/ViewModels/MainViewModel.swift index 87b5555..389cf69 100644 --- a/Nextcloud Cookbook iOS Client/ViewModels/MainViewModel.swift +++ b/Nextcloud Cookbook iOS Client/ViewModels/MainViewModel.swift @@ -18,7 +18,7 @@ import UIKit @Published var recipeDetails: [Int: RecipeDetail] = [:] var recipeImages: [Int: [String: UIImage]] = [:] var imagesNeedUpdate: [Int: [String: Bool]] = [:] - private var requestQueue: [RequestWrapper] = [] + var lastUpdates: [String: Date] = [:] private let api: CookbookApi.Type private let dataStore: DataStore @@ -65,6 +65,11 @@ import UIKit print("Failure!") } } + + // Initialize the lastUpdates with distantPast dates, so that each recipeDetail is updated on launch for all categories + for category in self.categories { + lastUpdates[category.name] = Date.distantPast + } } /** @@ -132,7 +137,7 @@ import UIKit guard userSettings.storeRecipes else { return } guard let recipes = self.recipes[category] else { return } for recipe in recipes { - if needsUpdate(lastModified: recipe.dateModified) { + if needsUpdate(category: category, lastModified: recipe.dateModified) { print("\(recipe.name) needs an update. (last modified: \(recipe.dateModified)") await updateRecipeDetail(id: recipe.recipe_id, withThumb: userSettings.storeThumb, withImage: userSettings.storeImages) } else { @@ -394,7 +399,6 @@ import UIKit self.categories = [] self.recipes = [:] self.recipeDetails = [:] - self.requestQueue = [] self.recipeImages = [:] self.imagesNeedUpdate = [:] } @@ -572,22 +576,21 @@ extension MainViewModel { return true } - private func needsUpdate(lastModified: String) -> Bool { + private func needsUpdate(category: String, lastModified: String) -> Bool { print("=======================") print("original date string: \(lastModified)") // Create a DateFormatter let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" dateFormatter.timeZone = TimeZone(secondsFromGMT: 0) - //dateFormatter.locale = Locale(identifier: "en_US_POSIX") // Set the locale to posix - + // Convert the string to a Date object - if let date = dateFormatter.date(from: lastModified) { - if date < userSettings.lastUpdate { - print("No update needed. (recipe: \(dateFormatter.string(from: date)), last: \(dateFormatter.string(from: userSettings.lastUpdate))") + if let date = dateFormatter.date(from: lastModified), let lastUpdate = lastUpdates[category] { + if date < lastUpdate { + print("No update needed. (recipe: \(dateFormatter.string(from: date)), last: \(dateFormatter.string(from: lastUpdate))") return false } else { - print("Update needed. (recipe: \(dateFormatter.string(from: date)), last: \(dateFormatter.string(from: userSettings.lastUpdate))") + print("Update needed. (recipe: \(dateFormatter.string(from: date)), last: \(dateFormatter.string(from: lastUpdate))") return true } }