diff --git a/medmap/DependencyInjection/ManagersAssembly.swift b/medmap/DependencyInjection/ManagersAssembly.swift index c2d4987..c38a023 100755 --- a/medmap/DependencyInjection/ManagersAssembly.swift +++ b/medmap/DependencyInjection/ManagersAssembly.swift @@ -17,6 +17,8 @@ final class ManagerAssembly: Assembly { return GRDBDatabaseManager() } .inObjectScope(.container) + + container.register(APIClient.self) { _ in return APIClient() } @@ -26,57 +28,12 @@ final class ManagerAssembly: Assembly { return EventsManager() } - /* - - + + container.register(MedMapAPI.self) { _ in + return MedMapAPI() + } + .inObjectScope(.container) - container.register(ComicsBooksManager.self) { _ in - return ComicsBooksManager() - } - .inObjectScope(.container) - container.register(EventsManager.self) { _ in - return EventsManager() - } - .inObjectScope(.container) - - // API Client - container.register(AuthorizationInterceptor.self) { _ in - return AuthorizationInterceptor() - } - .inObjectScope(.container) - - container.register(APIClient.self) { _ in - return APIClient() - } - .inObjectScope(.container) - - container.register(EventsManager.self) { _ in - return EventsManager() - } - .inObjectScope(.container) - container.register(EntityDetector.self) { _ in - return EntityDetector() - } - .inObjectScope(.container) - - container.register(FileSystemManager.self) { _ in - return FileSystemManager() - } - .inObjectScope(.container) - - container.register(FluxReaderAPI.self) { _ in - return FluxReaderAPI() - } - .inObjectScope(.container) - container.register(PreferencesManager.self) { _ in - return PreferencesManager() - } - .inObjectScope(.container) - - container.register(NetworkMonitor.self) { _ in - return NetworkMonitor() - } - .inObjectScope(.container) - */ + } } diff --git a/medmap/ViewModels/DashboardViewModel.swift b/medmap/ViewModels/DashboardViewModel.swift index 6955401..2f5ac25 100644 --- a/medmap/ViewModels/DashboardViewModel.swift +++ b/medmap/ViewModels/DashboardViewModel.swift @@ -11,12 +11,7 @@ final class DashboardViewModel: ViewModel { @Published private(set) var errorMessage: String? @Published private(set) var logoutErrorMessage: String? - private let api: MedMapAPI - - init(api: MedMapAPI = MedMapAPI()) { - self.api = api - super.init() - } + private let api: MedMapAPI = DIContainer.shared.resolve() var patientAge: Int? { guard let dateOfBirth = patient?.dateOfBirth else { return nil } diff --git a/medmap/ViewModels/LoginViewModel.swift b/medmap/ViewModels/LoginViewModel.swift index cbe3cfa..8070983 100644 --- a/medmap/ViewModels/LoginViewModel.swift +++ b/medmap/ViewModels/LoginViewModel.swift @@ -14,12 +14,10 @@ final class LoginViewModel: ViewModel { @Published private(set) var errorMessage: String? @Published private(set) var authenticatedPatient: LoginResponse? - private let api: MedMapAPI + private let api: MedMapAPI = DIContainer.shared.resolve() - init(api: MedMapAPI = MedMapAPI()) { - self.api = api - super.init() - } + + var canSubmit: Bool { !email.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty && !password.isEmpty && !isLoading diff --git a/medmap/ViewModels/PatientMonthlyHistoryViewModel.swift b/medmap/ViewModels/PatientMonthlyHistoryViewModel.swift index 41cbb21..af857e4 100644 --- a/medmap/ViewModels/PatientMonthlyHistoryViewModel.swift +++ b/medmap/ViewModels/PatientMonthlyHistoryViewModel.swift @@ -4,21 +4,19 @@ // import Foundation - +import Combine +import SwiftUI @MainActor final class PatientMonthlyHistoryViewModel: ViewModel { @Published private(set) var history: PatientMonthlyHistoryResponse? @Published private(set) var errorMessage: String? - private let api: MedMapAPI + private let api: MedMapAPI = DIContainer.shared.resolve() private let calendar = Calendar(identifier: .gregorian) private var selectedMonth = Date.now - init(api: MedMapAPI = MedMapAPI()) { - self.api = api - super.init() - } + func loadHistory() async { guard !isLoading else { return } @@ -51,4 +49,4 @@ final class PatientMonthlyHistoryViewModel: ViewModel { formatter.dateFormat = "yyyy-MM-dd" return formatter.string(from: selectedMonth) } -} \ No newline at end of file +} diff --git a/medmap/ViewModels/SignupViewModel.swift b/medmap/ViewModels/SignupViewModel.swift index c980f3e..4c2f87b 100644 --- a/medmap/ViewModels/SignupViewModel.swift +++ b/medmap/ViewModels/SignupViewModel.swift @@ -14,12 +14,9 @@ final class SignupViewModel: ViewModel { @Published var confirmationPassword = "" @Published private(set) var errorMessage: String? - private let api: MedMapAPI + private let api: MedMapAPI = DIContainer.shared.resolve() - init(api: MedMapAPI = MedMapAPI()) { - self.api = api - super.init() - } + var canSubmit: Bool { !email.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty && diff --git a/medmap/Views/DashboardView.swift b/medmap/Views/DashboardView.swift index e6335c1..82a79cc 100644 --- a/medmap/Views/DashboardView.swift +++ b/medmap/Views/DashboardView.swift @@ -60,42 +60,43 @@ struct DashboardView: View { // MARK: - Top bar private var topBar: some View { - HStack { - Image("timerIcon") - .foregroundStyle(Color.appBackground) - .frame(width: 32, height: 32) - - - Spacer() - - HStack(spacing: 6) { - Image("bluetoothIcon") - .foregroundStyle(Color.appTextPrimary.opacity(0.55)) - Circle() - .fill(.green) - .frame(width: 16, height: 16) - } - - Button { - isShowingLogoutConfirmation = true - } label: { - Image(systemName: "power") - .font(.system(size: 15, weight: .semibold)) - .foregroundStyle(Color.appTextPrimary.opacity(0.52)) + VStack(spacing: 8) { + HStack { + Image("timerIcon") + .foregroundStyle(Color.appBackground) .frame(width: 32, height: 32) - .background(.white.opacity(0.45)) - .clipShape(Circle()) - } - .buttonStyle(.plain) - .accessibilityLabel("Terminar sessao") - } - .padding(.horizontal, 32) - if let logoutErrorMessage = viewModel.logoutErrorMessage { - Text(logoutErrorMessage) - .font(.jakartaRegular12) - .foregroundStyle(.red) - .frame(maxWidth: .infinity) + Spacer() + + HStack(spacing: 6) { + Image("bluetoothIcon") + .foregroundStyle(Color.appTextPrimary.opacity(0.55)) + Circle() + .fill(.green) + .frame(width: 16, height: 16) + } + + Button { + isShowingLogoutConfirmation = true + } label: { + Image(systemName: "power") + .font(.system(size: 15, weight: .semibold)) + .foregroundStyle(Color.appTextPrimary.opacity(0.52)) + .frame(width: 32, height: 32) + .background(.white.opacity(0.45)) + .clipShape(Circle()) + } + .buttonStyle(.plain) + .accessibilityLabel("Terminar sessao") + } + .padding(.horizontal, 32) + + if let logoutErrorMessage = viewModel.logoutErrorMessage { + Text(logoutErrorMessage) + .font(.jakartaRegular12) + .foregroundStyle(.red) + .frame(maxWidth: .infinity) + } } } @@ -253,10 +254,13 @@ private struct MedicationCardView: View { .clipShape(Capsule()) if let nextDoseTime = card.nextDoseTime { - Group { - Text("Próxima toma às ") + - Text("\(nextDoseTime)h").fontWeight(.bold) - } + Text({ + var attributed = AttributedString("Próxima toma às ") + var timePart = AttributedString("\(nextDoseTime)h") + timePart.inlinePresentationIntent = .stronglyEmphasized + attributed.append(timePart) + return attributed + }()) .font(.jakartaRegular14) .foregroundStyle(Color.appBackground) }