Skip to content

Commit

Permalink
refactor(MultipleSelectionFloatingPanelViewController): Strong init
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Weidmann <[email protected]>
  • Loading branch information
PhilippeWeidmann committed Sep 17, 2024
1 parent de25882 commit 6b2b88f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 20 deletions.
35 changes: 22 additions & 13 deletions kDrive/UI/Controller/Files/File List/FileListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,23 +380,32 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
(floatingPanelViewController as? AdaptiveDriveFloatingPanelController)?
.trackAndObserve(scrollView: trashFloatingPanelTableViewController.tableView)
case .multipleSelection:
floatingPanelViewController = AdaptiveDriveFloatingPanelController()
let selectViewController = MultipleSelectionFloatingPanelViewController()
selectViewController.presentingParent = self
selectViewController.currentDirectory = viewModel.currentDirectory

let allItemsSelected: Bool
let exceptFileIds: [Int]?
let selectedFiles: [File]
if viewModel.multipleSelectionViewModel?.isSelectAllModeEnabled == true {
selectViewController.allItemsSelected = true
selectViewController.exceptFileIds = Array(viewModel.multipleSelectionViewModel?.exceptItemIds ?? Set<Int>())
allItemsSelected = true
selectedFiles = []
exceptFileIds = Array(viewModel.multipleSelectionViewModel?.exceptItemIds ?? Set<Int>())
} else {
selectViewController.allItemsSelected = false
selectViewController.files = files
}
selectViewController.driveFileManager = driveFileManager
selectViewController.reloadAction = { [weak self] in
self?.viewModel.multipleSelectionViewModel?.isMultipleSelectionEnabled = false
allItemsSelected = false
selectedFiles = files
exceptFileIds = nil
}

let selectViewController = MultipleSelectionFloatingPanelViewController(
driveFileManager: driveFileManager,
currentDirectory: viewModel.currentDirectory,
files: selectedFiles,
allItemsSelected: allItemsSelected,
exceptFileIds: exceptFileIds,
reloadAction: { [weak self] in
self?.viewModel.multipleSelectionViewModel?.isMultipleSelectionEnabled = false
},
presentingParent: self
)

floatingPanelViewController = AdaptiveDriveFloatingPanelController()
floatingPanelViewController.set(contentViewController: selectViewController)
(floatingPanelViewController as? AdaptiveDriveFloatingPanelController)?
.trackAndObserve(scrollView: selectViewController.collectionView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ final class MultipleSelectionFloatingPanelViewController: UICollectionViewContro
@LazyInjectService var accountManager: AccountManageable
@LazyInjectService var appNavigable: AppNavigable

var driveFileManager: DriveFileManager!
var files = [File]()
var allItemsSelected = false
var driveFileManager: DriveFileManager
var files: [File]
var allItemsSelected: Bool
var exceptFileIds: [Int]?
var currentDirectory: File!
var currentDirectory: File
var changedFiles: [File]? = []
var downloadInProgress = false
var reloadAction: (() -> Void)?
Expand All @@ -50,8 +50,28 @@ final class MultipleSelectionFloatingPanelViewController: UICollectionViewContro

var actions = FloatingPanelAction.listActions

convenience init() {
self.init(collectionViewLayout: MultipleSelectionFloatingPanelViewController.createLayout())
init(
driveFileManager: DriveFileManager,
currentDirectory: File,
files: [File],
allItemsSelected: Bool,
exceptFileIds: [Int]?,
reloadAction: (() -> Void)?,
presentingParent: UIViewController?
) {
self.driveFileManager = driveFileManager
self.currentDirectory = currentDirectory
self.files = files
self.allItemsSelected = allItemsSelected
self.exceptFileIds = exceptFileIds
self.reloadAction = reloadAction
self.presentingParent = presentingParent
super.init(collectionViewLayout: MultipleSelectionFloatingPanelViewController.createLayout())
}

@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
Expand All @@ -75,7 +95,7 @@ final class MultipleSelectionFloatingPanelViewController: UICollectionViewContro
} else if presentingParent is PhotoListViewController {
actions = FloatingPanelAction.multipleSelectionPhotosListActions
} else {
if files.contains { !$0.isDirectory } {
if files.contains(where: { !$0.isDirectory }) {
actions = FloatingPanelAction.multipleSelectionActions
} else {
actions = FloatingPanelAction.multipleSelectionActionsOnlyFolders
Expand Down

0 comments on commit 6b2b88f

Please sign in to comment.