Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update course resume logic, navigate learner to last viewed component #210

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Core/Core/SwiftGen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public enum CoreLocalization {
public static let backToOutline = CoreLocalization.tr("Localizable", "COURSEWARE.BACK_TO_OUTLINE", fallback: "Back to outline")
/// Continue
public static let `continue` = CoreLocalization.tr("Localizable", "COURSEWARE.CONTINUE", fallback: "Continue")
/// Continue with:
public static let continueWith = CoreLocalization.tr("Localizable", "COURSEWARE.CONTINUE_WITH", fallback: "Continue with:")
/// Course content
public static let courseContent = CoreLocalization.tr("Localizable", "COURSEWARE.COURSE_CONTENT", fallback: "Course content")
/// Course units
Expand All @@ -55,6 +53,8 @@ public enum CoreLocalization {
public static let previous = CoreLocalization.tr("Localizable", "COURSEWARE.PREVIOUS", fallback: "Prev")
/// Resume
public static let resume = CoreLocalization.tr("Localizable", "COURSEWARE.RESUME", fallback: "Resume")
/// Resume with:
public static let resumeWith = CoreLocalization.tr("Localizable", "COURSEWARE.RESUME_WITH", fallback: "Resume with:")
/// Section “
public static let section = CoreLocalization.tr("Localizable", "COURSEWARE.SECTION", fallback: "Section “")
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Core/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"COURSEWARE.IS_FINISHED" = "“ is finished.";
"COURSEWARE.CONTINUE" = "Continue";
"COURSEWARE.RESUME" = "Resume";
"COURSEWARE.CONTINUE_WITH" = "Continue with:";
"COURSEWARE.RESUME_WITH" = "Resume with:";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saeedbashir maybe we need to add this to uk.lproj too (even in English) to don't forget to localise this later. What do you think? Thank you

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rnr Yes, it should be changed in all the relevant files. I've changed it where needed.

"COURSEWARE.NEXT_SECTION" = "Next section";

"COURSEWARE.NEXT_SECTION_DESCRIPTION_FIRST" = "To proceed with “";
Expand Down
2 changes: 1 addition & 1 deletion Core/Core/uk.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"COURSEWARE.IS_FINISHED" = "“ завершена.";
"COURSEWARE.CONTINUE" = "Продовжити";
"COURSEWARE.RESUME" = "Resume";
"COURSEWARE.CONTINUE_WITH" = "Продовжити далі:";
"COURSEWARE.RESUME_WITH" = "Продовжити далі:";
"COURSEWARE.NEXT_SECTION" = "Наступний розділ";

"COURSEWARE.NEXT_SECTION_DESCRIPTION_FIRST" = "Щоб перейти до “";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ public class CourseContainerViewModel: BaseCourseViewModel {
return ContinueWith(
chapterIndex: chapterIndex,
sequentialIndex: sequentialIndex,
verticalIndex: verticalIndex
verticalIndex: verticalIndex,
lastVisitedBlockId: block.id
)
}
}
Expand Down
105 changes: 49 additions & 56 deletions Course/Course/Presentation/Outline/ContinueWithView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,28 @@ struct ContinueWith {
let chapterIndex: Int
let sequentialIndex: Int
let verticalIndex: Int
let lastVisitedBlockId: String
}

struct ContinueWithView: View {
private let data: ContinueWith
private let courseStructure: CourseStructure
private let action: () -> Void
private let courseContinueUnit: CourseVertical

private var idiom: UIUserInterfaceIdiom { UIDevice.current.userInterfaceIdiom }

init(data: ContinueWith, courseStructure: CourseStructure, action: @escaping () -> Void) {
init(data: ContinueWith, courseContinueUnit: CourseVertical, action: @escaping () -> Void) {
self.data = data
self.courseStructure = courseStructure
self.action = action
self.courseContinueUnit = courseContinueUnit
}

var body: some View {
VStack(alignment: .leading) {
let chapter = courseStructure.childs[data.chapterIndex]
if let vertical = chapter.childs[data.sequentialIndex].childs.first {
if idiom == .pad {
HStack(alignment: .top) {
VStack(alignment: .leading) {
ContinueTitle(vertical: vertical)
ContinueTitle(vertical: courseContinueUnit)
}.foregroundColor(Theme.Colors.textPrimary)
Spacer()
UnitButtonView(type: .continueLesson, action: action)
Expand All @@ -44,13 +43,11 @@ struct ContinueWithView: View {
.padding(.top, 32)
} else {
VStack(alignment: .leading) {
ContinueTitle(vertical: vertical)
ContinueTitle(vertical: courseContinueUnit)
.foregroundColor(Theme.Colors.textPrimary)
}
UnitButtonView(type: .continueLesson, action: action)
}

}
}.padding(.horizontal, 24)
.padding(.top, 32)
}
Expand All @@ -61,7 +58,7 @@ private struct ContinueTitle: View {
let vertical: CourseVertical

var body: some View {
Text(CoreLocalization.Courseware.continueWith)
Text(CoreLocalization.Courseware.resumeWith)
.font(Theme.Fonts.labelMedium)
.foregroundColor(Theme.Colors.textSecondary)
HStack {
Expand All @@ -78,55 +75,51 @@ private struct ContinueTitle: View {
#if DEBUG
struct ContinueWithView_Previews: PreviewProvider {
static var previews: some View {

let childs = [
CourseChapter(
blockId: "123",
id: "123",
displayName: "Continue lesson",
type: .chapter,
childs: [
CourseSequential(
blockId: "1",
id: "1",
displayName: "Name",
type: .sequential,
completion: 0,
childs: [
CourseVertical(
blockId: "1",
id: "1",
courseId: "123",
displayName: "Vertical",
type: .vertical,
completion: 0,
childs: [
CourseBlock(
blockId: "2",
id: "2",
courseId: "123",
graded: true,
completion: 0,
type: .html,
displayName: "Continue lesson",
studentUrl: "")
])])])
let blocks = [
CourseBlock(
blockId: "1",
id: "1",
courseId: "123",
topicId: "1",
graded: false,
completion: 0,
type: .video,
displayName: "Lesson 1",
studentUrl: "",
videoUrl: nil,
youTubeUrl: nil
),
CourseBlock(
blockId: "2",
id: "2",
courseId: "123",
topicId: "2",
graded: false,
completion: 0,
type: .video,
displayName: "Lesson 2",
studentUrl: "2",
videoUrl: nil,
youTubeUrl: nil
)
]

ContinueWithView(
data: ContinueWith(chapterIndex: 0, sequentialIndex: 0, verticalIndex: 0),
courseStructure: CourseStructure(
id: "123",
graded: true,
completion: 0,
viewYouTubeUrl: "",
encodedVideo: "",
displayName: "Namaste",
childs: childs,
media: DataLayer.CourseMedia(
image: .init(raw: "", small: "", large: "")
),
certificate: nil)
data: ContinueWith(
chapterIndex: 0,
sequentialIndex: 0,
verticalIndex: 0,
lastVisitedBlockId: "test_block_id"
),
courseContinueUnit: CourseVertical(
blockId: "2",
id: "2",
courseId: "123",
displayName: "Second Unit",
type: .vertical,
completion: 1,
childs: blocks
)
) {
}
}
Expand Down
37 changes: 25 additions & 12 deletions Course/Course/Presentation/Outline/CourseOutlineView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,39 @@ public struct CourseOutlineView: View {
if let continueWith = viewModel.continueWith,
let courseStructure = viewModel.courseStructure,
!isVideo {
let chapter = courseStructure.childs[continueWith.chapterIndex]
let sequential = chapter.childs[continueWith.sequentialIndex]
let continueUnit = sequential.childs[continueWith.verticalIndex]

// MARK: - ContinueWith button
ContinueWithView(
data: continueWith,
courseStructure: courseStructure
courseContinueUnit: continueUnit
) {
let chapter = courseStructure.childs[continueWith.chapterIndex]
let sequential = chapter.childs[continueWith.sequentialIndex]
var continueBlock: CourseBlock?
continueUnit.childs.forEach { block in
if block.id == continueWith.lastVisitedBlockId {
continueBlock = block
}
}

viewModel.trackResumeCourseTapped(
blockId: sequential.childs[continueWith.verticalIndex].blockId
)
viewModel.router.showCourseVerticalView(
courseID: courseStructure.id,
courseName: courseStructure.displayName,
title: sequential.displayName,
chapters: courseStructure.childs,
chapterIndex: continueWith.chapterIndex,
sequentialIndex: continueWith.sequentialIndex
blockId: continueBlock?.id ?? ""
)

if let course = viewModel.courseStructure {
viewModel.router.showCourseUnit(
courseName: course.displayName,
blockId: continueBlock?.id ?? "",
courseID: course.id,
sectionName: continueUnit.displayName,
verticalIndex: continueWith.verticalIndex,
chapters: course.childs,
chapterIndex: continueWith.chapterIndex,
sequentialIndex: continueWith.sequentialIndex
)
}
//"Saeed"
}
}

Expand Down
4 changes: 2 additions & 2 deletions Course/Course/SwiftGen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public enum CourseLocalization {
public static let backToOutline = CourseLocalization.tr("Localizable", "COURSEWARE.BACK_TO_OUTLINE", fallback: "Back to outline")
/// Continue
public static let `continue` = CourseLocalization.tr("Localizable", "COURSEWARE.CONTINUE", fallback: "Continue")
/// Continue with:
public static let continueWith = CourseLocalization.tr("Localizable", "COURSEWARE.CONTINUE_WITH", fallback: "Continue with:")
/// Course content
public static let courseContent = CourseLocalization.tr("Localizable", "COURSEWARE.COURSE_CONTENT", fallback: "Course content")
/// Course units
Expand All @@ -43,6 +41,8 @@ public enum CourseLocalization {
public static let next = CourseLocalization.tr("Localizable", "COURSEWARE.NEXT", fallback: "Next")
/// Prev
public static let previous = CourseLocalization.tr("Localizable", "COURSEWARE.PREVIOUS", fallback: "Prev")
/// Resume with:
public static let resumeWith = CourseLocalization.tr("Localizable", "COURSEWARE.RESUME_WITH", fallback: "Resume with:")
/// Section “
public static let section = CourseLocalization.tr("Localizable", "COURSEWARE.SECTION", fallback: "Section “")
}
Expand Down
2 changes: 1 addition & 1 deletion Course/Course/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"COURSEWARE.SECTION" = "Section “";
"COURSEWARE.IS_FINISHED" = "“ is finished.";
"COURSEWARE.CONTINUE" = "Continue";
"COURSEWARE.CONTINUE_WITH" = "Continue with:";
"COURSEWARE.RESUME_WITH" = "Resume with:";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


"ERROR.NO_INTERNET" = "You are not connected to the Internet. Please check your Internet connection.";
"ERROR.RELOAD" = "Reload";
Expand Down
2 changes: 1 addition & 1 deletion Course/Course/uk.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"COURSEWARE.SECTION" = "Секція “";
"COURSEWARE.IS_FINISHED" = "“ завершена.";
"COURSEWARE.CONTINUE" = "Продовжити";
"COURSEWARE.CONTINUE_WITH" = "Продовжити далі:";
"COURSEWARE.RESUME_WITH" = "Продовжити далі:";

"ERROR.NO_INTERNET" = "Ви не підключені до Інтернету. Перевірте підключення до Інтернету і спробуйте ще.";
"ERROR.RELOAD" = "Перезавантажити";
Expand Down