Merge pull request #2300 from vector-im/swift_lint

Use SwiftLint to enforce Swift style and conventions
This commit is contained in:
SBiOSoftWhare
2019-02-27 11:32:18 +01:00
committed by GitHub
21 changed files with 183 additions and 134 deletions
Executable
+64
View File
@@ -0,0 +1,64 @@
# rule identifiers to exclude from running
disabled_rules:
- trailing_whitespace
- todo
- conditional_binding_cascade
- mark
- vertical_whitespace
- syntactic_sugar
- unused_closure_parameter
- closure_parameter_position
- redundant_string_enum_value
- large_tuple
- shorthand_operator
- vertical_parameter_alignment
- identifier_name
# some rules are only opt-in
opt_in_rules:
- force_unwrapping
- private_action
- explicit_init
# paths to include during linting. `--path` is ignored if present.
included:
- Riot
# paths to ignore during linting. Takes precedence over `included`.
excluded:
- Carthage
- Pods
- Riot/Generated/
line_length:
warning: 250
error: 1000
file_length:
warning: 700
error: 1000
type_body_length:
warning: 700
error: 1000
function_parameter_count:
warning: 7
error: 10
cyclomatic_complexity:
ignores_case_statements: true
warning: 20
error: 25
function_body_length:
warning: 100
error: 150
# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
min_length: 3 # only warning
max_length: # warning and error
warning: 150
error: 1000
+1
View File
@@ -8,6 +8,7 @@ Improvements:
* Update deprecated contact availability checks (#2222).
* RoomVC: Remove the beta warning modal when enabling e2e in a room (#2239).
* Fastlane: Update to Xcode 10.1 (#2202).
* Use SwiftLint to enforce Swift style and conventions (PR #2300).
Bug fix:
* Reskin: status bar text is no more readable on iPad (#2276).
+1
View File
@@ -80,6 +80,7 @@ abstract_target 'RiotPods' do
# Tools
pod 'SwiftGen', '~> 6.1'
pod 'SwiftLint', '~> 0.30.1'
target "Riot" do
import_MatrixKit
+12 -8
View File
@@ -71,7 +71,7 @@ PODS:
- GZIP (~> 1.2.2)
- libbase58 (~> 0.1.4)
- OLMKit (~> 3.0.0)
- Realm (~> 3.13.1)
- Realm (~> 3.11.1)
- MatrixSDK/JingleCallStack (0.12.2):
- MatrixSDK/Core
- WebRTC (= 63.11.20455)
@@ -85,15 +85,16 @@ PODS:
- PiwikTracker (4.4.2):
- PiwikTracker/Core (= 4.4.2)
- PiwikTracker/Core (4.4.2)
- Realm (3.13.1):
- Realm/Headers (= 3.13.1)
- Realm/Headers (3.13.1)
- Realm (3.11.2):
- Realm/Headers (= 3.11.2)
- Realm/Headers (3.11.2)
- Reusable (4.0.5):
- Reusable/Storyboard (= 4.0.5)
- Reusable/View (= 4.0.5)
- Reusable/Storyboard (4.0.5)
- Reusable/View (4.0.5)
- SwiftGen (6.1.0)
- SwiftLint (0.30.1)
- WebRTC (63.11.20455)
- zxcvbn-ios (1.0.4)
@@ -108,7 +109,8 @@ DEPENDENCIES:
- OLMKit
- PiwikTracker (from `https://github.com/manuroe/matomo-sdk-ios.git`, branch `feature/CustomVariables`)
- Reusable (~> 4.0)
- SwiftGen (~> 6.0)
- SwiftGen (~> 6.1)
- SwiftLint (~> 0.30.1)
- zxcvbn-ios
SPEC REPOS:
@@ -128,6 +130,7 @@ SPEC REPOS:
- Realm
- Reusable
- SwiftGen
- SwiftLint
- WebRTC
- zxcvbn-ios
@@ -155,12 +158,13 @@ SPEC CHECKSUMS:
MatrixSDK: 60a9472eacdf51e5110b8bc7beba844debf992ef
OLMKit: 88eda69110489f817d59bcb4353b7c247570aa4f
PiwikTracker: 42862c7b13028065c3dfd36b4dc38db8a5765acf
Realm: 50071da38fe079e0735e47c9f2eae738c68c5996
Realm: 864477d028db77f7c5a0cba64a4892ad53db128a
Reusable: 188be1a54ac0691bc66e5bb24ec6eb91971b315b
SwiftGen: f872ca75cbd17bf7103c17f13dcfa0d9a15667b0
SwiftLint: a54bf1fe12b55c68560eb2a7689dfc81458508f7
WebRTC: f2a6203584745fe53532633397557876b5d71640
zxcvbn-ios: fef98b7c80f1512ff0eec47ac1fa399fc00f7e3c
PODFILE CHECKSUM: 17a74795e75026048d90793d2ebb0880eac5c55f
PODFILE CHECKSUM: e35dd68cbd07be4c9dcf9e481000dd4498982e8a
COCOAPODS: 1.6.0
COCOAPODS: 1.6.1
+19
View File
@@ -2964,6 +2964,7 @@
buildConfigurationList = F094A9C81B78D8F000B1FBBF /* Build configuration list for PBXNativeTarget "Riot" */;
buildPhases = (
E34E30CD2CEE4A42FF8081D6 /* [CP] Check Pods Manifest.lock */,
B1D1AC122225A43600D64A6C /* ⚠️ SwiftLint */,
B1098BD821ECD3ED000DDA48 /* 🛠 SwiftGen */,
F094A99E1B78D8F000B1FBBF /* Sources */,
F094A99F1B78D8F000B1FBBF /* Frameworks */,
@@ -3363,6 +3364,24 @@
shellPath = /bin/sh;
shellScript = "${PODS_ROOT}/SwiftGen/bin/swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml\n";
};
B1D1AC122225A43600D64A6C /* ⚠️ SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "⚠️ SwiftLint";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "${PODS_ROOT}/SwiftLint/swiftlint\n";
};
E34E30CD2CEE4A42FF8081D6 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
+3 -3
View File
@@ -18,9 +18,9 @@ import UIKit
// Source: https://stackoverflow.com/a/44917661
class ClosureSleeve {
let closure: () -> ()
let closure: () -> Void
init(attachTo: AnyObject, closure: @escaping () -> ()) {
init(attachTo: AnyObject, closure: @escaping () -> Void) {
self.closure = closure
objc_setAssociatedObject(attachTo, "[\(arc4random())]", self, .OBJC_ASSOCIATION_RETAIN)
}
@@ -31,7 +31,7 @@ class ClosureSleeve {
}
extension UIControl {
func vc_addAction(for controlEvents: UIControl.Event = .primaryActionTriggered, action: @escaping () -> ()) {
func vc_addAction(for controlEvents: UIControl.Event = .primaryActionTriggered, action: @escaping () -> Void) {
let sleeve = ClosureSleeve(attachTo: self, closure: action)
addTarget(sleeve, action: #selector(ClosureSleeve.invoke), for: controlEvents)
}
@@ -53,16 +53,16 @@ final public class OnBoardingManager: NSObject {
self.session.matrixRestClient.avatarUrl(forUser: Constants.riotBotMatrixId) { (response) in
switch response {
case .success(_):
case .success:
// Create DM room with Riot-bot
let httpOperation = self.session.createRoom(name: nil, visibility: .private, alias: nil, topic: nil, invite: [Constants.riotBotMatrixId], invite3PID: nil, isDirect: true, preset: .trustedPrivateChat) { (response) in
switch response {
case .success(_):
case .success:
success?()
case .failure(let error):
NSLog("[OnBoardingManager] Create chat with riot-bot failed");
NSLog("[OnBoardingManager] Create chat with riot-bot failed")
failure?(error)
}
}
@@ -71,7 +71,7 @@ final public class OnBoardingManager: NSObject {
httpOperation.maxNumberOfTries = Constants.createRiotBotDMRequestMaxNumberOfTries
case .failure(let error):
NSLog("[OnBoardingManager] riot-bot is unknown or the user hs is non federated. Do not try to create a room with riot-bot");
NSLog("[OnBoardingManager] riot-bot is unknown or the user hs is non federated. Do not try to create a room with riot-bot")
failure?(error)
}
}
+1 -1
View File
@@ -60,7 +60,7 @@ import UIKit
var scrollBarStyle: UIScrollView.IndicatorStyle { get }
var keyboardAppearance : UIKeyboardAppearance { get }
var keyboardAppearance: UIKeyboardAppearance { get }
// MARK: - Colors not defined in the design palette
+8 -8
View File
@@ -62,26 +62,26 @@ class DarkTheme: NSObject, Theme {
var matrixSearchBackgroundImageTintColor: UIColor = UIColor(rgb: 0x7E7E7E)
func applyStyle(onTabBar tabBar: UITabBar) {
tabBar.tintColor = self.tintColor;
tabBar.barTintColor = self.headerBackgroundColor;
tabBar.isTranslucent = false;
tabBar.tintColor = self.tintColor
tabBar.barTintColor = self.headerBackgroundColor
tabBar.isTranslucent = false
}
func applyStyle(onNavigationBar navigationBar: UINavigationBar) {
navigationBar.tintColor = self.baseTextPrimaryColor;
navigationBar.tintColor = self.baseTextPrimaryColor
navigationBar.titleTextAttributes = [
NSAttributedString.Key.foregroundColor: self.baseTextPrimaryColor
]
navigationBar.barTintColor = self.baseColor;
navigationBar.barTintColor = self.baseColor
// The navigation bar needs to be opaque so that its background color is the expected one
navigationBar.isTranslucent = false;
navigationBar.isTranslucent = false
}
func applyStyle(onSearchBar searchBar: UISearchBar) {
searchBar.barStyle = .black
searchBar.tintColor = self.searchPlaceholderColor;
searchBar.barTintColor = self.headerBackgroundColor;
searchBar.tintColor = self.searchPlaceholderColor
searchBar.barTintColor = self.headerBackgroundColor
}
func applyStyle(onTextField texField: UITextField) {
@@ -57,31 +57,31 @@ class DefaultTheme: NSObject, Theme {
var keyboardAppearance: UIKeyboardAppearance = .light
var placeholderTextColor: UIColor = UIColor(white: 0.7, alpha: 1.0) // Use default 70% gray color
var selectedBackgroundColor: UIColor? = nil // Use the default selection color
var selectedBackgroundColor: UIColor? // Use the default selection color
var overlayBackgroundColor: UIColor = UIColor(white: 0.7, alpha: 0.5)
var matrixSearchBackgroundImageTintColor: UIColor = UIColor(rgb: 0xE7E7E7)
func applyStyle(onTabBar tabBar: UITabBar) {
tabBar.tintColor = self.tintColor;
tabBar.barTintColor = self.headerBackgroundColor;
tabBar.isTranslucent = false;
tabBar.tintColor = self.tintColor
tabBar.barTintColor = self.headerBackgroundColor
tabBar.isTranslucent = false
}
func applyStyle(onNavigationBar navigationBar: UINavigationBar) {
navigationBar.tintColor = self.baseTextPrimaryColor;
navigationBar.tintColor = self.baseTextPrimaryColor
navigationBar.titleTextAttributes = [
NSAttributedString.Key.foregroundColor: self.baseTextPrimaryColor
]
navigationBar.barTintColor = self.baseColor;
navigationBar.barTintColor = self.baseColor
// The navigation bar needs to be opaque so that its background color is the expected one
navigationBar.isTranslucent = false;
navigationBar.isTranslucent = false
}
func applyStyle(onSearchBar searchBar: UISearchBar) {
searchBar.barStyle = .default
searchBar.tintColor = self.searchPlaceholderColor;
searchBar.barTintColor = self.headerBackgroundColor;
searchBar.tintColor = self.searchPlaceholderColor
searchBar.barTintColor = self.headerBackgroundColor
}
func applyStyle(onTextField texField: UITextField) {
@@ -24,7 +24,7 @@ final class TermsView: UIView, NibOwnerLoadable, UITableViewDelegate, UITableVie
@objc weak var delegate: MXKAuthInputsViewDelegate?
private var acceptedCallback: (()->Void)?
private var acceptedCallback: (() -> Void)?
/// NavigationVC to display a policy content
@@ -116,7 +116,7 @@ final class TermsView: UIView, NibOwnerLoadable, UITableViewDelegate, UITableVie
acceptButton.alpha = acceptButton.isEnabled ? 1 : 0.5
}
@IBAction func didAcceptButtonTapped(_ sender: Any) {
@IBAction private func didAcceptButtonTapped(_ sender: Any) {
if policies.count == acceptedPolicies.count {
acceptedCallback?()
}
@@ -131,7 +131,9 @@ final class TermsView: UIView, NibOwnerLoadable, UITableViewDelegate, UITableVie
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: TableViewCellWithCheckBoxAndLabel.defaultReuseIdentifier(), for: indexPath) as! TableViewCellWithCheckBoxAndLabel
guard let cell = tableView.dequeueReusableCell(withIdentifier: TableViewCellWithCheckBoxAndLabel.defaultReuseIdentifier(), for: indexPath) as? TableViewCellWithCheckBoxAndLabel else {
fatalError("\(String(describing: TableViewCellWithCheckBoxAndLabel.self)) should be registered")
}
let policy = policies[indexPath.row]
let accepted = acceptedPolicies .contains(indexPath.row)
@@ -186,7 +188,7 @@ final class TermsView: UIView, NibOwnerLoadable, UITableViewDelegate, UITableVie
let webViewViewController: WebViewViewController = WebViewViewController(url: policy.url)
webViewViewController.title = policy.name
let leftBarButtonItem: UIBarButtonItem = UIBarButtonItem(image: UIImage(named: "back_icon"), style: .plain, target: self, action:#selector(didTapCancelOnPolicyScreen))
let leftBarButtonItem: UIBarButtonItem = UIBarButtonItem(image: UIImage(named: "back_icon"), style: .plain, target: self, action: #selector(didTapCancelOnPolicyScreen))
webViewViewController.navigationItem.leftBarButtonItem = leftBarButtonItem
navigationController = RiotNavigationController()
@@ -129,4 +129,3 @@ extension KeyBackupRecoverCoordinator: KeyBackupRecoverSuccessViewControllerDele
self.delegate?.keyBackupRecoverCoordinatorDidRecover(self)
}
}
@@ -70,4 +70,3 @@ extension KeyBackupRecoverFromPassphraseCoordinator: KeyBackupRecoverFromPassphr
self.delegate?.keyBackupRecoverFromPassphraseCoordinatorDidCancel(self)
}
}
@@ -130,16 +130,16 @@ final class KeyBackupRecoverFromPassphraseViewController: UIViewController {
self.passphraseTitleLabel.textColor = theme.textPrimaryColor
theme.applyStyle(onTextField: self.passphraseTextField)
self.passphraseTextField.attributedPlaceholder = NSAttributedString(string: VectorL10n.keyBackupRecoverFromPassphrasePassphrasePlaceholder,
attributes: [.foregroundColor : theme.placeholderTextColor])
attributes: [.foregroundColor: theme.placeholderTextColor])
self.theme.applyStyle(onButton: self.passphraseVisibilityButton)
self.recoverButtonBackgroundView.backgroundColor = theme.backgroundColor
theme.applyStyle(onButton: self.recoverButton)
let unknownRecoveryKeyAttributedString = NSMutableAttributedString(string: VectorL10n.keyBackupRecoverFromPassphraseLostPassphraseActionPart1, attributes: [.foregroundColor : self.theme.textPrimaryColor])
let unknownRecoveryKeyAttributedStringPart2 = NSAttributedString(string: VectorL10n.keyBackupRecoverFromPassphraseLostPassphraseActionPart2, attributes: [.foregroundColor : self.theme.tintColor])
let unknownRecoveryKeyAttributedStringPart3 = NSAttributedString(string: VectorL10n.keyBackupRecoverFromPassphraseLostPassphraseActionPart3, attributes: [.foregroundColor : self.theme.textPrimaryColor])
let unknownRecoveryKeyAttributedString = NSMutableAttributedString(string: VectorL10n.keyBackupRecoverFromPassphraseLostPassphraseActionPart1, attributes: [.foregroundColor: self.theme.textPrimaryColor])
let unknownRecoveryKeyAttributedStringPart2 = NSAttributedString(string: VectorL10n.keyBackupRecoverFromPassphraseLostPassphraseActionPart2, attributes: [.foregroundColor: self.theme.tintColor])
let unknownRecoveryKeyAttributedStringPart3 = NSAttributedString(string: VectorL10n.keyBackupRecoverFromPassphraseLostPassphraseActionPart3, attributes: [.foregroundColor: self.theme.textPrimaryColor])
unknownRecoveryKeyAttributedString.append(unknownRecoveryKeyAttributedStringPart2)
unknownRecoveryKeyAttributedString.append(unknownRecoveryKeyAttributedStringPart3)
@@ -135,7 +135,7 @@ final class KeyBackupRecoverFromRecoveryKeyViewController: UIViewController {
self.recoveryKeyTitleLabel.textColor = theme.textPrimaryColor
theme.applyStyle(onTextField: self.recoveryKeyTextField)
self.recoveryKeyTextField.attributedPlaceholder = NSAttributedString(string: VectorL10n.keyBackupRecoverFromRecoveryKeyRecoveryKeyPlaceholder,
attributes: [.foregroundColor : theme.placeholderTextColor])
attributes: [.foregroundColor: theme.placeholderTextColor])
theme.applyStyle(onButton: self.importFileButton)
@@ -133,12 +133,12 @@ final class KeyBackupSetupIntroViewController: UIViewController {
private func showSkipAlert() {
let alertController = UIAlertController(title: VectorL10n.keyBackupSetupSkipAlertTitle,
message: VectorL10n.keyBackupSetupSkipAlertMessage,
preferredStyle:.alert)
preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: VectorL10n.continue, style: .cancel, handler: { action in
}))
alertController.addAction(UIAlertAction(title: VectorL10n.keyBackupSetupSkipAlertSkipAction , style: .default, handler: { action in
alertController.addAction(UIAlertAction(title: VectorL10n.keyBackupSetupSkipAlertSkipAction, style: .default, handler: { action in
self.delegate?.keyBackupSetupIntroViewControllerDidCancel(self)
}))
@@ -150,7 +150,7 @@ final class KeyBackupSetupPassphraseViewController: UIViewController {
self.passphraseTitleLabel.textColor = theme.textPrimaryColor
theme.applyStyle(onTextField: self.passphraseTextField)
self.passphraseTextField.attributedPlaceholder = NSAttributedString(string: VectorL10n.keyBackupSetupPassphrasePassphrasePlaceholder,
attributes: [.foregroundColor : theme.placeholderTextColor])
attributes: [.foregroundColor: theme.placeholderTextColor])
self.updatePassphraseAdditionalLabel()
self.formSeparatorView.backgroundColor = theme.lineBreakColor
@@ -158,7 +158,7 @@ final class KeyBackupSetupPassphraseViewController: UIViewController {
self.confirmPassphraseTitleLabel.textColor = theme.textPrimaryColor
theme.applyStyle(onTextField: self.confirmPassphraseTextField)
self.confirmPassphraseTextField.attributedPlaceholder = NSAttributedString(string: VectorL10n.keyBackupSetupPassphraseConfirmPassphraseTitle,
attributes: [.foregroundColor : theme.placeholderTextColor])
attributes: [.foregroundColor: theme.placeholderTextColor])
self.updateConfirmPassphraseAdditionalLabel()
self.setPassphraseButton.backgroundColor = theme.backgroundColor
@@ -277,12 +277,12 @@ final class KeyBackupSetupPassphraseViewController: UIViewController {
private func render(viewState: KeyBackupSetupPassphraseViewState) {
switch viewState {
case .loading:
self.renderLoading()
case .loaded:
self.renderLoaded()
case .error(let error):
self.render(error: error)
case .loading:
self.renderLoading()
case .loaded:
self.renderLoaded()
case .error(let error):
self.render(error: error)
}
}
@@ -308,13 +308,13 @@ final class KeyBackupSetupPassphraseViewController: UIViewController {
let alertController = UIAlertController(title: VectorL10n.keyBackupSetupSkipAlertTitle,
message: VectorL10n.keyBackupSetupSkipAlertMessage,
preferredStyle:.alert)
preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: VectorL10n.continue, style: .cancel, handler: { action in
self.viewModel.process(viewAction: .skipAlertContinue)
}))
alertController.addAction(UIAlertAction(title: VectorL10n.keyBackupSetupSkipAlertSkipAction , style: .default, handler: { action in
alertController.addAction(UIAlertAction(title: VectorL10n.keyBackupSetupSkipAlertSkipAction, style: .default, handler: { action in
self.viewModel.process(viewAction: .skipAlertSkip)
}))
@@ -193,7 +193,7 @@ final class KeyBackupSetupRecoveryKeyViewController: UIViewController {
let alertController = UIAlertController(title: VectorL10n.keyBackupSetupSkipAlertTitle,
message: VectorL10n.keyBackupSetupSkipAlertMessage,
preferredStyle:.alert)
preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: VectorL10n.continue, style: .cancel, handler: { action in
self.viewModel.process(viewAction: .skipAlertContinue)
@@ -24,11 +24,11 @@ import UIKit
func settingsKeyBackupTableViewSectionShowKeyBackupSetup(_ settingsKeyBackupTableViewSection: SettingsKeyBackupTableViewSection)
func settingsKeyBackup(_ settingsKeyBackupTableViewSection: SettingsKeyBackupTableViewSection, showKeyBackupRecover keyBackupVersion:MXKeyBackupVersion)
func settingsKeyBackup(_ settingsKeyBackupTableViewSection: SettingsKeyBackupTableViewSection, showKeyBackupDeleteConfirm keyBackupVersion:MXKeyBackupVersion)
func settingsKeyBackup(_ settingsKeyBackupTableViewSection: SettingsKeyBackupTableViewSection, showKeyBackupRecover keyBackupVersion: MXKeyBackupVersion)
func settingsKeyBackup(_ settingsKeyBackupTableViewSection: SettingsKeyBackupTableViewSection, showKeyBackupDeleteConfirm keyBackupVersion: MXKeyBackupVersion)
func settingsKeyBackup(_ settingsKeyBackupTableViewSection: SettingsKeyBackupTableViewSection, showActivityIndicator show:Bool)
func settingsKeyBackup(_ settingsKeyBackupTableViewSection: SettingsKeyBackupTableViewSection, showError error:Error)
func settingsKeyBackup(_ settingsKeyBackupTableViewSection: SettingsKeyBackupTableViewSection, showActivityIndicator show: Bool)
func settingsKeyBackup(_ settingsKeyBackupTableViewSection: SettingsKeyBackupTableViewSection, showError error: Error)
}
@objc final class SettingsKeyBackupTableViewSection: NSObject {
@@ -78,15 +78,15 @@ import UIKit
return numberOfRows
}
@objc func cellForRow(atRow row:Int) -> UITableViewCell {
@objc func cellForRow(atRow row: Int) -> UITableViewCell {
var cell: UITableViewCell
switch self.viewState {
case .checkingBackup:
cell = self.renderCheckingBackupCell(atRow:row)
cell = self.renderCheckingBackupCell(atRow: row)
case .noBackup:
cell = self.renderNoBackupCell(atRow:row)
cell = self.renderNoBackupCell(atRow: row)
case .backup(let keyBackupVersion, let keyBackupVersionTrust):
cell = self.renderBackupCell(atRow: row,
@@ -94,13 +94,13 @@ import UIKit
keyBackupVersionTrust: keyBackupVersionTrust)
case .backupAndRunning(let keyBackupVersion, let keyBackupVersionTrust, let backupProgress):
cell = self.renderBackupAndRunningCell(atRow:row,
cell = self.renderBackupAndRunningCell(atRow: row,
keyBackupVersion: keyBackupVersion,
keyBackupVersionTrust: keyBackupVersionTrust,
backupProgress: backupProgress)
case .backupNotTrusted(let keyBackupVersion, let keyBackupVersionTrust):
cell = self.renderBackupNotTrustedCell(atRow:row,
cell = self.renderBackupNotTrustedCell(atRow: row,
keyBackupVersion: keyBackupVersion,
keyBackupVersionTrust: keyBackupVersionTrust)
}
@@ -125,7 +125,7 @@ import UIKit
private func renderCheckingBackupCell(atRow row: Int) -> UITableViewCell {
guard let delegate = self.delegate else {
return UITableViewCell.init()
return UITableViewCell()
}
let cell: MXKTableViewCellWithTextView = delegate.settingsKeyBackupTableViewSection(self, textCellForRow: row)
@@ -146,7 +146,7 @@ import UIKit
private func renderNoBackupCell(atRow row: Int) -> UITableViewCell {
guard let delegate = self.delegate else {
return UITableViewCell.init()
return UITableViewCell()
}
var cell: UITableViewCell
@@ -167,7 +167,7 @@ import UIKit
cell = self.buttonCellForCreate(atRow: row)
default:
cell = UITableViewCell.init()
cell = UITableViewCell()
}
return cell
@@ -180,7 +180,7 @@ import UIKit
private func renderBackupCell(atRow row: Int, keyBackupVersion: MXKeyBackupVersion, keyBackupVersionTrust: MXKeyBackupVersionTrust) -> UITableViewCell {
guard let delegate = self.delegate else {
return UITableViewCell.init()
return UITableViewCell()
}
var cell: UITableViewCell
@@ -211,7 +211,7 @@ import UIKit
case 2:
let infoCell: MXKTableViewCellWithTextView = delegate.settingsKeyBackupTableViewSection(self, textCellForRow: row)
let backupTrust = self.stringForKeyBackupTrust(keyBackupVersionTrust);
let backupTrust = self.stringForKeyBackupTrust(keyBackupVersionTrust)
infoCell.mxkTextView.text = backupTrust.joined(separator: "\n")
cell = infoCell
@@ -223,7 +223,7 @@ import UIKit
cell = self.buttonCellForDelete(keyBackupVersion: keyBackupVersion, atRow: row)
default:
cell = UITableViewCell.init()
cell = UITableViewCell()
}
return cell
@@ -236,7 +236,7 @@ import UIKit
private func renderBackupAndRunningCell(atRow row: Int, keyBackupVersion: MXKeyBackupVersion, keyBackupVersionTrust: MXKeyBackupVersionTrust, backupProgress: Progress) -> UITableViewCell {
guard let delegate = self.delegate else {
return UITableViewCell.init()
return UITableViewCell()
}
var cell: UITableViewCell
@@ -269,7 +269,7 @@ import UIKit
case 2:
let infoCell: MXKTableViewCellWithTextView = delegate.settingsKeyBackupTableViewSection(self, textCellForRow: row)
let backupTrust = self.stringForKeyBackupTrust(keyBackupVersionTrust);
let backupTrust = self.stringForKeyBackupTrust(keyBackupVersionTrust)
infoCell.mxkTextView.text = backupTrust.joined(separator: "\n")
cell = infoCell
@@ -281,7 +281,7 @@ import UIKit
cell = self.buttonCellForDelete(keyBackupVersion: keyBackupVersion, atRow: row)
default:
cell = UITableViewCell.init()
cell = UITableViewCell()
}
return cell
@@ -294,7 +294,7 @@ import UIKit
private func renderBackupNotTrustedCell(atRow row: Int, keyBackupVersion: MXKeyBackupVersion, keyBackupVersionTrust: MXKeyBackupVersionTrust) -> UITableViewCell {
guard let delegate = self.delegate else {
return UITableViewCell.init()
return UITableViewCell()
}
var cell: UITableViewCell
@@ -325,7 +325,7 @@ import UIKit
case 2:
let infoCell: MXKTableViewCellWithTextView = delegate.settingsKeyBackupTableViewSection(self, textCellForRow: row)
let backupTrust = self.stringForKeyBackupTrust(keyBackupVersionTrust);
let backupTrust = self.stringForKeyBackupTrust(keyBackupVersionTrust)
infoCell.mxkTextView.text = backupTrust.joined(separator: "\n")
cell = infoCell
@@ -337,7 +337,7 @@ import UIKit
cell = self.buttonCellForDelete(keyBackupVersion: keyBackupVersion, atRow: row)
default:
cell = UITableViewCell.init()
cell = UITableViewCell()
}
return cell
@@ -357,64 +357,29 @@ import UIKit
if device.fingerprint == self.userDevice.fingerprint {
return VectorL10n.settingsKeyBackupInfoTrustSignatureValid
}
else if signature.valid && (device.verified == MXDeviceVerified) {
} else if signature.valid && (device.verified == MXDeviceVerified) {
return VectorL10n.settingsKeyBackupInfoTrustSignatureValidDeviceVerified(displayName)
}
else if signature.valid && (device.verified != MXDeviceVerified) {
} else if signature.valid && (device.verified != MXDeviceVerified) {
return VectorL10n.settingsKeyBackupInfoTrustSignatureValidDeviceUnverified(displayName)
}
else if !signature.valid && (device.verified == MXDeviceVerified) {
} else if !signature.valid && (device.verified == MXDeviceVerified) {
return VectorL10n.settingsKeyBackupInfoTrustSignatureInvalidDeviceVerified(displayName)
}
else if !signature.valid && (device.verified != MXDeviceVerified) {
} else if !signature.valid && (device.verified != MXDeviceVerified) {
return VectorL10n.settingsKeyBackupInfoTrustSignatureInvalidDeviceUnverified(displayName)
}
return "";
return ""
}
}
private func lastNonVerifiedDevice(_ keyBackupVersionTrust:MXKeyBackupVersionTrust) -> MXDeviceInfo?
{
var lastNonVerifiedDevice: MXDeviceInfo?
for signature in keyBackupVersionTrust.signatures.reversed() {
guard let device = signature.device else {
continue
}
if device.verified != MXDeviceVerified
{
lastNonVerifiedDevice = device
break
}
}
return lastNonVerifiedDevice
}
private func lastUnVerifiableDevice(_ keyBackupVersionTrust:MXKeyBackupVersionTrust) -> String?
{
var lastUnVerifiableDevice: String?
for signature in keyBackupVersionTrust.signatures.reversed() {
if signature.device == nil {
lastUnVerifiableDevice = signature.deviceId
break
}
}
return lastUnVerifiableDevice
}
// MARK: - Button cells
private func buttonCellForCreate(atRow row: Int) -> UITableViewCell {
guard let delegate = self.delegate else {
return UITableViewCell.init()
return UITableViewCell()
}
let cell:MXKTableViewCellWithButton = delegate.settingsKeyBackupTableViewSection(self, buttonCellForRow: row)
let cell: MXKTableViewCellWithButton = delegate.settingsKeyBackupTableViewSection(self, buttonCellForRow: row)
let btnTitle = VectorL10n.settingsKeyBackupButtonCreate
cell.mxkButton.setTitle(btnTitle, for: .normal)
@@ -429,10 +394,10 @@ import UIKit
private func buttonCellForRestore(keyBackupVersion: MXKeyBackupVersion, atRow row: Int, title: String = VectorL10n.settingsKeyBackupButtonRestore) -> UITableViewCell {
guard let delegate = self.delegate else {
return UITableViewCell.init()
return UITableViewCell()
}
let cell:MXKTableViewCellWithButton = delegate.settingsKeyBackupTableViewSection(self, buttonCellForRow: row)
let cell: MXKTableViewCellWithButton = delegate.settingsKeyBackupTableViewSection(self, buttonCellForRow: row)
cell.mxkButton.setTitle(title, for: .normal)
cell.mxkButton.setTitle(title, for: .highlighted)
cell.mxkButton.vc_addAction {
@@ -443,10 +408,10 @@ import UIKit
private func buttonCellForDelete(keyBackupVersion: MXKeyBackupVersion, atRow row: Int) -> UITableViewCell {
guard let delegate = self.delegate else {
return UITableViewCell.init()
return UITableViewCell()
}
let cell:MXKTableViewCellWithButton = delegate.settingsKeyBackupTableViewSection(self, buttonCellForRow: row)
let cell: MXKTableViewCellWithButton = delegate.settingsKeyBackupTableViewSection(self, buttonCellForRow: row)
let btnTitle = VectorL10n.settingsKeyBackupButtonDelete
cell.mxkButton.setTitle(btnTitle, for: .normal)
cell.mxkButton.setTitle(btnTitle, for: .highlighted)
@@ -48,16 +48,12 @@ final class SettingsKeyBackupViewModel: SettingsKeyBackupViewModelType {
self.checkKeyBackupState()
case .create:
viewDelegate.settingsKeyBackupViewModelShowKeyBackupSetup(self)
break
case .restore(let keyBackupVersion):
viewDelegate.settingsKeyBackup(self, showKeyBackupRecover: keyBackupVersion)
break
case .confirmDelete(let keyBackupVersion):
viewDelegate.settingsKeyBackup(self, showKeyBackupDeleteConfirm: keyBackupVersion)
break
case .delete(let keyBackupVersion):
self.deleteKeyBackupVersion(keyBackupVersion)
break
}
}
@@ -76,15 +72,14 @@ final class SettingsKeyBackupViewModel: SettingsKeyBackupViewModelType {
return
}
sself.computeState(withBackupVersionTrust:keyBackupVersionTrust)
sself.computeState(withBackupVersionTrust: keyBackupVersionTrust)
})
}
else {
} else {
computeState()
}
}
private func computeState(withBackupVersionTrust keyBackupVersionTrust:MXKeyBackupVersionTrust? = nil) {
private func computeState(withBackupVersionTrust keyBackupVersionTrust: MXKeyBackupVersionTrust? = nil) {
var viewState: SettingsKeyBackupViewState?
switch self.keyBackup.state {
@@ -21,8 +21,8 @@ protocol SettingsKeyBackupViewModelViewDelegate: class {
func settingsKeyBackupViewModel(_ viewModel: SettingsKeyBackupViewModelType, didUpdateNetworkRequestViewState networkRequestViewSate: SettingsKeyBackupNetworkRequestViewState)
func settingsKeyBackupViewModelShowKeyBackupSetup(_ viewModel: SettingsKeyBackupViewModelType)
func settingsKeyBackup(_ viewModel: SettingsKeyBackupViewModelType, showKeyBackupRecover keyBackupVersion:MXKeyBackupVersion)
func settingsKeyBackup(_ viewModel: SettingsKeyBackupViewModelType, showKeyBackupDeleteConfirm keyBackupVersion:MXKeyBackupVersion)
func settingsKeyBackup(_ viewModel: SettingsKeyBackupViewModelType, showKeyBackupRecover keyBackupVersion: MXKeyBackupVersion)
func settingsKeyBackup(_ viewModel: SettingsKeyBackupViewModelType, showKeyBackupDeleteConfirm keyBackupVersion: MXKeyBackupVersion)
}
protocol SettingsKeyBackupViewModelType {