From 4048fa3075e5a254f249e1b93d733ab8296a6799 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Thu, 25 Jan 2024 13:57:57 +0100 Subject: [PATCH] Add transfer call feature --- Linphone/Localizable.xcstrings | 6 +++++ Linphone/UI/Call/CallView.swift | 24 ++++++++++++------ .../UI/Call/ViewModel/CallViewModel.swift | 1 + Linphone/UI/Main/ContentView.swift | 3 ++- .../History/Fragments/StartCallFragment.swift | 25 +++++++++++++++++-- 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/Linphone/Localizable.xcstrings b/Linphone/Localizable.xcstrings index 7b60b114f..ecffb1921 100644 --- a/Linphone/Localizable.xcstrings +++ b/Linphone/Localizable.xcstrings @@ -187,6 +187,9 @@ } } } + }, + "Attended transfer" : { + }, "Block the address" : { @@ -567,6 +570,9 @@ }, "Transfer" : { + }, + "Transfer call to" : { + }, "Transport" : { diff --git a/Linphone/UI/Call/CallView.swift b/Linphone/UI/Call/CallView.swift index ddf800f88..999f0c691 100644 --- a/Linphone/UI/Call/CallView.swift +++ b/Linphone/UI/Call/CallView.swift @@ -741,19 +741,23 @@ struct CallView: View { HStack(spacing: 0) { VStack { Button { + withAnimation { + callViewModel.isTransferInsteadCall = true + MagicSearchSingleton.shared.searchForSuggestions() + isShowStartCallFragment.toggle() + } } label: { Image("phone-transfer") .renderingMode(.template) .resizable() - .foregroundStyle(Color.gray500) + .foregroundStyle(.white) .frame(width: 32, height: 32) } .frame(width: 60, height: 60) - .background(Color.gray600) + .background(Color.gray500) .cornerRadius(40) - .disabled(true) - Text("Transfer") + Text(callViewModel.calls.count < 2 ? "Transfer" : "Attended transfer") .foregroundStyle(.white) .default_text_style(styleSize: 15) } @@ -942,19 +946,23 @@ struct CallView: View { HStack { VStack { Button { + withAnimation { + callViewModel.isTransferInsteadCall = true + MagicSearchSingleton.shared.searchForSuggestions() + isShowStartCallFragment.toggle() + } } label: { Image("phone-transfer") .renderingMode(.template) .resizable() - .foregroundStyle(Color.gray500) + .foregroundStyle(.white) .frame(width: 32, height: 32) } .frame(width: 60, height: 60) - .background(Color.gray600) + .background(Color.gray500) .cornerRadius(40) - .disabled(true) - Text("Transfer") + Text(callViewModel.calls.count < 2 ? "Transfer" : "Attended transfer") .foregroundStyle(.white) .default_text_style(styleSize: 15) } diff --git a/Linphone/UI/Call/ViewModel/CallViewModel.swift b/Linphone/UI/Call/ViewModel/CallViewModel.swift index 7835dd9ef..cfd34c8eb 100644 --- a/Linphone/UI/Call/ViewModel/CallViewModel.swift +++ b/Linphone/UI/Call/ViewModel/CallViewModel.swift @@ -44,6 +44,7 @@ class CallViewModel: ObservableObject { @Published var isZrtpPq: Bool = false @Published var isRemoteDeviceTrusted: Bool = false @Published var selectedCall: Call? = nil + @Published var isTransferInsteadCall: Bool = false var calls: [Call] = [] diff --git a/Linphone/UI/Main/ContentView.swift b/Linphone/UI/Main/ContentView.swift index c830d265f..609f0eca7 100644 --- a/Linphone/UI/Main/ContentView.swift +++ b/Linphone/UI/Main/ContentView.swift @@ -524,6 +524,7 @@ struct ContentView: View { if isShowStartCallFragment { if #available(iOS 16.4, *), idiom != .pad { StartCallFragment( + callViewModel: callViewModel, startCallViewModel: startCallViewModel, isShowStartCallFragment: $isShowStartCallFragment, showingDialer: $showingDialer, @@ -538,11 +539,11 @@ struct ContentView: View { currentCall: nil ) .presentationDetents([.medium]) - // .interactiveDismissDisabled() .presentationBackgroundInteraction(.enabled(upThrough: .medium)) } } else { StartCallFragment( + callViewModel: callViewModel, startCallViewModel: startCallViewModel, isShowStartCallFragment: $isShowStartCallFragment, showingDialer: $showingDialer, diff --git a/Linphone/UI/Main/History/Fragments/StartCallFragment.swift b/Linphone/UI/Main/History/Fragments/StartCallFragment.swift index c113de297..2f90d0c43 100644 --- a/Linphone/UI/Main/History/Fragments/StartCallFragment.swift +++ b/Linphone/UI/Main/History/Fragments/StartCallFragment.swift @@ -26,6 +26,7 @@ struct StartCallFragment: View { @ObservedObject var magicSearch = MagicSearchSingleton.shared @ObservedObject private var telecomManager = TelecomManager.shared + @ObservedObject var callViewModel: CallViewModel @ObservedObject var startCallViewModel: StartCallViewModel @Binding var isShowStartCallFragment: Bool @@ -59,6 +60,12 @@ struct StartCallFragment: View { DispatchQueue.global().asyncAfter(deadline: .now() + 0.2) { magicSearch.searchForContacts( sourceFlags: MagicSearch.Source.Friends.rawValue | MagicSearch.Source.LdapServers.rawValue) + + if callViewModel.isTransferInsteadCall == true { + callViewModel.isTransferInsteadCall = false + } + + resetCallView() } startCallViewModel.searchField = "" @@ -69,7 +76,7 @@ struct StartCallFragment: View { } } - Text("New call") + Text(!callViewModel.isTransferInsteadCall ? "New call" : "Transfer call to") .multilineTextAlignment(.leading) .default_text_style_orange_800(styleSize: 16) @@ -176,6 +183,10 @@ struct StartCallFragment: View { magicSearch.searchForContacts( sourceFlags: MagicSearch.Source.Friends.rawValue | MagicSearch.Source.LdapServers.rawValue) + if callViewModel.isTransferInsteadCall == true { + callViewModel.isTransferInsteadCall = false + } + resetCallView() } @@ -230,6 +241,10 @@ struct StartCallFragment: View { magicSearch.searchForContacts( sourceFlags: MagicSearch.Source.Friends.rawValue | MagicSearch.Source.LdapServers.rawValue) + if callViewModel.isTransferInsteadCall == true { + callViewModel.isTransferInsteadCall = false + } + resetCallView() } @@ -283,5 +298,11 @@ struct StartCallFragment: View { } #Preview { - StartCallFragment(startCallViewModel: StartCallViewModel(), isShowStartCallFragment: .constant(true), showingDialer: .constant(false), resetCallView: {}) + StartCallFragment( + callViewModel: CallViewModel(), + startCallViewModel: StartCallViewModel(), + isShowStartCallFragment: .constant(true), + showingDialer: .constant(false), + resetCallView: {} + ) }