linphone-iphone/Linphone/UI/Main/Contacts/Fragments/SipAddressesPopup.swift
2024-07-03 17:22:01 +02:00

86 lines
2.5 KiB
Swift

//
// SipAddressesPopup.swift
// Linphone
//
// Created by Benoît Martins on 03/07/2024.
//
import SwiftUI
import linphonesw
struct SipAddressesPopup: View {
@ObservedObject private var telecomManager = TelecomManager.shared
@ObservedObject private var sharedMainViewModel = SharedMainViewModel.shared
@ObservedObject var contactAvatarModel: ContactAvatarModel
@ObservedObject var contactViewModel: ContactViewModel
@Binding var isShowSipAddressesPopup: Bool
var body: some View {
GeometryReader { geometry in
VStack(alignment: .leading) {
HStack {
Text("contact_dialog_pick_phone_number_or_sip_address_title")
.default_text_style_800(styleSize: 16)
.padding(.bottom, 2)
Spacer()
Image("x")
.renderingMode(.template)
.resizable()
.foregroundStyle(Color.grayMain2c600)
.frame(width: 25, height: 25)
.padding(.all, 10)
}
.frame(maxWidth: .infinity)
ForEach(0..<contactAvatarModel.addresses.count, id: \.self) { index in
HStack {
HStack {
VStack {
Text("SIP address :")
.default_text_style_700(styleSize: 14)
.frame(maxWidth: .infinity, alignment: .leading)
Text(contactAvatarModel.addresses[index].dropFirst(4))
.default_text_style(styleSize: 14)
.frame(maxWidth: .infinity, alignment: .leading)
.lineLimit(1)
.fixedSize(horizontal: false, vertical: true)
}
Spacer()
}
.padding(.vertical, 15)
.padding(.horizontal, 10)
}
.background(.white)
.onTapGesture {
do {
let address = try Factory.Instance.createAddress(addr: contactAvatarModel.addresses[index])
withAnimation {
isShowSipAddressesPopup.toggle()
telecomManager.doCallOrJoinConf(address: address)
}
} catch {
Log.error("[ContactInnerActionsFragment] unable to create address for a new outgoing call : \(contactAvatarModel.addresses[index]) \(error) ")
}
}
}
}
.padding(.horizontal, 20)
.padding(.vertical, 20)
.background(.white)
.cornerRadius(20)
.frame(maxHeight: .infinity)
.shadow(color: Color.orangeMain500, radius: 0, x: 0, y: 2)
.frame(maxWidth: sharedMainViewModel.maxWidth)
.position(x: geometry.size.width / 2, y: geometry.size.height / 2)
}
}
}
#Preview {
SipAddressesPopup(contactAvatarModel: ContactAvatarModel(friend: nil, name: "", address: "", withPresence: false), contactViewModel: ContactViewModel(), isShowSipAddressesPopup: .constant(true))
}