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

feat: Change iPadOS18 view #1329

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
31 changes: 29 additions & 2 deletions Tuist/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/ios-core-ui",
"state" : {
"revision" : "d83b9df4d8e7880fa8a55807549cac0fc4584ce6",
"version" : "13.1.0"
"revision" : "e0afbab522df72496b92042ee65c20f8d593a3f7",
"version" : "13.4.0"
}
},
{
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion Tuist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-algorithms", .upToNextMajor(from: "1.2.0")),
.package(url: "https://github.com/Alamofire/Alamofire", .upToNextMajor(from: "5.2.2")),
.package(url: "https://github.com/Infomaniak/ios-core", .upToNextMajor(from: "12.2.0")),
.package(url: "https://github.com/Infomaniak/ios-core-ui", .upToNextMajor(from: "13.1.0")),
.package(url: "https://github.com/Infomaniak/ios-core-ui", .upToNextMajor(from: "13.4.0")),
.package(url: "https://github.com/Infomaniak/ios-login", .upToNextMajor(from: "7.0.1")),
.package(url: "https://github.com/Infomaniak/ios-dependency-injection", .upToNextMajor(from: "2.0.0")),
.package(url: "https://github.com/Infomaniak/swift-concurrency", .upToNextMajor(from: "0.0.4")),
Expand Down
2 changes: 1 addition & 1 deletion Tuist/ProjectDescriptionHelpers/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum Constants {
.currentProjectVersion("1")
.marketingVersion("5.0.1")

public static let deploymentTarget = DeploymentTargets.iOS("13.4")
public static let deploymentTarget = DeploymentTargets.iOS("14.0")
public static let destinations = Set<Destination>([.iPhone, .iPad])

public static let fileProviderSettings = baseSettings
Expand Down
50 changes: 6 additions & 44 deletions kDrive/AppRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,52 +173,15 @@ public struct AppRouter: AppNavigable {
}

Task { @MainActor in
guard restoration, let tabBarViewController else {
guard restoration else {
return
}

guard let sceneUserInfo,
let lastViewControllerString = sceneUserInfo[SceneRestorationKeys.lastViewController.rawValue] as? String,
let lastViewController = SceneRestorationScreens(rawValue: lastViewControllerString) else {
SceneRestorationScreens(rawValue: lastViewControllerString) != nil else {
return
}

let selectedIndex = tabBarViewController.selectedIndex
let viewControllers = tabBarViewController.viewControllers
guard let rootNavigationController = viewControllers?[safe: selectedIndex] as? UINavigationController else {
Log.sceneDelegate("unable to access navigationController", level: .error)
return
}

switch lastViewController {
case .FileDetailViewController:
await restoreFileDetailViewController(
driveFileManager: driveFileManager,
navigationController: rootNavigationController,
sceneUserInfo: sceneUserInfo
)

case .FileListViewController:
await restoreFileListViewController(
driveFileManager: driveFileManager,
navigationController: rootNavigationController,
sceneUserInfo: sceneUserInfo
)

case .PreviewViewController:
await restorePreviewViewController(
driveFileManager: driveFileManager,
navigationController: rootNavigationController,
sceneUserInfo: sceneUserInfo
)

case .StoreViewController:
await restoreStoreViewController(
driveFileManager: driveFileManager,
navigationController: rootNavigationController,
sceneUserInfo: sceneUserInfo
)
}
}
}

Expand Down Expand Up @@ -339,19 +302,18 @@ public struct AppRouter: AppNavigable {

@discardableResult
@MainActor public func showMainViewController(driveFileManager: DriveFileManager,
selectedIndex: Int?) -> UITabBarController? {
selectedIndex: Int?) -> UISplitViewController? {
guard let window else {
SentryDebug.captureNoWindow()
return nil
}

let currentDriveObjectId = (window.rootViewController as? MainTabViewController)?.driveFileManager.drive.objectId
let currentDriveObjectId = (window.rootViewController as? RootViewController)?.driveFileManager.drive.objectId
guard currentDriveObjectId != driveFileManager.drive.objectId else {
return nil
}

let tabBarViewController = MainTabViewController(driveFileManager: driveFileManager,
selectedIndex: selectedIndex)
let tabBarViewController = RootViewController(driveFileManager: driveFileManager)

window.rootViewController = tabBarViewController
window.makeKeyAndVisible()
Expand Down Expand Up @@ -611,7 +573,7 @@ public struct AppRouter: AppNavigable {
navController.popToRootViewController(animated: false)
}

guard let rootMenuViewController = navController.topViewController as? RootMenuViewController else {
guard let rootMenuViewController = navController.topViewController as? SidebarViewController else {
return
}

Expand Down
60 changes: 51 additions & 9 deletions kDrive/OpenMediaHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,36 @@
import CocoaLumberjackSwift
import Foundation
import InfomaniakCore
import InfomaniakDI
import kDriveCore
import kDriveResources
import PhotosUI
import Vision
import VisionKit

struct OpenMediaHelper {
var currentDirectory: File?
var driveFileManager: DriveFileManager
class OpenMediaHelper: NSObject {
@LazyInjectService var accountManager: AccountManageable
@LazyInjectService var uploadQueue: UploadQueue
@LazyInjectService var fileImportHelper: FileImportHelper

let currentDirectory: File?
let driveFileManager: DriveFileManager
let photoPickerDelegate = PhotoPickerDelegate()

enum Media {
case library, camera
}

func openMedia(_ mainTabViewController: MainTabViewController, _ media: Media) {
mainTabViewController.photoPickerDelegate.driveFileManager = driveFileManager
mainTabViewController.photoPickerDelegate.currentDirectory = currentDirectory?.freezeIfNeeded()
init(currentDirectory: File? = nil, driveFileManager: DriveFileManager) {
self.currentDirectory = currentDirectory
self.driveFileManager = driveFileManager
super.init()
}

func openMedia(_ mainTabViewController: UIViewController, _ media: Media) {
photoPickerDelegate.viewController = mainTabViewController
photoPickerDelegate.driveFileManager = driveFileManager
photoPickerDelegate.currentDirectory = currentDirectory?.freezeIfNeeded()

if #available(iOS 14, *), media == .library {
// Check permission
Expand All @@ -46,7 +59,7 @@ struct OpenMediaHelper {
configuration.selectionLimit = 0

let picker = PHPickerViewController(configuration: configuration)
picker.delegate = mainTabViewController.photoPickerDelegate
picker.delegate = self.photoPickerDelegate
mainTabViewController.present(picker, animated: true)
}
} else {
Expand Down Expand Up @@ -85,14 +98,14 @@ struct OpenMediaHelper {

let picker = UIImagePickerController()
picker.sourceType = sourceType
picker.delegate = mainTabViewController.photoPickerDelegate
picker.delegate = photoPickerDelegate
picker.mediaTypes = UIImagePickerController
.availableMediaTypes(for: sourceType) ?? [UTI.image.identifier, UTI.movie.identifier]
mainTabViewController.present(picker, animated: true)
}
}

func openScan(_ mainTabViewController: MainTabViewController, _ presentedAboveFileList: Bool) {
func openScan(_ mainTabViewController: UIViewController, _ presentedAboveFileList: Bool) {
guard VNDocumentCameraViewController.isSupported else {
DDLogError("VNDocumentCameraViewController is not supported on this device")
return
Expand All @@ -109,3 +122,32 @@ struct OpenMediaHelper {
mainTabViewController.present(navigationViewController, animated: true)
}
}

extension OpenMediaHelper: UIDocumentPickerDelegate {
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
if let documentPicker = controller as? DriveImportDocumentPickerViewController {
for url in urls {
let targetURL = fileImportHelper.generateImportURL(for: url.uti)

do {
if FileManager.default.fileExists(atPath: targetURL.path) {
try FileManager.default.removeItem(at: targetURL)
}

try FileManager.default.moveItem(at: url, to: targetURL)
uploadQueue.saveToRealm(
UploadFile(
parentDirectoryId: documentPicker.importDriveDirectory.id,
userId: accountManager.currentUserId,
driveId: documentPicker.importDriveDirectory.driveId,
url: targetURL,
name: url.lastPathComponent
)
)
} catch {
UIConstants.showSnackBarIfNeeded(error: DriveError.unknownError)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class PlusButtonFloatingPanelViewController: UITableViewController, FloatingPane
}
dismiss(animated: true)

guard let mainTabViewController = parent?.presentingViewController as? MainTabViewController else {
guard let mainTabViewController = parent?.presentingViewController else {
return
}

Expand Down Expand Up @@ -240,23 +240,23 @@ class PlusButtonFloatingPanelViewController: UITableViewController, FloatingPane

// MARK: Actions

private func importAction(_ mainTabViewController: MainTabViewController) {
private func importAction(_ mainTabViewController: UIViewController) {
let documentPicker = DriveImportDocumentPickerViewController(documentTypes: [UTI.data.identifier], in: .import)
documentPicker.importDrive = driveFileManager.drive
documentPicker.importDriveDirectory = currentDirectory.freezeIfNeeded()
documentPicker.delegate = mainTabViewController
// documentPicker.delegate = mainTabViewController
mainTabViewController.present(documentPicker, animated: true)
}

private func folderAction(_ mainTabViewController: MainTabViewController) {
private func folderAction(_ mainTabViewController: UIViewController) {
let newFolderViewController = NewFolderTypeTableViewController.instantiateInNavigationController(
parentDirectory: currentDirectory,
driveFileManager: driveFileManager
)
mainTabViewController.present(newFolderViewController, animated: true)
}

private func scanAction(_ mainTabViewController: MainTabViewController) {
private func scanAction(_ mainTabViewController: UIViewController) {
guard VNDocumentCameraViewController.isSupported else {
DDLogError("VNDocumentCameraViewController is not supported on this device")
return
Expand All @@ -273,12 +273,12 @@ class PlusButtonFloatingPanelViewController: UITableViewController, FloatingPane
mainTabViewController.present(navigationViewController, animated: true)
}

private func mediaAction(_ mainTabViewController: MainTabViewController, action: PlusButtonMenuAction) {
private func mediaAction(_ mainTabViewController: UIViewController, action: PlusButtonMenuAction) {
let openMediaHelper = OpenMediaHelper(currentDirectory: currentDirectory, driveFileManager: driveFileManager)
openMediaHelper.openMedia(mainTabViewController, action == .importMediaAction ? .library : .camera)
}

private func documentAction(_ mainTabViewController: MainTabViewController, action: PlusButtonMenuAction) {
private func documentAction(_ mainTabViewController: UIViewController, action: PlusButtonMenuAction) {
let alertViewController = AlertDocViewController(fileType: action.docType,
directory: currentDirectory.freezeIfNeeded(),
driveFileManager: driveFileManager)
Expand Down
Loading
Loading