From e62d4a83942708b6eb940bad06736e736c592e34 Mon Sep 17 00:00:00 2001 From: Alexander Romanov Date: Mon, 10 Apr 2023 18:29:01 +0300 Subject: [PATCH] Clean code --- Package.swift | 8 +++ .../CreateEventViewModel.swift | 5 +- .../AttendeesList/AttendeesViewModel.swift | 3 +- .../ContactsListsViewModel.swift | 3 +- .../ContactsPicker/EmailPickerViewModel.swift | 3 +- .../LauncherKit/LauncherViewModel.swift | 11 ++-- .../LauncherKit/RateAppScreen.swift | 4 +- .../PINCode/SetPINCodeViewModel.swift | 2 - .../Views/Security/SecuritySettingsView.swift | 4 +- .../SettingsKit/Views/SettingsView.swift | 1 - .../SoundsAndVibrationsSettingsView.swift | 1 - .../ViewModel/StoreViewModel.swift | 3 +- .../StoreKit/Views/StoreProductView.swift | 3 +- .../Views/SubscriptionPrivacyView.swift | 2 - .../SystemKit/SystemServices.swift | 7 ++- .../AddressPickerViewModel.swift | 3 +- .../OversizeNoticeKit/NoticeListView.swift | 3 +- .../LocalNotificationSetScreenViewModel.swift | 3 +- .../NotificationSetScreen.swift | 60 ------------------- 19 files changed, 41 insertions(+), 88 deletions(-) delete mode 100644 Sources/OversizeNotificationKit/NotificationSetScreen.swift diff --git a/Package.swift b/Package.swift index e50173d..7708eff 100644 --- a/Package.swift +++ b/Package.swift @@ -10,6 +10,7 @@ let productionDependencies: [PackageDescription.Package.Dependency] = { [ .package(url: "https://github.com/oversizedev/OversizeCore.git", branch: "main"), .package(url: "https://github.com/oversizedev/OversizeComponents.git", branch: "main"), .package(url: "https://github.com/oversizedev/OversizeResources.git", branch: "main"), + .package(url: "https://github.com/hmlongco/Factory.git", .upToNextMajor(from: "2.1.3")) ] }() let developmentDependencies: [PackageDescription.Package.Dependency] = { [ @@ -19,6 +20,7 @@ let developmentDependencies: [PackageDescription.Package.Dependency] = { [ .package(name: "OversizeCore", path: "../OversizeCore"), .package(name: "OversizeComponents", path: "../OversizeComponents"), .package(name: "OversizeResources", path: "../OversizeResources"), + .package(url: "https://github.com/hmlongco/Factory.git", .upToNextMajor(from: "2.1.3")) ] }() let package = Package( @@ -52,6 +54,7 @@ let package = Package( .product(name: "OversizeComponents", package: "OversizeComponents"), .product(name: "OversizeLocalizable", package: "OversizeLocalizable"), .product(name: "OversizeResources", package: "OversizeResources"), + .product(name: "Factory", package: "Factory") ] ), .target( @@ -71,6 +74,7 @@ let package = Package( .product(name: "OversizeServices", package: "OversizeServices"), .product(name: "OversizeCalendarService", package: "OversizeServices"), .product(name: "OversizeLocationService", package: "OversizeServices"), + .product(name: "Factory", package: "Factory") ] ), .target( @@ -81,6 +85,7 @@ let package = Package( .product(name: "OversizeServices", package: "OversizeServices"), .product(name: "OversizeContactsService", package: "OversizeServices"), .product(name: "OversizeCalendarService", package: "OversizeServices"), + .product(name: "Factory", package: "Factory") ] ), .target( @@ -89,6 +94,7 @@ let package = Package( .product(name: "OversizeUI", package: "OversizeUI"), .product(name: "OversizeServices", package: "OversizeServices"), .product(name: "OversizeLocationService", package: "OversizeServices"), + .product(name: "Factory", package: "Factory") ] ), .target( @@ -99,6 +105,7 @@ let package = Package( .product(name: "OversizeUI", package: "OversizeUI"), .product(name: "OversizeServices", package: "OversizeServices"), .product(name: "OversizeStoreService", package: "OversizeServices"), + .product(name: "Factory", package: "Factory") ] ), .target( @@ -114,6 +121,7 @@ let package = Package( .product(name: "OversizeUI", package: "OversizeUI"), .product(name: "OversizeServices", package: "OversizeServices"), .product(name: "OversizeNotificationService", package: "OversizeServices"), + .product(name: "Factory", package: "Factory") ] ), .target( diff --git a/Sources/OversizeCalendarKit/CreateEventScreen/CreateEventViewModel.swift b/Sources/OversizeCalendarKit/CreateEventScreen/CreateEventViewModel.swift index 5947764..27774fd 100644 --- a/Sources/OversizeCalendarKit/CreateEventScreen/CreateEventViewModel.swift +++ b/Sources/OversizeCalendarKit/CreateEventScreen/CreateEventViewModel.swift @@ -9,6 +9,7 @@ import OversizeCore import OversizeLocationService import OversizeServices import SwiftUI +import Factory public enum CreateEventType: Equatable { case new(Date?, calendar: EKCalendar?) @@ -17,8 +18,8 @@ public enum CreateEventType: Equatable { @MainActor public class CreateEventViewModel: ObservableObject { - @Injected(Container.calendarService) private var calendarService: CalendarService - @Injected(Container.locationService) private var locationService: LocationServiceProtocol + @Injected(\.calendarService) private var calendarService: CalendarService + @Injected(\.locationService) private var locationService: LocationServiceProtocol @Published var state = CreateEventViewModelState.initial @Published var sheet: CreateEventViewModel.Sheet? = nil diff --git a/Sources/OversizeContactsKit/AttendeesList/AttendeesViewModel.swift b/Sources/OversizeContactsKit/AttendeesList/AttendeesViewModel.swift index 555070c..c39641e 100644 --- a/Sources/OversizeContactsKit/AttendeesList/AttendeesViewModel.swift +++ b/Sources/OversizeContactsKit/AttendeesList/AttendeesViewModel.swift @@ -9,10 +9,11 @@ import OversizeContactsService import OversizeCore import OversizeServices import SwiftUI +import Factory @MainActor class AttendeesViewModel: ObservableObject { - @Injected(Container.contactsService) private var contactsService: ContactsService + @Injected(\.contactsService) private var contactsService: ContactsService @Published var state = AttendeesViewModelState.initial @Published var searchText: String = .init() diff --git a/Sources/OversizeContactsKit/ContactsLists/ContactsListsViewModel.swift b/Sources/OversizeContactsKit/ContactsLists/ContactsListsViewModel.swift index efb0a02..6d62691 100644 --- a/Sources/OversizeContactsKit/ContactsLists/ContactsListsViewModel.swift +++ b/Sources/OversizeContactsKit/ContactsLists/ContactsListsViewModel.swift @@ -8,10 +8,11 @@ import OversizeContactsService import OversizeCore import OversizeServices import SwiftUI +import Factory @MainActor public class ContactsListsViewModel: ObservableObject { - @Injected(Container.contactsService) private var contactsService: ContactsService + @Injected(\.contactsService) private var contactsService: ContactsService @Published var state = ContactsPickerViewModelState.initial @Published var searchText: String = .init() diff --git a/Sources/OversizeContactsKit/ContactsPicker/EmailPickerViewModel.swift b/Sources/OversizeContactsKit/ContactsPicker/EmailPickerViewModel.swift index ff61a92..31892c1 100644 --- a/Sources/OversizeContactsKit/ContactsPicker/EmailPickerViewModel.swift +++ b/Sources/OversizeContactsKit/ContactsPicker/EmailPickerViewModel.swift @@ -8,10 +8,11 @@ import OversizeContactsService import OversizeCore import OversizeServices import SwiftUI +import Factory @MainActor class EmailPickerViewModel: ObservableObject { - @Injected(Container.contactsService) private var contactsService: ContactsService + @Injected(\.contactsService) private var contactsService: ContactsService @Published var state = ContactsPickerViewModelState.initial @Published var searchText: String = .init() diff --git a/Sources/OversizeKit/LauncherKit/LauncherViewModel.swift b/Sources/OversizeKit/LauncherKit/LauncherViewModel.swift index 0df2434..5a1f715 100644 --- a/Sources/OversizeKit/LauncherKit/LauncherViewModel.swift +++ b/Sources/OversizeKit/LauncherKit/LauncherViewModel.swift @@ -11,14 +11,15 @@ import SwiftUI #if canImport(LocalAuthentication) import LocalAuthentication #endif +import Factory @MainActor public final class LauncherViewModel: ObservableObject { - @Injected(Container.biometricService) var biometricService - @Injected(Container.appStateService) var appStateService: AppStateService - @Injected(Container.settingsService) var settingsService - @Injected(Container.appStoreReviewService) var reviewService: AppStoreReviewServiceProtocol - @Injected(Container.storeKitService) private var storeKitService: StoreKitService + @Injected(\.biometricService) var biometricService + @Injected(\.appStateService) var appStateService: AppStateService + @Injected(\.settingsService) var settingsService + @Injected(\.appStoreReviewService) var reviewService: AppStoreReviewServiceProtocol + @Injected(\.storeKitService) private var storeKitService: StoreKitService @AppStorage("AppState.PremiumState") var isPremium: Bool = false @AppStorage("AppState.SubscriptionsState") var subscriptionsState: RenewalState = .expired diff --git a/Sources/OversizeKit/LauncherKit/RateAppScreen.swift b/Sources/OversizeKit/LauncherKit/RateAppScreen.swift index 8370d57..3c0b699 100644 --- a/Sources/OversizeKit/LauncherKit/RateAppScreen.swift +++ b/Sources/OversizeKit/LauncherKit/RateAppScreen.swift @@ -5,12 +5,12 @@ import OversizeResources import OversizeServices - +import Factory import OversizeUI import SwiftUI struct RateAppScreen: View { - @Injected(Container.appStoreReviewService) var reviewService + @Injected(\.appStoreReviewService) var reviewService @Environment(\.dismiss) var dismiss var body: some View { diff --git a/Sources/OversizeKit/SettingsKit/Views/Security/PINCode/SetPINCodeViewModel.swift b/Sources/OversizeKit/SettingsKit/Views/Security/PINCode/SetPINCodeViewModel.swift index 739bc17..a75ebd3 100644 --- a/Sources/OversizeKit/SettingsKit/Views/Security/PINCode/SetPINCodeViewModel.swift +++ b/Sources/OversizeKit/SettingsKit/Views/Security/PINCode/SetPINCodeViewModel.swift @@ -5,9 +5,7 @@ import OversizeCore import OversizeLocalizable - import OversizeServices - import OversizeUI import SwiftUI diff --git a/Sources/OversizeKit/SettingsKit/Views/Security/SecuritySettingsView.swift b/Sources/OversizeKit/SettingsKit/Views/Security/SecuritySettingsView.swift index b7039fc..3d5c1e6 100644 --- a/Sources/OversizeKit/SettingsKit/Views/Security/SecuritySettingsView.swift +++ b/Sources/OversizeKit/SettingsKit/Views/Security/SecuritySettingsView.swift @@ -5,14 +5,14 @@ import OversizeLocalizable import OversizeServices - import OversizeUI import SwiftUI +import Factory // swiftlint:disable line_length #if os(iOS) public struct SecuritySettingsView: View { - @Injected(Container.biometricService) var biometricService + @Injected(\.biometricService) var biometricService @Environment(\.verticalSizeClass) private var verticalSizeClass @Environment(\.isPortrait) var isPortrait @Environment(\.presentationMode) var presentationMode diff --git a/Sources/OversizeKit/SettingsKit/Views/SettingsView.swift b/Sources/OversizeKit/SettingsKit/Views/SettingsView.swift index 700a660..e913598 100644 --- a/Sources/OversizeKit/SettingsKit/Views/SettingsView.swift +++ b/Sources/OversizeKit/SettingsKit/Views/SettingsView.swift @@ -6,7 +6,6 @@ import OversizeLocalizable import OversizeResources import OversizeServices - import OversizeUI import SwiftUI diff --git a/Sources/OversizeKit/SettingsKit/Views/SoundAndVibration/SoundsAndVibrationsSettingsView.swift b/Sources/OversizeKit/SettingsKit/Views/SoundAndVibration/SoundsAndVibrationsSettingsView.swift index 166a704..eb841c7 100644 --- a/Sources/OversizeKit/SettingsKit/Views/SoundAndVibration/SoundsAndVibrationsSettingsView.swift +++ b/Sources/OversizeKit/SettingsKit/Views/SoundAndVibration/SoundsAndVibrationsSettingsView.swift @@ -6,7 +6,6 @@ import OversizeCore import OversizeLocalizable import OversizeServices - import OversizeUI import SwiftUI diff --git a/Sources/OversizeKit/StoreKit/StoreScreen/ViewModel/StoreViewModel.swift b/Sources/OversizeKit/StoreKit/StoreScreen/ViewModel/StoreViewModel.swift index 848480d..a31aef5 100644 --- a/Sources/OversizeKit/StoreKit/StoreScreen/ViewModel/StoreViewModel.swift +++ b/Sources/OversizeKit/StoreKit/StoreScreen/ViewModel/StoreViewModel.swift @@ -9,6 +9,7 @@ import OversizeServices import OversizeStoreService import StoreKit import SwiftUI +import Factory @MainActor class StoreViewModel: ObservableObject { @@ -19,7 +20,7 @@ class StoreViewModel: ObservableObject { case error(AppError) } - @Injected(Container.storeKitService) var storeKitService: StoreKitService + @Injected(\.storeKitService) var storeKitService: StoreKitService @Published var state = State.initial public var updateListenerTask: Task? diff --git a/Sources/OversizeKit/StoreKit/Views/StoreProductView.swift b/Sources/OversizeKit/StoreKit/Views/StoreProductView.swift index fac9083..88b7c9f 100644 --- a/Sources/OversizeKit/StoreKit/Views/StoreProductView.swift +++ b/Sources/OversizeKit/StoreKit/Views/StoreProductView.swift @@ -8,13 +8,14 @@ import OversizeStoreService import OversizeUI import StoreKit import SwiftUI +import Factory public struct StoreProductView: View { public enum StoreProductViewType { case row, collumn } - @Injected(Container.storeKitService) private var store: StoreKitService + @Injected(\.storeKitService) private var store: StoreKitService @State var isPurchased: Bool = false @Binding var isSelected: Bool diff --git a/Sources/OversizeKit/StoreKit/Views/SubscriptionPrivacyView.swift b/Sources/OversizeKit/StoreKit/Views/SubscriptionPrivacyView.swift index 7380ae6..692e91e 100644 --- a/Sources/OversizeKit/StoreKit/Views/SubscriptionPrivacyView.swift +++ b/Sources/OversizeKit/StoreKit/Views/SubscriptionPrivacyView.swift @@ -31,8 +31,6 @@ struct SubscriptionPrivacyView: View { HStack(spacing: .xxSmall) { Button("Restore") { Task { - // This call displays a system prompt that asks users to authenticate with their App Store credentials. - // Call this function only in response to an explicit user action, such as tapping a button. try? await AppStore.sync() } } diff --git a/Sources/OversizeKit/SystemKit/SystemServices.swift b/Sources/OversizeKit/SystemKit/SystemServices.swift index d884e91..781bd93 100644 --- a/Sources/OversizeKit/SystemKit/SystemServices.swift +++ b/Sources/OversizeKit/SystemKit/SystemServices.swift @@ -9,11 +9,12 @@ import OversizeServices import OversizeStoreService import OversizeUI import SwiftUI +import Factory public struct SystemServicesModifier: ViewModifier { - @Injected(Container.appStateService) var appState: AppStateService - @Injected(Container.settingsService) var settingsService: SettingsServiceProtocol - @Injected(Container.appStoreReviewService) var appStoreReviewService: AppStoreReviewServiceProtocol + @Injected(\.appStateService) var appState: AppStateService + @Injected(\.settingsService) var settingsService: SettingsServiceProtocol + @Injected(\.appStoreReviewService) var appStoreReviewService: AppStoreReviewServiceProtocol @Environment(\.scenePhase) var scenePhase: ScenePhase @Environment(\.theme) var theme: ThemeSettings diff --git a/Sources/OversizeLocationKit/AddressPicker/AddressPickerViewModel.swift b/Sources/OversizeLocationKit/AddressPicker/AddressPickerViewModel.swift index 1c29a2a..dff7788 100644 --- a/Sources/OversizeLocationKit/AddressPicker/AddressPickerViewModel.swift +++ b/Sources/OversizeLocationKit/AddressPicker/AddressPickerViewModel.swift @@ -9,10 +9,11 @@ import MapKit import OversizeLocationService import OversizeServices import SwiftUI +import Factory @MainActor class AddressPickerViewModel: NSObject, ObservableObject { - @Injected(Container.locationService) var locationService: LocationServiceProtocol + @Injected(\.locationService) var locationService: LocationServiceProtocol @Published var locationResults: [MKLocalSearchCompletion] = .init() @Published var searchTerm: String = .init() diff --git a/Sources/OversizeNoticeKit/NoticeListView.swift b/Sources/OversizeNoticeKit/NoticeListView.swift index 4eec60b..527eb98 100644 --- a/Sources/OversizeNoticeKit/NoticeListView.swift +++ b/Sources/OversizeNoticeKit/NoticeListView.swift @@ -9,9 +9,10 @@ import OversizeStoreService import OversizeUI import StoreKit import SwiftUI +import Factory public struct NoticeListView: View { - @Injected(Container.appStoreReviewService) var reviewService + @Injected(\.appStoreReviewService) var reviewService @Environment(\.isPremium) var isPremium: Bool @State private var isBannerClosed = false diff --git a/Sources/OversizeNotificationKit/LocalNotificationSetScreenViewModel.swift b/Sources/OversizeNotificationKit/LocalNotificationSetScreenViewModel.swift index 9440ea3..00017a9 100644 --- a/Sources/OversizeNotificationKit/LocalNotificationSetScreenViewModel.swift +++ b/Sources/OversizeNotificationKit/LocalNotificationSetScreenViewModel.swift @@ -7,10 +7,11 @@ import OversizeCore import OversizeNotificationService import OversizeServices import SwiftUI +import Factory @MainActor class LocalNotificationSetScreenViewModel: ObservableObject { - @Injected(Container.localNotificationService) var localNotificationService: LocalNotificationServiceProtocol + @Injected(\.localNotificationService) var localNotificationService: LocalNotificationServiceProtocol @Published var state = State.initial public let id: UUID diff --git a/Sources/OversizeNotificationKit/NotificationSetScreen.swift b/Sources/OversizeNotificationKit/NotificationSetScreen.swift deleted file mode 100644 index afa386e..0000000 --- a/Sources/OversizeNotificationKit/NotificationSetScreen.swift +++ /dev/null @@ -1,60 +0,0 @@ -// -// Copyright © 2023 Alexander Romanov -// NotificationSetScreen.swift -// - -/* - import OversizeUI - import UserNotifications - import OversizeNotificationService - import SwiftUI - - public struct LocalNotificationSetScreen: View { - - @Environment(\.dismiss) var dismiss - @StateObject var viewModel: LocalNotificationSetScreenViewModel - @Binding private var selection: [LocalNotificationAlertsTimes] - @State private var selectedAlerts: [LocalNotificationAlertsTimes] = [] - private let notification: LocalNotification - - public init(selection: Binding<[LocalNotificationAlertsTimes]>, notification: LocalNotification) { - _selection = selection - _selectedAlerts = State(wrappedValue: selection.wrappedValue) - _viewModel = StateObject(wrappedValue: LocalNotificationSetScreenViewModel()) - self.notification = notification - } - - public var body: some View { - PageView("Alarm") { - SectionView { - VStack(spacing: .zero) { - ForEach(LocalNotificationAlertsTimes.allCases) { alert in - Checkbox(alert.title, isOn: .constant((selectedAlerts.first { $0.id == alert.id } != nil) ? true : false)) { - if !selectedAlerts.isEmpty, let index = selectedAlerts.firstIndex(where: { $0.id == alert.id }) { - selectedAlerts.remove(at: index) - } else { - selectedAlerts.append(alert) - } - } - } - } - } - .surfaceContentRowInsets() - } - .backgroundSecondary() - .leadingBar { - BarButton(.close) - } - .trailingBar { - if selectedAlerts.isEmpty { - BarButton(.disabled("Done")) - } else { - BarButton(.accent("Done", action: { - selection = selectedAlerts - dismiss() - })) - } - } - } - } - */