Skip to content

Commit

Permalink
fix: first batch of fix PRs to synchronise with upstream (#526)
Browse files Browse the repository at this point in the history
* Merge pull request #23 from edx/small-fix-for-downloading-cancelling

fix: fixes for downloading

* chore: fix for Xcode 16 and after merge

* Merge pull request #24 from edx/2U/fix/download-states

fix: [iOS] On Course "Home" tab the row height

* fix: after merge, deleted IAP part

fix: [iOS] On Course "Home" tab the row height

* Merge pull request #25 from edx/2U/feat/primary-horizontal

feat: Landscape mode Improvement

* fix: removed IAP part

* chore: remove snack bar error for course dates info API on course home (#27)

* Merge pull request #28 from shafqat-muneer/Shafqat/LEARNER-10020-ErrorHandling

feat: Course Level Error Handling for Empty States

* chore: remove IAP part after merging

---------

Co-authored-by: Anton Yarmolenko <[email protected]>
Co-authored-by: Saeed Bashir <[email protected]>
  • Loading branch information
3 people authored Oct 8, 2024
1 parent c632a01 commit 004666e
Show file tree
Hide file tree
Showing 37 changed files with 594 additions and 337 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "noVideos.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "noAnnouncements.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "noHandouts.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Core/Core/Assets.xcassets/information.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "Vector.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
3 changes: 3 additions & 0 deletions Core/Core/Assets.xcassets/information.imageset/Vector.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 12 additions & 4 deletions Core/Core/Extensions/UIApplicationExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ import Theme

public extension UIApplication {

var windows: [UIWindow]? {
let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene
return scene?.windows
}

var window: UIWindow? {
windows?.first
}

var keyWindow: UIWindow? {
UIApplication.shared.windows.first { $0.isKeyWindow }
windows?.first { $0.isKeyWindow }
}

func endEditing(force: Bool = true) {
windows.forEach { $0.endEditing(force) }
windows?.forEach { $0.endEditing(force) }
}

class func topViewController(
Expand All @@ -36,8 +45,7 @@ public extension UIApplication {
}

var windowInsets: UIEdgeInsets {
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first else {
guard let window = window else {
return .zero
}

Expand Down
46 changes: 24 additions & 22 deletions Core/Core/Network/DownloadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ public class DownloadManager: DownloadManagerProtocol {

public func cancelDownloading(courseId: String, blocks: [CourseBlock]) async throws {
downloadRequest?.cancel()
let downloaded = await getDownloadTasksForCourse(courseId).filter { $0.state == .finished }
let downloaded = await getDownloadTasksForCourse(courseId)
let blocksForDelete = blocks.filter { block in
downloaded.first(where: { $0.blockId == block.id }) == nil
downloaded.first(where: { $0.blockId == block.id }) != nil
}
await deleteFile(blocks: blocksForDelete)
downloaded.forEach {
Expand All @@ -267,10 +267,10 @@ public class DownloadManager: DownloadManagerProtocol {
public func cancelDownloading(task: DownloadDataTask) async throws {
downloadRequest?.cancel()
do {
try await persistence.deleteDownloadDataTask(id: task.id)
if let fileUrl = await fileUrl(for: task.id) {
if let fileUrl = fileUrl(for: task.id) {
try FileManager.default.removeItem(at: fileUrl)
}
try await persistence.deleteDownloadDataTask(id: task.id)
currentDownloadEventPublisher.send(.canceled(task))
} catch {
NSLog("Error deleting file: \(error.localizedDescription)")
Expand All @@ -297,7 +297,8 @@ public class DownloadManager: DownloadManagerProtocol {
public func deleteFile(blocks: [CourseBlock]) async {
for block in blocks {
do {
if let fileURL = await fileUrl(for: block.id) {
if let fileURL = fileUrl(for: block.id),
FileManager.default.fileExists(atPath: fileURL.path) {
try FileManager.default.removeItem(at: fileURL)
}
try await persistence.deleteDownloadDataTask(id: block.id)
Expand Down Expand Up @@ -442,7 +443,7 @@ public class DownloadManager: DownloadManagerProtocol {
}

private func downloadFileWithProgress(_ download: DownloadDataTask) throws {
guard let url = URL(string: download.url) else {
guard let url = URL(string: download.url), let folderURL = self.filesFolderUrl else {
return
}

Expand All @@ -452,10 +453,14 @@ public class DownloadManager: DownloadManagerProtocol {
resumeData: download.resumeData
)
self.isDownloadingInProgress = true
let destination: DownloadRequest.Destination = { _, _ in
let file = folderURL.appendingPathComponent(download.fileName)
return (file, [.createIntermediateDirectories, .removePreviousFile])
}
if let resumeData = download.resumeData {
downloadRequest = AF.download(resumingWith: resumeData)
downloadRequest = AF.download(resumingWith: resumeData, to: destination)
} else {
downloadRequest = AF.download(url)
downloadRequest = AF.download(url, to: destination)
}

downloadRequest?.downloadProgress { [weak self] prog in
Expand All @@ -479,18 +484,15 @@ public class DownloadManager: DownloadManagerProtocol {
return
}
}
if let data = data.value, let url = self.filesFolderUrl {
self.saveFile(fileName: download.fileName, data: data, folderURL: url)
self.persistence.updateDownloadState(
id: download.id,
state: .finished,
resumeData: nil
)
self.currentDownloadTask?.state = .finished
self.currentDownloadEventPublisher.send(.finished(download))
Task {
try? await self.newDownload()
}
self.persistence.updateDownloadState(
id: download.id,
state: .finished,
resumeData: nil
)
self.currentDownloadTask?.state = .finished
self.currentDownloadEventPublisher.send(.finished(download))
Task {
try? await self.newDownload()
}
}
}
Expand Down Expand Up @@ -567,10 +569,10 @@ public class DownloadManager: DownloadManagerProtocol {
private func cancel(tasks: [DownloadDataTask]) async {
for task in tasks {
do {
try await persistence.deleteDownloadDataTask(id: task.id)
if let fileUrl = await fileUrl(for: task.id) {
if let fileUrl = fileUrl(for: task.id) {
try FileManager.default.removeItem(at: fileUrl)
}
try await persistence.deleteDownloadDataTask(id: task.id)
} catch {
debugLog("Error deleting file: \(error.localizedDescription)")
}
Expand Down
4 changes: 4 additions & 0 deletions Core/Core/SwiftGen/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public enum CoreAssets {
public static let downloads = ImageAsset(name: "downloads")
public static let home = ImageAsset(name: "home")
public static let more = ImageAsset(name: "more")
public static let noVideos = ImageAsset(name: "noVideos")
public static let videos = ImageAsset(name: "videos")
public static let dashboardEmptyPage = ImageAsset(name: "DashboardEmptyPage")
public static let addComment = ImageAsset(name: "addComment")
Expand Down Expand Up @@ -72,6 +73,8 @@ public enum CoreAssets {
public static let stopDownloading = ImageAsset(name: "stopDownloading")
public static let announcements = ImageAsset(name: "announcements")
public static let handouts = ImageAsset(name: "handouts")
public static let noAnnouncements = ImageAsset(name: "noAnnouncements")
public static let noHandouts = ImageAsset(name: "noHandouts")
public static let dashboard = ImageAsset(name: "dashboard")
public static let discovery = ImageAsset(name: "discovery")
public static let learn = ImageAsset(name: "learn")
Expand Down Expand Up @@ -111,6 +114,7 @@ public enum CoreAssets {
public static let favorite = ImageAsset(name: "favorite")
public static let finishedSequence = ImageAsset(name: "finished_sequence")
public static let goodWork = ImageAsset(name: "goodWork")
public static let information = ImageAsset(name: "information")
public static let learnEmpty = ImageAsset(name: "learn_empty")
public static let airmail = ImageAsset(name: "airmail")
public static let defaultMail = ImageAsset(name: "defaultMail")
Expand Down
35 changes: 23 additions & 12 deletions Core/Core/View/Base/DynamicOffsetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ public struct DynamicOffsetView: View {

@Binding private var coordinate: CGFloat
@Binding private var collapsed: Bool
@Binding private var viewHeight: CGFloat
@State private var collapseHeight: CGFloat = .zero

@Environment(\.isHorizontal) private var isHorizontal

public init(
coordinate: Binding<CGFloat>,
collapsed: Binding<Bool>
collapsed: Binding<Bool>,
viewHeight: Binding<CGFloat>
) {
self._coordinate = coordinate
self._collapsed = collapsed
self._viewHeight = viewHeight
}

public var body: some View {
Expand All @@ -56,28 +59,36 @@ public struct DynamicOffsetView: View {
}
)
.onAppear {
changeCollapsedHeight()
changeCollapsedHeight(collapsed: collapsed, isHorizontal: isHorizontal)
}
.onChange(of: collapsed) { collapsed in
if !collapsed {
changeCollapsedHeight()
changeCollapsedHeight(collapsed: collapsed, isHorizontal: isHorizontal)
}
}
.onChange(of: isHorizontal) { isHorizontal in
if isHorizontal {
collapsed = true
}
changeCollapsedHeight()
changeCollapsedHeight(collapsed: collapsed, isHorizontal: isHorizontal)
}
}

private func changeCollapsedHeight() {
collapseHeight = idiom == .pad
? padHeight
: (
collapsed
? (isHorizontal ? collapsedHorizontalHeight : collapsedVerticalHeight)
: expandedHeight
)
private func changeCollapsedHeight(
collapsed: Bool,
isHorizontal: Bool
) {
if idiom == .pad {
collapseHeight = padHeight
} else if collapsed {
if isHorizontal {
collapseHeight = collapsedHorizontalHeight
} else {
collapseHeight = collapsedVerticalHeight
}
} else {
collapseHeight = 240
}
viewHeight = collapseHeight
}
}
Loading

0 comments on commit 004666e

Please sign in to comment.