Skip to content

Commit

Permalink
Merge branch 'develop' into feat/Setup-Calendar-Synchronization-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanStepanok committed Jun 19, 2024
2 parents 23394f7 + 34cee0d commit ce09947
Show file tree
Hide file tree
Showing 20 changed files with 621 additions and 37 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,10 @@ vendor/
venv/
Podfile.lock
config_settings.yaml
default_config/
default_config/

# Translations ignored files
.venv/
I18N/
*.lproj/
!en.lproj/
15 changes: 15 additions & 0 deletions Authorization/AuthorizationTests/AuthorizationMock.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,12 @@ open class DownloadManagerProtocolMock: DownloadManagerProtocol, Mock {
return __value
}

open func removeAppSupportDirectoryUnusedContent() {
addInvocation(.m_removeAppSupportDirectoryUnusedContent)
let perform = methodPerformValue(.m_removeAppSupportDirectoryUnusedContent) as? () -> Void
perform?()
}


fileprivate enum MethodType {
case m_publisher
Expand All @@ -2421,6 +2427,7 @@ open class DownloadManagerProtocolMock: DownloadManagerProtocol, Mock {
case m_fileUrl__for_blockId(Parameter<String>)
case m_resumeDownloading
case m_isLargeVideosSize__blocks_blocks(Parameter<[CourseBlock]>)
case m_removeAppSupportDirectoryUnusedContent
case p_currentDownloadTask_get

static func compareParameters(lhs: MethodType, rhs: MethodType, matcher: Matcher) -> Matcher.ComparisonResult {
Expand Down Expand Up @@ -2477,6 +2484,8 @@ open class DownloadManagerProtocolMock: DownloadManagerProtocol, Mock {
var results: [Matcher.ParameterComparisonResult] = []
results.append(Matcher.ParameterComparisonResult(Parameter.compare(lhs: lhsBlocks, rhs: rhsBlocks, with: matcher), lhsBlocks, rhsBlocks, "blocks"))
return Matcher.ComparisonResult(results)

case (.m_removeAppSupportDirectoryUnusedContent, .m_removeAppSupportDirectoryUnusedContent): return .match
case (.p_currentDownloadTask_get,.p_currentDownloadTask_get): return Matcher.ComparisonResult.match
default: return .none
}
Expand All @@ -2498,6 +2507,7 @@ open class DownloadManagerProtocolMock: DownloadManagerProtocol, Mock {
case let .m_fileUrl__for_blockId(p0): return p0.intValue
case .m_resumeDownloading: return 0
case let .m_isLargeVideosSize__blocks_blocks(p0): return p0.intValue
case .m_removeAppSupportDirectoryUnusedContent: return 0
case .p_currentDownloadTask_get: return 0
}
}
Expand All @@ -2517,6 +2527,7 @@ open class DownloadManagerProtocolMock: DownloadManagerProtocol, Mock {
case .m_fileUrl__for_blockId: return ".fileUrl(for:)"
case .m_resumeDownloading: return ".resumeDownloading()"
case .m_isLargeVideosSize__blocks_blocks: return ".isLargeVideosSize(blocks:)"
case .m_removeAppSupportDirectoryUnusedContent: return ".removeAppSupportDirectoryUnusedContent()"
case .p_currentDownloadTask_get: return "[get] .currentDownloadTask"
}
}
Expand Down Expand Up @@ -2673,6 +2684,7 @@ open class DownloadManagerProtocolMock: DownloadManagerProtocol, Mock {
public static func fileUrl(for blockId: Parameter<String>) -> Verify { return Verify(method: .m_fileUrl__for_blockId(`blockId`))}
public static func resumeDownloading() -> Verify { return Verify(method: .m_resumeDownloading)}
public static func isLargeVideosSize(blocks: Parameter<[CourseBlock]>) -> Verify { return Verify(method: .m_isLargeVideosSize__blocks_blocks(`blocks`))}
public static func removeAppSupportDirectoryUnusedContent() -> Verify { return Verify(method: .m_removeAppSupportDirectoryUnusedContent)}
public static var currentDownloadTask: Verify { return Verify(method: .p_currentDownloadTask_get) }
}

Expand Down Expand Up @@ -2722,6 +2734,9 @@ open class DownloadManagerProtocolMock: DownloadManagerProtocol, Mock {
public static func isLargeVideosSize(blocks: Parameter<[CourseBlock]>, perform: @escaping ([CourseBlock]) -> Void) -> Perform {
return Perform(method: .m_isLargeVideosSize__blocks_blocks(`blocks`), performs: perform)
}
public static func removeAppSupportDirectoryUnusedContent(perform: @escaping () -> Void) -> Perform {
return Perform(method: .m_removeAppSupportDirectoryUnusedContent, performs: perform)
}
}

public func given(_ method: Given) {
Expand Down
2 changes: 2 additions & 0 deletions Core/Core/Data/CoreStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public protocol CoreStorage {
var lastReviewDate: Date? {get set}
var user: DataLayer.User? {get set}
var userSettings: UserSettings? {get set}
var resetAppSupportDirectoryUserData: Bool? {get set}
func clear()
}

Expand All @@ -31,6 +32,7 @@ public class CoreStorageMock: CoreStorage {
public var lastReviewDate: Date?
public var user: DataLayer.User?
public var userSettings: UserSettings?
public var resetAppSupportDirectoryUserData: Bool?
public func clear() {}

public init() {}
Expand Down
59 changes: 59 additions & 0 deletions Core/Core/Network/DownloadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public protocol DownloadManagerProtocol {
func resumeDownloading() throws
func fileUrl(for blockId: String) -> URL?
func isLargeVideosSize(blocks: [CourseBlock]) -> Bool

func removeAppSupportDirectoryUnusedContent()
}

public enum DownloadManagerEvent {
Expand Down Expand Up @@ -470,6 +472,60 @@ public class DownloadManager: DownloadManagerProtocol {
debugLog("SaveFile Error", error.localizedDescription)
}
}

public func removeAppSupportDirectoryUnusedContent() {
deleteMD5HashedFolders()
}

private func getApplicationSupportDirectory() -> URL? {
let fileManager = FileManager.default
do {
let appSupportDirectory = try fileManager.url(
for: .applicationSupportDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true
)
return appSupportDirectory
} catch {
debugPrint("Error getting Application Support Directory: \(error)")
return nil
}
}

private func isMD5Hash(_ folderName: String) -> Bool {
let md5Regex = "^[a-fA-F0-9]{32}$"
let predicate = NSPredicate(format: "SELF MATCHES %@", md5Regex)
return predicate.evaluate(with: folderName)
}

private func deleteMD5HashedFolders() {
guard let appSupportDirectory = getApplicationSupportDirectory() else {
return
}

let fileManager = FileManager.default
do {
let folderContents = try fileManager.contentsOfDirectory(
at: appSupportDirectory,
includingPropertiesForKeys: nil,
options: []
)
for folderURL in folderContents {
let folderName = folderURL.lastPathComponent
if isMD5Hash(folderName) {
do {
try fileManager.removeItem(at: folderURL)
debugPrint("Deleted folder: \(folderName)")
} catch {
debugPrint("Error deleting folder \(folderName): \(error)")
}
}
}
} catch {
debugPrint("Error reading contents of Application Support directory: \(error)")
}
}
}

@available(iOSApplicationExtension, unavailable)
Expand Down Expand Up @@ -638,6 +694,9 @@ public class DownloadManagerMock: DownloadManagerProtocol {
false
}

public func removeAppSupportDirectoryUnusedContent() {

}
}
#endif
// swiftlint:enable file_length
11 changes: 6 additions & 5 deletions Core/Core/View/Base/ProgressBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ public struct ProgressBar: View {
Circle()
.stroke(lineWidth: lineWidth)
.foregroundColor(Theme.Colors.accentColor.opacity(0.3))
.frame(width: size, height: size)

Circle()
.trim(from: 0.0, to: 0.7)
.stroke(gradient, style: StrokeStyle(lineWidth: lineWidth, lineCap: .round))
.frame(width: size, height: size)
.rotationEffect(Angle.degrees(isAnimating ? 360 : 0), anchor: .center)
.animation(animation, value: isAnimating)
}
.frame(width: size, height: size)
.rotationEffect(Angle.degrees(isAnimating ? 360 : 0), anchor: .center)
.animation(animation, value: isAnimating)
.onAppear {
isAnimating = true
DispatchQueue.main.async {
isAnimating = true
}
}
}
}
Expand Down
77 changes: 49 additions & 28 deletions Core/Core/View/Base/VideoDownloadQualityView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ public struct VideoDownloadQualityView: View {
private var viewModel: VideoDownloadQualityViewModel
private var analytics: CoreAnalytics
private var router: BaseRouter
private var isModal: Bool
@Environment (\.isHorizontal) private var isHorizontal

public init(
downloadQuality: DownloadQuality,
didSelect: ((DownloadQuality) -> Void)?,
analytics: CoreAnalytics,
router: BaseRouter
router: BaseRouter,
isModal: Bool = false
) {
self._viewModel = StateObject(
wrappedValue: .init(
Expand All @@ -50,41 +52,46 @@ public struct VideoDownloadQualityView: View {
)
self.analytics = analytics
self.router = router
self.isModal = isModal
}

public var body: some View {
GeometryReader { proxy in
ZStack(alignment: .top) {
VStack {
ThemeAssets.headerBackground.swiftUIImage
.resizable()
.edgesIgnoringSafeArea(.top)
if !isModal {
VStack {
ThemeAssets.headerBackground.swiftUIImage
.resizable()
.edgesIgnoringSafeArea(.top)
}
.frame(maxWidth: .infinity, maxHeight: 200)
.accessibilityIdentifier("auth_bg_image")
}
.frame(maxWidth: .infinity, maxHeight: 200)
.accessibilityIdentifier("auth_bg_image")

// MARK: - Page name
VStack(alignment: .center) {
ZStack {
HStack {
Text(CoreLocalization.Settings.videoDownloadQualityTitle)
.titleSettings(color: Theme.Colors.loginNavigationText)
.accessibilityIdentifier("manage_account_text")
if !isModal {
ZStack {
HStack {
Text(CoreLocalization.Settings.videoDownloadQualityTitle)
.titleSettings(color: Theme.Colors.loginNavigationText)
.accessibilityIdentifier("manage_account_text")
}
VStack {
BackNavigationButton(
color: Theme.Colors.loginNavigationText,
action: {
router.back()
}
)
.backViewStyle()
.padding(.leading, isHorizontal ? 48 : 0)
.accessibilityIdentifier("back_button")

}.frame(minWidth: 0,
maxWidth: .infinity,
alignment: .topLeading)
}
VStack {
BackNavigationButton(
color: Theme.Colors.loginNavigationText,
action: {
router.back()
}
)
.backViewStyle()
.padding(.leading, isHorizontal ? 48 : 0)
.accessibilityIdentifier("back_button")

}.frame(minWidth: 0,
maxWidth: .infinity,
alignment: .topLeading)
}
// MARK: - Page Body
ScrollView {
Expand Down Expand Up @@ -129,8 +136,8 @@ public struct VideoDownloadQualityView: View {
}
}
}
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)
.navigationBarHidden(!isModal)
.navigationBarBackButtonHidden(!isModal)
.navigationTitle(CoreLocalization.Settings.videoDownloadQualityTitle)
.ignoresSafeArea(.all, edges: .horizontal)
.background(
Expand Down Expand Up @@ -210,3 +217,17 @@ public extension DownloadQuality {
}
}
}

#if DEBUG
struct VideoDownloadQualityView_Previews: PreviewProvider {
static var previews: some View {
VideoDownloadQualityView(
downloadQuality: .auto,
didSelect: nil,
analytics: CoreAnalyticsMock(),
router: BaseRouterMock(),
isModal: true
)
}
}
#endif
1 change: 1 addition & 0 deletions Course/Course/Presentation/Downloads/DownloadsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public struct DownloadsView: View {
}
} label: {
DownloadProgressView()
.id("cirle loading indicator " + task.id)
.accessibilityElement(children: .ignore)
.accessibilityLabel(CourseLocalization.Accessibility.cancelDownload)
.accessibilityIdentifier("cancel_download_button")
Expand Down
3 changes: 2 additions & 1 deletion Course/Course/Presentation/Outline/CourseOutlineView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public struct CourseOutlineView: View {
downloadQuality: $0.downloadQuality,
didSelect: viewModel.update(downloadQuality:),
analytics: viewModel.coreAnalytics,
router: viewModel.router
router: viewModel.router,
isModal: true
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ struct VideoDownloadQualityContainerView: View {
private var didSelect: ((DownloadQuality) -> Void)?
private let analytics: CoreAnalytics
private let router: CourseRouter
private var isModal: Bool

init(
downloadQuality: DownloadQuality,
didSelect: ((DownloadQuality) -> Void)?,
analytics: CoreAnalytics,
router: CourseRouter
router: CourseRouter,
isModal: Bool = false
) {
self.downloadQuality = downloadQuality
self.didSelect = didSelect
self.analytics = analytics
self.router = router
self.isModal = isModal
}

var body: some View {
Expand All @@ -36,7 +39,8 @@ struct VideoDownloadQualityContainerView: View {
downloadQuality: downloadQuality,
didSelect: didSelect,
analytics: analytics,
router: router
router: router,
isModal: isModal
)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
Expand Down
Loading

0 comments on commit ce09947

Please sign in to comment.