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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
384b52d
refactor: Upsale floating panel constructor method
adrien-coye Dec 12, 2024
abd2bae
feat: Add to my kDrive floating action.
adrien-coye Dec 12, 2024
f80e953
chore: Merge branch 'externalLinks-famousLastFivePercent' into extern…
adrien-coye Dec 17, 2024
691feee
fix(AddToMykDrive): Big button selects the correct drive by default
adrien-coye Dec 18, 2024
f349a1a
chore: Merge branch 'externalLinks-famousLastFivePercent' into extern…
adrien-coye Dec 18, 2024
26b1097
chore: Merge branch 'externalLinks-famousLastFivePercent' into extern…
adrien-coye Dec 18, 2024
b9eb981
chore: Merge branch 'externalLinks-famousLastFivePercent' into extern…
adrien-coye Jan 2, 2025
16985c9
chore: Merge branch 'externalLinks-famousLastFivePercent' into extern…
adrien-coye Jan 7, 2025
944dac6
chore: Merge branch 'externalLinks-famousLastFivePercent' into extern…
adrien-coye Jan 7, 2025
7907779
feat: Keep addToMyDrive button enabled while multiselect
adrien-coye Jan 8, 2025
dd7c93c
chore: Matomo event naming
adrien-coye Jan 8, 2025
10332da
chore(UpsaleViewController): Removed comments
adrien-coye Jan 8, 2025
fe4a329
refactor(PublicShareAction): Factorised addToMyDrive code
adrien-coye Jan 8, 2025
6aa1342
feat(Router): New showUpsaleFloatingPanel method
adrien-coye Jan 8, 2025
46a882f
fix(addToMyDrive): Modified and checked new logic against every use c…
adrien-coye Jan 8, 2025
60bba8f
feat(PublicShareViewModel): Disable multi selection on addToMyDrive a…
adrien-coye Jan 8, 2025
3cbf6b3
chore(UT): Fix protocol changes in mocks
adrien-coye Jan 8, 2025
511dac2
chore: Merge branch 'externalLinks-famousLastFivePercent' into extern…
adrien-coye Jan 8, 2025
65db643
refactor(SaveFileViewController): Rework init method
adrien-coye Jan 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions kDrive/AppRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,21 @@ public struct AppRouter: AppNavigable {
}
}

@MainActor public func showUpsaleFloatingPanel() {
guard let window else {
SentryDebug.captureNoWindow()
return
}

guard let rootViewController = window.rootViewController else {
return
}

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

@MainActor public func showUpdateRequired() {
guard let window else {
SentryDebug.captureNoWindow()
Expand Down
24 changes: 2 additions & 22 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 Expand Up @@ -656,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 @@ -666,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
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,30 @@ extension FileActionsFloatingPanelViewController {
}
}
}

private func addToMyDrive() {
guard accountManager.currentAccount != nil else {
adrien-coye marked this conversation as resolved.
Show resolved Hide resolved
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)
}
)
}
}
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
41 changes: 41 additions & 0 deletions kDrive/UI/Controller/Files/PublicShareAction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Infomaniak kDrive - iOS App
Copyright (C) 2024 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import kDriveCore
import UIKit

struct PublicShareAction {
adrien-coye marked this conversation as resolved.
Show resolved Hide resolved
@MainActor func addToMyDrive(
publicShareProxy: PublicShareProxy,
currentUserDriveFileManager: DriveFileManager,
selectedItemsIds: [Int],
exceptItemIds: [Int],
onPresentViewController: (UIViewController, Bool) -> Void,
onDismissViewController: (() -> Void)?
) {
let saveNavigationViewController = SaveFileViewController.instantiateInNavigationController(
driveFileManager: currentUserDriveFileManager,
publicShareProxy: publicShareProxy,
publicShareFileIds: selectedItemsIds,
publicShareExceptIds: exceptItemIds,
onDismissViewController: onDismissViewController
)

onPresentViewController(saveNavigationViewController, true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ extension SaveFileViewController: FooterButtonDelegate {
return
}
let drive = selectedDriveFileManager.drive

// Making sure the user cannot spam the button on tasks that may take a while
let button = sender as? IKLargeButton
button?.setLoading(true)

Expand Down
34 changes: 24 additions & 10 deletions kDrive/UI/Controller/Files/Save File/SaveFileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,34 @@ class SaveFileViewController: UIViewController {
return viewController
}

class func setInNavigationController(saveViewController: SaveFileViewController,
files: [ImportedFile]? = nil) -> TitleSizeAdjustingNavigationController {
if let files {
saveViewController.items = files
}
let navigationController = TitleSizeAdjustingNavigationController(rootViewController: saveViewController)
navigationController.navigationBar.prefersLargeTitles = true
return navigationController
class func instantiateInNavigationController(driveFileManager: DriveFileManager,
publicShareProxy: PublicShareProxy,
publicShareFileIds: [Int],
publicShareExceptIds: [Int],
onDismissViewController: (() -> Void)?)
-> TitleSizeAdjustingNavigationController {
let saveViewController = instantiate(driveFileManager: driveFileManager)

saveViewController.publicShareFileIds = publicShareFileIds
saveViewController.publicShareExceptIds = publicShareExceptIds
saveViewController.publicShareProxy = publicShareProxy

return wrapInNavigationController(saveViewController)
}

class func instantiateInNavigationController(driveFileManager: DriveFileManager?,
files: [ImportedFile]? = nil) -> TitleSizeAdjustingNavigationController {
let saveViewController = instantiate(driveFileManager: driveFileManager)
return setInNavigationController(saveViewController: saveViewController,
files: files)
if let files {
saveViewController.items = files
}

return wrapInNavigationController(saveViewController)
}

private class func wrapInNavigationController(_ viewController: UIViewController) -> TitleSizeAdjustingNavigationController {
let navigationController = TitleSizeAdjustingNavigationController(rootViewController: viewController)
navigationController.navigationBar.prefersLargeTitles = true
return navigationController
}
}
39 changes: 23 additions & 16 deletions kDrive/UI/Controller/Menu/Share/PublicShareViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import UIKit
/// Public share view model, loading content from memory realm
final class PublicShareViewModel: InMemoryFileListViewModel {
@LazyInjectService private var accountManager: AccountManageable
@LazyInjectService private var router: AppNavigable

private var downloadObserver: ObservationToken?

Expand Down Expand Up @@ -148,29 +149,35 @@ final class PublicShareViewModel: InMemoryFileListViewModel {
}

private func addToMyDrive(sender: Any?, publicShareProxy: PublicShareProxy) {
guard accountManager.currentAccount != nil else {
router.showUpsaleFloatingPanel()
return
}

guard let currentUserDriveFileManager = accountManager.currentDriveFileManager else {
return
}

let selectedItemsIds = multipleSelectionViewModel?.selectedItems.map(\.id) ?? [] + [rootProxy.id]
var selectedItemsIds = multipleSelectionViewModel?.selectedItems.map(\.id) ?? []
let exceptItemIds = multipleSelectionViewModel?.exceptItemIds.map { $0 } ?? []

let saveViewController = SaveFileViewController.instantiate(driveFileManager: currentUserDriveFileManager)
let saveNavigationViewController = SaveFileViewController
.setInNavigationController(saveViewController: saveViewController)

saveViewController.onDismissViewController = { [weak self] in
guard let self else { return }
self.onDismissViewController?()
if publicShareProxy.fileId != rootProxy.id, selectedItemsIds.isEmpty {
adrien-coye marked this conversation as resolved.
Show resolved Hide resolved
selectedItemsIds += [rootProxy.id]
}

if let saveViewController = saveNavigationViewController.viewControllers.first as? SaveFileViewController {
saveViewController.publicShareFileIds = selectedItemsIds
saveViewController.publicShareExceptIds = exceptItemIds
saveViewController.publicShareProxy = publicShareProxy
saveViewController.selectedDirectory = currentDirectory
}

onPresentViewController?(.modal, saveNavigationViewController, true)
PublicShareAction().addToMyDrive(
publicShareProxy: publicShareProxy,
currentUserDriveFileManager: currentUserDriveFileManager,
selectedItemsIds: selectedItemsIds,
exceptItemIds: exceptItemIds,
onPresentViewController: { saveNavigationViewController, animated in
onPresentViewController?(.modal, saveNavigationViewController, animated)
},
onDismissViewController: { [weak self] in
guard let self else { return }
self.onDismissViewController?()
self.multipleSelectionViewModel?.isMultipleSelectionEnabled = false
}
)
}
}
25 changes: 25 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,28 @@ public class UpsaleViewController: UIViewController {
dismiss(animated: true, completion: nil)
onLoginCompleted?()
}

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

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)
}
}

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)
}
}
2 changes: 2 additions & 0 deletions kDriveCore/Utils/AppNavigable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public protocol RouterAppNavigable {

@MainActor func showLaunchFloatingPanel()

@MainActor func showUpsaleFloatingPanel()

@MainActor func showUpdateRequired()

@MainActor func showPhotoSyncSettings()
Expand Down
2 changes: 1 addition & 1 deletion kDriveCore/Utils/MatomoUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public enum MatomoUtils {

// MARK: - Public Share

public static func trackAddToMykDrive() {
public static func trackAddToMyDrive() {
track(eventWithCategory: .publicShareAction, name: "saveToKDrive")
}

Expand Down
13 changes: 13 additions & 0 deletions kDriveTestShared/MCKRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import Foundation
import InfomaniakCore
import InfomaniakLogin
import kDrive
import kDriveCore
import UIKit
Expand Down Expand Up @@ -74,6 +75,10 @@ public final class MCKRouter: AppNavigable {
logNoop()
}

public func showUpsaleFloatingPanel() {
logNoop()
}

public func showUpdateRequired() {
logNoop()
}
Expand All @@ -82,6 +87,14 @@ public final class MCKRouter: AppNavigable {
logNoop()
}

public func showLogin(delegate: InfomaniakLoginDelegate) {
logNoop()
}

public func showRegister(delegate: InfomaniakLoginDelegate) {
logNoop()
}

public func present(file: kDriveCore.File, driveFileManager: kDriveCore.DriveFileManager) {
logNoop()
}
Expand Down
2 changes: 1 addition & 1 deletion kDriveTests/kDrive/Launch/MockAccountManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class MockAccountManager: AccountManageable, RefreshTokenDelegate {

func logoutCurrentAccountAndSwitchToNextIfPossible() { fatalError("Not implemented") }

func getInMemoryDriveFileManager(for publicShareId: String, driveId: Int, rootFileId: Int) -> DriveFileManager {
func getInMemoryDriveFileManager(for publicShareId: String, driveId: Int, rootFileId: Int) -> DriveFileManager? {
fatalError("Not implemented")
}
}
Loading