Skip to content

Commit

Permalink
ios 17 bugfixes (#77)
Browse files Browse the repository at this point in the history
* bugfixes
  • Loading branch information
IvanStepanok authored Sep 22, 2023
1 parent a92a22c commit 9cbde2d
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21754" systemVersion="22G90" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22222" systemVersion="22G91" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="CDDownloadData" representedClassName="CDDownloadData" syncable="YES" codeGenerationType="class">
<attribute name="courseId" optional="YES" attributeType="String"/>
<attribute name="fileName" optional="YES" attributeType="String"/>
<attribute name="id" optional="YES" attributeType="String"/>
<attribute name="path" optional="YES" attributeType="String"/>
<attribute name="progress" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="resumeData" optional="YES" attributeType="Binary"/>
<attribute name="state" optional="YES" attributeType="String"/>
Expand Down
2 changes: 1 addition & 1 deletion Core/Core/Data/Persistence/CorePersistenceProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public protocol CorePersistenceProtocol {
func getNextBlockForDownloading() -> DownloadData?
func getDownloadsForCourse(_ courseId: String) -> [DownloadData]
func downloadData(by blockId: String) -> DownloadData?
func updateDownloadState(id: String, state: DownloadState, path: String?, resumeData: Data?)
func updateDownloadState(id: String, state: DownloadState, resumeData: Data?)
func deleteDownloadData(id: String) throws
func saveDownloadData(data: DownloadData)
}
Expand Down
43 changes: 17 additions & 26 deletions Core/Core/Network/DownloadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public struct DownloadData {
public let id: String
public let courseId: String
public let url: String
public let path: String?
public let fileName: String
public let progress: Double
public let resumeData: Data?
Expand All @@ -35,7 +34,6 @@ public struct DownloadData {
id: String,
courseId: String,
url: String,
path: String?,
fileName: String,
progress: Double,
resumeData: Data?,
Expand All @@ -45,7 +43,6 @@ public struct DownloadData {
self.id = id
self.courseId = courseId
self.url = url
self.path = path
self.fileName = fileName
self.progress = progress
self.resumeData = resumeData
Expand Down Expand Up @@ -148,28 +145,27 @@ public class DownloadManager: DownloadManagerProtocol {
persistence.updateDownloadState(
id: download.id,
state: .inProgress,
path: nil,
resumeData: download.resumeData
)
self.isDownloadingInProgress = true
let fileName = url.lastPathComponent
if let resumeData = download.resumeData {
downloadRequest = AF.download(resumingWith: resumeData)
} else {
downloadRequest = AF.download(url)
}
// downloadRequest?.downloadProgress { prog in
// let completed = Double(prog.fractionCompleted * 100)
// print(">>>>> Downloading", download.url, completed, "%")
// }
#if DEBUG
downloadRequest?.downloadProgress { prog in
let completed = Double(prog.fractionCompleted * 100)
print(">>>>> Downloading", download.url, completed, "%")
}
#endif
downloadRequest?.responseData(completionHandler: { [weak self] data in
guard let self else { return }
if let data = data.value, let url = self.videosFolderUrl() {
let fileUrl = self.saveFile(fileName: fileName, data: data, folderURL: url)
self.saveFile(fileName: download.fileName, data: data, folderURL: url)
self.persistence.updateDownloadState(
id: download.id,
state: .finished,
path: fileUrl?.absoluteString,
resumeData: nil
)
try? self.newDownload()
Expand All @@ -188,32 +184,28 @@ public class DownloadManager: DownloadManagerProtocol {
self.persistence.updateDownloadState(
id: currentDownload.id,
state: .paused,
path: nil,
resumeData: resumeData
)
})
}

public func deleteFile(blocks: [CourseBlock]) {
for block in blocks {
let downloadData = persistence.downloadData(by: block.id)
guard let path = persistence.downloadData(by: block.id)?.path,
let fileUrl = URL(string: path) else { return }

do {
try persistence.deleteDownloadData(id: block.id)
try FileManager.default.removeItem(at: fileUrl)
print("File deleted successfully")
if let fileUrl = fileUrl(for: block.id) {
try FileManager.default.removeItem(at: fileUrl)
}
} catch {
print("Error deleting file: \(error.localizedDescription)")
NSLog("Error deleting file: \(error.localizedDescription)")
}
}
}

public func deleteAllFiles() {
let downloadData = persistence.getAllDownloadData()
downloadData.forEach {
if let path = $0.path, let fileURL = URL(string: path) {
if let fileURL = fileUrl(for: $0.id) {
do {
try FileManager.default.removeItem(at: fileURL)
} catch {
Expand All @@ -227,8 +219,9 @@ public class DownloadManager: DownloadManagerProtocol {
guard let data = persistence.downloadData(by: blockId),
data.url.count > 0,
data.state == .finished else { return nil }

return URL(string: data.path ?? "")
let path = videosFolderUrl()
let fileName = data.fileName
return path?.appendingPathComponent(fileName)
}

private func videosFolderUrl() -> URL? {
Expand All @@ -252,15 +245,13 @@ public class DownloadManager: DownloadManagerProtocol {
}
}

private func saveFile(fileName: String, data: Data, folderURL: URL) -> URL? {
private func saveFile(fileName: String, data: Data, folderURL: URL) {
let fileURL = folderURL.appendingPathComponent(fileName)
do {
try data.write(to: fileURL)
return fileURL
} catch {
print("SaveFile Error", error.localizedDescription)
NSLog("SaveFile Error", error.localizedDescription)
}
return nil
}
}

Expand Down
20 changes: 10 additions & 10 deletions Core/Core/View/Base/WebBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ public struct WebBrowser: View {

public var body: some View {
ZStack(alignment: .top) {

CoreAssets.background.swiftUIColor.ignoresSafeArea()
// MARK: - Page name
VStack(alignment: .center) {
NavigationBar(title: pageTitle,
leftButtonAction: { presentationMode.wrappedValue.dismiss() })

// MARK: - Page Body
VStack {
ZStack(alignment: .top) {
NavigationView {
// NavigationView {
WebView(
viewModel: .init(url: url, baseURL: ""),
isLoading: $isShowProgress,
refreshCookies: {}
)
.navigationBarTitle(Text("")) // Needed for hide navBar on ios 14, 15
.navigationBarHidden(true)
.ignoresSafeArea()
}
}

// }
}.navigationBarTitle(Text("")) // Needed for hide navBar on ios 14, 15
.navigationBarHidden(true)
.ignoresSafeArea()
}
}
.navigationBarHidden(false)
.navigationBarBackButtonHidden(false)
.navigationTitle(pageTitle)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Course/Course/Data/Model/Data_UpdatesResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public extension DataLayer {
public let id: Int
public let date: String
public let content: String
public let status: String
public let status: String?
}
typealias CourseUpdates = [CourseUpdate]
}
Expand Down
4 changes: 2 additions & 2 deletions Course/Course/Domain/Model/CourseUpdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public struct CourseUpdate {
public let id: Int
public let date: String
public var content: String
public let status: String
public let status: String?

public init(id: Int, date: String, content: String, status: String) {
public init(id: Int, date: String, content: String, status: String?) {
self.id = id
self.date = date
self.content = content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public struct HandoutsUpdatesDetailView: View {
private var handouts: String?
private var announcements: [CourseUpdate]?
private let title: String
@State private var height: [Int: CGFloat] = [:]

public init(
handouts: String?,
Expand Down Expand Up @@ -68,6 +67,8 @@ public struct HandoutsUpdatesDetailView: View {

public var body: some View {
ZStack(alignment: .top) {
Theme.Colors.background
.ignoresSafeArea()
GeometryReader { reader in

// MARK: - Page Body
Expand Down Expand Up @@ -98,12 +99,12 @@ public struct HandoutsUpdatesDetailView: View {
type: .discovery,
screenWidth: reader.size.width
)
HTMLFormattedText(
fixBrokenLinks(in: formattedAnnouncements),
isScrollEnabled: true,
textViewHeight: $height[index]
)
.frame(height: height[index])
HStack {
HTMLFormattedText(formattedAnnouncements)
Spacer()
}

.id(UUID())

if index != announcements.count - 1 {
Divider()
Expand All @@ -120,13 +121,7 @@ public struct HandoutsUpdatesDetailView: View {
router.back()
}
Spacer(minLength: 84)

.background(
Theme.Colors.background
.ignoresSafeArea()
)
}

}
.navigationBarHidden(false)
.navigationBarBackButtonHidden(false)
Expand Down
5 changes: 3 additions & 2 deletions Course/Course/Presentation/Handouts/HandoutsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ struct HandoutsView: View {

private let courseID: String

@ObservedObject
@StateObject
private var viewModel: HandoutsViewModel

public init(
courseID: String,
viewModel: HandoutsViewModel
) {
self.courseID = courseID
self.viewModel = viewModel
// self.viewModel = viewModel
self._viewModel = StateObject(wrappedValue: { viewModel }())
}

public var body: some View {
Expand Down
1 change: 1 addition & 0 deletions Course/Course/Presentation/Outline/CourseOutlineView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public struct CourseOutlineView: View {
)
.frame(width: 141)
.padding(.top, 8)

.fullScreenCover(
isPresented: $openCertificateView,
content: {
Expand Down
Loading

0 comments on commit 9cbde2d

Please sign in to comment.