diff --git a/Apps/LekaApp/Resources/l10n/Localizable.xcstrings b/Apps/LekaApp/Resources/l10n/Localizable.xcstrings index 3288aa39e..ab7d70e16 100644 --- a/Apps/LekaApp/Resources/l10n/Localizable.xcstrings +++ b/Apps/LekaApp/Resources/l10n/Localizable.xcstrings @@ -1748,6 +1748,60 @@ } } }, + "lekaapp.main_view.app_update_alert.action": { + "comment": "The action button of the alert to inform the user that an update is available", + "extractionState": "extracted_with_value", + "localizations": { + "en": { + "stringUnit": { + "state": "new", + "value": "Update now" + } + }, + "fr": { + "stringUnit": { + "state": "translated", + "value": "Mettre \u00e0 jour maintenant" + } + } + } + }, + "lekaapp.main_view.app_update_alert.message": { + "comment": "The message of the alert to inform the user that an update is available", + "extractionState": "extracted_with_value", + "localizations": { + "en": { + "stringUnit": { + "state": "new", + "value": "Enjoy new features by updating to the latest version of Leka!" + } + }, + "fr": { + "stringUnit": { + "state": "translated", + "value": "Profitez des nouvelles fonctionnalit\u00e9s en t\u00e9l\u00e9chargeant la nouvelle mise \u00e0 jour de l\u2019app Leka !" + } + } + } + }, + "lekaapp.main_view.app_update_alert.title": { + "comment": "The title of the alert to inform the user that an update is available", + "extractionState": "extracted_with_value", + "localizations": { + "en": { + "stringUnit": { + "state": "new", + "value": "New update available" + } + }, + "fr": { + "stringUnit": { + "state": "translated", + "value": "Nouvelle mise \u00e0 jour disponible" + } + } + } + }, "lekaapp.main_view.detailView.disconnected_library_message": { "comment": "The message to invite users to connect to display the Library", "extractionState": "extracted_with_value", @@ -2162,60 +2216,6 @@ } } }, - "lekaapp.main_view.update_alert.action": { - "comment": "The action button of the alert to inform the user that an update is available", - "extractionState": "extracted_with_value", - "localizations": { - "en": { - "stringUnit": { - "state": "new", - "value": "Update now" - } - }, - "fr": { - "stringUnit": { - "state": "translated", - "value": "Mettre \u00e0 jour maintenant" - } - } - } - }, - "lekaapp.main_view.update_alert.message": { - "comment": "The message of the alert to inform the user that an update is available", - "extractionState": "extracted_with_value", - "localizations": { - "en": { - "stringUnit": { - "state": "new", - "value": "Enjoy new features by updating to the latest version of Leka!" - } - }, - "fr": { - "stringUnit": { - "state": "translated", - "value": "Profitez des nouvelles fonctionnalit\u00e9s en t\u00e9l\u00e9chargeant la nouvelle mise \u00e0 jour de l\u2019app Leka !" - } - } - } - }, - "lekaapp.main_view.update_alert.title": { - "comment": "The title of the alert to inform the user that an update is available", - "extractionState": "extracted_with_value", - "localizations": { - "en": { - "stringUnit": { - "state": "new", - "value": "New update available" - } - }, - "fr": { - "stringUnit": { - "state": "translated", - "value": "Nouvelle mise \u00e0 jour disponible" - } - } - } - }, "lekaapp.news_view.description": { "comment": "News description", "extractionState": "extracted_with_value", diff --git a/Apps/LekaApp/Sources/MainApp.swift b/Apps/LekaApp/Sources/MainApp.swift index 1788abf92..518247279 100644 --- a/Apps/LekaApp/Sources/MainApp.swift +++ b/Apps/LekaApp/Sources/MainApp.swift @@ -4,7 +4,6 @@ import AccountKit import AnalyticsKit -import AppUpdately import Combine import ContentKit import DesignKit @@ -12,6 +11,7 @@ import FirebaseKit import LocalizationKit import LogKit import SwiftUI +import UtilsKit let log = LogKit.createLoggerFor(app: "LekaApp") @@ -48,7 +48,7 @@ struct LekaApp: App { class UpdateStatus: ObservableObject { static let shared = UpdateStatus() - @Published var isUpdateAvailable: Bool = false + @Published var status: UpdateStatusFetcher.Status = .upToDate } @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate @@ -87,23 +87,14 @@ struct LekaApp: App { guard let status = try? result.get() else { DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { self.showMainView = true - self.appUpdateStatus.isUpdateAvailable = false + self.appUpdateStatus.status = .upToDate } return } - switch status { - case .upToDate, - .newerVersion: - DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { - self.showMainView = true - self.appUpdateStatus.isUpdateAvailable = false - } - case .updateAvailable: - DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { - self.showMainView = true - self.appUpdateStatus.isUpdateAvailable = true - } + DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { + self.showMainView = true + self.appUpdateStatus.status = status } } } diff --git a/Apps/LekaApp/Sources/Views/MainView/MainView+l10n.swift b/Apps/LekaApp/Sources/Views/MainView/MainView+l10n.swift index 6945b6b53..e3a4a6ab9 100644 --- a/Apps/LekaApp/Sources/Views/MainView/MainView+l10n.swift +++ b/Apps/LekaApp/Sources/Views/MainView/MainView+l10n.swift @@ -45,10 +45,10 @@ extension l10n { static let disconnectedLibraryMessage = LocalizedString("lekaapp.main_view.detailView.disconnected_library_message", value: "Log in to your account to access your personal library.", comment: "The message to invite users to connect to display the Library") } - enum UpdateAlert { - static let title = LocalizedString("lekaapp.main_view.update_alert.title", value: "New update available", comment: "The title of the alert to inform the user that an update is available") - static let message = LocalizedString("lekaapp.main_view.update_alert.message", value: "Enjoy new features by updating to the latest version of Leka!", comment: "The message of the alert to inform the user that an update is available") - static let action = LocalizedString("lekaapp.main_view.update_alert.action", value: "Update now", comment: "The action button of the alert to inform the user that an update is available") + enum AppUpdateAlert { + static let title = LocalizedString("lekaapp.main_view.app_update_alert.title", value: "New update available", comment: "The title of the alert to inform the user that an update is available") + static let message = LocalizedString("lekaapp.main_view.app_update_alert.message", value: "Enjoy new features by updating to the latest version of Leka!", comment: "The message of the alert to inform the user that an update is available") + static let action = LocalizedString("lekaapp.main_view.app_update_alert.action", value: "Update now", comment: "The action button of the alert to inform the user that an update is available") } } } diff --git a/Apps/LekaApp/Sources/Views/MainView/MainView.swift b/Apps/LekaApp/Sources/Views/MainView/MainView.swift index 54b18b401..c7cff34d2 100644 --- a/Apps/LekaApp/Sources/Views/MainView/MainView.swift +++ b/Apps/LekaApp/Sources/Views/MainView/MainView.swift @@ -122,11 +122,11 @@ struct MainView: View { } .listStyle(.sidebar) } - .alert(isPresented: self.$showingUpdateAlert) { + .alert(isPresented: self.$showingAppUpdateAlert) { Alert( - title: Text(l10n.MainView.UpdateAlert.title), - message: Text(l10n.MainView.UpdateAlert.message), - primaryButton: .default(Text(l10n.MainView.UpdateAlert.action), action: { + title: Text(l10n.MainView.AppUpdateAlert.title), + message: Text(l10n.MainView.AppUpdateAlert.message), + primaryButton: .default(Text(l10n.MainView.AppUpdateAlert.action), action: { AnalyticsManager.logEventAppUpdateOpenAppStore() if let url = URL(string: "https://apps.apple.com/app/leka/id6446940339") { UIApplication.shared.open(url) @@ -317,8 +317,11 @@ struct MainView: View { } .onDisappear { DispatchQueue.main.asyncAfter(deadline: .now() + 2) { - if self.appUpdateStatus.isUpdateAvailable { - self.showingUpdateAlert = true + switch self.appUpdateStatus.status { + case .updateAvailable: + self.showingAppUpdateAlert = true + default: + break } } } @@ -417,7 +420,7 @@ struct MainView: View { @StateObject private var rootAccountViewModel = RootAccountManagerViewModel() @StateObject var appUpdateStatus: LekaApp.UpdateStatus = .shared - @State private var showingUpdateAlert: Bool = false + @State private var showingAppUpdateAlert: Bool = false private var persistentDataManager: PersistentDataManager = .shared private var caregiverManager: CaregiverManager = .shared diff --git a/Apps/LekaApp/Sources/Views/MainView/SettingsLabel.swift b/Apps/LekaApp/Sources/Views/MainView/SettingsLabel.swift index d3368ca88..a2be9305a 100644 --- a/Apps/LekaApp/Sources/Views/MainView/SettingsLabel.swift +++ b/Apps/LekaApp/Sources/Views/MainView/SettingsLabel.swift @@ -28,7 +28,12 @@ struct SettingsLabel: View { .background(.red) .clipShape(.circle) .offset(x: 95, y: -20) - .opacity(self.appUpdateStatus.isUpdateAvailable ? 1 : 0) + .opacity({ + if case .updateAvailable = self.appUpdateStatus.status { + return 1.0 + } + return 0.0 + }()) ) } diff --git a/Apps/LekaApp/Sources/Views/Settings/SettingsView.swift b/Apps/LekaApp/Sources/Views/Settings/SettingsView.swift index 8a1865060..341e782af 100644 --- a/Apps/LekaApp/Sources/Views/Settings/SettingsView.swift +++ b/Apps/LekaApp/Sources/Views/Settings/SettingsView.swift @@ -23,7 +23,7 @@ struct SettingsView: View { var body: some View { Form { - if self.appUpdateStatus.isUpdateAvailable { + if case .updateAvailable = self.appUpdateStatus.status { Section { VStack(alignment: .center) { HStack(spacing: 20) {