[KB-2396]: added custom edit domains cell and view controller

This commit is contained in:
Aliaksandr Dvoineu
2023-04-11 13:55:44 +03:00
parent 94f1d283c6
commit a80968f7f6
4 changed files with 22 additions and 24 deletions

View File

@@ -160,6 +160,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
application.registerForRemoteNotifications()
setupWidgetToggleWorkaround()
// TODO: - Remove after testing viewcontrollers
// self.window = UIWindow(frame: UIScreen.main.bounds)
// self.window?.rootViewController = EditDomainsViewController()
// self.window?.makeKeyAndVisible()
// If not yet agreed to privacy policy, set initial view controller to TitleViewController
if (defaults.bool(forKey: kHasShownTitlePage) == false) {
// TODO: removed this check because this was causing crashes possibly due to Locale

View File

@@ -525,6 +525,8 @@ extension BlockListViewController {
}
@objc func editDomains() {
let controller = EditDomainsViewController()
self.present(controller, animated: true)
print("editDomains .....")
}
}

View File

@@ -16,8 +16,8 @@ final class EditDomainsCell: UIView {
let title: String?
let status: String?
static func userBlocked(domain: String, isSelected: Bool) -> Contents {
let checkMark = isSelected ? UIImage(systemName: "checkmark.circle.fill") : UIImage(systemName: "checkmark.circle")
static func userBlocked(domain: String, isUnselected: Bool) -> Contents {
let checkMark = isUnselected ? UIImage(systemName: "circle") : UIImage(systemName: "checkmark.circle.fill")
let image = UIImage(named: "website_icon.png")
let status = NSLocalizedString("Blocked", comment: "")
return Contents(checkMark: checkMark, icon: image, title: domain, status: status)

View File

@@ -12,7 +12,7 @@ final class EditDomainsViewController: UIViewController {
// MARK: - Properties
private var didMakeChange = false
private var customBlockedDomains: [(String, Bool)] = []
var customBlockedDomains: [(String, Bool)] = []
private var titleName = NSLocalizedString("Edit Domains", comment: "")
@@ -21,10 +21,6 @@ final class EditDomainsViewController: UIViewController {
view.titleLabel.text = NSLocalizedString(titleName, comment: "")
view.leftNavButton.setTitle(NSLocalizedString("CLOSE", comment: ""), for: .normal)
view.leftNavButton.addTarget(self, action: #selector(closeButtonClicked), for: .touchUpInside)
view.rightNavButton.setTitle(NSLocalizedString("DONE", comment: ""), for: .normal)
view.rightNavButton.titleLabel?.font = fontBold13
view.rightNavButton.tintColor = .gray
view.rightNavButton.addTarget(self, action: #selector(doneButtonClicked), for: .touchUpInside)
return view
}()
@@ -115,15 +111,19 @@ private extension EditDomainsViewController {
}
for (domain, status) in customBlockedDomains {
var checkedStatus = status
let blockListView = EditDomainsCell()
// var statusChecked = status.toggle()
blockListView.contents = .userBlocked(domain: domain, isSelected: status)
blockListView.contents = .userBlocked(domain: domain, isUnselected: status)
let cell = tableView.addRow { (contentView) in
contentView.addSubview(blockListView)
blockListView.anchors.edges.pin()
}.onSelect { [unowned blockListView] in
self.didMakeChange = true
checkedStatus.toggle()
blockListView.contents = .userBlocked(domain: domain, isUnselected: checkedStatus)
self.bottomMenu.middleButton.setTitleColor(.tunnelsBlue, for: .normal)
self.bottomMenu.rightButton.setTitleColor(.red, for: .normal)
// TODO: - move domains to list
}
@@ -133,27 +133,18 @@ private extension EditDomainsViewController {
}
@objc func closeButtonClicked() {
print("Close btn pressed ....")
dismiss(animated: true)
}
@objc func doneButtonClicked() {
print("doneButtonTapped btn pressed ....")
}
@objc func selectAllddDomains() {
// let cell = CheckboxTableViewCell()
// cell.isChecked = false
// tableView.reloadData()
print("selectAllddDomains btn pressed ....")
let tableView = customBlockedDomainsTableView
tableView.reloadData()
}
@objc func moveToList() {
print("moveToList btn pressed ....")
}
@objc func deleteDomains() {
print("deleteDomains btn pressed ....")
let alert = UIAlertController(title: NSLocalizedString("Delete Entries?", comment: ""),
message: NSLocalizedString("Are you sure you want to remove these domains?", comment: ""),
preferredStyle: .alert)
@@ -164,10 +155,10 @@ private extension EditDomainsViewController {
}))
alert.addAction(UIAlertAction(title: NSLocalizedString("Yes, Delete", comment: ""),
style: UIAlertAction.Style.destructive,
handler: {(_: UIAlertAction!) in
// Delete action
// tableView.clear()
// tableView.reloadData()
handler: { [weak self] (_) in
guard let self else { return }
self.customBlockedDomainsTableView.clear()
self.customBlockedDomainsTableView.reloadData()
}))
self.present(alert, animated: true, completion: nil)
}