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

Open
wants to merge 21 commits into
base: feature-externalLinks
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 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
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
17 changes: 16 additions & 1 deletion kDrive/AppRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,27 @@ public struct AppRouter: AppNavigable {
return
}

// TODO: i18n
let configuration = FileListViewModel.Configuration(selectAllSupported: true,
rootTitle: "public share",
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.viewControllerDismissable = viewController

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 @@ -49,7 +49,7 @@ extension SortType: Selectable {
}

class FileListViewController: UICollectionViewController, SwipeActionCollectionViewDelegate,
SwipeActionCollectionViewDataSource, FilesHeaderViewDelegate, SceneStateRestorable {
SwipeActionCollectionViewDataSource, FilesHeaderViewDelegate, SceneStateRestorable, ViewControllerDismissable {
@LazyInjectService var accountManager: AccountManageable

// MARK: - Constants
Expand Down 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 @@ -614,6 +612,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 @@ -623,6 +622,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: 3 additions & 0 deletions kDrive/UI/Controller/Files/File List/FileListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class FileListViewModel: SelectDelegate {
var matomoViewPath = ["FileList"]
}

/// Tracking a way to dismiss the current stack
weak var viewControllerDismissable: ViewControllerDismissable?

var realmObservationToken: NotificationToken?
var currentDirectoryObservationToken: NotificationToken?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class MultipleSelectionFileListViewModel {
leftBarButtons = [.cancel]
if configuration.selectAllSupported {
rightBarButtons = [.selectAll]
} else {
rightBarButtons = []
}
} else {
leftBarButtons = nil
Expand Down
14 changes: 13 additions & 1 deletion kDrive/UI/Controller/Files/FilePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,23 @@ final class FilePresenter {
if driveFileManager.drive.sharedWithMe {
viewModel = SharedWithMeViewModel(driveFileManager: driveFileManager, currentDirectory: file)
} else if let publicShareProxy = driveFileManager.publicShareProxy {
// TODO: i18n
let configuration = FileListViewModel.Configuration(selectAllSupported: true,
rootTitle: "public share",
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ protocol SelectDelegate: AnyObject {
func didSelect(option: Selectable)
}

/// Something that can dismiss the current VC if presented
@MainActor
public protocol ViewControllerDismissable: AnyObject {
func dismiss(animated flag: Bool, completion: (() -> Void)?)
}

class FloatingPanelSelectOptionViewController<T: Selectable & Equatable>: UITableViewController {
var headerTitle = ""
var selectedOption: T?
Expand Down
40 changes: 23 additions & 17 deletions kDrive/UI/Controller/Menu/Share/PublicShareViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,7 @@ final class PublicShareViewModel: InMemoryFileListViewModel {
let rootProxy: ProxyFile
var publicShareApiFetcher: PublicShareApiFetcher?

required init(driveFileManager: DriveFileManager, currentDirectory: File? = nil) {
guard let currentDirectory else {
fatalError("PublicShareViewModel requires a currentDirectory to work")
}

let configuration = Configuration(selectAllSupported: false,
rootTitle: KDriveCoreStrings.Localizable.sharedWithMeTitle,
emptyViewType: .emptyFolder,
supportsDrop: false,
rightBarButtons: [.downloadAll],
matomoViewPath: [MatomoUtils.Views.menu.displayName, "publicShare"])

override init(configuration: Configuration, driveFileManager: DriveFileManager, currentDirectory: File) {
rootProxy = currentDirectory.proxify()
super.init(configuration: configuration, driveFileManager: driveFileManager, currentDirectory: currentDirectory)
observedFiles = AnyRealmCollection(currentDirectory.children)
Expand All @@ -52,14 +41,20 @@ final class PublicShareViewModel: InMemoryFileListViewModel {
sortType: SortType,
driveFileManager: DriveFileManager,
currentDirectory: File,
apiFetcher: PublicShareApiFetcher
apiFetcher: PublicShareApiFetcher,
configuration: Configuration
) {
self.init(driveFileManager: driveFileManager, currentDirectory: currentDirectory)
self.init(configuration: configuration, driveFileManager: driveFileManager, currentDirectory: currentDirectory)

self.publicShareProxy = publicShareProxy
self.sortType = sortType
publicShareApiFetcher = apiFetcher
}

required init(driveFileManager: DriveFileManager, currentDirectory: File?) {
fatalError("Use init(publicShareProxy:… ) instead")
}

override func loadFiles(cursor: String? = nil, forceRefresh: Bool = false) async throws {
guard !isLoading || cursor != nil,
let publicShareProxy,
Expand All @@ -84,14 +79,25 @@ final class PublicShareViewModel: InMemoryFileListViewModel {
}
}

// TODO: Move away from view model
override func barButtonPressed(sender: Any?, type: FileListBarButtonType) {
guard type == .downloadAll else {
// We try to close the "Public Share screen"
if type == .cancel,
!(multipleSelectionViewModel?.isMultipleSelectionEnabled ?? true),
let viewControllerDismissable = viewControllerDismissable {
viewControllerDismissable.dismiss(animated: true, completion: nil)
return
}

super.barButtonPressed(sender: sender, type: type)
return
}

guard downloadObserver == nil else {
return
}

guard type == .downloadAll,
let publicShareProxy = publicShareProxy else {
guard let publicShareProxy = publicShareProxy else {
return
}

Expand Down
Loading