From 05361e133bc7a289fbaa56bde99e2633cfb5ac6f Mon Sep 17 00:00:00 2001 From: IvanStepanok Date: Thu, 5 Dec 2024 13:24:22 +0200 Subject: [PATCH] fix: address feedback --- Core/Core/Network/OfflineSyncManager.swift | 4 +- .../Video/PlayerViewControllerHolder.swift | 1 - .../DiscussionSearchTopicsViewModel.swift | 18 ++++---- OpenEdX/Data/DiscoveryPersistence.swift | 8 ++-- OpenEdX/Managers/PipManager.swift | 8 +--- .../DatesAndCalendarViewModel.swift | 45 ++++++++----------- .../Settings/SettingsViewModel.swift | 3 -- 7 files changed, 34 insertions(+), 53 deletions(-) diff --git a/Core/Core/Network/OfflineSyncManager.swift b/Core/Core/Network/OfflineSyncManager.swift index a5fd17eb..bb4d995f 100644 --- a/Core/Core/Network/OfflineSyncManager.swift +++ b/Core/Core/Network/OfflineSyncManager.swift @@ -55,11 +55,11 @@ public class OfflineSyncManager: OfflineSyncManagerProtocol { ) var correctedProgressJson = progressJson correctedProgressJson = correctedProgressJson.removingPercentEncoding ?? correctedProgressJson - _ = message.webView?.evaluateJavaScript("markProblemCompleted('\(correctedProgressJson)')") { _ ,_ in } + _ = message.webView?.evaluateJavaScript("markProblemCompleted('\(correctedProgressJson)')") { _, _ in } } else if let offlineProgress = await persistence.loadProgress(for: blockID) { var correctedProgressJson = offlineProgress.progressJson correctedProgressJson = correctedProgressJson.removingPercentEncoding ?? correctedProgressJson - _ = message.webView?.evaluateJavaScript("markProblemCompleted('\(correctedProgressJson)')") { _ ,_ in } + _ = message.webView?.evaluateJavaScript("markProblemCompleted('\(correctedProgressJson)')") { _, _ in } } } diff --git a/Course/Course/Presentation/Video/PlayerViewControllerHolder.swift b/Course/Course/Presentation/Video/PlayerViewControllerHolder.swift index f2ee3448..787423c4 100644 --- a/Course/Course/Presentation/Video/PlayerViewControllerHolder.swift +++ b/Course/Course/Presentation/Video/PlayerViewControllerHolder.swift @@ -7,7 +7,6 @@ @preconcurrency import AVKit @preconcurrency import Combine -import Core @MainActor public protocol PlayerViewControllerHolderProtocol: AnyObject, Sendable { diff --git a/Discussion/Discussion/Presentation/DiscussionTopics/DiscussionSearchTopicsViewModel.swift b/Discussion/Discussion/Presentation/DiscussionTopics/DiscussionSearchTopicsViewModel.swift index d6887703..641f768c 100644 --- a/Discussion/Discussion/Presentation/DiscussionTopics/DiscussionSearchTopicsViewModel.swift +++ b/Discussion/Discussion/Presentation/DiscussionTopics/DiscussionSearchTopicsViewModel.swift @@ -167,15 +167,15 @@ public final class DiscussionSearchTopicsViewModel: ObservableObje thread.discussionPost( useRelativeDates: storage.useRelativeDates, action: { [weak self] in - guard let self else { return } - self.router.showThread( - thread: thread, - postStateSubject: self.postStateSubject, - isBlackedOut: false, - animated: true - ) - }) -) + guard let self else { return } + self.router.showThread( + thread: thread, + postStateSubject: self.postStateSubject, + isBlackedOut: false, + animated: true + ) + }) + ) } return result } diff --git a/OpenEdX/Data/DiscoveryPersistence.swift b/OpenEdX/Data/DiscoveryPersistence.swift index 06f955cb..0fadd5ed 100644 --- a/OpenEdX/Data/DiscoveryPersistence.swift +++ b/OpenEdX/Data/DiscoveryPersistence.swift @@ -17,7 +17,7 @@ public final class DiscoveryPersistence: DiscoveryPersistenceProtocol { public init(container: NSPersistentContainer) { self.container = container } - + public func loadDiscovery() async throws -> [CourseItem] { return try await container.performBackgroundTask { context in let result = try? context.fetch(CDDiscoveryCourse.fetchRequest()) @@ -71,8 +71,8 @@ public final class DiscoveryPersistence: DiscoveryPersistenceProtocol { } public func loadCourseDetails(courseID: String) async throws -> CourseDetails { - let request = CDCourseDetails.fetchRequest() - request.predicate = NSPredicate(format: "courseID = %@", courseID) + let request = CDCourseDetails.fetchRequest() + request.predicate = NSPredicate(format: "courseID = %@", courseID) return try await container.performBackgroundTask { context in guard let courseDetails = try? context.fetch(request).first else { throw NoCachedDataError() } return CourseDetails( @@ -95,7 +95,7 @@ public final class DiscoveryPersistence: DiscoveryPersistenceProtocol { public func saveCourseDetails(course: CourseDetails) async { await container.performBackgroundTask { context in - let newCourseDetails = CDCourseDetails(context: context) + let newCourseDetails = CDCourseDetails(context: context) newCourseDetails.courseID = course.courseID newCourseDetails.org = course.org newCourseDetails.courseTitle = course.courseTitle diff --git a/OpenEdX/Managers/PipManager.swift b/OpenEdX/Managers/PipManager.swift index 3e83cbb5..fc848f04 100644 --- a/OpenEdX/Managers/PipManager.swift +++ b/OpenEdX/Managers/PipManager.swift @@ -74,7 +74,6 @@ public final class PipManager: PipManagerProtocol { controllerHolder?.getRatePublisher() } - @MainActor public func restore(holder: PlayerViewControllerHolderProtocol) async throws { let courseID = holder.courseID @@ -92,12 +91,11 @@ public final class PipManager: PipManagerProtocol { try await navigate(to: holder) } - @MainActor public func pauseCurrentPipVideo() { + public func pauseCurrentPipVideo() { guard let holder = controllerHolder else { return } holder.playerController?.pause() } - @MainActor private func navigate(to holder: PlayerViewControllerHolderProtocol) async throws { let currentControllers = router.getNavigationController().viewControllers guard let mainController = currentControllers.first as? UIHostingController else { @@ -125,7 +123,6 @@ public final class PipManager: PipManagerProtocol { router.getNavigationController().setViewControllers(viewControllers, animated: true) } - @MainActor private func courseVerticalController( for holder: PlayerViewControllerHolderProtocol ) async throws -> UIHostingController { @@ -148,7 +145,6 @@ public final class PipManager: PipManagerProtocol { throw PipManagerError.cantCreateCourseVerticalView } - @MainActor private func courseUnitController( for holder: PlayerViewControllerHolderProtocol ) async throws -> UIHostingController { @@ -176,7 +172,6 @@ public final class PipManager: PipManagerProtocol { throw PipManagerError.cantCreateCourseUnitView } - @MainActor private func containerController( for holder: PlayerViewControllerHolderProtocol ) async throws -> UIHostingController { @@ -210,7 +205,6 @@ public final class PipManager: PipManagerProtocol { } } - @MainActor private var topCourseUnitController: UIHostingController? { router.getNavigationController().visibleViewController as? UIHostingController } diff --git a/Profile/Profile/Presentation/DatesAndCalendar/DatesAndCalendarViewModel.swift b/Profile/Profile/Presentation/DatesAndCalendar/DatesAndCalendarViewModel.swift index f9570be8..ca90966c 100644 --- a/Profile/Profile/Presentation/DatesAndCalendar/DatesAndCalendarViewModel.swift +++ b/Profile/Profile/Presentation/DatesAndCalendar/DatesAndCalendarViewModel.swift @@ -99,7 +99,6 @@ public final class DatesAndCalendarViewModel: ObservableObject { self.calendarNameHint = ProfileLocalization.Calendar.courseDates((Bundle.main.applicationName ?? "")) } - @MainActor var isInternetAvaliable: Bool { let avaliable = connectivity.isInternetAvaliable if !avaliable { @@ -125,10 +124,10 @@ public final class DatesAndCalendarViewModel: ObservableObject { $hideInactiveCourses .receive(on: DispatchQueue.main) .sink(receiveValue: { [weak self] hide in - guard let self = self else { return } - self.profileStorage.hideInactiveCourses = hide - }) - .store(in: &cancellables) + guard let self = self else { return } + self.profileStorage.hideInactiveCourses = hide + }) + .store(in: &cancellables) $courseCalendarSync .receive(on: DispatchQueue.main) @@ -145,7 +144,6 @@ public final class DatesAndCalendarViewModel: ObservableObject { updateCoursesCount() } - @MainActor func clearAllData() async { await calendarManager.clearAllData(removeCalendar: true) router.back(animated: false) @@ -195,9 +193,8 @@ public final class DatesAndCalendarViewModel: ObservableObject { } } } - + // MARK: - Fetch Courses and Sync - @MainActor func fetchCourses() async { guard connectivity.isInternetAvaliable else { return } assignmentStatus = .loading @@ -220,9 +217,9 @@ public final class DatesAndCalendarViewModel: ObservableObject { } && course.recentlyActive return updatedCourse } - + let addingIDs = Set(coursesForAdding.map { $0.courseID }) - + coursesForSync = coursesForSync.map { course in var updatedCourse = course if addingIDs.contains(course.courseID) { @@ -231,7 +228,7 @@ public final class DatesAndCalendarViewModel: ObservableObject { return updatedCourse } - for course in coursesForSync.filter{ $0.synced } { + for course in coursesForSync.filter { $0.synced } { do { let courseDates = try await interactor.getCourseDates(courseID: course.courseID) await syncSelectedCourse( @@ -259,7 +256,6 @@ public final class DatesAndCalendarViewModel: ObservableObject { syncingCoursesCount = coursesForSync.filter { $0.recentlyActive && $0.synced }.count } - @MainActor private func syncAllActiveCourses() async { guard profileStorage.firstCalendarUpdate == false else { coursesForAdding = [] @@ -318,7 +314,7 @@ public final class DatesAndCalendarViewModel: ObservableObject { courseDates: CourseDates, active: Bool ) async { - assignmentStatus = .loading + assignmentStatus = .loading await calendarManager.removeOutdatedEvents(courseID: courseID) guard active else { @@ -327,7 +323,7 @@ public final class DatesAndCalendarViewModel: ObservableObject { } return } - + await calendarManager.syncCourse(courseID: courseID, courseName: courseName, dates: courseDates) Task { if let index = self.coursesForSync.firstIndex(where: { $0.courseID == courseID && $0.recentlyActive }) { @@ -336,7 +332,7 @@ public final class DatesAndCalendarViewModel: ObservableObject { self.assignmentStatus = .synced } } - + func removeDeselectedCoursesFromCalendar() async { for course in coursesForDeleting { await calendarManager.removeOutdatedEvents(courseID: course.courseID) @@ -361,7 +357,7 @@ public final class DatesAndCalendarViewModel: ObservableObject { updateCoursesForSyncAndDeletion(course: coursesForSync[index]) } } - + private func updateCoursesForSyncAndDeletion(course: CourseForSync) { guard let initialCourse = coursesForSyncBeforeChanges.first(where: { $0.courseID == course.courseID @@ -394,7 +390,6 @@ public final class DatesAndCalendarViewModel: ObservableObject { } // MARK: - Request Calendar Permission - @MainActor func requestCalendarPermission() async { if await calendarManager.requestAccess() { await showNewCalendarSetup() @@ -403,28 +398,24 @@ public final class DatesAndCalendarViewModel: ObservableObject { } } - @MainActor private func showCalendarAccessDenied() async { - withAnimation(.bouncy(duration: 0.3)) { - self.showCalendaAccessDenied = true - } + withAnimation(.bouncy(duration: 0.3)) { + self.showCalendaAccessDenied = true + } } - @MainActor private func showDisableCalendarSync() async { withAnimation(.bouncy(duration: 0.3)) { self.showDisableCalendarSync = true } } - @MainActor private func showNewCalendarSetup() async { - withAnimation(.bouncy(duration: 0.3)) { - self.openNewCalendarView = true - } + withAnimation(.bouncy(duration: 0.3)) { + self.openNewCalendarView = true + } } - @MainActor func openAppSettings() { if let url = URL(string: UIApplication.openSettingsURLString), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHandler: nil) diff --git a/Profile/Profile/Presentation/Settings/SettingsViewModel.swift b/Profile/Profile/Presentation/Settings/SettingsViewModel.swift index 515ab12e..fa868f16 100644 --- a/Profile/Profile/Presentation/Settings/SettingsViewModel.swift +++ b/Profile/Profile/Presentation/Settings/SettingsViewModel.swift @@ -121,7 +121,6 @@ public final class SettingsViewModel: ObservableObject { }.store(in: &cancellables) } - @MainActor func contactSupport() -> URL? { let osVersion = UIDevice.current.systemVersion let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "" @@ -140,13 +139,11 @@ public final class SettingsViewModel: ObservableObject { await interactor.saveSettings(userSettings) } - @MainActor func openAppStore() { guard let appStoreURL = URL(string: config.appStoreLink) else { return } UIApplication.shared.open(appStoreURL) } - @MainActor func logOut() async { try? await interactor.logOut() try? await downloadManager.cancelAllDownloading()