Skip to content

Commit

Permalink
Merge pull request #1322 from Infomaniak/feat-Multiple-files-save
Browse files Browse the repository at this point in the history
feat: Multiple file can be receive in queries
  • Loading branch information
lebojo authored Nov 1, 2024
2 parents ab31908 + 0c02459 commit 8cb54f5
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 39 deletions.
51 changes: 39 additions & 12 deletions Tuist/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire",
"state" : {
"revision" : "f455c2975872ccd2d9c81594c658af65716e9b9a",
"version" : "5.9.1"
"revision" : "ea6a94b7dddffd0ca4d0f29252d95310b84dec84",
"version" : "5.10.0"
}
},
{
Expand Down Expand Up @@ -86,17 +86,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/ios-core",
"state" : {
"revision" : "3275b3dafa41d3bf8e618b715dfac17e236f86b0",
"version" : "12.2.0"
"revision" : "550e8fe4a4132570a63e144c88d095bfc7d5bac2",
"version" : "12.3.2"
}
},
{
"identity" : "ios-core-ui",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/ios-core-ui",
"state" : {
"revision" : "d83b9df4d8e7880fa8a55807549cac0fc4584ce6",
"version" : "13.1.0"
"revision" : "1aeba8dae671e8c2d7ea239a9669c0b9e085b2de",
"version" : "13.2.0"
}
},
{
Expand Down Expand Up @@ -230,8 +230,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/getsentry/sentry-cocoa",
"state" : {
"revision" : "5575af93efb776414f243e93d6af9f6258dc539a",
"version" : "8.36.0"
"revision" : "54cc2e3e4fcbf9d4c7708ce00d3b6eee29aecbb1",
"version" : "8.38.0"
}
},
{
Expand Down Expand Up @@ -302,17 +302,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "665206000b8307cab5ac51203d29b0f232d7e31b",
"version" : "2.74.0"
"revision" : "f7dc3f527576c398709b017584392fb58592e7f5",
"version" : "2.75.0"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "38ac8221dd20674682148d6451367f89c2652980",
"version" : "1.21.0"
"revision" : "dbace16f126fdcd80d58dc54526c561ca17327d7",
"version" : "1.22.0"
}
},
{
Expand All @@ -333,6 +333,15 @@
"version" : "1.3.2"
}
},
{
"identity" : "swiftbackports",
"kind" : "remoteSourceControl",
"location" : "https://github.com/shaps80/SwiftBackports",
"state" : {
"revision" : "ddca6a237c1ba2291d5a3cc47ec8480ce6e9f805",
"version" : "1.0.3"
}
},
{
"identity" : "swiftregex",
"kind" : "remoteSourceControl",
Expand All @@ -341,6 +350,24 @@
"revision" : "d8c4846dfbbe04aa8196ae5a5a3cdc6cd7f9f6bc",
"version" : "1.0.0"
}
},
{
"identity" : "swiftui-introspect",
"kind" : "remoteSourceControl",
"location" : "https://github.com/siteline/SwiftUI-Introspect",
"state" : {
"revision" : "807f73ce09a9b9723f12385e592b4e0aaebd3336",
"version" : "1.3.0"
}
},
{
"identity" : "swiftuibackports",
"kind" : "remoteSourceControl",
"location" : "https://github.com/shaps80/SwiftUIBackports",
"state" : {
"revision" : "556d42f391b74059a354b81b8c8e19cc7cb576f4",
"version" : "1.15.1"
}
}
],
"version" : 2
Expand Down
8 changes: 4 additions & 4 deletions kDrive/AppRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ public struct AppRouter: AppNavigable {
}

switch route {
case .saveFile(let file):
case .saveFiles(let files):
guard let driveFileManager = accountManager.currentDriveFileManager else {
Log.sceneDelegate("NavigationManager: Unable to navigate to .saveFile without a DriveFileManager", level: .error)
return
}

showSaveFileVC(from: viewController, driveFileManager: driveFileManager, file: file)
showSaveFileVC(from: viewController, driveFileManager: driveFileManager, files: files)

case .store(let driveId, let userId):
guard let driveFileManager = accountManager.getDriveFileManager(for: driveId, userId: userId) else {
Expand Down Expand Up @@ -439,8 +439,8 @@ public struct AppRouter: AppNavigable {
navController.pushViewController(photoSyncSettingsViewController, animated: true)
}

public func showSaveFileVC(from viewController: UIViewController, driveFileManager: DriveFileManager, file: ImportedFile) {
let vc = SaveFileViewController.instantiateInNavigationController(driveFileManager: driveFileManager, file: file)
public func showSaveFileVC(from viewController: UIViewController, driveFileManager: DriveFileManager, files: [ImportedFile]) {
let vc = SaveFileViewController.instantiateInNavigationController(driveFileManager: driveFileManager, files: files)
viewController.present(vc, animated: true)
}

Expand Down
2 changes: 1 addition & 1 deletion kDrive/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate, AccountManagerDel

Task {
let success = await DeeplinkParser().parse(url: url)
Log.sceneDelegate("scene open url\(url) success:\(success)")
Log.sceneDelegate("scene open url: \(url) success: \(success)")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ class SaveFileViewController: UIViewController {
}

class func instantiateInNavigationController(driveFileManager: DriveFileManager?,
file: ImportedFile? = nil) -> TitleSizeAdjustingNavigationController {
files: [ImportedFile]? = nil) -> TitleSizeAdjustingNavigationController {
let saveViewController = instantiate(driveFileManager: driveFileManager)
if let file {
saveViewController.items = [file]
if let files {
saveViewController.items = files
}
let navigationController = TitleSizeAdjustingNavigationController(rootViewController: saveViewController)
navigationController.navigationBar.prefersLargeTitles = true
Expand Down
6 changes: 5 additions & 1 deletion kDriveCore/Utils/AppNavigable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public protocol RouterAppNavigable {

@MainActor func showPhotoSyncSettings()

@MainActor func showSaveFileVC(from viewController: UIViewController, driveFileManager: DriveFileManager, file: ImportedFile)
@MainActor func showSaveFileVC(
from viewController: UIViewController,
driveFileManager: DriveFileManager,
files: [ImportedFile]
)
}

/// Routing methods available from both the AppExtension mode and App
Expand Down
17 changes: 12 additions & 5 deletions kDriveCore/Utils/DeeplinkParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ public struct DeeplinkParser: DeeplinkParsable {
await router.navigate(to: .store(driveId: driveIdInt, userId: userIdInt))
return true

} else if components.host == DeeplinkPath.file.rawValue,
let filePath = params.first(where: { $0.name == "url" })?.value {
let fileUrl = URL(fileURLWithPath: filePath)
let file = ImportedFile(name: fileUrl.lastPathComponent, path: fileUrl, uti: fileUrl.uti ?? .data)
await router.navigate(to: .saveFile(file: file))
} else if components.host == DeeplinkPath.file.rawValue {
let files: [ImportedFile] = params.compactMap { param in
guard param.name == "url", let filePath = param.value else { return nil }
let fileUrl = URL(fileURLWithPath: filePath)

return ImportedFile(name: fileUrl.lastPathComponent, path: fileUrl, uti: fileUrl.uti ?? .data)
}
guard !files.isEmpty else {
Log.sceneDelegate("Failed to import files: No files found", level: .error)
return false
}
await router.navigate(to: .saveFiles(files: files))
return true
}

Expand Down
4 changes: 2 additions & 2 deletions kDriveCore/Utils/Routable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import UIKit
/// Abstract `Routes` that can be navigated to
public enum NavigationRoutes: Equatable {
case store(driveId: Int, userId: Int)
case saveFile(file: ImportedFile)
case saveFiles(files: [ImportedFile])

public static func == (lhs: NavigationRoutes, rhs: NavigationRoutes) -> Bool {
switch (lhs, rhs) {
case (.store(let lhdDriveId, let lhdUserId), .store(let rhdDriveId, let rhdUserId)):
return lhdDriveId == rhdDriveId && lhdUserId == rhdUserId
case (.saveFile(let lhdFile), .saveFile(let rhdDile)):
case (.saveFiles(let lhdFile), .saveFiles(let rhdDile)):
return lhdFile == rhdDile
default:
return false
Expand Down
2 changes: 1 addition & 1 deletion kDriveTestShared/MCKRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public final class MCKRouter: AppNavigable {
logNoop()
}

public func showSaveFileVC(from viewController: UIViewController, driveFileManager: DriveFileManager, file: ImportedFile) {
public func showSaveFileVC(from viewController: UIViewController, driveFileManager: DriveFileManager, files: [ImportedFile]) {
logNoop()
}
}
20 changes: 10 additions & 10 deletions kDriveTests/UTNavigationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class MckRoutable_navigate: Routable {
XCTFail("unexpected call to \(#function)")
}

func showSaveFileVC(from viewController: UIViewController, driveFileManager: DriveFileManager, file: ImportedFile) {
func showSaveFileVC(from viewController: UIViewController, driveFileManager: DriveFileManager, files: [ImportedFile]) {
XCTFail("unexpected call to \(#function)")
}

Expand Down Expand Up @@ -54,7 +54,7 @@ final class UTNavigationManager: XCTestCase {
}
SimpleResolver.sharedResolver.store(factory: routerFactory)
let expectedFile = ImportedFile(name: "name", path: URL(string: "http://infoamaniak.com")!, uti: .aiff)
let expectedRoute = NavigationRoutes.saveFile(file: expectedFile)
let expectedRoute = NavigationRoutes.saveFiles(files: [expectedFile])

// WHEN
@InjectService var router: Routable
Expand Down Expand Up @@ -104,8 +104,8 @@ final class UTNavigationRoutes: XCTestCase {
func testRouteEqual_File() {
// GIVEN
let expectedFile = ImportedFile(name: "name", path: URL(string: "http://infoamaniak.com")!, uti: .aiff)
let routeA = NavigationRoutes.saveFile(file: expectedFile)
let routeB = NavigationRoutes.saveFile(file: expectedFile)
let routeA = NavigationRoutes.saveFiles(files: [expectedFile])
let routeB = NavigationRoutes.saveFiles(files: [expectedFile])

// THEN
XCTAssertEqual(routeA, routeB)
Expand All @@ -115,8 +115,8 @@ final class UTNavigationRoutes: XCTestCase {
// GIVEN
let fileA = ImportedFile(name: "name", path: URL(string: "http://infoamaniak.com")!, uti: .aiff)
let fileB = ImportedFile(name: "name", path: URL(string: "http://infoamaniak.com")!, uti: .jpeg)
let routeA = NavigationRoutes.saveFile(file: fileA)
let routeB = NavigationRoutes.saveFile(file: fileB)
let routeA = NavigationRoutes.saveFiles(files: [fileA])
let routeB = NavigationRoutes.saveFiles(files: [fileB])

// THEN
XCTAssertNotEqual(routeA, routeB)
Expand All @@ -126,8 +126,8 @@ final class UTNavigationRoutes: XCTestCase {
// GIVEN
let fileA = ImportedFile(name: "name", path: URL(string: "http://infoamaniak.com")!, uti: .jpeg)
let fileB = ImportedFile(name: "name", path: URL(string: "http://infoamaniak.ch")!, uti: .jpeg)
let routeA = NavigationRoutes.saveFile(file: fileA)
let routeB = NavigationRoutes.saveFile(file: fileB)
let routeA = NavigationRoutes.saveFiles(files: [fileA])
let routeB = NavigationRoutes.saveFiles(files: [fileB])

// THEN
XCTAssertNotEqual(routeA, routeB)
Expand All @@ -137,8 +137,8 @@ final class UTNavigationRoutes: XCTestCase {
// GIVEN
let fileA = ImportedFile(name: "name", path: URL(string: "http://infoamaniak.com")!, uti: .jpeg)
let fileB = ImportedFile(name: "another", path: URL(string: "http://infoamaniak.com")!, uti: .jpeg)
let routeA = NavigationRoutes.saveFile(file: fileA)
let routeB = NavigationRoutes.saveFile(file: fileB)
let routeA = NavigationRoutes.saveFiles(files: [fileA])
let routeB = NavigationRoutes.saveFiles(files: [fileB])

// THEN
XCTAssertNotEqual(routeA, routeB)
Expand Down

0 comments on commit 8cb54f5

Please sign in to comment.