Skip to content

Commit

Permalink
fix: address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanStepanok committed Dec 5, 2024
1 parent 9a2a7d0 commit 05361e1
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Core/Core/Network/OfflineSyncManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

@preconcurrency import AVKit
@preconcurrency import Combine
import Core

@MainActor
public protocol PlayerViewControllerHolderProtocol: AnyObject, Sendable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ public final class DiscussionSearchTopicsViewModel<S: Scheduler>: 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
}
Expand Down
8 changes: 4 additions & 4 deletions OpenEdX/Data/DiscoveryPersistence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions OpenEdX/Managers/PipManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public final class PipManager: PipManagerProtocol {
controllerHolder?.getRatePublisher()
}

@MainActor
public func restore(holder: PlayerViewControllerHolderProtocol) async throws {
let courseID = holder.courseID

Expand All @@ -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<MainScreenView> else {
Expand Down Expand Up @@ -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<CourseVerticalView> {
Expand All @@ -148,7 +145,6 @@ public final class PipManager: PipManagerProtocol {
throw PipManagerError.cantCreateCourseVerticalView
}

@MainActor
private func courseUnitController(
for holder: PlayerViewControllerHolderProtocol
) async throws -> UIHostingController<CourseUnitView> {
Expand Down Expand Up @@ -176,7 +172,6 @@ public final class PipManager: PipManagerProtocol {
throw PipManagerError.cantCreateCourseUnitView
}

@MainActor
private func containerController(
for holder: PlayerViewControllerHolderProtocol
) async throws -> UIHostingController<CourseContainerView> {
Expand Down Expand Up @@ -210,7 +205,6 @@ public final class PipManager: PipManagerProtocol {
}
}

@MainActor
private var topCourseUnitController: UIHostingController<CourseUnitView>? {
router.getNavigationController().visibleViewController as? UIHostingController<CourseUnitView>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -145,7 +144,6 @@ public final class DatesAndCalendarViewModel: ObservableObject {
updateCoursesCount()
}

@MainActor
func clearAllData() async {
await calendarManager.clearAllData(removeCalendar: true)
router.back(animated: false)
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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(
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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 {
Expand All @@ -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 }) {
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -394,7 +390,6 @@ public final class DatesAndCalendarViewModel: ObservableObject {
}

// MARK: - Request Calendar Permission
@MainActor
func requestCalendarPermission() async {
if await calendarManager.requestAccess() {
await showNewCalendarSetup()
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions Profile/Profile/Presentation/Settings/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? ""
Expand All @@ -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()
Expand Down

0 comments on commit 05361e1

Please sign in to comment.