Files
bundesmessenger-ios/bwi/SplashScreen/View/OnboardingBwiSplashScreen.swift
2022-09-19 11:53:45 +02:00

136 lines
4.8 KiB
Swift

/*
* Copyright (c) 2022 BWI GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import SwiftUI
@available(iOS 14.0, *)
/// The splash screen shown at the beginning of the onboarding flow.
struct OnboardingBwiSplashScreen: View {
// MARK: - Properties
// MARK: Private
@Environment(\.theme) private var theme
@Environment(\.layoutDirection) private var layoutDirection
/// The dimensions of the stack with the action buttons and page indicator.
@State private var overlayFrame: CGRect = .zero
@State private var showServerMaintananceAlert = false
@State private var showServerMaintananceDefaultAlert = false
@State private var showInvalidAppVersionAlert = false
@State private var isFetchingDowntime = false
// MARK: Public
@ObservedObject var viewModel: OnboardingBwiSplashScreenViewModel.Context
/// The main action buttons.
var startButton: some View {
Button(action: startButtonAction) {
if isFetchingDowntime {
ProgressView()
} else {
Text(BWIL10n.splashScreenStart)
.font(theme.fonts.body.bold())
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 32)
}
}
.foregroundColor(.white)
.background(theme.colors.accent)
.cornerRadius(5)
.padding([.leading, .trailing], 20)
}
var footer: some View {
Image("powered_by_BWI_blk")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 140, alignment: .center)
}
var body: some View {
ZStack {
VStack(spacing: 30) {
startButton
.padding()
Spacer()
footer
.padding()
}
}
.navigationTitle("")
.navigationBarHidden(true)
.alert(isPresented: $showServerMaintananceAlert) {
Alert(title: Text(BWIL10n.downtimeTitle),
message: Text(ServerDowntimeDefaultService().downtimeText()),
dismissButton: .destructive(Text(BWIL10n.downtimeAlertDismissButton)) {
viewModel.send(viewAction: .login)
})
}
.alert(isPresented: $showServerMaintananceDefaultAlert) {
Alert(title: Text(BWIL10n.downtimeTitle),
message: Text(BWIL10n.downtimeDefaultMessage),
dismissButton: .destructive(Text(BWIL10n.downtimeAlertDismissButton)) {
viewModel.send(viewAction: .login)
})
}
.alert(isPresented: $showInvalidAppVersionAlert) {
Alert(title: Text(BWIL10n.bwiOutdatedVersionWarningTitle),
message: Text(BWIL10n.bwiOutdatedVersionWarningMessage(AppInfo.current.displayName)),
dismissButton: .destructive(Text(BWIL10n.bwiOutdatedVersionAppstoreButton), action: {
let iTunesLink = "itms://itunes.apple.com/app/BwMessenger/id1518548153?mt=8"
UIApplication.shared.open(URL(string: iTunesLink)!, options: [:], completionHandler: nil)
}))
}
}
private func startButtonAction() {
// let service = ServerDowntimeDefaultService()
// if service.isDowntimePresentable() /*&& service.isDowntimeNow()*/ {
// showServerMaintananceAlert = true
// } else {
viewModel.send(viewAction: .login)
// }
// isFetchingDowntime = true // show progresview
//
// let service = ServerDowntimeDefaultService()
// service.fetchDowntimesWithDirectRequest { success in
// self.isFetchingDowntime = false // hide progressview
// if success {
// if service.isDowntimePresentable() && service.isDowntimeNow() {
// showServerMaintananceAlert = true
// } else {
// viewModel.send(viewAction: .login)
// }
// } else {
// showServerMaintananceDefaultAlert = true
// }
// }
}
}
// MARK: - Previews
@available(iOS 14.0, *)
struct OnboardingBwiSplashScreen_Previews: PreviewProvider {
static let stateRenderer = MockOnboardingBwiSplashScreenScreenState.stateRenderer
static var previews: some View {
stateRenderer.screenGroup()
}
}