Clean UI
This commit is contained in:
parent
4723c98502
commit
0e0166f308
@ -96,7 +96,7 @@ enum ClientState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var openButtonText: String {
|
var actionText: String {
|
||||||
switch self {
|
switch self {
|
||||||
case .noKeyAvailable:
|
case .noKeyAvailable:
|
||||||
return "Create key"
|
return "Create key"
|
||||||
@ -104,19 +104,38 @@ enum ClientState {
|
|||||||
return "Unlock"
|
return "Unlock"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var openButtonColor: Color {
|
var requiresDescription: Bool {
|
||||||
switch self {
|
switch self {
|
||||||
case .noKeyAvailable, .requestingStatus:
|
|
||||||
return .yellow
|
|
||||||
case .deviceNotAvailable, .messageRejected, .internalError:
|
case .deviceNotAvailable, .messageRejected, .internalError:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var color: Color {
|
||||||
|
switch self {
|
||||||
|
case .noKeyAvailable:
|
||||||
|
return .gray
|
||||||
|
case .requestingStatus:
|
||||||
|
return .yellow
|
||||||
|
case .deviceNotAvailable:
|
||||||
|
return Color(red: 1.0, green: 0.6, blue: 0.6)
|
||||||
|
case .messageRejected:
|
||||||
return .red
|
return .red
|
||||||
case .ready, .waitingForResponse, .openSesame:
|
case .internalError:
|
||||||
|
return Color(red: 0.7, green: 0, blue: 0)
|
||||||
|
case .ready:
|
||||||
|
return Color(red: 0.7, green: 1.0, blue: 0.5)
|
||||||
|
case .waitingForResponse:
|
||||||
|
return Color(red: 0.9, green: 1.0, blue: 0.5)
|
||||||
|
case .openSesame:
|
||||||
return .green
|
return .green
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var openButtonIsEnabled: Bool {
|
var allowsAction: Bool {
|
||||||
switch self {
|
switch self {
|
||||||
case .requestingStatus, .deviceNotAvailable, .waitingForResponse:
|
case .requestingStatus, .deviceNotAvailable, .waitingForResponse:
|
||||||
return false
|
return false
|
||||||
|
@ -26,7 +26,7 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var buttonBackground: Color {
|
var buttonBackground: Color {
|
||||||
state.openButtonIsEnabled ?
|
state.allowsAction ?
|
||||||
.white.opacity(0.2) :
|
.white.opacity(0.2) :
|
||||||
.gray.opacity(0.2)
|
.gray.opacity(0.2)
|
||||||
}
|
}
|
||||||
@ -34,34 +34,28 @@ struct ContentView: View {
|
|||||||
let buttonBorderWidth: CGFloat = 3
|
let buttonBorderWidth: CGFloat = 3
|
||||||
|
|
||||||
var buttonColor: Color {
|
var buttonColor: Color {
|
||||||
state.openButtonIsEnabled ? .white : .gray
|
state.allowsAction ? .white : .gray
|
||||||
}
|
}
|
||||||
|
|
||||||
private let buttonWidth: CGFloat = 200
|
private let buttonWidth: CGFloat = 250
|
||||||
|
|
||||||
private let topButtonHeight: CGFloat = 60
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
GeometryReader { geo in
|
GeometryReader { geo in
|
||||||
VStack(spacing: 20) {
|
VStack(spacing: 20) {
|
||||||
Spacer()
|
Spacer()
|
||||||
HStack {
|
if state.requiresDescription {
|
||||||
if isPerformingRequests {
|
|
||||||
ProgressView()
|
|
||||||
.progressViewStyle(CircularProgressViewStyle())
|
|
||||||
}
|
|
||||||
Text(state.description)
|
Text(state.description)
|
||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
Button(state.openButtonText, action: mainButtonPressed)
|
Button(state.actionText, action: mainButtonPressed)
|
||||||
.frame(width: buttonWidth, height: buttonWidth, alignment: .center)
|
.frame(width: buttonWidth, height: buttonWidth, alignment: .center)
|
||||||
.background(buttonBackground)
|
.background(buttonBackground)
|
||||||
.cornerRadius(buttonWidth / 2)
|
.cornerRadius(buttonWidth / 2)
|
||||||
.overlay(RoundedRectangle(cornerRadius: buttonWidth / 2).stroke(lineWidth: buttonBorderWidth).foregroundColor(buttonColor))
|
.overlay(RoundedRectangle(cornerRadius: buttonWidth / 2).stroke(lineWidth: buttonBorderWidth).foregroundColor(buttonColor))
|
||||||
.foregroundColor(buttonColor)
|
.foregroundColor(buttonColor)
|
||||||
.font(.title)
|
.font(.title)
|
||||||
.disabled(!state.openButtonIsEnabled)
|
.disabled(!state.allowsAction)
|
||||||
.padding(20)
|
.padding(.bottom, (geo.size.width-buttonWidth) / 2)
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
if KeyManagement.hasKey {
|
if KeyManagement.hasKey {
|
||||||
@ -73,8 +67,8 @@ struct ContentView: View {
|
|||||||
endRegularStatusUpdates()
|
endRegularStatusUpdates()
|
||||||
}
|
}
|
||||||
.frame(width: geo.size.width, height: geo.size.height)
|
.frame(width: geo.size.width, height: geo.size.height)
|
||||||
.background(state.openButtonColor)
|
.background(state.color)
|
||||||
.animation(.easeInOut, value: state.openButtonColor)
|
.animation(.easeInOut, value: state.color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ final class KeyManagement {
|
|||||||
kSecClass as String: kSecClassInternetPassword,
|
kSecClass as String: kSecClassInternetPassword,
|
||||||
kSecAttrAccount as String: "account",
|
kSecAttrAccount as String: "account",
|
||||||
kSecAttrServer as String: "christophhagen.de",
|
kSecAttrServer as String: "christophhagen.de",
|
||||||
]//kSecAttrLabel as String: "sesame"]
|
kSecAttrLabel as String: "sesame"]
|
||||||
|
|
||||||
private static func loadKeys() -> Data? {
|
private static func loadKeys() -> Data? {
|
||||||
var query = query
|
var query = query
|
||||||
|
Loading…
Reference in New Issue
Block a user