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: Factorise add to my drive action. #1350

Draft
wants to merge 9 commits into
base: externalLinks-famousLastFivePercent
Choose a base branch
from
22 changes: 2 additions & 20 deletions kDrive/UI/Controller/Files/File List/FileListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,26 +296,8 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV

guard accountManager.currentAccount != nil else {
#if !ISEXTENSION
let upsaleViewController = UpsaleViewController()

upsaleViewController.onFreeTrialCompleted = { [weak self] in
guard let self else { return }
self.dismiss(animated: true) {
let loginDelegateHandler = LoginDelegateHandler()
self.router.showRegister(delegate: loginDelegateHandler)
}
}

upsaleViewController.onLoginCompleted = { [weak self] in
guard let self else { return }
self.dismiss(animated: true) {
let loginDelegateHandler = LoginDelegateHandler()
self.router.showLogin(delegate: loginDelegateHandler)
}
}

let floatingPanel = UpsaleFloatingPanelController(upsaleViewController: upsaleViewController)
present(floatingPanel, animated: true, completion: nil)
let upsaleFloatingPanelController = UpsaleViewController.instantiateInFloatingPanel(rootViewController: self)
present(upsaleFloatingPanelController, animated: true, completion: nil)
#else
dismiss(animated: true)
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ extension FileActionsFloatingPanelViewController {
leaveShareAction()
case .cancelImport:
cancelImportAction()
case .addToMyDrive:
addToMyKDrive()
default:
break
}
Expand Down Expand Up @@ -520,4 +522,32 @@ extension FileActionsFloatingPanelViewController {
}
}
}

private func addToMyKDrive() {
guard accountManager.currentAccount != nil else {
let upsaleFloatingPanelController = UpsaleViewController.instantiateInFloatingPanel(rootViewController: self)
present(upsaleFloatingPanelController, animated: true, completion: nil)
return
}

guard let currentUserDriveFileManager = accountManager.currentDriveFileManager,
let publicShareProxy = driveFileManager.publicShareProxy else {
return
}

let itemId = [file.id]
let saveViewController = SaveFileViewController.instantiate(driveFileManager: currentUserDriveFileManager)
let saveNavigationViewController = SaveFileViewController
.setInNavigationController(saveViewController: saveViewController)

saveViewController.onDismissViewController = { [weak self] in
guard let self else { return }
self.dismiss(animated: true)
}

saveViewController.publicShareFileIds = itemId
saveViewController.publicShareProxy = publicShareProxy

present(saveNavigationViewController, animated: true, completion: nil)
}
}
8 changes: 7 additions & 1 deletion kDrive/UI/Controller/Files/FloatingPanelAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class FloatingPanelAction: Equatable {
case shareAndRights
case shareLink
case upsaleColor
case addToMyDrive
}

init(
Expand Down Expand Up @@ -188,6 +189,11 @@ public class FloatingPanelAction: Equatable {
name: KDriveResourcesStrings.Localizable.buttonChangeFolderColor,
image: KDriveResourcesAsset.colorBucket.image
)
static let addToMyDrive = FloatingPanelAction(
id: .addToMyDrive,
name: KDriveResourcesStrings.Localizable.buttonAddToKDrive,
image: KDriveResourcesAsset.drive.image
)

static var listActions: [FloatingPanelAction] {
return [
Expand Down Expand Up @@ -226,7 +232,7 @@ public class FloatingPanelAction: Equatable {
}

static var publicShareActions: [FloatingPanelAction] {
return [openWith, sendCopy, download].map { $0.reset() }
return [openWith, sendCopy, download, addToMyDrive].map { $0.reset() }
}

static var publicShareFolderActions: [FloatingPanelAction] {
Expand Down
27 changes: 27 additions & 0 deletions kDrive/UI/View/Upsale/UpsaleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import InfomaniakCoreUIKit
import InfomaniakDI
import kDriveCore
import kDriveResources
import UIKit
Expand Down Expand Up @@ -228,4 +229,30 @@ public class UpsaleViewController: UIViewController {
dismiss(animated: true, completion: nil)
onLoginCompleted?()
}

public static func instantiateInFloatingPanel(rootViewController: UIViewController) -> UIViewController {
let upsaleViewController = UpsaleViewController()

// Create an account
upsaleViewController.onFreeTrialCompleted = { [weak rootViewController] in
guard let rootViewController else { return }
rootViewController.dismiss(animated: true) {
let loginDelegateHandler = LoginDelegateHandler()
@InjectService var router: AppNavigable
router.showRegister(delegate: loginDelegateHandler)
}
}

// Let the user login with the onboarding
upsaleViewController.onLoginCompleted = { [weak rootViewController] in
guard let rootViewController else { return }
rootViewController.dismiss(animated: true) {
let loginDelegateHandler = LoginDelegateHandler()
@InjectService var router: AppNavigable
router.showLogin(delegate: loginDelegateHandler)
}
}

return UpsaleFloatingPanelController(upsaleViewController: upsaleViewController)
}
}
Loading