Skip to content

Commit

Permalink
Update API access methods functionality UI to conform with designs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Petersson committed Jan 11, 2024
1 parent b5decd1 commit fc0b70c
Show file tree
Hide file tree
Showing 68 changed files with 1,394 additions and 2,179 deletions.
32 changes: 14 additions & 18 deletions ios/MullvadSettings/AccessMethodRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,34 @@ public class AccessMethodRepository: AccessMethodRepositoryProtocol {
public static let shared = AccessMethodRepository()

private init() {
add(passthroughSubject.value)
}

public func add(_ method: PersistentAccessMethod) {
add([method])
}

public func add(_ methods: [PersistentAccessMethod]) {
var storedMethods = fetchAll()

methods.forEach { method in
guard !storedMethods.contains(where: { $0.id == method.id }) else { return }
storedMethods.append(method)
passthroughSubject.value.forEach { method in
if !storedMethods.contains(where: { $0.id == method.id }) {
storedMethods.append(method)
}
}

do {
try writeApiAccessMethods(storedMethods)
} catch {
print("Could not add access method(s): \(methods) \nError: \(error)")
print("Could not update access methods: \(storedMethods) \nError: \(error)")
}
}

public func update(_ method: PersistentAccessMethod) {
var methods = fetchAll()
public func save(_ method: PersistentAccessMethod) {
var storedMethods = fetchAll()

guard let index = methods.firstIndex(where: { $0.id == method.id }) else { return }
methods[index] = method
if let index = storedMethods.firstIndex(where: { $0.id == method.id }) {
storedMethods[index] = method
} else {
storedMethods.append(method)
}

do {
try writeApiAccessMethods(methods)
try writeApiAccessMethods(storedMethods)
} catch {
print("Could not update access method: \(method) \nError: \(error)")
print("Could not update access methods: \(storedMethods) \nError: \(error)")
}
}

Expand Down
7 changes: 1 addition & 6 deletions ios/MullvadSettings/AccessMethodRepositoryProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Combine
import Foundation

public protocol AccessMethodRepositoryDataSource {
/// Publisher that propagates a snapshot of persistent store upon modifications.
Expand All @@ -17,11 +16,7 @@ public protocol AccessMethodRepositoryDataSource {
public protocol AccessMethodRepositoryProtocol: AccessMethodRepositoryDataSource {
/// Add new access method.
/// - Parameter method: persistent access method model.
func add(_ method: PersistentAccessMethod)

/// Persist modified access method locating existing entry by id.
/// - Parameter method: persistent access method model.
func update(_ method: PersistentAccessMethod)
func save(_ method: PersistentAccessMethod)

/// Delete access method by id.
/// - Parameter id: an access method id.
Expand Down
146 changes: 30 additions & 116 deletions ios/MullvadVPN.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

116 changes: 0 additions & 116 deletions ios/MullvadVPN/AccessMethodRepository/AccessMethodRepository.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ProxyConfigurationTester: ProxyConfigurationTesterProtocol {
}

func cancel() {
cancellable?.cancel()
cancellable = nil
}
}
3 changes: 2 additions & 1 deletion ios/MullvadVPN/Coordinators/ApplicationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
presentTOS(animated: animated, completion: completion)

case .main:
presentMain(animated: animated, completion: completion)
// presentMain(animated: animated, completion: completion)
presentSettings(route: .apiAccess, animated: false, completion: completion)

case .welcome:
presentWelcome(animated: animated, completion: completion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@

import UIKit

/// View controller used for presenting a detailed information on some topic using markdown in a scrollable text view.
/// View controller used for presenting a detailed information on some topic using a scrollable stack view.
class AboutViewController: UIViewController {
private let textView = UITextView()
private let markdown: String
private let scrollView = UIScrollView()
private let contentView = UIStackView()
private let header: String?
private let preamble: String?
private let body: [String]

init(header: String?, preamble: String?, body: [String]) {
self.header = header
self.preamble = preamble
self.body = body

init(markdown: String) {
self.markdown = markdown
super.init(nibName: nil, bundle: nil)
}

Expand All @@ -25,20 +31,62 @@ class AboutViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.paragraphSpacing = 16
view.backgroundColor = .secondaryColor
navigationController?.navigationBar.configureCustomAppeareance()

setUpContentView()

scrollView.addConstrainedSubviews([contentView]) {
contentView.pinEdgesToSuperview()
contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor)
}

view.addConstrainedSubviews([scrollView]) {
scrollView.pinEdgesToSuperview()
}
}

private func setUpContentView() {
contentView.axis = .vertical
contentView.spacing = 15
contentView.layoutMargins = UIMetrics.contentInsets
contentView.isLayoutMarginsRelativeArrangement = true

if let header {
let label = UILabel()

label.text = header
label.font = .systemFont(ofSize: 28, weight: .bold)
label.textColor = .white
label.numberOfLines = 0
label.textAlignment = .center

contentView.addArrangedSubview(label)
contentView.setCustomSpacing(32, after: label)
}

if let preamble {
let label = UILabel()

label.text = preamble
label.font = .systemFont(ofSize: 18)
label.textColor = .white
label.numberOfLines = 0
label.textAlignment = .center

contentView.addArrangedSubview(label)
contentView.setCustomSpacing(24, after: label)
}

let stylingOptions = MarkdownStylingOptions(
font: .systemFont(ofSize: 17),
paragraphStyle: paragraphStyle
)
for text in body {
let label = UILabel()

textView.attributedText = NSAttributedString(markdownString: markdown, options: stylingOptions)
textView.textContainerInset = UIMetrics.contentInsets
textView.isEditable = false
label.text = text
label.font = .systemFont(ofSize: 15)
label.textColor = .white
label.numberOfLines = 0

view.addConstrainedSubviews([textView]) {
textView.pinEdgesToSuperview()
contentView.addArrangedSubview(label)
}
}
}
Loading

0 comments on commit fc0b70c

Please sign in to comment.