Skip to content

Commit

Permalink
chore: PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Oct 23, 2024
2 parents 0b2fd4e + 6c99ba0 commit 0fe23be
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 71 deletions.
2 changes: 1 addition & 1 deletion kDrive/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate, AccountManagerDel
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let incomingURL = userActivity.webpageURL,
let components = URLComponents(url: incomingURL, resolvingAgainstBaseURL: true) else {
Log.sceneDelegate("scene continue userActivity - unable", level: .error)
Log.sceneDelegate("scene continue userActivity - invalid activity", level: .error)
return
}

Expand Down
86 changes: 23 additions & 63 deletions kDrive/UI/Controller/Files/File List/FileListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
private let leftRightInset = 12.0
private let gridInnerSpacing = 16.0
private let headerViewIdentifier = "FilesHeaderView"
private var addToKDriveButton: IKButton?

// MARK: - Properties

Expand Down Expand Up @@ -93,6 +92,14 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
viewModel.driveFileManager
}

lazy var addToKDriveButton: IKLargeButton = {
let button = IKLargeButton(frame: .zero)
button.setTitle(KDriveCoreStrings.Localizable.buttonAddToKDrive, for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, action: #selector(addToMyDriveButtonTapped(_:)), for: .touchUpInside)
return button
}()

// MARK: - View controller lifecycle

deinit {
Expand Down Expand Up @@ -254,39 +261,27 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
}

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

let addToKDrive = IKButton(type: .custom)
addToKDriveButton = addToKDrive
guard driveFileManager.isPublicShare else { return }

addToKDrive.setTitle("Add to My kDrive", for: .normal)
addToKDrive.addTarget(self, action: #selector(addToMyDriveButtonTapped(_:)), for: .touchUpInside)
addToKDrive.setBackgroundColors(normal: .systemBlue, highlighted: .darkGray)
addToKDrive.translatesAutoresizingMaskIntoConstraints = false
addToKDrive.cornerRadius = 8.0
addToKDrive.clipsToBounds = true
view.addSubview(addToKDriveButton)
view.bringSubviewToFront(addToKDriveButton)

view.addSubview(addToKDrive)
view.bringSubviewToFront(addToKDrive)

let leadingConstraint = addToKDrive.leadingAnchor.constraint(greaterThanOrEqualTo: view.leadingAnchor,
constant: 16)
let leadingConstraint = addToKDriveButton.leadingAnchor.constraint(greaterThanOrEqualTo: view.leadingAnchor,
constant: 16)
leadingConstraint.priority = .defaultHigh
let trailingConstraint = addToKDrive.trailingAnchor.constraint(
let trailingConstraint = addToKDriveButton.trailingAnchor.constraint(
greaterThanOrEqualTo: view.trailingAnchor,
constant: -16
)
trailingConstraint.priority = .defaultHigh
let widthConstraint = addToKDrive.widthAnchor.constraint(lessThanOrEqualToConstant: 360)
let widthConstraint = addToKDriveButton.widthAnchor.constraint(lessThanOrEqualToConstant: 360)

NSLayoutConstraint.activate([
addToKDrive.centerXAnchor.constraint(equalTo: view.centerXAnchor),
addToKDriveButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
leadingConstraint,
trailingConstraint,
addToKDrive.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -16),
addToKDrive.heightAnchor.constraint(equalToConstant: 60),
addToKDriveButton.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -16),
addToKDriveButton.heightAnchor.constraint(equalToConstant: 60),
widthConstraint
])
}
Expand Down Expand Up @@ -393,7 +388,7 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
}
}

private func fileLayout(files: [File]) -> FloatingPanelLayout {
private func fileFloatingPanelLayout(files: [File]) -> FloatingPanelLayout {
guard driveFileManager.isPublicShare else {
return FileFloatingPanelLayout(
initialState: .half,
Expand All @@ -402,7 +397,7 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
)
}

if files.first?.isDirectory ?? false {
if files.first?.isDirectory == true {
return PublicShareFolderFloatingPanelLayout(
initialState: .half,
hideTip: true,
Expand All @@ -428,7 +423,7 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
fileInformationsViewController.presentingParent = self
fileInformationsViewController.normalFolderHierarchy = viewModel.configuration.normalFolderHierarchy

floatingPanelViewController.layout = fileLayout(files: files)
floatingPanelViewController.layout = fileFloatingPanelLayout(files: files)

if let file = files.first {
fileInformationsViewController.setFile(file, driveFileManager: driveFileManager)
Expand Down Expand Up @@ -617,7 +612,7 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV

func toggleMultipleSelection(_ on: Bool) {
if on {
addToKDriveButton?.isHidden = true
addToKDriveButton.isHidden = true
navigationItem.title = nil
headerView?.selectView.isHidden = false
headerView?.selectView.setActions(viewModel.multipleSelectionViewModel?.multipleSelectionActions ?? [])
Expand All @@ -627,7 +622,7 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
generator.prepare()
generator.impactOccurred()
} else {
addToKDriveButton?.isHidden = false
addToKDriveButton.isHidden = false
headerView?.selectView.isHidden = true
collectionView.allowsMultipleSelection = false
navigationController?.navigationBar.prefersLargeTitles = true
Expand Down Expand Up @@ -963,38 +958,3 @@ extension FileListViewController: UICollectionViewDropDelegate {
}
}
}

// Move to CoreUIKit or use something else ?
extension UIImage {
convenience init?(color: UIColor) {
let size = CGSize(width: 1, height: 1)
UIGraphicsBeginImageContext(size)
guard let context = UIGraphicsGetCurrentContext() else {
return nil
}

context.setFillColor(color.cgColor)
context.fill(CGRect(origin: .zero, size: size))

let image = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
guard let cgImage = image.cgImage else {
return nil
}

self.init(cgImage: cgImage)
}
}

// Move to CoreUIKit or use something else ?
extension IKButton {
func setBackgroundColors(normal normalColor: UIColor, highlighted highlightedColor: UIColor) {
if let normalImage = UIImage(color: normalColor) {
setBackgroundImage(normalImage, for: .normal)
}

if let highlightedImage = UIImage(color: highlightedColor) {
setBackgroundImage(highlightedImage, for: .highlighted)
}
}
}
4 changes: 1 addition & 3 deletions kDrive/UI/Controller/Files/File List/FileListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,7 @@ class FileListViewModel: SelectDelegate {
}

func didSelectFile(at indexPath: IndexPath) {
guard let file: File = getFile(at: indexPath) else {
return
}
guard let file: File = getFile(at: indexPath) else { return }

if ReachabilityListener.instance.currentStatus == .offline && !file.isDirectory && !file.isAvailableOffline {
return
Expand Down
2 changes: 1 addition & 1 deletion kDrive/UI/View/Files/FileCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ protocol FileCellDelegate: AnyObject {
imageView.layer.masksToBounds = true
imageView.backgroundColor = KDriveResourcesAsset.loaderDefaultColor.color

if let publicShareProxy = publicShareProxy {
if let publicShareProxy {
// Fetch public share thumbnail
thumbnailDownloadTask = file.getPublicShareThumbnail(publicShareId: publicShareProxy.shareLinkUid,
publicDriveId: publicShareProxy.driveId,
Expand Down
1 change: 0 additions & 1 deletion kDriveCore/Data/Api/Endpoint+Share.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public extension Endpoint {
shareUrlV3.appending(path: "/\(driveId)/share/\(linkUuid)/files/\(fileId)")
}

/// Some legacy calls like thumbnails require a V2 call
static func shareLinkFileV2(driveId: Int, linkUuid: String, fileId: Int) -> Endpoint {
shareUrlV2.appending(path: "/\(driveId)/share/\(linkUuid)/files/\(fileId)")
}
Expand Down
4 changes: 2 additions & 2 deletions kDriveCore/Data/Cache/AccountManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ public class AccountManager: RefreshTokenDelegate, AccountManageable {
} catch {
fatalError("unable to update public share drive in base, \(error)")
}
let forzenPublicShareDrive = publicShareDrive.freeze()
let frozenPublicShareDrive = publicShareDrive.freeze()

let apiFetcher = DriveApiFetcher(token: someToken, delegate: SomeRefreshTokenDelegate())
let publicShareProxy = PublicShareProxy(driveId: driveId, fileId: rootFileId, shareLinkUid: publicShareId)
let context = DriveFileManagerContext.publicShare(shareProxy: publicShareProxy)

return DriveFileManager(drive: forzenPublicShareDrive, apiFetcher: apiFetcher, context: context)
return DriveFileManager(drive: frozenPublicShareDrive, apiFetcher: apiFetcher, context: context)
}

public func getFirstAvailableDriveFileManager(for userId: Int) throws -> DriveFileManager {
Expand Down

0 comments on commit 0fe23be

Please sign in to comment.