From b4a19c9fd0ae560de1682c4d3204c8b18d3fee5e Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Mon, 9 Jun 2025 17:00:42 +0200 Subject: [PATCH] Refactored AccountProfile --- .../Fragments/RegisterFragment.swift | 5 +- .../Viewmodel/RegisterViewModel.swift | 33 +- Linphone/UI/Main/ContentView.swift | 82 +-- Linphone/UI/Main/Fragments/SideMenu.swift | 5 +- .../Main/Fragments/SideMenuAccountRow.swift | 2 +- .../Fragments/HistoryListFragment.swift | 4 +- .../History/Fragments/StartCallFragment.swift | 500 +++++++++--------- .../UI/Main/History/Model/HistoryModel.swift | 9 +- .../Fragments/AccountProfileFragment.swift | 6 +- .../ViewModel/AccountProfileViewModel.swift | 22 +- .../Main/Viewmodel/SharedMainViewModel.swift | 30 ++ 11 files changed, 346 insertions(+), 352 deletions(-) diff --git a/Linphone/UI/Assistant/Fragments/RegisterFragment.swift b/Linphone/UI/Assistant/Fragments/RegisterFragment.swift index 3ae61bb2e..025ae5f27 100644 --- a/Linphone/UI/Assistant/Fragments/RegisterFragment.swift +++ b/Linphone/UI/Assistant/Fragments/RegisterFragment.swift @@ -24,6 +24,7 @@ import SwiftUI struct RegisterFragment: View { @ObservedObject var registerViewModel: RegisterViewModel + @ObservedObject var sharedMainViewModel = SharedMainViewModel.shared @Environment(\.dismiss) var dismiss @@ -154,8 +155,8 @@ struct RegisterFragment: View { HStack { Menu { Picker("", selection: $registerViewModel.dialPlanValueSelected) { - ForEach(Array(registerViewModel.dialPlansLabelList.enumerated()), id: \.offset) { index, dialPlan in - Text(dialPlan).tag(registerViewModel.dialPlansShortLabelList[index]) + ForEach(Array(sharedMainViewModel.dialPlansLabelList.enumerated()), id: \.offset) { index, dialPlan in + Text(dialPlan).tag(sharedMainViewModel.dialPlansShortLabelList[index]) } } } label: { diff --git a/Linphone/UI/Assistant/Viewmodel/RegisterViewModel.swift b/Linphone/UI/Assistant/Viewmodel/RegisterViewModel.swift index 6993992c1..fe2a7e6a2 100644 --- a/Linphone/UI/Assistant/Viewmodel/RegisterViewModel.swift +++ b/Linphone/UI/Assistant/Viewmodel/RegisterViewModel.swift @@ -42,9 +42,6 @@ class RegisterViewModel: ObservableObject { @Published var transportType: String = "TLS" @Published var dialPlanValueSelected: String = "🇫🇷 +33" - @Published var dialPlansList: [DialPlan] = [] - @Published var dialPlansLabelList: [String] = [] - @Published var dialPlansShortLabelList: [String] = [] private let HASHALGORITHM = "SHA-256" @@ -95,7 +92,6 @@ class RegisterViewModel: ObservableObject { } init() { - getDialPlansList() getAccountCreationToken() self.usernameError = "" @@ -205,31 +201,6 @@ class RegisterViewModel: ObservableObject { } } - func getDialPlansList() { - coreContext.doOnCoreQueue { _ in - let dialPlans = Factory.Instance.dialPlans - var dialPlansListTmp: [DialPlan] = [] - var dialPlansLabelListTmp: [String] = [] - var dialPlansShortLabelListTmp: [String] = [] - - dialPlans.forEach { dialPlan in - dialPlansListTmp.append(dialPlan) - dialPlansLabelListTmp.append( - "\(dialPlan.flag) \(dialPlan.country) | +\(dialPlan.countryCallingCode)" - ) - dialPlansShortLabelListTmp.append( - "\(dialPlan.flag) +\(dialPlan.countryCallingCode)" - ) - } - - DispatchQueue.main.async { - self.dialPlansList = dialPlansListTmp - self.dialPlansLabelList = dialPlansLabelListTmp - self.dialPlansShortLabelList = dialPlansShortLabelListTmp - } - } - } - func getAccountCreationToken() { coreContext.doOnCoreQueue { core in do { @@ -281,7 +252,7 @@ class RegisterViewModel: ObservableObject { var dialPlan: DialPlan? - dialPlansList.forEach { dial in + SharedMainViewModel.shared.dialPlansList.forEach { dial in let countryCode = dialPlanValueSelected.components(separatedBy: "+") if dial.countryCallingCode == countryCode[1] { dialPlan = dial @@ -432,7 +403,7 @@ class RegisterViewModel: ObservableObject { if self.accountManagerServices != nil { var dialPlan: DialPlan? - for dial in self.dialPlansList { + for dial in SharedMainViewModel.shared.dialPlansList { let countryCode = self.dialPlanValueSelected.components(separatedBy: "+") if dial.countryCallingCode == countryCode[1] { dialPlan = dial diff --git a/Linphone/UI/Main/ContentView.swift b/Linphone/UI/Main/ContentView.swift index 5b81b022a..d8fe3c738 100644 --- a/Linphone/UI/Main/ContentView.swift +++ b/Linphone/UI/Main/ContentView.swift @@ -25,7 +25,6 @@ import linphonesw struct ContentView: View { @Environment(\.scenePhase) var scenePhase - private var idiom: UIUserInterfaceIdiom { UIDevice.current.userInterfaceIdiom } @EnvironmentObject var navigationManager: NavigationManager @@ -35,14 +34,14 @@ struct ContentView: View { @ObservedObject private var magicSearch = MagicSearchSingleton.shared @ObservedObject private var sharedMainViewModel = SharedMainViewModel.shared + @StateObject private var callViewModel = CallViewModel() + @StateObject private var accountProfileViewModel = AccountProfileViewModel() + @State private var contactsListViewModel: ContactsListViewModel? @State private var historyListViewModel: HistoryListViewModel? - //@ObservedObject var startCallViewModel: StartCallViewModel //@ObservedObject var startConversationViewModel: StartConversationViewModel - //@ObservedObject var callViewModel: CallViewModel - //@ObservedObject var meetingWaitingRoomViewModel: MeetingWaitingRoomViewModel //@ObservedObject var conversationsListViewModel: ConversationsListViewModel @@ -53,7 +52,6 @@ struct ContentView: View { //@ObservedObject var conversationForwardMessageViewModel: ConversationForwardMessageViewModel - //@ObservedObject var accountProfileViewModel: AccountProfileViewModel //@Binding var index: Int @State private var orientation = UIDevice.current.orientation @@ -102,7 +100,6 @@ struct ContentView: View { .publisher(for: NSNotification.Name("CoreStarted")) GeometryReader { geometry in VStack(spacing: 0) { - /* if (telecomManager.callInProgress && !fullscreenVideo && ((!telecomManager.callDisplayed && callViewModel.callsCounter == 1) || callViewModel.callsCounter > 1)) || isShowConversationFragment { HStack { Image("phone") @@ -137,7 +134,7 @@ struct ContentView: View { } } } - */ + ZStack { VStack(spacing: 0) { HStack(spacing: 0) { @@ -326,7 +323,6 @@ struct ContentView: View { VStack(spacing: 0) { if searchIsActive == false { HStack { - /* if let accountModelIndex = accountProfileViewModel.accountModelIndex, accountModelIndex < coreContext.accounts.count { AsyncImage(url: imagePath) { image in @@ -395,7 +391,7 @@ struct ContentView: View { } } } - */ + Text(String(localized: sharedMainViewModel.indexView == 0 ? "bottom_navigation_contacts_label" : (sharedMainViewModel.indexView == 1 ? "bottom_navigation_calls_label" : (sharedMainViewModel.indexView == 2 ? "bottom_navigation_conversations_label" : "bottom_navigation_meetings_label")))) .default_text_style_white_800(styleSize: 20) .padding(.leading, 10) @@ -1032,9 +1028,7 @@ struct ContentView: View { .zIndex(1) } - /* SideMenu( - accountProfileViewModel: accountProfileViewModel, width: geometry.size.width / 5 * 4, isOpen: $sideMenuIsOpen, menuClose: self.openMenu, @@ -1044,9 +1038,11 @@ struct ContentView: View { isShowSettingsFragment: $isShowSettingsFragment, isShowHelpFragment: $isShowHelpFragment ) + .environmentObject(accountProfileViewModel) .ignoresSafeArea(.all) .zIndex(2) + /* if isShowLoginFragment { LoginFragment( accountLoginViewModel: AccountLoginViewModel(), @@ -1077,51 +1073,18 @@ struct ContentView: View { } } - /* if isShowStartCallFragment { - if #available(iOS 16.4, *), idiom != .pad { - StartCallFragment( - callViewModel: callViewModel, - startCallViewModel: startCallViewModel, - isShowStartCallFragment: $isShowStartCallFragment, - showingDialer: $showingDialer, - resetCallView: {callViewModel.resetCallView()} - ) - .zIndex(6) - .transition(.opacity.combined(with: .move(edge: .bottom))) - .sheet(isPresented: $showingDialer) { - DialerBottomSheet( - startCallViewModel: startCallViewModel, - callViewModel: callViewModel, - isShowStartCallFragment: $isShowStartCallFragment, - showingDialer: $showingDialer, - currentCall: nil - ) - .presentationDetents([.medium]) - .presentationBackgroundInteraction(.enabled(upThrough: .medium)) - } - } else { - StartCallFragment( - callViewModel: callViewModel, - startCallViewModel: startCallViewModel, - isShowStartCallFragment: $isShowStartCallFragment, - showingDialer: $showingDialer, - resetCallView: {callViewModel.resetCallView()} - ) - .zIndex(6) - .transition(.opacity.combined(with: .move(edge: .bottom))) - .halfSheet(showSheet: $showingDialer) { - DialerBottomSheet( - startCallViewModel: startCallViewModel, - callViewModel: callViewModel, - isShowStartCallFragment: $isShowStartCallFragment, - showingDialer: $showingDialer, - currentCall: nil - ) - } onDismiss: {} - } + StartCallFragment( + isShowStartCallFragment: $isShowStartCallFragment, + showingDialer: $showingDialer, + resetCallView: {callViewModel.resetCallView()} + ) + .environmentObject(callViewModel) + .zIndex(6) + .transition(.opacity.combined(with: .move(edge: .bottom))) } + /* if isShowStartConversationFragment { StartConversationFragment( startConversationViewModel: startConversationViewModel, @@ -1258,17 +1221,18 @@ struct ContentView: View { .onAppear { } } + */ if isShowAccountProfileFragment { AccountProfileFragment( - accountProfileViewModel: accountProfileViewModel, - registerViewModel: RegisterViewModel(), isShowAccountProfileFragment: $isShowAccountProfileFragment ) + .environmentObject(accountProfileViewModel) .zIndex(3) .transition(.move(edge: .trailing)) } + /* if isShowSettingsFragment { SettingsFragment( settingsViewModel: SettingsViewModel(), @@ -1378,7 +1342,8 @@ struct ContentView: View { meetingWaitingRoomViewModel.resetMeetingRoomView() } } - + */ + /* if telecomManager.callDisplayed && ((telecomManager.callInProgress && telecomManager.outgoingCallStarted) || telecomManager.callConnected) && !telecomManager.meetingWaitingRoomDisplayed { CallView( callViewModel: callViewModel, @@ -1432,7 +1397,7 @@ struct ContentView: View { //conversationsListViewModel.updateChatRoom(address: address) } .onReceive(coreStarted) { _ in - //accountProfileViewModel.setAvatarModel() + accountProfileViewModel.setAvatarModel() } } .overlay { @@ -1482,9 +1447,6 @@ class NavigationManager: ObservableObject { #Preview { ContentView( - //startCallViewModel: StartCallViewModel(), - //startConversationViewModel: StartConversationViewModel(), - //callViewModel: CallViewModel(), //meetingWaitingRoomViewModel: MeetingWaitingRoomViewModel(), //conversationsListViewModel: ConversationsListViewModel(), //conversationViewModel: ConversationViewModel(), diff --git a/Linphone/UI/Main/Fragments/SideMenu.swift b/Linphone/UI/Main/Fragments/SideMenu.swift index 0f1b27cdf..2e0e1941a 100644 --- a/Linphone/UI/Main/Fragments/SideMenu.swift +++ b/Linphone/UI/Main/Fragments/SideMenu.swift @@ -23,7 +23,7 @@ import UniformTypeIdentifiers struct SideMenu: View { - @ObservedObject var accountProfileViewModel: AccountProfileViewModel + @EnvironmentObject var accountProfileViewModel: AccountProfileViewModel let width: CGFloat @Binding var isOpen: Bool @@ -71,7 +71,7 @@ struct SideMenu: View { List { ForEach(0..