Skip to content

Commit

Permalink
feat: Add to my drive action (#1349)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye authored Jan 21, 2025
2 parents af68df8 + 4c4e8fd commit eb38f35
Show file tree
Hide file tree
Showing 35 changed files with 680 additions and 200 deletions.
77 changes: 41 additions & 36 deletions kDrive/AppRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import InfomaniakCore
import InfomaniakCoreUIKit
import InfomaniakDI
import InfomaniakLogin
import kDriveCore
import kDriveResources
import SafariServices
Expand All @@ -33,6 +34,7 @@ public struct AppRouter: AppNavigable {
@LazyInjectService private var reviewManager: ReviewManageable
@LazyInjectService private var availableOfflineManager: AvailableOfflineManageable
@LazyInjectService private var accountManager: AccountManageable
@LazyInjectService private var infomaniakLogin: InfomaniakLoginable

@LazyInjectService var backgroundDownloadSessionManager: BackgroundDownloadSessionManager
@LazyInjectService var backgroundUploadSessionManager: BackgroundUploadSessionManager
Expand Down Expand Up @@ -412,6 +414,16 @@ public struct AppRouter: AppNavigable {
}
}

@MainActor public func showUpsaleFloatingPanel() {
guard let topMostViewController else {
return
}

let upsaleFloatingPanelController = UpsaleViewController
.instantiateInFloatingPanel(rootViewController: topMostViewController)
topMostViewController.present(upsaleFloatingPanelController, animated: true)
}

@MainActor public func showUpdateRequired() {
guard let window else {
SentryDebug.captureNoWindow()
Expand Down Expand Up @@ -444,6 +456,27 @@ public struct AppRouter: AppNavigable {
viewController.present(vc, animated: true)
}

@MainActor public func showRegister(delegate: InfomaniakLoginDelegate) {
guard let topMostViewController else {
return
}

MatomoUtils.track(eventWithCategory: .account, name: "openCreationWebview")
let registerViewController = RegisterViewController.instantiateInNavigationController(delegate: delegate)
topMostViewController.present(registerViewController, animated: true)
}

@MainActor public func showLogin(delegate: InfomaniakLoginDelegate) {
guard let topMostViewController else {
return
}

MatomoUtils.track(eventWithCategory: .account, name: "openLoginWebview")
infomaniakLogin.webviewLoginFrom(viewController: topMostViewController,
hideCreateAccountButton: true,
delegate: delegate)
}

// MARK: AppExtensionRouter

public func showStore(from viewController: UIViewController, driveFileManager: DriveFileManager) {
Expand Down Expand Up @@ -587,8 +620,7 @@ public struct AppRouter: AppNavigable {

@MainActor public func presentPublicShareLocked(_ destinationURL: URL) {
guard let window,
let rootViewController = window.rootViewController as? MainTabViewController else {
fatalError("TODO: fix offline routing - presentPublicShareLocked")
let rootViewController = window.rootViewController else {
return
}

Expand All @@ -599,20 +631,13 @@ public struct AppRouter: AppNavigable {
publicShareNavigationController.modalPresentationStyle = .fullScreen
publicShareNavigationController.modalTransitionStyle = .coverVertical

rootViewController.selectedIndex = MainTabBarIndex.files.rawValue

guard let navigationController = rootViewController.selectedViewController as? UINavigationController else {
return
}

navigationController.present(publicShareNavigationController, animated: true, completion: nil)
rootViewController.present(publicShareNavigationController, animated: true, completion: nil)
}
}

@MainActor public func presentPublicShareExpired() {
guard let window,
let rootViewController = window.rootViewController as? MainTabViewController else {
fatalError("TODO: fix offline routing - presentPublicShareExpired")
let rootViewController = window.rootViewController else {
return
}

Expand All @@ -622,13 +647,7 @@ public struct AppRouter: AppNavigable {
publicShareNavigationController.modalPresentationStyle = .fullScreen
publicShareNavigationController.modalTransitionStyle = .coverVertical

rootViewController.selectedIndex = MainTabBarIndex.files.rawValue

guard let navigationController = rootViewController.selectedViewController as? UINavigationController else {
return
}

navigationController.present(publicShareNavigationController, animated: true, completion: nil)
rootViewController.present(publicShareNavigationController, animated: true, completion: nil)
}
}

Expand All @@ -639,24 +658,11 @@ public struct AppRouter: AppNavigable {
apiFetcher: PublicShareApiFetcher
) {
guard let window,
let rootViewController = window.rootViewController as? MainTabViewController else {
fatalError("TODO: fix offline routing - presentPublicShare")
return
}

// TODO: Fix access right
guard !frozenRootFolder.isDisabled else {
fatalError("isDisabled")
let rootViewController = window.rootViewController else {
return
}

rootViewController.dismiss(animated: false) {
rootViewController.selectedIndex = MainTabBarIndex.files.rawValue

guard let navigationController = rootViewController.selectedViewController as? UINavigationController else {
return
}

let configuration = FileListViewModel.Configuration(selectAllSupported: true,
rootTitle: nil,
emptyViewType: .emptyFolder,
Expand All @@ -675,15 +681,14 @@ public struct AppRouter: AppNavigable {
apiFetcher: apiFetcher,
configuration: configuration)
let viewController = FileListViewController(viewModel: viewModel)
viewModel.onDismiss = { [weak viewController] in
viewController?.dismiss(animated: true)
viewModel.onDismissViewController = { [weak viewController] in
viewController?.dismiss(animated: false)
}

let publicShareNavigationController = UINavigationController(rootViewController: viewController)
publicShareNavigationController.modalPresentationStyle = .fullScreen
publicShareNavigationController.modalTransitionStyle = .coverVertical

navigationController.present(publicShareNavigationController, animated: true, completion: nil)
rootViewController.present(publicShareNavigationController, animated: true, completion: nil)
}
}

Expand Down
24 changes: 20 additions & 4 deletions kDrive/UI/Controller/Files/File List/FileListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ extension SortType: Selectable {
class FileListViewController: UICollectionViewController, SwipeActionCollectionViewDelegate,
SwipeActionCollectionViewDataSource, FilesHeaderViewDelegate, SceneStateRestorable {
@LazyInjectService var accountManager: AccountManageable
@LazyInjectService var router: AppNavigable

// MARK: - Constants

Expand Down Expand Up @@ -286,8 +287,25 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
])
}

@objc func addToMyDriveButtonTapped(_ sender: UIView?) {
viewModel.barButtonPressed(sender: sender, type: .downloadAll)
@objc func addToMyDriveButtonTapped(_ sender: UIButton?) {
defer {
sender?.isSelected = false
sender?.isEnabled = true
sender?.isHighlighted = false
}

guard accountManager.currentAccount != nil else {
#if !ISEXTENSION
let upsaleFloatingPanelController = UpsaleViewController.instantiateInFloatingPanel(rootViewController: self)
present(upsaleFloatingPanelController, animated: true, completion: nil)
#else
dismiss(animated: true)
#endif

return
}

viewModel.barButtonPressed(sender: sender, type: .addToMyDrive)
}

func reloadCollectionViewWith(files: [File]) {
Expand Down Expand Up @@ -620,7 +638,6 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV

func toggleMultipleSelection(_ on: Bool) {
if on {
addToKDriveButton.isHidden = true
navigationItem.title = nil
headerView?.selectView.isHidden = false
headerView?.selectView.setActions(viewModel.multipleSelectionViewModel?.multipleSelectionActions ?? [])
Expand All @@ -630,7 +647,6 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
generator.prepare()
generator.impactOccurred()
} else {
addToKDriveButton.isHidden = false
headerView?.selectView.isHidden = true
collectionView.allowsMultipleSelection = false
navigationController?.navigationBar.prefersLargeTitles = true
Expand Down
14 changes: 11 additions & 3 deletions kDrive/UI/Controller/Files/File List/FileListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ enum FileListBarButtonType {
case photoSort
case addFolder
case downloadAll
case downloadingAll
case addToMyDrive
}

enum FileListQuickActionType {
Expand Down Expand Up @@ -93,7 +95,6 @@ class FileListViewModel: SelectDelegate {
var matomoViewPath = ["FileList"]
}

var onDismiss: (() -> Void)?
var realmObservationToken: NotificationToken?
var currentDirectoryObservationToken: NotificationToken?

Expand Down Expand Up @@ -139,6 +140,8 @@ class FileListViewModel: SelectDelegate {
}
}

var onDismissViewController: (() -> Void)?

var sortTypeObservation: AnyCancellable?
var listStyleObservation: AnyCancellable?
var bindStore = Set<AnyCancellable>()
Expand All @@ -162,8 +165,6 @@ class FileListViewModel: SelectDelegate {
listStyle = FileListOptions.instance.currentStyle
isRefreshing = false
isLoading = false
currentLeftBarButtons = configuration.leftBarButtons
currentRightBarButtons = configuration.rightBarButtons

if self.currentDirectory.isRoot {
if let rootTitle = configuration.rootTitle {
Expand Down Expand Up @@ -197,6 +198,13 @@ class FileListViewModel: SelectDelegate {
currentDirectory: self.currentDirectory
)
}

loadButtonsConfiguration()
}

func loadButtonsConfiguration() {
currentLeftBarButtons = configuration.leftBarButtons
currentRightBarButtons = configuration.rightBarButtons
}

func updateRealmObservation() {
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:
addToMyDrive()
default:
break
}
Expand Down Expand Up @@ -520,4 +522,32 @@ extension FileActionsFloatingPanelViewController {
}
}
}

private func addToMyDrive() {
guard accountManager.currentAccount != nil else {
dismiss(animated: true) {
self.router.showUpsaleFloatingPanel()
}
return
}

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

PublicShareAction().addToMyDrive(
publicShareProxy: publicShareProxy,
currentUserDriveFileManager: currentUserDriveFileManager,
selectedItemsIds: [file.id],
exceptItemIds: [],
onPresentViewController: { saveNavigationViewController, animated in
self.present(saveNavigationViewController, animated: animated, completion: nil)
},
onDismissViewController: { [weak self] in
guard let self else { return }
self.dismiss(animated: true)
}
)
}
}
6 changes: 3 additions & 3 deletions kDrive/UI/Controller/Files/FileDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ class FileDetailViewController: UIViewController, SceneStateRestorable {

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toShareLinkSettingsSegue" {
let nextVC = segue.destination as! ShareLinkSettingsViewController
nextVC.driveFileManager = driveFileManager
nextVC.file = file
let destinationViewController = segue.destination as! ShareLinkSettingsViewController
destinationViewController.driveFileManager = driveFileManager
destinationViewController.file = file
}
}

Expand Down
10 changes: 7 additions & 3 deletions kDrive/UI/Controller/Files/FilePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,13 @@ final class FilePresenter {
viewModel = ConcreteFileListViewModel(driveFileManager: driveFileManager, currentDirectory: file)
}

let nextVC = FileListViewController(viewModel: viewModel)
let destinationViewController = FileListViewController(viewModel: viewModel)
viewModel.onDismissViewController = { [weak destinationViewController] in
destinationViewController?.dismiss(animated: true)
}

guard file.isDisabled else {
navigationController?.pushViewController(nextVC, animated: animated)
navigationController?.pushViewController(destinationViewController, animated: animated)
return
}

Expand All @@ -190,7 +194,7 @@ final class FilePresenter {
let response = try await driveFileManager.apiFetcher.forceAccess(to: proxyFile)
if response {
accessFileDriveFloatingPanelController.dismiss(animated: true)
self.navigationController?.pushViewController(nextVC, animated: true)
self.navigationController?.pushViewController(destinationViewController, animated: true)
} else {
UIConstants.showSnackBar(message: KDriveResourcesStrings.Localizable.errorRightModification)
}
Expand Down
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
Loading

0 comments on commit eb38f35

Please sign in to comment.