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

Added custom back button for downloads view #430

Merged
merged 2 commits into from
May 10, 2024
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
28 changes: 27 additions & 1 deletion Course/Course/Presentation/Downloads/DownloadsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ public struct DownloadsView: View {
// MARK: - Properties

@Environment(\.dismiss) private var dismiss
@Environment (\.isHorizontal) private var isHorizontal
@StateObject private var viewModel: DownloadsViewModel

var isSheet: Bool = true

public init(
isSheet: Bool = true,
router: CourseRouter,
courseId: String? = nil,
downloads: [DownloadDataTask] = [],
manager: DownloadManagerProtocol
) {
self.isSheet = isSheet
self._viewModel = .init(
wrappedValue: .init(
router: router,
courseId: courseId,
downloads: downloads,
manager: manager
Expand All @@ -38,13 +41,36 @@ public struct DownloadsView: View {
// MARK: - Body

public var body: some View {
ZStack {
ZStack(alignment: .top) {
Theme.Colors.background
.ignoresSafeArea()
if !isSheet {
HStack {
Text(CourseLocalization.Download.downloads)
.titleSettings(color: Theme.Colors.textPrimary)
.accessibilityIdentifier("downloads_text")
}
.padding(.top, isHorizontal ? 10 : 0)
VStack {
BackNavigationButton(
color: Theme.Colors.accentColor,
action: {
viewModel.router.back()
}
)
.backViewStyle()
.padding(.leading, 8)

}
.frame(minWidth: 0, maxWidth: .infinity, alignment: .topLeading)
.padding(.top, isHorizontal ? 23 : 13)

}
content
.sheetNavigation(isSheet: isSheet) {
dismiss()
}
.padding(.top, isSheet ? 0 : 40)
}
}

Expand Down
4 changes: 4 additions & 0 deletions Course/Course/Presentation/Downloads/DownloadsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ final class DownloadsViewModel: ObservableObject {

@Published private(set) var downloads: [DownloadDataTask] = []
private let courseId: String?

let router: CourseRouter

private let manager: DownloadManagerProtocol
private var cancellables = Set<AnyCancellable>()

init(
router: CourseRouter,
courseId: String? = nil,
downloads: [DownloadDataTask] = [],
manager: DownloadManagerProtocol
) {
self.router = router
self.courseId = courseId
self.manager = manager
self.downloads = downloads
Expand Down
2 changes: 1 addition & 1 deletion Course/Course/Presentation/Outline/CourseOutlineView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public struct CourseOutlineView: View {
.ignoresSafeArea()
)
.sheet(isPresented: $showingDownloads) {
DownloadsView(manager: viewModel.manager)
DownloadsView(router: viewModel.router, manager: viewModel.manager)
}
.sheet(isPresented: $showingVideoDownloadQuality) {
viewModel.storage.userSettings.map {
Expand Down
7 changes: 6 additions & 1 deletion OpenEdX/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,12 @@ public class Router: AuthorizationRouter,
downloads: [DownloadDataTask],
manager: DownloadManagerProtocol
) {
let downloadsView = DownloadsView(isSheet: false, downloads: downloads, manager: manager)
let downloadsView = DownloadsView(
isSheet: false,
router: Container.shared.resolve(CourseRouter.self)!,
downloads: downloads,
manager: manager
)
let controller = UIHostingController(rootView: downloadsView)
navigationController.pushViewController(controller, animated: true)
}
Expand Down
Loading