Skip to content

Commit

Permalink
♻️ (LekaApp): Use custom UpdateStatusFetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Nov 22, 2024
1 parent 8adc157 commit 85192ff
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 82 deletions.
108 changes: 54 additions & 54 deletions Apps/LekaApp/Resources/l10n/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
21 changes: 6 additions & 15 deletions Apps/LekaApp/Sources/MainApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import AccountKit
import AnalyticsKit
import AppUpdately
import Combine
import ContentKit
import DesignKit
import FirebaseKit
import LocalizationKit
import LogKit
import SwiftUI
import UtilsKit

let log = LogKit.createLoggerFor(app: "LekaApp")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Apps/LekaApp/Sources/Views/MainView/MainView+l10n.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand Down
17 changes: 10 additions & 7 deletions Apps/LekaApp/Sources/Views/MainView/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion Apps/LekaApp/Sources/Views/MainView/SettingsLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}())
)
}

Expand Down
2 changes: 1 addition & 1 deletion Apps/LekaApp/Sources/Views/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 85192ff

Please sign in to comment.