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: Multiselect behaviour #1311

Merged
merged 37 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5368da7
feat: Multiselect behaviour
adrien-coye Sep 27, 2024
e1e77ca
chore: Merge branch 'master' into externalLinks-multiSelect
adrien-coye Oct 22, 2024
0b2fd4e
chore: Merge branch 'externalLinks-downloadFiles' into externalLinks-…
adrien-coye Oct 23, 2024
0fe23be
chore: PR Feedback
adrien-coye Oct 23, 2024
8ac9134
chore: Merge branch 'feature-externalLinks' into externalLinks-multiS…
adrien-coye Oct 30, 2024
1861f13
feat: Public Share multi selection actions are set to download only
adrien-coye Oct 30, 2024
7054054
chore: Merge branch 'feature-externalLinks' into externalLinks-multiS…
adrien-coye Nov 27, 2024
ced6c19
chore: Removed unnecessary title
adrien-coye Nov 27, 2024
0513dfb
refactor: Split download action in manageable bits
adrien-coye Nov 27, 2024
7c48ef2
chore: PR notes
adrien-coye Nov 27, 2024
66fa72f
chore: Merge branch 'feature-externalLinks' into externalLinks-multiS…
adrien-coye Nov 28, 2024
424a60c
feat: Public share archive request working
adrien-coye Nov 28, 2024
6c88f15
feat: Download public share
adrien-coye Nov 29, 2024
c38313c
chore: Merge branch 'feature-externalLinks' into externalLinks-multiS…
adrien-coye Nov 29, 2024
744fc93
feat: Dedicated public share archive download endpoint
adrien-coye Dec 3, 2024
c53c4c1
chore: Self assessment
adrien-coye Dec 3, 2024
c5644a6
refactor: Removed action from ViewController and moved to the view in…
adrien-coye Dec 3, 2024
8918aa6
feat: Public share file count for select all
adrien-coye Dec 3, 2024
b7cfac7
fix: Working select all
adrien-coye Dec 4, 2024
a78e782
chore: Merge branch 'feature-externalLinks' into externalLinks-multiS…
adrien-coye Dec 5, 2024
3105166
refactor: Substitute ViewControllerDismissable for a simple closure.
adrien-coye Dec 11, 2024
c35026c
chore: Merge branch 'feature-externalLinks' into externalLinks-multiS…
adrien-coye Dec 17, 2024
4d709db
chore: PR feedback
adrien-coye Dec 19, 2024
20ff0ef
chore: Merge branch 'feature-externalLinks' into externalLinks-multiS…
adrien-coye Dec 30, 2024
3ff747c
refactor(DownloadArchiveOperation): Split dedicated public share code
adrien-coye Dec 30, 2024
d96e98d
refactor(DownloadArchiveOperation): Factorised download request
adrien-coye Dec 30, 2024
17109b6
refactor(DownloadArchiveOperation): Split code related to publicShare…
adrien-coye Dec 30, 2024
62ddb92
refactor(DownloadOperation): Renamed DownloadAuthenticatedOperation
adrien-coye Jan 2, 2025
351a198
refactor(DownloadOperationable): Renamed DownloadFileOperationable
adrien-coye Jan 2, 2025
2d60725
chore(DownloadOperation): Explicit sendable requirements from base Op…
adrien-coye Jan 2, 2025
052442b
refactor(DownloadOperation): Factorise a base DownloadOperation.
adrien-coye Jan 2, 2025
e93a347
chore: Sonar naming conventions
adrien-coye Jan 2, 2025
2825da0
chore: Merge branch 'feature-externalLinks' into externalLinks-multiS…
adrien-coye Jan 2, 2025
24b3fec
chore: Merge branch 'externalLinks-multiSelect' into externalLinks-co…
adrien-coye Jan 2, 2025
399acfb
refactor(DownloadOperation): Public accessor for progress value
adrien-coye Jan 6, 2025
cc16b7a
refactor: Common download operation (#1370)
adrien-coye Jan 6, 2025
d294a79
refactor(DownloadQueue): Use abstract type DownloadFileOperationable …
adrien-coye Jan 7, 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
35 changes: 20 additions & 15 deletions kDrive/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,27 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
Task {
try! await Task.sleep(nanoseconds: 5_000_000_000)

@InjectService var router: AppNavigable
//let upsaleViewController = UpsaleViewController()
let noDriveViewController = NoDriveUpsaleViewController()
let floatingPanel = UpsaleFloatingPanelController(upsaleViewController: noDriveViewController)
router.topMostViewController?.present(floatingPanel, animated: true, completion: nil)

/* Temp code to test out the feature. TODO: Remove later
// a public share expired
let somePublicShare =
URL(string: "https://kdrive.infomaniak.com/app/share/140946/81de098a-3156-4ae6-93df-be7f9ae78ddd")
// a public share password protected
// let somePublicShare = URL(string:
// "https://kdrive.infomaniak.com/app/share/140946/34844cea-db8d-4d87-b66f-e944e9759a2e")

await UniversalLinksHelper.handleURL(somePublicShare!)
/* TODO: Remove later
@InjectService var router: AppNavigable
let upsaleViewController = UpsaleViewController()
let noDriveViewController = NoDriveUpsaleViewController()
let floatingPanel = UpsaleFloatingPanelController(upsaleViewController: noDriveViewController)
router.topMostViewController?.present(floatingPanel, animated: true, completion: nil)
*/

/* TODO: Remove later
// a public share expired
let somePublicShareExpired =
URL(string: "https://kdrive.infomaniak.com/app/share/140946/81de098a-3156-4ae6-93df-be7f9ae78ddd")
// a public share password protected
let somePublicShareProtected =
URL(string: "https://kdrive.infomaniak.com/app/share/140946/34844cea-db8d-4d87-b66f-e944e9759a2e")
*/

// a valid public share
let somePublicShare =
URL(string: "https://kdrive.infomaniak.com/app/share/140946/01953831-16d3-4df6-8b48-33c8001c7981")
await UniversalLinksHelper.handleURL(somePublicShare!)
}

return true
Expand Down
18 changes: 17 additions & 1 deletion kDrive/AppRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,28 @@ public struct AppRouter: AppNavigable {
return
}

let configuration = FileListViewModel.Configuration(selectAllSupported: true,
rootTitle: nil,
emptyViewType: .emptyFolder,
supportsDrop: false,
leftBarButtons: [.cancel],
rightBarButtons: [.downloadAll],
matomoViewPath: [
MatomoUtils.Views.menu.displayName,
"publicShare"
])

let viewModel = PublicShareViewModel(publicShareProxy: publicShareProxy,
sortType: .nameAZ,
driveFileManager: driveFileManager,
currentDirectory: frozenRootFolder,
apiFetcher: apiFetcher)
apiFetcher: apiFetcher,
configuration: configuration)
let viewController = FileListViewController(viewModel: viewModel)
viewModel.dismissClosure = { [weak viewController] in
viewController?.dismiss(animated: true)
}

let publicShareNavigationController = UINavigationController(rootViewController: viewController)
publicShareNavigationController.modalPresentationStyle = .fullScreen
publicShareNavigationController.modalTransitionStyle = .coverVertical
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
}

func setupFooterIfNeeded() {
guard driveFileManager.isPublicShare else {
return
}
guard driveFileManager.isPublicShare else { return }

view.addSubview(addToKDriveButton)
view.bringSubviewToFront(addToKDriveButton)
Expand Down Expand Up @@ -447,7 +445,7 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
floatingPanelViewController.set(contentViewController: trashFloatingPanelTableViewController)
(floatingPanelViewController as? AdaptiveDriveFloatingPanelController)?
.trackAndObserve(scrollView: trashFloatingPanelTableViewController.tableView)
case .multipleSelection:
case .multipleSelection(let downloadOnly):
let allItemsSelected: Bool
let exceptFileIds: [Int]?
let selectedFiles: [File]
Expand All @@ -473,6 +471,10 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
presentingParent: self
)

if downloadOnly {
selectViewController.actions = [.download]
}

floatingPanelViewController = AdaptiveDriveFloatingPanelController()
floatingPanelViewController.set(contentViewController: selectViewController)
(floatingPanelViewController as? AdaptiveDriveFloatingPanelController)?
Expand Down Expand Up @@ -618,6 +620,7 @@ 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 @@ -627,6 +630,7 @@ 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
3 changes: 2 additions & 1 deletion kDrive/UI/Controller/Files/File List/FileListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ enum FileListBarButtonType {
enum FileListQuickActionType {
case file
case trash
case multipleSelection
case multipleSelection(onlyDownload: Bool)
}

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

var dismissClosure: (() -> Void)?
adrien-coye marked this conversation as resolved.
Show resolved Hide resolved
var realmObservationToken: NotificationToken?
var currentDirectoryObservationToken: NotificationToken?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,48 @@ import kDriveCore
import kDriveResources

struct MultipleSelectionAction: Equatable {
let id: Int
private let id: MultipleSelectionActionId
let name: String
let icon: KDriveResourcesImages
var enabled = true

private enum MultipleSelectionActionId: Equatable {
case move
case delete
case more
case deletePermanently
case download
}

static func == (lhs: MultipleSelectionAction, rhs: MultipleSelectionAction) -> Bool {
return lhs.id == rhs.id
}

static let move = MultipleSelectionAction(
id: 0,
id: MultipleSelectionActionId.move,
adrien-coye marked this conversation as resolved.
Show resolved Hide resolved
name: KDriveResourcesStrings.Localizable.buttonMove,
icon: KDriveResourcesAsset.folderSelect
)
static let delete = MultipleSelectionAction(
id: 1,
id: MultipleSelectionActionId.delete,
name: KDriveResourcesStrings.Localizable.buttonDelete,
icon: KDriveResourcesAsset.delete
)
static let more = MultipleSelectionAction(
id: 2,
id: MultipleSelectionActionId.more,
name: KDriveResourcesStrings.Localizable.buttonMenu,
icon: KDriveResourcesAsset.menu
)
static let deletePermanently = MultipleSelectionAction(
id: 3,
id: MultipleSelectionActionId.deletePermanently,
name: KDriveResourcesStrings.Localizable.buttonDelete,
icon: KDriveResourcesAsset.delete
)
static let download = MultipleSelectionAction(
id: MultipleSelectionActionId.download,
name: KDriveResourcesStrings.Localizable.buttonDownload,
icon: KDriveResourcesAsset.menu
)
}

@MainActor
Expand All @@ -67,6 +80,8 @@ class MultipleSelectionFileListViewModel {
leftBarButtons = [.cancel]
if configuration.selectAllSupported {
rightBarButtons = [.selectAll]
} else {
rightBarButtons = []
}
} else {
leftBarButtons = nil
Expand Down Expand Up @@ -108,14 +123,13 @@ class MultipleSelectionFileListViewModel {
isMultipleSelectionEnabled = false
selectedCount = 0

self.driveFileManager = driveFileManager

if driveFileManager.isPublicShare {
multipleSelectionActions = []
multipleSelectionActions = [.more]
} else {
multipleSelectionActions = [.move, .delete, .more]
}

self.driveFileManager = driveFileManager
self.currentDirectory = currentDirectory
self.configuration = configuration
}
Expand Down Expand Up @@ -168,7 +182,9 @@ class MultipleSelectionFileListViewModel {
}
onPresentViewController?(.modal, alert, true)
case .more:
onPresentQuickActionPanel?(Array(selectedItems), .multipleSelection)
onPresentQuickActionPanel?(Array(selectedItems), .multipleSelection(onlyDownload: false))
case .download:
onPresentQuickActionPanel?(Array(selectedItems), .multipleSelection(onlyDownload: true))
default:
break
}
Expand Down Expand Up @@ -208,7 +224,16 @@ class MultipleSelectionFileListViewModel {
onSelectAll?()
Task { [proxyCurrentDirectory = currentDirectory.proxify()] in
do {
let directoryCount = try await driveFileManager.apiFetcher.count(of: proxyCurrentDirectory)
let directoryCount: FileCount
if let publicShareProxy = driveFileManager.publicShareProxy {
directoryCount = try await PublicShareApiFetcher()
.countPublicShare(drive: publicShareProxy.proxyDrive,
linkUuid: publicShareProxy.shareLinkUid,
fileId: publicShareProxy.fileId)
} else {
directoryCount = try await driveFileManager.apiFetcher.count(of: proxyCurrentDirectory)
}

selectedCount = directoryCount.count
rightBarButtons = [.deselectAll]
} catch {
Expand Down
13 changes: 12 additions & 1 deletion kDrive/UI/Controller/Files/FilePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,22 @@ final class FilePresenter {
if driveFileManager.drive.sharedWithMe {
viewModel = SharedWithMeViewModel(driveFileManager: driveFileManager, currentDirectory: file)
} else if let publicShareProxy = driveFileManager.publicShareProxy {
let configuration = FileListViewModel.Configuration(selectAllSupported: true,
rootTitle: nil,
emptyViewType: .emptyFolder,
supportsDrop: false,
rightBarButtons: [.downloadAll],
matomoViewPath: [
MatomoUtils.Views.menu.displayName,
"publicShare"
])

viewModel = PublicShareViewModel(publicShareProxy: publicShareProxy,
sortType: .nameAZ,
driveFileManager: driveFileManager,
currentDirectory: file,
apiFetcher: PublicShareApiFetcher())
apiFetcher: PublicShareApiFetcher(),
configuration: configuration)
} else if file.isTrashed || file.deletedAt != nil {
viewModel = TrashListViewModel(driveFileManager: driveFileManager, currentDirectory: file)
} else {
Expand Down
4 changes: 4 additions & 0 deletions kDrive/UI/Controller/Files/FloatingPanelAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ public class FloatingPanelAction: Equatable {
return [download].map { $0.reset() }
}

static var multipleSelectionPublicShareActions: [FloatingPanelAction] {
return [download].map { $0.reset() }
}

static var quickActions: [FloatingPanelAction] {
return [informations, sendCopy, shareAndRights, shareLink].map { $0.reset() }
}
Expand Down
Loading
Loading