Skip to content

Commit

Permalink
chore: add course expandable sections enabled and course banner enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
eyatsenkoperpetio committed Dec 7, 2023
1 parent fb4e218 commit 464b2a3
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 60 deletions.
8 changes: 7 additions & 1 deletion Core/Core/Configuration/Config/FeaturesConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ import Foundation

private enum FeaturesKeys: String {
case whatNewEnabled = "WHATS_NEW_ENABLED"
case courseExpandableSectionsEnabled = "COURSE_EXPANDABLE_SECTIONS_ENABLED"
case courseBannerEnabled = "COURSE_BANNER_ENABLED"
}

public class FeaturesConfig: NSObject {
public var whatNewEnabled: Bool

public var courseExpandableSectionsEnabled: Bool
public var courseBannerEnabled: Bool

init(dictionary: [String: Any]) {
whatNewEnabled = dictionary[FeaturesKeys.whatNewEnabled.rawValue] as? Bool ?? false
courseExpandableSectionsEnabled = dictionary[FeaturesKeys.courseExpandableSectionsEnabled.rawValue] as? Bool ?? false
courseBannerEnabled = dictionary[FeaturesKeys.courseBannerEnabled.rawValue] as? Bool ?? false
super.init()
}
}
Expand Down
2 changes: 2 additions & 0 deletions Core/Core/SwiftGen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public enum CoreLocalization {
public static let nextSectionDescriptionLast = CoreLocalization.tr("Localizable", "COURSEWARE.NEXT_SECTION_DESCRIPTION_LAST", fallback: "” press “Next section”.")
/// Prev
public static let previous = CoreLocalization.tr("Localizable", "COURSEWARE.PREVIOUS", fallback: "Prev")
/// Resume
public static let resume = CoreLocalization.tr("Localizable", "COURSEWARE.RESUME", fallback: "Resume")
/// Section “
public static let section = CoreLocalization.tr("Localizable", "COURSEWARE.SECTION", fallback: "Section “")
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Core/View/Base/UnitButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum UnitButtonType: Equatable {
case .reload:
return CoreLocalization.Error.reload
case .continueLesson:
return CoreLocalization.Courseware.continue
return CoreLocalization.Courseware.resume
case .nextSection:
return CoreLocalization.Courseware.nextSection
case let .custom(text):
Expand Down
1 change: 1 addition & 0 deletions Core/Core/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"COURSEWARE.SECTION" = "Section “";
"COURSEWARE.IS_FINISHED" = "“ is finished.";
"COURSEWARE.CONTINUE" = "Continue";
"COURSEWARE.RESUME" = "Resume";
"COURSEWARE.CONTINUE_WITH" = "Continue with:";
"COURSEWARE.NEXT_SECTION" = "Next section";

Expand Down
1 change: 1 addition & 0 deletions Core/Core/uk.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"COURSEWARE.SECTION" = "Секція “";
"COURSEWARE.IS_FINISHED" = "“ завершена.";
"COURSEWARE.CONTINUE" = "Продовжити";
"COURSEWARE.RESUME" = "Resume";
"COURSEWARE.CONTINUE_WITH" = "Продовжити далі:";
"COURSEWARE.NEXT_SECTION" = "Наступний розділ";

Expand Down
127 changes: 71 additions & 56 deletions Course/Course/Presentation/Outline/CourseOutlineView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,57 +41,10 @@ public struct CourseOutlineView: View {
await viewModel.getCourseBlocks(courseID: courseID, withProgress: false)
}) {
VStack(alignment: .leading) {
// ZStack {
// // MARK: - Course Banner
// if let banner = viewModel.courseStructure?.media.image.raw
// .addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
// KFImage(URL(string: viewModel.config.baseURL.absoluteString + banner))
// .onFailureImage(CoreAssets.noCourseImage.image)
// .resizable()
// .aspectRatio(contentMode: .fill)
// .frame(maxWidth: proxy.size.width - 12, maxHeight: .infinity)
// }
//
// // MARK: - Course Certificate
// if let certificate = viewModel.courseStructure?.certificate {
// if let url = certificate.url, url.count > 0 {
// Theme.Colors.certificateForeground
// VStack(alignment: .center, spacing: 8) {
// CoreAssets.certificate.swiftUIImage
// Text(CourseLocalization.Outline.congratulations)
// .multilineTextAlignment(.center)
// .font(Theme.Fonts.headlineMedium)
// Text(CourseLocalization.Outline.passedTheCourse)
// .font(Theme.Fonts.bodyMedium)
// .multilineTextAlignment(.center)
// StyledButton(
// CourseLocalization.Outline.viewCertificate,
// action: { openCertificateView = true },
// isTransparent: true
// )
// .frame(width: 141)
// .padding(.top, 8)
//
// .fullScreenCover(
// isPresented: $openCertificateView,
// content: {
// WebBrowser(
// url: url,
// pageTitle: CourseLocalization.Outline.certificate
// )
// })
// }.padding(.horizontal, 24)
// .padding(.top, 8)
// .foregroundColor(.white)
// }
// }
// }
// .frame(maxHeight: 250)
// .cornerRadius(12)
// .padding(.horizontal, 6)
// .padding(.top, 7)
// .fixedSize(horizontal: false, vertical: true)

if viewModel.config.features.courseBannerEnabled {
courseBanner(proxy: proxy)
}

if let continueWith = viewModel.continueWith,
let courseStructure = viewModel.courseStructure,
!isVideo {
Expand Down Expand Up @@ -123,11 +76,20 @@ public struct CourseOutlineView: View {
: viewModel.courseStructure {

// MARK: - Sections
CourseExpandableContentView(
proxy: proxy,
course: course,
viewModel: viewModel
)
if viewModel.config.features.courseExpandableSectionsEnabled {
CourseExpandableContentView(
proxy: proxy,
course: course,
viewModel: viewModel
)
} else {
CourseStructureView(
proxy: proxy,
course: course,
viewModel: viewModel
)
}

} else {
if let courseStart = viewModel.courseStart {
Text(courseStart > Date() ? CourseLocalization.Outline.courseHasntStarted : "")
Expand Down Expand Up @@ -182,6 +144,59 @@ public struct CourseOutlineView: View {
.ignoresSafeArea()
)
}

private func courseBanner(proxy: GeometryProxy) -> some View {
ZStack {
// MARK: - Course Banner
if let banner = viewModel.courseStructure?.media.image.raw
.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
KFImage(URL(string: viewModel.config.baseURL.absoluteString + banner))
.onFailureImage(CoreAssets.noCourseImage.image)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(maxWidth: proxy.size.width - 12, maxHeight: .infinity)
}

// MARK: - Course Certificate
if let certificate = viewModel.courseStructure?.certificate {
if let url = certificate.url, url.count > 0 {
Theme.Colors.certificateForeground
VStack(alignment: .center, spacing: 8) {
CoreAssets.certificate.swiftUIImage
Text(CourseLocalization.Outline.congratulations)
.multilineTextAlignment(.center)
.font(Theme.Fonts.headlineMedium)
Text(CourseLocalization.Outline.passedTheCourse)
.font(Theme.Fonts.bodyMedium)
.multilineTextAlignment(.center)
StyledButton(
CourseLocalization.Outline.viewCertificate,
action: { openCertificateView = true },
isTransparent: true
)
.frame(width: 141)
.padding(.top, 8)

.fullScreenCover(
isPresented: $openCertificateView,
content: {
WebBrowser(
url: url,
pageTitle: CourseLocalization.Outline.certificate
)
})
}.padding(.horizontal, 24)
.padding(.top, 8)
.foregroundColor(.white)
}
}
}
.frame(maxHeight: 250)
.cornerRadius(12)
.padding(.horizontal, 6)
.padding(.top, 7)
.fixedSize(horizontal: false, vertical: true)
}
}

struct CourseStructureView: View {
Expand Down
10 changes: 8 additions & 2 deletions OpenEdX/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,14 @@ public class Router: AuthorizationRouter,
let view = CourseUnitView(viewModel: viewModel, sectionName: sectionName)
let controllerUnit = UIHostingController(rootView: view)
var controllers = navigationController.viewControllers
controllers.removeLast(2)
controllers.append(contentsOf: [controllerVertical, controllerUnit])
if let config = container.resolve(ConfigProtocol.self),
config.features.courseExpandableSectionsEnabled {
controllers.removeLast(1)
controllers.append(contentsOf: [controllerUnit])
} else {
controllers.removeLast(2)
controllers.append(contentsOf: [controllerVertical, controllerUnit])
}
navigationController.setViewControllers(controllers, animated: true)
}

Expand Down

0 comments on commit 464b2a3

Please sign in to comment.