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

fix(HomeLastPicCollectionViewCell): Refresh during multi selection deselects all #1371

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -635,13 +635,20 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV

let cell = collectionView.dequeueReusableCell(type: cellType, for: indexPath) as! FileCollectionViewCell
let file = displayedFiles[indexPath.row]
let multipleSelectionEnabled = viewModel.multipleSelectionViewModel?.isMultipleSelectionEnabled ?? false

cell.initStyle(isFirst: file.isFirstInList, isLast: file.isLastInList)
cell.configureWith(
driveFileManager: viewModel.driveFileManager,
file: file,
selectionMode: viewModel.multipleSelectionViewModel?.isMultipleSelectionEnabled == true
selectionMode: multipleSelectionEnabled
)

if multipleSelectionEnabled,
let multipleSelectionViewModel = viewModel.multipleSelectionViewModel {
cell.isSelected = multipleSelectionViewModel.selectedItems.contains(file)
}

cell.delegate = self
if ReachabilityListener.instance.currentStatus == .offline && !file.isDirectory && !file.isAvailableOffline {
cell.setEnabled(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,23 @@ final class PhotoListViewController: FileListViewController {
return cell
}

let multipleSelectionEnabled: Bool
let isSelected: Bool
if let multipleSelectionViewModel = viewModel.multipleSelectionViewModel {
multipleSelectionEnabled = multipleSelectionViewModel.isMultipleSelectionEnabled
isSelected = multipleSelectionViewModel.selectedItems.contains { $0.uid == file.uid }
} else {
multipleSelectionEnabled = false
isSelected = false
}

cell.configureWith(
file: file,
roundedCorners: false,
selectionMode: viewModel.multipleSelectionViewModel?.isMultipleSelectionEnabled == true
selectionMode: multipleSelectionEnabled,
isSelected: isSelected
)

return cell
}

Expand Down
10 changes: 8 additions & 2 deletions kDrive/UI/View/Home/HomeLastPicCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class HomeLastPicCollectionViewCell: UICollectionViewCell {
private var thumbnailDownloadTask: Kingfisher.DownloadTask?

override var isSelected: Bool {
willSet {
// NOTE: DifferenceKit reset the selected flag mid air. Investigating
print("•• isSelected changed: \(newValue) fid:\(file?.id)")
Copy link
Contributor Author

@adrien-coye adrien-coye Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diffKit will set to false after the configuration of the cell, disabling it.
I'm still looking for an elegant fix.

}
didSet {
configureForSelection()
}
Expand Down Expand Up @@ -77,9 +81,10 @@ class HomeLastPicCollectionViewCell: UICollectionViewCell {
contentInsetView.cornerRadius = UIConstants.cornerRadius
}

func configureWith(file: File, roundedCorners: Bool = true, selectionMode: Bool = false) {
func configureWith(file: File, roundedCorners: Bool = true, selectionMode: Bool = false, isSelected: Bool = false) {
self.selectionMode = selectionMode
self.file = file

checkmarkImage.isHidden = !selectionMode
darkLayer.isHidden = false
thumbnailDownloadTask = file.getThumbnail { [weak self, fileId = file.id] image, isThumbnail in
Expand All @@ -94,7 +99,8 @@ class HomeLastPicCollectionViewCell: UICollectionViewCell {
contentInsetView.cornerRadius = UIConstants.cornerRadius
}
videoData.isHidden = !(file.uti.conforms(to: .video) || file.uti.conforms(to: .movie))
configureForSelection()

self.isSelected = isSelected
Copy link
Contributor Author

@adrien-coye adrien-coye Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting it will call configureForSelection on didSet

}

private func configureForSelection() {
Expand Down
Loading