Skip to content

Commit

Permalink
Merge pull request #1308 from Infomaniak/externalLinks-downloadFiles
Browse files Browse the repository at this point in the history
feat: External links download files
  • Loading branch information
adrien-coye authored Oct 23, 2024
2 parents 95e4825 + 6c99ba0 commit 3624e82
Show file tree
Hide file tree
Showing 28 changed files with 531 additions and 106 deletions.
1 change: 1 addition & 0 deletions Tuist/ProjectDescriptionHelpers/ExtensionTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public extension Target {
"kDrive/UI/Controller/DriveUpdateRequiredViewController.swift",
"kDrive/UI/Controller/FloatingPanelSelectOptionViewController.swift",
"kDrive/UI/Controller/Create File/FloatingPanelUtils.swift",
"kDrive/UI/Controller/Create File/FloatingPanelLayouts.swift",
"kDrive/UI/Controller/Files/Categories/**",
"kDrive/UI/Controller/Files/Rights and Share/**",
"kDrive/UI/Controller/Files/Save File/**",
Expand Down
5 changes: 2 additions & 3 deletions kDrive/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,13 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
Task {
try! await Task.sleep(nanoseconds:5_000_000_000)

Check warning on line 108 in kDrive/AppDelegate.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Add or remove space around operators or delimiters. (spaceAroundOperators)

Check failure on line 108 in kDrive/AppDelegate.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Colons should be next to the identifier when specifying a type and next to the key in dictionary literals (colon)
print("coucou")
let somePublicShare = URL(string: "")
let somePublicShare = URL(string: "https://kdrive.infomaniak.com/app/share/140946/01953831-16d3-4df6-8b48-33c8001c7981")

Check warning on line 110 in kDrive/AppDelegate.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Wrap lines that exceed the specified maximum width. (wrap)
//await UIApplication.shared.open(somePublicShare!) // opens safari

Check warning on line 111 in kDrive/AppDelegate.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Add leading and/or trailing space inside comments. (spaceInsideComments)

Check failure on line 111 in kDrive/AppDelegate.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Prefer at least one space after slashes for comments (comment_spacing)

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


return true
}

Expand Down
7 changes: 5 additions & 2 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,7 +620,11 @@ public struct AppRouter: AppNavigable {
currentDirectory: frozenRootFolder,
apiFetcher: apiFetcher)
let viewController = FileListViewController(viewModel: viewModel)
navigationController.pushViewController(viewController, animated: true)
let publicShareNavigationController = UINavigationController(rootViewController: viewController)
publicShareNavigationController.modalPresentationStyle = .fullScreen
publicShareNavigationController.modalTransitionStyle = .coverVertical

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 - invalid activity", level: .error)
return
}

Expand Down
141 changes: 141 additions & 0 deletions kDrive/UI/Controller/Create File/FloatingPanelLayouts.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
Infomaniak kDrive - iOS App
Copyright (C) 2024 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import FloatingPanel
import kDriveCore
import kDriveResources
import UIKit

/// Layout used for a folder within a public share
class PublicShareFolderFloatingPanelLayout: FloatingPanelLayout {
var position: FloatingPanelPosition = .bottom
var initialState: FloatingPanelState = .tip
var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring]
private var backdropAlpha: CGFloat

init(initialState: FloatingPanelState = .tip, hideTip: Bool = false, safeAreaInset: CGFloat = 0, backdropAlpha: CGFloat = 0) {
self.initialState = initialState
self.backdropAlpha = backdropAlpha
let extendedAnchor = FloatingPanelLayoutAnchor(
absoluteInset: 140.0 + safeAreaInset,
edge: .bottom,
referenceGuide: .superview
)
anchors = [
.full: extendedAnchor,
.half: extendedAnchor,
.tip: FloatingPanelLayoutAnchor(absoluteInset: 86.0 + safeAreaInset, edge: .bottom, referenceGuide: .superview)
]
}

func backdropAlpha(for state: FloatingPanelState) -> CGFloat {
return backdropAlpha
}
}

/// Layout used for a file within a public share
class PublicShareFileFloatingPanelLayout: FloatingPanelLayout {
var position: FloatingPanelPosition = .bottom
var initialState: FloatingPanelState = .tip
var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring]
private var backdropAlpha: CGFloat

init(initialState: FloatingPanelState = .tip, hideTip: Bool = false, safeAreaInset: CGFloat = 0, backdropAlpha: CGFloat = 0) {
self.initialState = initialState
self.backdropAlpha = backdropAlpha
let extendedAnchor = FloatingPanelLayoutAnchor(
absoluteInset: 248.0 + safeAreaInset,
edge: .bottom,
referenceGuide: .superview
)
anchors = [
.full: extendedAnchor,
.half: extendedAnchor,
.tip: FloatingPanelLayoutAnchor(absoluteInset: 86.0 + safeAreaInset, edge: .bottom, referenceGuide: .superview)
]
}

func backdropAlpha(for state: FloatingPanelState) -> CGFloat {
return backdropAlpha
}
}

class FileFloatingPanelLayout: FloatingPanelLayout {
var position: FloatingPanelPosition = .bottom
var initialState: FloatingPanelState = .tip
var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring]
private var backdropAlpha: CGFloat

init(initialState: FloatingPanelState = .tip, hideTip: Bool = false, safeAreaInset: CGFloat = 0, backdropAlpha: CGFloat = 0) {
self.initialState = initialState
self.backdropAlpha = backdropAlpha
if hideTip {
anchors = [
.full: FloatingPanelLayoutAnchor(absoluteInset: 16.0, edge: .top, referenceGuide: .safeArea),
.half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea)
]
} else {
anchors = [
.full: FloatingPanelLayoutAnchor(absoluteInset: 16.0, edge: .top, referenceGuide: .safeArea),
.half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea),
.tip: FloatingPanelLayoutAnchor(absoluteInset: 86.0 + safeAreaInset, edge: .bottom, referenceGuide: .superview)
]
}
}

func backdropAlpha(for state: FloatingPanelState) -> CGFloat {
return backdropAlpha
}
}

class PlusButtonFloatingPanelLayout: FloatingPanelLayout {
var position: FloatingPanelPosition = .bottom
var height: CGFloat = 16

init(height: CGFloat) {
self.height = height
}

var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] {
return [
.full: FloatingPanelLayoutAnchor(absoluteInset: height, edge: .bottom, referenceGuide: .safeArea)
]
}

var initialState: FloatingPanelState = .full

func backdropAlpha(for state: FloatingPanelState) -> CGFloat {
return 0.2
}
}

class InformationViewFloatingPanelLayout: FloatingPanelLayout {
var position: FloatingPanelPosition = .bottom

var initialState: FloatingPanelState = .full

var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] {
return [
.full: FloatingPanelIntrinsicLayoutAnchor(absoluteOffset: 0, referenceGuide: .safeArea)
]
}

func backdropAlpha(for state: FloatingPanelState) -> CGFloat {
return 0.3
}
}
65 changes: 0 additions & 65 deletions kDrive/UI/Controller/Create File/FloatingPanelUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,68 +73,3 @@ class AdaptiveDriveFloatingPanelController: DriveFloatingPanelController {
track(scrollView: scrollView)
}
}

class FileFloatingPanelLayout: FloatingPanelLayout {
var position: FloatingPanelPosition = .bottom
var initialState: FloatingPanelState = .tip
var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring]
private var backdropAlpha: CGFloat

init(initialState: FloatingPanelState = .tip, hideTip: Bool = false, safeAreaInset: CGFloat = 0, backdropAlpha: CGFloat = 0) {
self.initialState = initialState
self.backdropAlpha = backdropAlpha
if hideTip {
anchors = [
.full: FloatingPanelLayoutAnchor(absoluteInset: 16.0, edge: .top, referenceGuide: .safeArea),
.half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea)
]
} else {
anchors = [
.full: FloatingPanelLayoutAnchor(absoluteInset: 16.0, edge: .top, referenceGuide: .safeArea),
.half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea),
.tip: FloatingPanelLayoutAnchor(absoluteInset: 86.0 + safeAreaInset, edge: .bottom, referenceGuide: .superview)
]
}
}

func backdropAlpha(for state: FloatingPanelState) -> CGFloat {
return backdropAlpha
}
}

class PlusButtonFloatingPanelLayout: FloatingPanelLayout {
var position: FloatingPanelPosition = .bottom
var height: CGFloat = 16

init(height: CGFloat) {
self.height = height
}

var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] {
return [
.full: FloatingPanelLayoutAnchor(absoluteInset: height, edge: .bottom, referenceGuide: .safeArea)
]
}

var initialState: FloatingPanelState = .full

func backdropAlpha(for state: FloatingPanelState) -> CGFloat {
return 0.2
}
}

class InformationViewFloatingPanelLayout: FloatingPanelLayout {
var position: FloatingPanelPosition = .bottom

var initialState: FloatingPanelState = .full

var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] {
return [
.full: FloatingPanelIntrinsicLayoutAnchor(absoluteOffset: 0, referenceGuide: .safeArea)
]
}

func backdropAlpha(for state: FloatingPanelState) -> CGFloat {
return 0.3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ class ConcreteFileListViewModel: FileListViewModel {
try await loadFiles()
}

override func barButtonPressed(type: FileListBarButtonType) {
override func barButtonPressed(sender: Any?, type: FileListBarButtonType) {
if type == .search {
let viewModel = SearchFilesViewModel(driveFileManager: driveFileManager)
let searchViewController = SearchViewController.instantiateInNavigationController(viewModel: viewModel)
onPresentViewController?(.modal, searchViewController, true)
} else {
super.barButtonPressed(type: type)
super.barButtonPressed(sender: sender, type: type)
}
}
}
Loading

0 comments on commit 3624e82

Please sign in to comment.