-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Hub improvements #403
Closed
Closed
Hub improvements #403
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d76c000
WIP - Create new EnterURLScreen for SharePoint, add SharePoint Icons …
iammajid afec091
Fixed build errors
tobihagemann 2e557ea
Fixed runtime errors
tobihagemann 2f3c070
Add SharePoint drive selection.
iammajid 8a197db
WIP: Keychain implementation for sharepoint
iammajid 054a90c
Add SharePointDriveListView to the project file
iammajid abe88d3
Improve Hub error handling and updates
iammajid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
44 changes: 44 additions & 0 deletions
44
Cryptomator/AddVault/CreateNewVault/EnterSharePointURLViewController.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,44 @@ | ||
// | ||
// EnterSharePointURLViewController.swift | ||
// Cryptomator | ||
// | ||
// Created by Majid Achhoud on 03.12.24. | ||
// | ||
|
||
import Combine | ||
import CryptomatorCommonCore | ||
import UIKit | ||
|
||
class EnterSharePointURLViewController: SingleSectionStaticUITableViewController { | ||
weak var coordinator: (SharePointURLSetting & Coordinator)? | ||
private var viewModel: EnterSharePointURLViewModelProtocol | ||
private var lastReturnButtonPressedSubscriber: AnyCancellable? | ||
init(viewModel: EnterSharePointURLViewModelProtocol) { | ||
self.viewModel = viewModel | ||
super.init(viewModel: viewModel) | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
let doneButton = UIBarButtonItem(title: LocalizedString.getValue("common.button.next"), style: .done, target: self, action: #selector(nextButtonClicked)) | ||
navigationItem.rightBarButtonItem = doneButton | ||
lastReturnButtonPressedSubscriber = viewModel.lastReturnButtonPressed.sink { [weak self] in | ||
self?.lastReturnButtonPressedAction() | ||
} | ||
} | ||
|
||
@objc func nextButtonClicked() { | ||
guard let coordinator = coordinator else { return } | ||
do { | ||
let url = try viewModel.getValidatedSharePointURL() | ||
coordinator.setSharePointURL(url) | ||
} catch { | ||
print("Error validating SharePoint URL: \(error)") | ||
coordinator.handleError(error, for: self) | ||
} | ||
} | ||
|
||
func lastReturnButtonPressedAction() { | ||
nextButtonClicked() | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
Cryptomator/AddVault/CreateNewVault/EnterSharePointURLViewModel.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,72 @@ | ||
// | ||
// EnterSharePointURLViewModel.swift | ||
// Cryptomator | ||
// | ||
// Created by Majid Achhoud on 03.12.24. | ||
// Copyright © 2024 Skymatic GmbH. All rights reserved. | ||
// | ||
|
||
import Combine | ||
import CryptomatorCommonCore | ||
import Foundation | ||
|
||
protocol EnterSharePointURLViewModelProtocol: SingleSectionTableViewModel, ReturnButtonSupport { | ||
func getValidatedSharePointURL() throws -> String | ||
} | ||
|
||
class EnterSharePointURLViewModel: SingleSectionTableViewModel, EnterSharePointURLViewModelProtocol { | ||
let account: AccountInfo | ||
init(account: AccountInfo) { | ||
self.account = account | ||
} | ||
|
||
var lastReturnButtonPressed: AnyPublisher<Void, Never> { | ||
return setupReturnButtonSupport(for: [sharePointURLCellViewModel], subscribers: &subscribers) | ||
} | ||
|
||
override var cells: [TableViewCellViewModel] { | ||
return [sharePointURLCellViewModel] | ||
} | ||
|
||
override var title: String? { | ||
return LocalizedString.getValue("addVault.enterSharePointURL.title") | ||
} | ||
|
||
let sharePointURLCellViewModel = TextFieldCellViewModel( | ||
type: .normal, | ||
placeholder: LocalizedString.getValue("addVault.enterSharePointURL.placeholder"), | ||
isInitialFirstResponder: true | ||
) | ||
var trimmedSharePointURL: String { | ||
return sharePointURLCellViewModel.input.value.trimmingCharacters(in: .whitespacesAndNewlines) | ||
} | ||
|
||
private lazy var subscribers = Set<AnyCancellable>() | ||
func getValidatedSharePointURL() throws -> String { | ||
guard !trimmedSharePointURL.isEmpty else { | ||
throw EnterSharePointURLViewModelError.emptyURL | ||
} | ||
try URLValidator.validateSharePointURL(urlString: trimmedSharePointURL) | ||
return trimmedSharePointURL | ||
} | ||
|
||
override func getHeaderTitle(for section: Int) -> String? { | ||
guard section == 0 else { | ||
return nil | ||
} | ||
return LocalizedString.getValue("addVault.enterSharePointURL.header.title") | ||
} | ||
} | ||
|
||
enum EnterSharePointURLViewModelError: LocalizedError { | ||
case emptyURL | ||
case invalidURL | ||
var errorDescription: String? { | ||
switch self { | ||
case .emptyURL: | ||
return LocalizedString.getValue("addVault.enterSharePointURL.error.emptyURL") | ||
case .invalidURL: | ||
return LocalizedString.getValue("addVault.enterSharePointURL.error.invalidURL") | ||
} | ||
} | ||
} |
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) | ||
} | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace fatalError with proper error handling
Using
fatalError
for cell dequeue failure is not suitable for production code as it could crash the app. Consider handling this gracefully.📝 Committable suggestion