-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
250 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
Cryptomator/AddVault/CreateNewVault/SharePointDriveListViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// SharePointDriveListViewController.swift | ||
// Cryptomator | ||
// | ||
// Created by Majid Achhoud | ||
// Copyright © 2024 Skymatic GmbH. All rights reserved. | ||
// | ||
|
||
import CryptomatorCloudAccessCore | ||
import CryptomatorCommonCore | ||
import Foundation | ||
import UIKit | ||
|
||
class SharePointDriveListViewController: BaseUITableViewController { | ||
private var viewModel: SharePointDriveListViewModel | ||
|
||
init(viewModel: SharePointDriveListViewModel) { | ||
self.viewModel = viewModel | ||
super.init() | ||
} | ||
|
||
@available(*, unavailable) | ||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
tableView.register(CloudCell.self, forCellReuseIdentifier: "SharePointDriveCell") | ||
viewModel.reloadData = { [weak self] in | ||
self?.tableView.reloadData() | ||
} | ||
|
||
self.title = LocalizedString.getValue("addVault.selectDrive.navigation.title") | ||
} | ||
|
||
// MARK: - UITableViewDataSource | ||
|
||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return viewModel.drives.count | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
guard let cell = tableView.dequeueReusableCell(withIdentifier: "SharePointDriveCell", for: indexPath) as? CloudCell else { | ||
fatalError("Could not dequeue CloudCell") | ||
} | ||
|
||
let drive = viewModel.drives[indexPath.row] | ||
configure(cell, with: drive) | ||
|
||
return cell | ||
} | ||
|
||
// MARK: - Styling Configuration | ||
|
||
private func configure(_ cell: CloudCell, with drive: MicrosoftGraphDrive) { | ||
cell.textLabel?.text = drive.name | ||
cell.imageView?.image = UIImage(systemName: "folder") | ||
} | ||
|
||
// MARK: - UITableViewDelegate | ||
|
||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
let selectedDrive = viewModel.drives[indexPath.row] | ||
viewModel.selectDrive(selectedDrive) | ||
tableView.deselectRow(at: indexPath, animated: true) | ||
} | ||
} | ||
|
75 changes: 75 additions & 0 deletions
75
Cryptomator/AddVault/CreateNewVault/SharePointDriveListViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// SharePointDriveListViewModel.swift | ||
// Cryptomator | ||
// | ||
// Created by Majid Achhoud | ||
// Copyright © 2024 Skymatic GmbH. All rights reserved. | ||
// | ||
|
||
import CryptomatorCloudAccessCore | ||
import CryptomatorCommonCore | ||
import Foundation | ||
|
||
class SharePointDriveListViewModel: SingleSectionTableViewModel { | ||
private let discovery: MicrosoftGraphDiscovery | ||
private let sharePointURL: String | ||
private let account: AccountInfo | ||
|
||
var drives: [MicrosoftGraphDrive] = [] { | ||
didSet { | ||
reloadData?() | ||
} | ||
} | ||
|
||
var reloadData: (() -> Void)? | ||
var didSelectDrive: ((MicrosoftGraphDrive) -> Void)? | ||
|
||
init(discovery: MicrosoftGraphDiscovery, sharePointURL: String, account: AccountInfo) { | ||
self.discovery = discovery | ||
self.sharePointURL = sharePointURL | ||
self.account = account | ||
super.init() | ||
fetchSiteAndDrives() | ||
} | ||
|
||
func selectDrive(_ drive: MicrosoftGraphDrive) { | ||
didSelectDrive?(drive) | ||
} | ||
|
||
private func fetchSiteAndDrives() { | ||
guard let urlComponents = URL(string: sharePointURL), | ||
let hostName = urlComponents.host else { | ||
print("Invalid SharePoint URL") | ||
return | ||
} | ||
|
||
var serverRelativePath = urlComponents.path.trimmingCharacters(in: CharacterSet(charactersIn: "/")) | ||
if serverRelativePath.hasPrefix("sites/") { | ||
serverRelativePath = String(serverRelativePath.dropFirst("sites/".count)) | ||
} | ||
|
||
discovery.fetchSharePointSite(for: hostName, serverRelativePath: serverRelativePath) | ||
.then { site in | ||
self.fetchDrives(for: site.identifier) | ||
}.catch { error in | ||
print("Failed to fetch SharePoint site: \(error)") | ||
} | ||
} | ||
|
||
private func fetchDrives(for siteIdentifier: String) { | ||
discovery.fetchSharePointDocumentLibraries(for: siteIdentifier).then { drives in | ||
self.drives = drives | ||
}.catch { error in | ||
print("Failed to fetch drives: \(error)") | ||
} | ||
} | ||
|
||
override func getHeaderTitle(for section: Int) -> String? { | ||
guard section == 0 else { return nil } | ||
return LocalizedString.getValue("addVault.selectDrive.navigation.title") | ||
} | ||
|
||
override var title: String? { | ||
return LocalizedString.getValue("addVault.selectDrive.header.description") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters