Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions RIADigiDoc/UI/Component/Container/Crypto/EncryptView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,6 @@ struct EncryptView: View {
await updateAsyncLabels()
await viewModel.updateAsyncProperties()

Toast.show(languageSettings.localized(
"Container successfully encrypted"
), type: .success)

encryptionButtonEnabled = true
}
}
Expand Down Expand Up @@ -466,9 +462,7 @@ struct EncryptView: View {
await updateAsyncLabels()
await viewModel.updateAsyncProperties()

Toast.show(languageSettings.localized(
"Container successfully decrypted"
), type: .success)
showMessage("Container successfully decrypted", type: .success)
isWithDecryption = false
} else {
await viewModel.loadContainerData(
Expand Down Expand Up @@ -579,7 +573,7 @@ struct EncryptView: View {

private func handlePasswordDecrypt(_ password: String) async {
guard let containerFile = viewModel.containerURL else {
Toast.show(languageSettings.localized("Decrypt general error"))
showMessage("Decrypt general error")
return
}
do {
Expand All @@ -596,14 +590,20 @@ struct EncryptView: View {
selectedTab = .files
await updateAsyncLabels()
await viewModel.updateAsyncProperties()
Toast.show(languageSettings.localized("Container successfully decrypted"), type: .success)
showMessage("Container successfully decrypted", type: .success)
} catch CryptoError.wrongDecryptionKey {
Toast.show(languageSettings.localized("Decrypt wrong password error"))
showMessage("Decrypt wrong password error")
} catch {
Toast.show(languageSettings.localized("Decrypt general error"))
showMessage("Decrypt general error")
}
}

private func showMessage(_ key: String, type: ToastType = .error) {
let message = languageSettings.localized(key)
Toast.show(message, type: type)
AccessibilityUtil.announceMessage(message)
}

func updateAsyncLabels() async {
let containerTitle = await containerTitle()
let encryptDecryptLabel = await self.encryptDecryptLabel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ struct EncryptPasswordModalView: View {
@State private var keyLabel: String = ""
@State private var password: String = ""
@State private var repeatPassword: String = ""
@FocusState private var focusedField: String?

private let keyLabelFieldId = "passwordKeyLabel"
private let passwordFieldId = "passwordInput"
private let repeatPasswordFieldId = "repeatPasswordInput"

let onEncrypt: (String, String) -> Void
let onCancel: () -> Void
Expand Down Expand Up @@ -79,8 +84,11 @@ struct EncryptPasswordModalView: View {
placeholder: keyLabelTitle,
text: $keyLabel,
submitLabel: .next,
identifier: "passwordKeyLabel",
accessibilityHint: languageSettings.localized("Crypto password key label description")
identifier: keyLabelFieldId,
accessibilityHint: languageSettings.localized("Crypto password key label description"),
textContentType: .oneTimeCode,
sharedFocus: $focusedField,
nextFocus: passwordFieldId
)
Text(verbatim: languageSettings.localized("Crypto password key label description"))
.font(typography.labelMedium)
Expand Down Expand Up @@ -141,8 +149,10 @@ struct EncryptPasswordModalView: View {
isSecure: true,
isError: showPasswordError,
submitLabel: .next,
identifier: "passwordInput",
sortPriority: 0
identifier: passwordFieldId,
sortPriority: 0,
sharedFocus: $focusedField,
nextFocus: repeatPasswordFieldId
)
VStack(alignment: .leading, spacing: Dimensions.Padding.ZeroPadding) {
ForEach(EncryptPasswordModalView.requirementKeys, id: \.self) { key in
Expand All @@ -167,7 +177,8 @@ struct EncryptPasswordModalView: View {
? languageSettings.localized("Crypto password repeat mismatch")
: "",
submitLabel: .done,
identifier: "repeatPasswordInput"
identifier: repeatPasswordFieldId,
sharedFocus: $focusedField
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct PasswordModalCard<Content: View>: View {
}

struct PasswordModalTitleView: View {
@Environment(\.accessibilityVoiceOverEnabled) private var voiceOverEnabled
@AppTheme private var theme
@AppTypography private var typography

Expand All @@ -84,11 +85,10 @@ struct PasswordModalTitleView: View {
.accessibilityHeading(.h1)
.accessibilityAddTraits([.isHeader])
.accessibilityFocused($isFocused)
.onAppear {
Task {
try? await Task.sleep(for: .seconds(0.3))
isFocused = true
}
.task(id: voiceOverEnabled) {
guard voiceOverEnabled else { return }
try? await Task.sleep(for: .seconds(0.3))
isFocused = true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,15 +505,21 @@ struct EncryptRecipientView: View {
do {
try await viewModel.encryptWithPassword(label: label, password: password)
showPasswordEncryptModal = false
showMessage("Container successfully encrypted", type: .success)
pathManager.replaceLast(
to: .encryptView(isWithEncryption: false, cdocOption: cdocOption, selectedTab: .recipients)
)
Toast.show(languageSettings.localized("Container successfully encrypted"), type: .success)
} catch {
Toast.show(languageSettings.localized("Encrypt general error"))
showMessage("Encrypt general error")
}
}

private func showMessage(_ key: String, type: ToastType = .error) {
let message = languageSettings.localized(key)
Toast.show(message, type: type)
AccessibilityUtil.announceMessage(message)
}

private func emptyStateView(_ text: String) -> some View {
ContentUnavailableView {
Text(verbatim: text)
Expand Down
57 changes: 35 additions & 22 deletions RIADigiDoc/UI/Component/Shared/FloatingLabelTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ struct FloatingLabelTextField: View {
let spellOutCharacters: Bool
let showBorder: Bool
let accessibilityHint: String
let textContentType: UITextContentType?
let sharedFocus: FocusState<String?>.Binding?
let nextFocus: String?
let onDone: (() -> Void)

init(
Expand All @@ -71,6 +74,9 @@ struct FloatingLabelTextField: View {
spellOutCharacters: Bool = false,
showBorder: Bool = true,
accessibilityHint: String = "",
textContentType: UITextContentType? = nil,
sharedFocus: FocusState<String?>.Binding? = nil,
nextFocus: String? = nil,
onDone: @escaping (() -> Void) = {}
) {
self.title = title
Expand All @@ -90,13 +96,20 @@ struct FloatingLabelTextField: View {
self.spellOutCharacters = spellOutCharacters
self.showBorder = showBorder
self.accessibilityHint = accessibilityHint
self.textContentType = textContentType
self.sharedFocus = sharedFocus
self.nextFocus = nextFocus
self.onDone = onDone
}

// MARK: - State
@State private var isPasswordVisible: Bool = false
@State private var isFocused: Bool = false
@FocusState private var fieldIsFocused: Bool
@FocusState private var privateFocus: String?

private var focus: FocusState<String?>.Binding { sharedFocus ?? $privateFocus }
private var focusKey: String { identifier.isEmpty ? "field" : identifier }
private var fieldIsFocused: Bool { focus.wrappedValue == focusKey }

// MARK: - Computed properties

Expand All @@ -118,7 +131,10 @@ struct FloatingLabelTextField: View {

// Dont show password saving options
private var fieldContentType: UITextContentType? {
isSecure ? .oneTimeCode : .init(rawValue: "")
if let textContentType {
return textContentType
}
return isSecure ? .oneTimeCode : .init(rawValue: "")
}

private var isInteractionEnabled: Bool {
Expand Down Expand Up @@ -323,17 +339,10 @@ struct FloatingLabelTextField: View {
contentType: fieldContentType,
isAccessibilityFocused: $isAccessibilityFocused,
onAppear: {},
onSubmit: {
isFocused = false
isAccessibilityFocused = true
onDone()
}
onSubmit: submit
)
.privacySensitive()
.toolbar { keyboardToolbar }
.onChange(of: errorText, { _, newValue in
AccessibilityUtil.announceMessage(newValue)
})
.accessibilitySortPriority(sortPriority)
.accessibilityLabel(Text(verbatim: title))
} else {
Expand All @@ -353,11 +362,7 @@ struct FloatingLabelTextField: View {
onAppear: {
selection = TextSelection(insertionPoint: text.endIndex)
},
onSubmit: {
fieldIsFocused = false
isAccessibilityFocused = true
onDone()
}
onSubmit: submit
)
.toolbar { keyboardToolbar }
.accessibilitySortPriority(sortPriority)
Expand All @@ -366,15 +371,17 @@ struct FloatingLabelTextField: View {
}
.font(typography.bodyLarge)
.foregroundStyle(textColor)
.focused($fieldIsFocused)
.onChange(of: fieldIsFocused) { _, newValue in
.focused(focus, equals: focusKey)
.onChange(of: focus.wrappedValue) { _, newFocus in
let newValue = newFocus == focusKey
if isInteractionEnabled {
withAnimation(.easeInOut(duration: Dimensions.Duration.focusAnimation)) {
isFocused = newValue
}
}
}
.onChange(of: errorText, { _, newValue in
guard !newValue.isEmpty else { return }
AccessibilityUtil.announceMessage(newValue)
})
.accessibilityHint(Text(verbatim: accessibilityHint))
Expand Down Expand Up @@ -406,13 +413,19 @@ struct FloatingLabelTextField: View {
)
}

private func submit() {
if let nextFocus {
focus.wrappedValue = nextFocus
} else {
focus.wrappedValue = nil
isAccessibilityFocused = true
}
onDone()
}

private var doneButton: some View {
Button(
action: {
fieldIsFocused = false
isAccessibilityFocused = true
onDone()
},
action: submit,
label: { Text(verbatim: languageSettings.localized("Done")) }
)
}
Expand Down
2 changes: 1 addition & 1 deletion RIADigiDoc/UI/Component/Toast/Toast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import SwiftUI
struct Toast {
static func show(
_ message: String,
duration: TimeInterval = 5.0,
duration: TimeInterval = 4.0,
type: ToastType = .error
) {
if message.isEmpty { return }
Expand Down
3 changes: 2 additions & 1 deletion RIADigiDoc/ViewModel/CryptoFileOpeningViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ class CryptoFileOpeningViewModel: CryptoFileOpeningViewModelProtocol, Loggable {
CryptoFileOpeningViewModel.logger().error("\(dde)")
errorMessage = createToastMessage(for: dde)
} else {
errorMessage = ToastMessage(key: error.localizedDescription)
CryptoFileOpeningViewModel.logger().error("\(error.localizedDescription)")
errorMessage = ToastMessage(key: "General error")
}
}

Expand Down
24 changes: 12 additions & 12 deletions RIADigiDoc/ViewModel/EncryptViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class EncryptViewModel: EncryptViewModelProtocol, Loggable {
private let fileInspector: FileInspectorProtocol
private let sivaRepository: SivaRepositoryProtocol

var encryptAction: (URL, [URL], [Addressee]) async throws -> any CryptoContainerProtocol =
CryptoContainer.encrypt

private(set) var cryptoContainer: CryptoContainerProtocol?

private(set) var isContainerWithoutRecipients = false
Expand Down Expand Up @@ -297,14 +300,16 @@ class EncryptViewModel: EncryptViewModelProtocol, Loggable {

public func encryptContainer() async {
await loadContainerData(cryptoContainer: nil)
guard let cryptoContainer else { return }
guard let containerFile = await cryptoContainer.getRawContainerFile() else { return }
guard let cryptoContainer else {
errorMessage = ToastMessage(key: "Encrypt general error", args: [])
return
}
guard let containerFile = await cryptoContainer.getRawContainerFile() else {
errorMessage = ToastMessage(key: "Encrypt general error", args: [])
return
}
do {
let encryptedContainer = try await CryptoContainer.encrypt(
containerFile: containerFile,
dataFiles: dataFiles,
recipients: recipients
)
let encryptedContainer = try await encryptAction(containerFile, dataFiles, recipients)
sharedContainerViewModel.clearContainers()
sharedContainerViewModel.setCryptoContainer(encryptedContainer)
await loadContainerData(
Expand All @@ -329,11 +334,6 @@ class EncryptViewModel: EncryptViewModelProtocol, Loggable {
return
}

if let nsError = error as NSError? {
errorMessage = ToastMessage(key: nsError.localizedDescription, args: [])
return
}

errorMessage = ToastMessage(key: "Encrypt general error", args: [])
}

Expand Down
Loading
Loading