-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - Create new EnterURLScreen for SharePoint, add SharePoint Icons …
…and add SharePoint as CloudProvider
- Loading branch information
Showing
33 changed files
with
338 additions
and
25 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
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
// | ||
// 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() { | ||
do { | ||
try coordinator?.setSharePointURL(viewModel.getValidatedSharePointURL()) | ||
} catch { | ||
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") | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Cryptomator/AddVault/CreateNewVault/SharePointURLSetting.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,14 @@ | ||
// | ||
// SharePointURLSetting.swift | ||
// Cryptomator | ||
// | ||
// Created by Majid Achhoud on 03.12.24. | ||
// Copyright © 2024 Skymatic GmbH. All rights reserved. | ||
// | ||
|
||
import CryptomatorCommonCore | ||
import UIKit | ||
|
||
protocol SharePointURLSetting: AnyObject { | ||
func setSharePointURL(_ url: String) | ||
} |
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,34 @@ | ||
// | ||
// URLValidator.swift | ||
// Cryptomator | ||
// | ||
// Created by Majid Achhoud on 03.12.24. | ||
// Copyright © 2024 Skymatic GmbH. All rights reserved. | ||
// | ||
|
||
import CryptomatorCommonCore | ||
import Foundation | ||
|
||
public enum URLValidatorError: Error, Equatable { | ||
case invalidURLFormat | ||
} | ||
|
||
extension URLValidatorError: LocalizedError { | ||
public var errorDescription: String? { | ||
switch self { | ||
case .invalidURLFormat: | ||
return LocalizedString.getValue("addVault.enterSharePointURL.error.invalidURL") | ||
} | ||
} | ||
} | ||
|
||
public enum URLValidator { | ||
public static func validateSharePointURL(urlString: String) throws { | ||
let pattern = #"^https:\/\/[a-zA-Z0-9\-]+\.sharepoint\.com\/sites\/[a-zA-Z0-9\-]+$"# | ||
let regex = try NSRegularExpression(pattern: pattern) | ||
let range = NSRange(location: 0, length: urlString.utf16.count) | ||
if regex.firstMatch(in: urlString, options: [], range: range) == nil { | ||
throw URLValidatorError.invalidURLFormat | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.