Feature/3811 appconfig

This commit is contained in:
Frank Rotermund
2023-09-19 11:21:12 +00:00
parent e3cfb301a9
commit 5dd5dc2db7
13 changed files with 205 additions and 145 deletions

View File

@@ -17,10 +17,6 @@
import SwiftUI
import AVKit
enum AuthenticationServerSelectionScreenAlertType {
case showServerMaintenanceInfoMessageAlert, showServerMaintenanceDefaultAlert, showInvalidAppVersionAlert, showDowntimeTimeAlert, showInvalidServerAlert
}
struct AuthenticationServerSelectionScreen: View {
// MARK: - Properties
@@ -39,7 +35,8 @@ struct AuthenticationServerSelectionScreen: View {
// bwi #4976 show maintenance alert
@State private var isFetchingDowntime = false
@State private var showAlert = false
@State private var activeAlert: AuthenticationServerSelectionScreenAlertType = .showInvalidAppVersionAlert
@State private var isInvalidServerAlert = false
@State private var activeAlert: ServerMaintenanceAlertType = .showInvalidAppVersionAlert
private var textFieldFooterColor: Color {
viewModel.viewState.hasValidationError ? theme.colors.alert : theme.colors.tertiaryContent
@@ -98,67 +95,12 @@ struct AuthenticationServerSelectionScreen: View {
}
}
.alert(isPresented: $showAlert, content: {
switch activeAlert {
case .showInvalidAppVersionAlert:
return Alert(title: Text(BWIL10n.bwiOutdatedVersionWarningTitle),
message: Text(BWIL10n.bwiOutdatedVersionWarningMessage(AppInfo.current.displayName)),
dismissButton: .destructive(Text(BWIL10n.bwiOutdatedVersionAppstoreButton), action: {
let iTunesLink = BWIBuildSettings.shared.itunesAppLink
UIApplication.shared.open(URL(string: iTunesLink)!, options: [:], completionHandler: nil)
}))
case .showDowntimeTimeAlert:
if BWIBuildSettings.shared.ignoreBlockingMaintenance && service.isBlocking() {
return Alert( title: Text(""),
message: Text(ServerDowntimeDefaultService().downtimeText()),
primaryButton: .cancel(Text(BWIL10n.blockingDowntimeAlertIgnoreButton)) {
UserDefaults.standard.set(false, forKey: "ServerDownTimeBlockingKey")
service.setManuallyIgnored()
self.submit()
},
secondaryButton: .destructive(Text(BWIL10n.blockingDowntimeAlertDismissButton))
)
} else {
return Alert(title: Text(BWIL10n.downtimeTitle),
message: Text(ServerDowntimeDefaultService().downtimeText() != "" ? BWIL10n.downtimeDefaultMessage + "\n\n" + ServerDowntimeDefaultService().downtimeText() : BWIL10n.downtimeDefaultMessage),
dismissButton: .destructive(Text(service.isBlocking() ? BWIL10n.blockingDowntimeAlertDismissButton : BWIL10n.downtimeAlertDismissButton)) {
if service.isBlocking() {
return
} else {
self.submit()
}
})
}
case .showServerMaintenanceInfoMessageAlert:
if BWIBuildSettings.shared.ignoreBlockingMaintenance && service.isBlocking() {
return Alert( title: Text(""),
message: Text(ServerDowntimeDefaultService().downtimeText()),
primaryButton: .cancel(Text(BWIL10n.blockingDowntimeAlertIgnoreButton)) {
self.submit()
},
secondaryButton: .destructive(Text(BWIL10n.blockingDowntimeAlertDismissButton))
)
} else {
return Alert(title: Text(""),
message: Text(ServerDowntimeDefaultService().downtimeText()),
dismissButton: .destructive(Text(service.isBlocking() ? BWIL10n.blockingDowntimeAlertDismissButton : BWIL10n.downtimeAlertDismissButton)) {
if service.isBlocking() {
return
} else {
self.submit()
}
})
}
case .showServerMaintenanceDefaultAlert:
return Alert(title: Text(BWIL10n.downtimeTitle),
message: Text(BWIL10n.downtimeDefaultMessage),
dismissButton: .destructive(Text(BWIL10n.downtimeAlertDismissButton)) {
self.submit()
})
case .showInvalidServerAlert:
if isInvalidServerAlert {
return self.invalidServerAlert()
} else {
return service.alert(alertType: activeAlert) {
self.submit()
}
}
})
@@ -274,7 +216,7 @@ struct AuthenticationServerSelectionScreen: View {
if isHomeserverAddressValid(viewModel.homeserverAddress) {
viewModel.send(viewAction: .confirm)
} else {
activeAlert = .showInvalidServerAlert
isInvalidServerAlert = true
showAlert = true
}
}
@@ -362,18 +304,11 @@ struct AuthenticationServerSelectionScreen: View {
}
private func showAlertIfNeeded() {
switch service.nextDowntimeStatus() {
case .none, .warning:
self.submit()
break
case .ongoing:
if service.downtimeType() == .adhocMessage {
activeAlert = .showServerMaintenanceInfoMessageAlert
} else {
activeAlert = .showDowntimeTimeAlert
}
if service.showAlert() {
activeAlert = service.alertType()
showAlert = true
break
} else {
self.submit()
}
}
}