Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljohanneskraft committed Sep 25, 2024
1 parent 6d556aa commit 17219c4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
65 changes: 34 additions & 31 deletions Sources/SpeziContact/Models/ContactOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,30 @@ extension ContactOption {
UIApplication.shared.open(url)
}
}



/// A ``ContactOption`` encoding a possibility to call an individual using a phone number.
/// - Parameter number: The phone number to be called.
public static func call(_ number: String) -> ContactOption {
ContactOption(
image: Image(systemName: "phone.fill"),
title: String(localized: "Call", bundle: .module, comment: "Contact Option"),
action: CallContactOptionAction(number: number)
)
private struct EmailContactOptionAction: ContactOptionAction {
let addresses: [String]
let subject: String?

func handle() {
guard let subject = (subject ?? "").addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
let url = URL(string: "mailto:\(addresses.joined(separator: ";"))?subject=\(subject)"), UIApplication.shared.canOpenURL(url) else {
presentAlert(
title: String(localized: "Email", bundle: .module),
message: String(
localized: "Email unavailable. You can manually reach out to \(addresses.joined(separator: ", "))",
bundle: .module,
comment: "Email unavailable. Manual approach."
)
)
return
}
UIApplication.shared.open(url)
}
}



private struct TextContactOptionAction: ContactOptionAction {
let number: String

Expand All @@ -104,6 +116,18 @@ extension ContactOption {
UIApplication.shared.open(url)
}
}


/// A ``ContactOption`` encoding a possibility to call an individual using a phone number.
/// - Parameter number: The phone number to be called.
public static func call(_ number: String) -> ContactOption {
ContactOption(
image: Image(systemName: "phone.fill"),
title: String(localized: "Call", bundle: .module, comment: "Contact Option"),
action: CallContactOptionAction(number: number)
)
}


/// A ``ContactOption`` encoding a possibility to text an individual using a phone numer.
/// - Parameter number: The phone number to text to.
Expand All @@ -115,27 +139,6 @@ extension ContactOption {
)
}

private struct EmailContactOptionAction: ContactOptionAction {
let addresses: [String]
let subject: String?

func handle() {
guard let subject = (subject ?? "").addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
let url = URL(string: "mailto:\(addresses.joined(separator: ";"))?subject=\(subject)"), UIApplication.shared.canOpenURL(url) else {
presentAlert(
title: String(localized: "Email", bundle: .module),
message: String(
localized: "Email unavailable. You can manually reach out to \(addresses.joined(separator: ", "))",
bundle: .module,
comment: "Email unavailable. Manual approach."
)
)
return
}
UIApplication.shared.open(url)
}
}


/// A ``ContactOption`` encoding a possibility to email an individual using a collection of email addresses.
/// - Parameters:
Expand Down
8 changes: 7 additions & 1 deletion Sources/SpeziContact/Models/ContactOptionAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
// SPDX-License-Identifier: MIT
//


/// A type handling the action to be performed by a ContactOption.
public protocol ContactOptionAction {
@MainActor func handle()

Check failure on line 12 in Sources/SpeziContact/Models/ContactOptionAction.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint / SwiftLint

Vertical Whitespace after Opening Braces Violation: Don't include vertical whitespace (empty line) after opening braces (vertical_whitespace_opening_braces)
/// Handles the event of the contact option being selected by performing the action.
@MainActor
func handle()

Check failure on line 16 in Sources/SpeziContact/Models/ContactOptionAction.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint / SwiftLint

Vertical Whitespace before Closing Braces Violation: Don't include vertical whitespace (empty line) before closing braces (vertical_whitespace_closing_braces)
}

0 comments on commit 17219c4

Please sign in to comment.