mirror of
https://github.com/home-assistant/iOS.git
synced 2026-06-19 07:24:05 -05:00
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> I couldn't find the explanation for why this happens but having THClient as a class variable inside ThreadClientService makes notifications attachment to not be displayed. Besides that this PR also clean up some ghosts folders that I created and forgot to delete and rename THClientService protocol to not have prefix TH avoiding confusion with Apple prefixes ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
118 lines
3.7 KiB
Swift
118 lines
3.7 KiB
Swift
import Shared
|
|
import SwiftUI
|
|
|
|
struct ThreadCredentialDetailsView: View {
|
|
enum ActionButtonState {
|
|
case standard
|
|
case loading
|
|
case success
|
|
case error
|
|
}
|
|
|
|
@EnvironmentObject private var viewModel: ThreadCredentialsManagementViewModel
|
|
@State private var actionButtonState: ActionButtonState = .standard
|
|
private let feedbackGenerator = UINotificationFeedbackGenerator()
|
|
|
|
let source: HAThreadNetworkConfig.Source
|
|
let credential: ThreadCredential
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
infoRow(header: L10n.Thread.BorderAgentId.title, value: credential.borderAgentID)
|
|
infoRow(header: L10n.Thread.NetworkKey.title, value: credential.networkKey)
|
|
infoRow(header: L10n.Thread.ExtendedPanId.title, value: credential.extendedPANID)
|
|
infoRow(header: L10n.Thread.ActiveOperationalDataSet.title, value: credential.activeOperationalDataSet)
|
|
transferButton
|
|
}
|
|
}
|
|
|
|
private var transferButton: some View {
|
|
Button {
|
|
feedbackGenerator.prepare()
|
|
actionButtonState = .loading
|
|
viewModel.transfer(credential, to: source == .HomeAssistant ? .Apple : .HomeAssistant) { success in
|
|
defer {
|
|
resetActionButtonState()
|
|
}
|
|
|
|
if success {
|
|
actionButtonState = .success
|
|
feedbackGenerator.notificationOccurred(.success)
|
|
} else {
|
|
actionButtonState = .error
|
|
feedbackGenerator.notificationOccurred(.error)
|
|
}
|
|
}
|
|
} label: {
|
|
switch actionButtonState {
|
|
case .standard:
|
|
Text(
|
|
source == .HomeAssistant ? L10n.Thread.TransterToApple.title : L10n.Thread.TransterToHomeassistant
|
|
.title
|
|
)
|
|
case .loading:
|
|
ProgressView()
|
|
.progressViewStyle(.circular)
|
|
case .success:
|
|
Image(systemName: "checkmark.circle")
|
|
case .error:
|
|
Image(systemName: "xmark.circle")
|
|
}
|
|
}
|
|
.buttonStyle(.plain)
|
|
.disabled(actionButtonState != .standard)
|
|
.frame(maxWidth: .infinity)
|
|
.frame(height: 50)
|
|
.background(actionButtonbackgroundColor)
|
|
.foregroundColor(.white)
|
|
.clipShape(RoundedRectangle(cornerRadius: 8))
|
|
.padding(.top)
|
|
}
|
|
|
|
private func resetActionButtonState() {
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
|
|
actionButtonState = .standard
|
|
}
|
|
}
|
|
|
|
private var actionButtonbackgroundColor: some View {
|
|
switch actionButtonState {
|
|
case .standard, .loading:
|
|
Color.asset(Asset.Colors.haPrimary)
|
|
case .success:
|
|
Color.green
|
|
case .error:
|
|
Color.red
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private func infoRow(header: String, value: String) -> some View {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text(header)
|
|
.font(.footnote)
|
|
.foregroundColor(.gray)
|
|
Text(value)
|
|
.textSelection(.enabled)
|
|
.lineLimit(1)
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
ThreadCredentialDetailsView(
|
|
source: .Apple,
|
|
credential: .init(
|
|
networkName: "MyHOme987654",
|
|
networkKey: "23456",
|
|
extendedPANID: "23456",
|
|
borderAgentID: "23456",
|
|
macExtendedAddress: "123",
|
|
activeOperationalDataSet: "2456",
|
|
pskc: "23456",
|
|
channel: 25,
|
|
panID: "23456"
|
|
)
|
|
)
|
|
}
|