/* * Copyright (c) 2010-2023 Belledonne Communications SARL. * * This file is part of Linphone * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import SwiftUI struct ToastView: View { @ObservedObject private var toastViewModel = ToastViewModel.shared var body: some View { VStack { if toastViewModel.displayToast { HStack { if toastViewModel.toastMessage.contains("toast_call_transfer") { Image("phone-transfer") .resizable() .renderingMode(.template) .frame(width: 25, height: 25, alignment: .leading) .foregroundStyle(toastViewModel.toastMessage.contains("Success") ? Color.greenSuccess500 : Color.redDanger500) } else if toastViewModel.toastMessage.contains("Info_") { Image("trusted") .resizable() .frame(width: 25, height: 25, alignment: .leading) } else { Image(toastViewModel.toastMessage.contains("Success") ? "check" : "warning-circle") .resizable() .renderingMode(.template) .frame(width: 25, height: 25, alignment: .leading) .foregroundStyle(toastViewModel.toastMessage.contains("Success") ? Color.greenSuccess500 : Color.redDanger500) } switch toastViewModel.toastMessage { case "Successful": Text("QR code validated!") .multilineTextAlignment(.center) .foregroundStyle(Color.greenSuccess500) .default_text_style(styleSize: 15) .padding(8) case "Success_remove_call_logs": Text("History has been deleted") .multilineTextAlignment(.center) .foregroundStyle(Color.greenSuccess500) .default_text_style(styleSize: 15) .padding(8) case "Success_clear_logs": Text("Logs cleared") .multilineTextAlignment(.center) .foregroundStyle(Color.greenSuccess500) .default_text_style(styleSize: 15) .padding(8) case "Success_send_logs": Text("Logs URL copied into clipboard") .multilineTextAlignment(.center) .foregroundStyle(Color.greenSuccess500) .default_text_style(styleSize: 15) .padding(8) case "Success_copied_into_clipboard": Text("SIP address copied into clipboard") .multilineTextAlignment(.center) .foregroundStyle(Color.greenSuccess500) .default_text_style(styleSize: 15) .padding(8) case "Info_call_securised": Text("This call is completely securised") .multilineTextAlignment(.center) .foregroundStyle(Color.blueInfo500) .default_text_style(styleSize: 15) .padding(8) case let str where str.contains("is recording"): Text(toastViewModel.toastMessage) .multilineTextAlignment(.center) .foregroundStyle(Color.redDanger500) .default_text_style(styleSize: 15) .padding(8) case "Failed": Text("Invalid QR code!") .multilineTextAlignment(.center) .foregroundStyle(Color.redDanger500) .default_text_style(styleSize: 15) .padding(8) case "Invalide URI": Text("Invalide URI") .multilineTextAlignment(.center) .foregroundStyle(Color.redDanger500) .default_text_style(styleSize: 15) .padding(8) case "Registration failed": Text("The user name or password is incorrects") .multilineTextAlignment(.center) .foregroundStyle(Color.redDanger500) .default_text_style(styleSize: 15) .padding(8) case "Success_toast_call_transfer_successful": Text("Call has been successfully transferred") .multilineTextAlignment(.center) .foregroundStyle(Color.greenSuccess500) .default_text_style(styleSize: 15) .padding(8) case "Success_toast_call_transfer_in_progress": Text("Call is being transferred") .multilineTextAlignment(.center) .foregroundStyle(Color.greenSuccess500) .default_text_style(styleSize: 15) .padding(8) case "Failed_toast_call_transfer_failed": Text("Call transfer failed!") .multilineTextAlignment(.center) .foregroundStyle(Color.redDanger500) .default_text_style(styleSize: 15) .padding(8) default: Text("Error") .multilineTextAlignment(.center) .foregroundStyle(Color.redDanger500) .default_text_style(styleSize: 15) .padding(8) } } .frame(maxWidth: .infinity) .background(.white) .cornerRadius(50) .overlay( RoundedRectangle(cornerRadius: 50) .inset(by: 0.5) .stroke(toastViewModel.toastMessage.contains("Success") ? Color.greenSuccess500 : (toastViewModel.toastMessage.contains("Info_") ? Color.blueInfo500 : Color.redDanger500), lineWidth: 1) ) .onTapGesture { if !toastViewModel.toastMessage.contains("is recording") { withAnimation { toastViewModel.toastMessage = "" toastViewModel.displayToast = false } } } .onAppear { if !toastViewModel.toastMessage.contains("is recording") { DispatchQueue.main.asyncAfter(deadline: .now() + 2) { withAnimation { toastViewModel.toastMessage = "" toastViewModel.displayToast = false } } } } Spacer() } } .frame(maxWidth: SharedMainViewModel.shared.maxWidth) .padding(.horizontal, 16) .padding(.bottom, 18) .transition(.move(edge: .top)) .padding(.top, 60) } }