mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-25 19:10:49 +02:00
Feature/4976 ignore blocking maintenance
This commit is contained in:
+115
-1
@@ -24,12 +24,19 @@ struct AuthenticationServerSelectionScreen: View {
|
||||
|
||||
@Environment(\.theme) private var theme
|
||||
|
||||
private let service = ServerDowntimeDefaultService()
|
||||
|
||||
@State private var showAlertForMissingCameraAuthorization = false
|
||||
@State private var showAlertForInvalidServer = false
|
||||
@State private var isEditingTextField = false
|
||||
@State private var presentQRCodeScanner = false
|
||||
@State private var qrCode = ""
|
||||
|
||||
// bwi #4976 show maintenance alert
|
||||
@State private var isFetchingDowntime = false
|
||||
@State private var showAlert = false
|
||||
@State private var activeAlert: OnBoardingSplashScreenAlertType = .showInvalidAppVersionAlert
|
||||
|
||||
private var textFieldFooterColor: Color {
|
||||
viewModel.viewState.hasValidationError ? theme.colors.alert : theme.colors.tertiaryContent
|
||||
}
|
||||
@@ -88,6 +95,69 @@ 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()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/// The title, message and icon at the top of the screen.
|
||||
@@ -157,7 +227,7 @@ struct AuthenticationServerSelectionScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
Button(action: submit) {
|
||||
Button(action: startButtonAction) {
|
||||
Text(viewModel.viewState.buttonTitle)
|
||||
}
|
||||
.buttonStyle(PrimaryActionButtonStyle())
|
||||
@@ -257,6 +327,50 @@ struct AuthenticationServerSelectionScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
// bwi #4295 ask for maintenance before going to login
|
||||
private func startButtonAction() {
|
||||
// #4295: Only ask for maintenance here when there is no server selection afterwards
|
||||
if BWIBuildSettings.shared.enableMaintenanceInfoOnLogin {
|
||||
isFetchingDowntime = true // show progresview
|
||||
|
||||
if BWIBuildSettings.shared.useTestDataForDowntime {
|
||||
service.fetchDowntimes {
|
||||
self.isFetchingDowntime = false // hide progressview
|
||||
self.showAlertIfNeeded()
|
||||
}
|
||||
} else {
|
||||
service.fetchDowntimesWithDirectRequest { success in
|
||||
DispatchQueue.main.async {
|
||||
self.isFetchingDowntime = false // hide progressview
|
||||
if success {
|
||||
self.showAlertIfNeeded()
|
||||
} else {
|
||||
showAlert = true
|
||||
activeAlert = .showServerMaintenanceDefaultAlert
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.submit()
|
||||
}
|
||||
}
|
||||
|
||||
private func showAlertIfNeeded() {
|
||||
switch service.nextDowntimeStatus() {
|
||||
case .none, .warning:
|
||||
self.submit()
|
||||
break
|
||||
case .ongoing:
|
||||
if service.downtimeType() == .adhocMessage {
|
||||
activeAlert = .showServerMaintenanceInfoMessageAlert
|
||||
} else {
|
||||
activeAlert = .showDowntimeTimeAlert
|
||||
}
|
||||
showAlert = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
Reference in New Issue
Block a user