Skip to content

Commit

Permalink
refactor: address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
shafqat-muneer committed Apr 9, 2024
1 parent 97fb26d commit 995c1a6
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 74 deletions.
38 changes: 0 additions & 38 deletions Core/Core/Analytics/CoreAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,41 +254,3 @@ public struct EventCategory {
public static let video = "video"
public static let course = "course"
}

public enum EnrollmentMode: String {
case audit
case verified
case none
}

public enum Pacing: String {
case `self` = "self"
case instructor = "instructor"
}

public enum Action: String {
case on = "on"
case off = "off"
case allow = "Allow"
case doNotAllow = "donot_allow"
case ok = "OK"
case cancel = "Cancel"
case update = "Update"
case remove = "Remove"
case done = "Done"
case viewEvent = "view_event"
}

public enum Dialog: String {
case permission = "Permission"
case add = "Add"
case remove = "Remove"
case update = "Update"
case confirmed = "Confirmed"
}

public enum Snackbar: String {
case add = "Add"
case remove = "Remove"
case update = "Update"
}
12 changes: 10 additions & 2 deletions Course/Course.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
02F0144E28F46474002E513D /* CourseContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseContainerView.swift; sourceTree = "<group>"; };
02F0145628F4A2FF002E513D /* CourseContainerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseContainerViewModel.swift; sourceTree = "<group>"; };
02F066E729DC71750073E13B /* SubtittlesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubtittlesView.swift; sourceTree = "<group>"; };
02F175362A4DAFD20019CD70 /* CourseAnalytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseAnalytics.swift; sourceTree = "<group>"; };
02F175362A4DAFD20019CD70 /* CourseAnalytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CourseAnalytics.swift; path = ../Presentation/CourseAnalytics.swift; sourceTree = "<group>"; };
02F3BFDC29252E900051930C /* CourseRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseRouter.swift; sourceTree = "<group>"; };
02F78AEA29E6BCA20038DE30 /* VideoPlayerViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = VideoPlayerViewModelTests.swift; path = CourseTests/Presentation/Unit/VideoPlayerViewModelTests.swift; sourceTree = SOURCE_ROOT; };
02F98A8028F8224200DE94C0 /* Discussion.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Discussion.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -288,6 +288,7 @@
0289F8F028E1C3510064F8F3 /* Course */ = {
isa = PBXGroup;
children = (
979A6AB92BC3FFF8001B0DE3 /* Analytics */,
02B6B3AD28E1C47100232911 /* SwiftGen */,
02B6B3B828E1D12900232911 /* Data */,
02B6B3B528E1D10700232911 /* Domain */,
Expand Down Expand Up @@ -382,7 +383,6 @@
BAC0E0DC2B32F0EA006B68A9 /* Downloads */,
BAD9CA482B2C88D500DE790A /* Subviews */,
02F3BFDC29252E900051930C /* CourseRouter.swift */,
02F175362A4DAFD20019CD70 /* CourseAnalytics.swift */,
);
path = Presentation;
sourceTree = "<group>";
Expand Down Expand Up @@ -493,6 +493,14 @@
path = Mock;
sourceTree = "<group>";
};
979A6AB92BC3FFF8001B0DE3 /* Analytics */ = {
isa = PBXGroup;
children = (
02F175362A4DAFD20019CD70 /* CourseAnalytics.swift */,
);
path = Analytics;
sourceTree = "<group>";
};
97CA95212B875EA200A9EDEA /* Views */ = {
isa = PBXGroup;
children = (
Expand Down
62 changes: 50 additions & 12 deletions Course/Course/Presentation/CourseAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,44 @@
import Foundation
import Core

public enum EnrollmentMode: String {
case audit
case verified
case none
}

public enum CoursePacing: String {
case `self` = "self"
case instructor = "instructor"
}

public enum CalendarDialogueAction: String {
case on = "on"
case off = "off"
case allow = "allow"
case doNotAllow = "donot_allow"
case add = "add"
case cancel = "cancel"
case remove = "remove"
case update = "update"
case done = "done"
case viewEvent = "view_event"
}

public enum CalendarDialogueType: String {
case devicePermission = "device_permission"
case addCalendar = "add_calendar"
case removeCalendar = "remove_calendar"
case updateCalendar = "update_calendar"
case eventsAdded = "events_added"
}

public enum Snackbar: String {
case added
case removed
case updated
}

//sourcery: AutoMockable
public protocol CourseAnalytics {
func resumeCourseClicked(courseId: String, courseName: String, blockId: String)
Expand All @@ -31,20 +69,20 @@ public protocol CourseAnalytics {
)
func calendarSyncToggle(
userType: EnrollmentMode,
pacing: Pacing,
pacing: CoursePacing,
courseId: String,
action: Action
action: CalendarDialogueAction
)
func calendarSyncDialogAction(
userType: EnrollmentMode,
pacing: Pacing,
pacing: CoursePacing,
courseId: String,
dialog: Dialog,
action: Action
dialog: CalendarDialogueType,
action: CalendarDialogueAction
)
func calendarSyncSnackbar(
userType: EnrollmentMode,
pacing: Pacing,
pacing: CoursePacing,
courseId: String,
snackbar: Snackbar
)
Expand Down Expand Up @@ -108,20 +146,20 @@ class CourseAnalyticsMock: CourseAnalytics {
) {}
func calendarSyncToggle(
userType: EnrollmentMode,
pacing: Pacing,
pacing: CoursePacing,
courseId: String,
action: Action
action: CalendarDialogueAction
) {}
func calendarSyncDialogAction(
userType: EnrollmentMode,
pacing: Pacing,
pacing: CoursePacing,
courseId: String,
dialog: Dialog,
action: Action
dialog: CalendarDialogueType,
action: CalendarDialogueAction
) {}
func calendarSyncSnackbar(
userType: EnrollmentMode,
pacing: Pacing,
pacing: CoursePacing,
courseId: String,
snackbar: Snackbar
) {}
Expand Down
32 changes: 16 additions & 16 deletions Course/Course/Presentation/Dates/CourseDatesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ extension CourseDatesViewModel {
switch status {
case .authorized:
if previousStatus == .notDetermined {
trackCalendarSyncDialogAction(dialog: .permission, action: .allow)
trackCalendarSyncDialogAction(dialog: .devicePermission, action: .allow)
}
showAddCalendarAlert()
default:
if previousStatus == .notDetermined {
trackCalendarSyncDialogAction(dialog: .permission, action: .doNotAllow)
trackCalendarSyncDialogAction(dialog: .devicePermission, action: .doNotAllow)
}
isOn = false
if previousStatus == status {
Expand Down Expand Up @@ -268,13 +268,13 @@ extension CourseDatesViewModel {
),
positiveAction: CoreLocalization.Alert.accept,
onCloseTapped: { [weak self] in
self?.trackCalendarSyncDialogAction(dialog: .add, action: .cancel)
self?.trackCalendarSyncDialogAction(dialog: .addCalendar, action: .cancel)
self?.router.dismiss(animated: true)
self?.isOn = false
self?.calendar.syncOn = false
},
okTapped: { [weak self] in
self?.trackCalendarSyncDialogAction(dialog: .add, action: .ok)
self?.trackCalendarSyncDialogAction(dialog: .addCalendar, action: .add)
self?.router.dismiss(animated: true)
Task { [weak self] in
await self?.addCourseEvents()
Expand All @@ -293,14 +293,14 @@ extension CourseDatesViewModel {
),
positiveAction: CoreLocalization.Alert.accept,
onCloseTapped: { [weak self] in
self?.trackCalendarSyncDialogAction(dialog: .remove, action: .cancel)
self?.trackCalendarSyncDialogAction(dialog: .removeCalendar, action: .cancel)
self?.router.dismiss(animated: true)
},
okTapped: { [weak self] in
self?.trackCalendarSyncDialogAction(dialog: .remove, action: .ok)
self?.trackCalendarSyncDialogAction(dialog: .removeCalendar, action: .remove)
self?.router.dismiss(animated: true)
self?.removeCourseCalendar { [weak self] _ in
self?.trackCalendarSyncSnackbar(snackbar: .remove)
self?.trackCalendarSyncSnackbar(snackbar: .removed)
self?.eventState = .removedCalendar
}

Expand All @@ -311,7 +311,7 @@ extension CourseDatesViewModel {

private func showEventsAddedSuccessAlert() {
if calendar.isModalPresented {
trackCalendarSyncSnackbar(snackbar: .add)
trackCalendarSyncSnackbar(snackbar: .added)
eventState = .addedCalendar
return
}
Expand All @@ -323,13 +323,13 @@ extension CourseDatesViewModel {
),
positiveAction: CourseLocalization.CourseDates.calendarViewEvents,
onCloseTapped: { [weak self] in
self?.trackCalendarSyncDialogAction(dialog: .confirmed, action: .done)
self?.trackCalendarSyncDialogAction(dialog: .eventsAdded, action: .done)
self?.router.dismiss(animated: true)
self?.isOn = true
self?.calendar.syncOn = true
},
okTapped: { [weak self] in
self?.trackCalendarSyncDialogAction(dialog: .confirmed, action: .viewEvent)
self?.trackCalendarSyncDialogAction(dialog: .eventsAdded, action: .viewEvent)
self?.router.dismiss(animated: true)
if let url = URL(string: "calshow://"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
Expand Down Expand Up @@ -366,24 +366,24 @@ extension CourseDatesViewModel {
positiveAction: CourseLocalization.CourseDates.calendarShiftPromptUpdateNow,
onCloseTapped: { [weak self] in
// Remove course calendar
self?.trackCalendarSyncDialogAction(dialog: .update, action: .remove)
self?.trackCalendarSyncDialogAction(dialog: .updateCalendar, action: .remove)
self?.router.dismiss(animated: true)
self?.removeCourseCalendar { [weak self] _ in
self?.trackCalendarSyncSnackbar(snackbar: .remove)
self?.trackCalendarSyncSnackbar(snackbar: .removed)
self?.eventState = .removedCalendar
}
},
okTapped: { [weak self] in
// Update Calendar Now
self?.trackCalendarSyncDialogAction(dialog: .update, action: .update)
self?.trackCalendarSyncDialogAction(dialog: .updateCalendar, action: .update)
self?.router.dismiss(animated: true)
self?.removeCourseCalendar(trackAnalytics: false) { success in
self?.isOn = !success
self?.calendar.syncOn = false
self?.addCourseEvents(trackAnalytics: false) { [weak self] calendarEventsAdded in
self?.isOn = calendarEventsAdded
if calendarEventsAdded {
self?.trackCalendarSyncSnackbar(snackbar: .update)
self?.trackCalendarSyncSnackbar(snackbar: .updated)
self?.calendar.syncOn = calendarEventsAdded
self?.eventState = .updatedCalendar
}
Expand Down Expand Up @@ -466,7 +466,7 @@ extension CourseDatesViewModel {
}

extension CourseDatesViewModel {
private func trackCalendarSyncToggle(action: Action) {
private func trackCalendarSyncToggle(action: CalendarDialogueAction) {
analytics.calendarSyncToggle(
userType: .none,
pacing: courseStructure?.isSelfPaced ?? true ? .`self` : .instructor,
Expand All @@ -475,7 +475,7 @@ extension CourseDatesViewModel {
)
}

private func trackCalendarSyncDialogAction(dialog: Dialog, action: Action) {
private func trackCalendarSyncDialogAction(dialog: CalendarDialogueType, action: CalendarDialogueAction) {
analytics.calendarSyncDialogAction(
userType: .none,
pacing: courseStructure?.isSelfPaced ?? true ? .`self` : .instructor,
Expand Down
12 changes: 6 additions & 6 deletions OpenEdX/Managers/AnalyticsManager/AnalyticsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,9 @@ class AnalyticsManager: AuthorizationAnalytics,

func calendarSyncToggle(
userType: EnrollmentMode,
pacing: Pacing,
pacing: CoursePacing,
courseId: String,
action: Action
action: CalendarDialogueAction
) {
let parameters: [String: Any] = [
EventParamKey.userType: userType.rawValue,
Expand All @@ -567,10 +567,10 @@ class AnalyticsManager: AuthorizationAnalytics,

func calendarSyncDialogAction(
userType: EnrollmentMode,
pacing: Pacing,
pacing: CoursePacing,
courseId: String,
dialog: Dialog,
action: Action
dialog: CalendarDialogueType,
action: CalendarDialogueAction
) {
let parameters: [String: Any] = [
EventParamKey.userType: userType.rawValue,
Expand All @@ -587,7 +587,7 @@ class AnalyticsManager: AuthorizationAnalytics,

func calendarSyncSnackbar(
userType: EnrollmentMode,
pacing: Pacing,
pacing: CoursePacing,
courseId: String,
snackbar: Snackbar
) {
Expand Down

0 comments on commit 995c1a6

Please sign in to comment.