Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from Shnipper/feature/addNewAccounts_fix
Browse files Browse the repository at this point in the history
Feature/add new accounts fix
  • Loading branch information
rhiskey authored Apr 7, 2022
2 parents 6cea5e3 + badfc45 commit e3f85a2
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 140 deletions.
34 changes: 29 additions & 5 deletions CipherEverything.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
5BF1186427F89665004A55E7 /* Services */,
5BF1186327F8965E004A55E7 /* Models */,
5BF1185F27F89610004A55E7 /* App */,
A591AC0A27FE1FA0002894A2 /* Views */,
5BF1186027F89614004A55E7 /* ViewControllers */,
5BF1186127F8961D004A55E7 /* Storyboards */,
5BF1186227F89652004A55E7 /* Resources */,
Expand All @@ -99,13 +100,10 @@
5BF1186027F89614004A55E7 /* ViewControllers */ = {
isa = PBXGroup;
children = (
146B585227FCA03200CE6B0B /* DeveloperTableViewCell.swift */,
5BF1184F27F89601004A55E7 /* LoginViewController.swift */,
5BF1186A27F896DB004A55E7 /* TabBarViewController.swift */,
5BBB893727F9FF6200E78E5C /* AccountsTableViewController.swift */,
5BBB893927F9FF6D00E78E5C /* TeamTableViewController.swift */,
5BBB893D27FA01CD00E78E5C /* EditAccountViewController.swift */,
A591AC0827FE0599002894A2 /* AddNewAccountViewController.swift */,
A591AC0B27FE1FE5002894A2 /* AccountsViewControllers */,
A591AC0C27FE1FFC002894A2 /* TeamViewControllers */,
);
path = ViewControllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -144,6 +142,32 @@
path = Services;
sourceTree = "<group>";
};
A591AC0A27FE1FA0002894A2 /* Views */ = {
isa = PBXGroup;
children = (
146B585227FCA03200CE6B0B /* DeveloperTableViewCell.swift */,
);
path = Views;
sourceTree = "<group>";
};
A591AC0B27FE1FE5002894A2 /* AccountsViewControllers */ = {
isa = PBXGroup;
children = (
5BBB893727F9FF6200E78E5C /* AccountsTableViewController.swift */,
5BBB893D27FA01CD00E78E5C /* EditAccountViewController.swift */,
A591AC0827FE0599002894A2 /* AddNewAccountViewController.swift */,
);
path = AccountsViewControllers;
sourceTree = "<group>";
};
A591AC0C27FE1FFC002894A2 /* TeamViewControllers */ = {
isa = PBXGroup;
children = (
5BBB893927F9FF6D00E78E5C /* TeamTableViewController.swift */,
);
path = TeamViewControllers;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down
Binary file not shown.
10 changes: 5 additions & 5 deletions CipherEverything/Storyboards/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
</imageView>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="Rbl-hQ-WpV" kind="show" id="xLs-kx-FUX"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
Expand All @@ -60,9 +63,6 @@
</connections>
</barButtonItem>
</navigationItem>
<connections>
<segue destination="Rbl-hQ-WpV" kind="show" identifier="showEditPassword" id="jcC-9b-PGG"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="KxC-wu-tMJ" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
Expand Down Expand Up @@ -410,7 +410,7 @@
<tabBarItem key="tabBarItem" title="Accounts" image="wallet.pass.fill" catalog="system" id="aPI-2O-ESC"/>
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" largeTitles="YES" id="Sct-sz-GCe">
<rect key="frame" x="0.0" y="0.0" width="320" height="102"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="96"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand All @@ -429,7 +429,7 @@
<tabBarItem key="tabBarItem" title="Team" image="person.fill" catalog="system" id="5he-gZ-xty"/>
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" largeTitles="YES" id="iHw-aR-jJ0">
<rect key="frame" x="0.0" y="0.0" width="320" height="102"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="96"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand Down
72 changes: 0 additions & 72 deletions CipherEverything/ViewControllers/AccountsTableViewController.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// AccountsTableViewController.swift
// CipherEverything
//
// Created by Владимир Киселев on 03.04.2022.
//

import UIKit

protocol AddNewAccountViewControllerDelegate {
func updateTable(with account: Account)
}

class AccountsTableViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = 80
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tableView.reloadData()
}

// MARK: - Table view data source
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
DataManager.shared.accounts.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "passwordCell", for: indexPath)
var content = cell.defaultContentConfiguration()

content.text = DataManager.shared.accounts[indexPath.row].website
content.image = UIImage(systemName: "key")

cell.contentConfiguration = content

return cell
}

// MARK: - Navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

guard let editAccountVC = segue.destination as? EditAccountViewController,
let indexPath = tableView.indexPathForSelectedRow else { return }
editAccountVC.account = DataManager.shared.accounts[indexPath.row]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ class AddNewAccountViewController: UIViewController {

DataManager.shared.addNew(account: newAccount)

delegate.updateTable(with: newAccount)

// проверка на кол-во аккаунтов в массиве
print(DataManager.shared.accounts.count)

navigationController?.popViewController(animated: true)
dismiss(animated: true, completion: nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ class EditAccountViewController: UIViewController, UITextFieldDelegate {
@IBOutlet var editSwitch: UISwitch!

// MARK: - Public Properties
var account: Account?
var account: Account!

override func viewDidLoad() {
super.viewDidLoad()

passwordTF.delegate = self

title = account?.website
passwordTF.text = account?.password
title = account.website
passwordTF.text = account.password

editSwitch.setOn(false, animated: false)

passwordRegularExpressionCheck(for: account?.password ?? "")
passwordRegularExpressionCheck(for: account.password)
}

override func viewDidDisappear(_ animated: Bool) {
Expand All @@ -50,7 +50,6 @@ class EditAccountViewController: UIViewController, UITextFieldDelegate {
guard let text = sender.text else { return }
passwordRegularExpressionCheck(for: text)
}

}

// MARK: - Public UI Methods
Expand Down Expand Up @@ -96,9 +95,6 @@ extension EditAccountViewController: UITextViewDelegate {

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
navigationController?.popViewController(animated: true)
dismiss(animated: true, completion: nil)
return true

}

}
14 changes: 2 additions & 12 deletions CipherEverything/ViewControllers/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,18 @@ class LoginViewController: UIViewController {

let passwordForLogin = ""


let dmInstance = DataManager.shared

var accounts: [Account]?
var teamMembers: [TeamMember]?

override func viewDidLoad() {
super.viewDidLoad()

accounts = dmInstance.accounts
teamMembers = dmInstance.teamMembers
accounts = DataManager.shared.accounts
teamMembers = DataManager.shared.teamMembers

navigationItem.leftBarButtonItem?.title = "Exit"
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let destination = segue.destination as? TabBarViewController else { return }
destination.accounts = accounts
destination.teamMembers = teamMembers
}

@IBAction func logInPressed() {
if passwordTF.text != passwordForLogin {
Expand Down Expand Up @@ -61,7 +53,6 @@ extension LoginViewController {
let alertAction = UIAlertAction(title: "Close", style: .default)

alert.addAction(alertAction)

}

private func showAlertForLogin(with title: String, and text: String) {
Expand All @@ -75,7 +66,6 @@ extension LoginViewController {
}

alert.addAction(alertAction)

}
}

Expand Down
24 changes: 1 addition & 23 deletions CipherEverything/ViewControllers/TabBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,12 @@
import UIKit

class TabBarViewController: UITabBarController {

var accounts: [Account]!
var teamMembers: [TeamMember]!


override func viewDidLoad() {
super.viewDidLoad()

title = "Accounts"
navigationItem.hidesBackButton = true
setupViewControllers()
}
}

// MARK: - Private Methods
extension TabBarViewController {

private func setupViewControllers() {
guard let tabBarChildViewControllers = viewControllers else { return }

for viewController in tabBarChildViewControllers {
guard let navigationVC = viewController as? UINavigationController else { return }

if let accountsVC = navigationVC.topViewController as? AccountsTableViewController {
accountsVC.accounts = accounts
} else if let teamVC = navigationVC.topViewController as? TeamTableViewController {
teamVC.developersList = teamMembers
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import UIKit

class TeamTableViewController: UITableViewController {

var developersList: [TeamMember]!

override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -26,21 +24,19 @@ class TeamTableViewController: UITableViewController {
// MARK: - Table view data source

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
developersList.count
DataManager.shared.teamMembers.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCell(withIdentifier: "developerCell", for: indexPath) as! DeveloperTableViewCell

cell.forceChanges(teamMember: developersList[indexPath.row])

guard let cell = tableView.dequeueReusableCell(
withIdentifier: "developerCell", for: indexPath) as? DeveloperTableViewCell else {
return tableView.dequeueReusableCell(withIdentifier: "developerCell", for: indexPath) }
cell.forceChanges(teamMember: DataManager.shared.teamMembers[indexPath.row])
return cell

}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}

}

0 comments on commit e3f85a2

Please sign in to comment.