Skip to content

Commit

Permalink
feat: Add to my drive button
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Sep 23, 2024
1 parent 14c2ca0 commit 7224695
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 16 deletions.
12 changes: 0 additions & 12 deletions kDrive/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
}
application.registerForRemoteNotifications()

// swiftlint:disable force_try
Task {
try! await Task.sleep(nanoseconds:5_000_000_000)
print("coucou")
let somePublicShare = URL(string: "")
//await UIApplication.shared.open(somePublicShare!) // opens safari

let components = URLComponents(url: somePublicShare!, resolvingAgainstBaseURL: true)
await UniversalLinksHelper.handlePath(components!.path)
}


return true
}

Expand Down
7 changes: 4 additions & 3 deletions kDrive/AppRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ public struct AppRouter: AppNavigable {
driveFileManager: DriveFileManager,
apiFetcher: PublicShareApiFetcher
) {
// TODO: Present on top of existing views
guard let window,
let rootViewController = window.rootViewController else {
fatalError("TODO: lazy load a rootViewController")
Expand Down Expand Up @@ -621,9 +620,11 @@ public struct AppRouter: AppNavigable {
currentDirectory: frozenRootFolder,
apiFetcher: apiFetcher)
let viewController = FileListViewController(viewModel: viewModel)
print("viewController:\(viewController) viewModel:\(viewModel) navigationController:\(navigationController)")
let publicShareNavigationController = UINavigationController(rootViewController: viewController)
publicShareNavigationController.modalPresentationStyle = .fullScreen
publicShareNavigationController.modalTransitionStyle = .coverVertical

navigationController.pushViewController(viewController, animated: true)
navigationController.present(publicShareNavigationController, animated: true, completion: nil)
}
}

Expand Down
1 change: 1 addition & 0 deletions kDrive/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +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)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import CocoaLumberjackSwift
import Combine
import DifferenceKit
import FloatingPanel
import InfomaniakCore
import InfomaniakDI
import kDriveCore
import kDriveResources
import RealmSwift
import UIKit
import FloatingPanel

extension SwipeCellAction {
static let share = SwipeCellAction(
Expand Down Expand Up @@ -142,6 +142,7 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
)

setupViewModel()
setupFooterIfNeeded()
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -251,6 +252,46 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV
}
}

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

let addToKDriveButton = IKButton(type: .custom)
addToKDriveButton.setTitle("Add to My Drive", for: .normal)
addToKDriveButton.addTarget(self, action: #selector(addToMyDriveButtonTapped), for: .touchUpInside)
addToKDriveButton.setBackgroundColors(normal: .systemBlue, highlighted: .darkGray)
addToKDriveButton.translatesAutoresizingMaskIntoConstraints = false
addToKDriveButton.cornerRadius = 8.0
addToKDriveButton.clipsToBounds = true

view.addSubview(addToKDriveButton)
view.bringSubviewToFront(addToKDriveButton)

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

NSLayoutConstraint.activate([
addToKDriveButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
leadingConstraint,
trailingConstraint,
addToKDriveButton.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -16),
addToKDriveButton.heightAnchor.constraint(equalToConstant: 60),
widthConstraint
])
}

@objc func addToMyDriveButtonTapped() {
print("button tapped")
}

func reloadCollectionViewWith(files: [File]) {
let changeSet = StagedChangeset(source: displayedFiles, target: files)
collectionView.reload(using: changeSet,
Expand Down Expand Up @@ -915,3 +956,38 @@ 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)
}
}
}

0 comments on commit 7224695

Please sign in to comment.