From d91996c351f409125d1a78b5ac411a1967393104 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Thu, 15 Feb 2024 16:49:06 +0100 Subject: [PATCH] Missed calls counter added to bottom navigation bar --- Linphone/UI/Main/ContentView.swift | 119 +++++++++++++----- .../ViewModel/HistoryListViewModel.swift | 38 ++++++ 2 files changed, 123 insertions(+), 34 deletions(-) diff --git a/Linphone/UI/Main/ContentView.swift b/Linphone/UI/Main/ContentView.swift index 2a90ad2cb..938aa7b42 100644 --- a/Linphone/UI/Main/ContentView.swift +++ b/Linphone/UI/Main/ContentView.swift @@ -108,25 +108,51 @@ struct ContentView: View { Spacer() - Button(action: { - self.index = 1 - contactViewModel.indexDisplayedFriend = nil - }, label: { - VStack { - Image("phone") - .renderingMode(.template) - .resizable() - .foregroundStyle(self.index == 1 ? Color.orangeMain500 : Color.grayMain2c600) - .frame(width: 25, height: 25) - if self.index == 1 { - Text("Calls") - .default_text_style_700(styleSize: 10) - } else { - Text("Calls") + ZStack { + if historyListViewModel.missedCallsCount > 0 { + VStack { + HStack { + Text( + historyListViewModel.missedCallsCount < 99 + ? String(historyListViewModel.missedCallsCount) + : "99+" + ) + .foregroundStyle(.white) .default_text_style(styleSize: 10) + .lineLimit(1) + } + .frame(width: 18, height: 18) + .background(Color.redDanger500) + .cornerRadius(50) } + .padding(.bottom, 30) + .padding(.leading, 30) } - }) + + Button(action: { + self.index = 1 + contactViewModel.indexDisplayedFriend = nil + if historyListViewModel.missedCallsCount > 0 { + historyListViewModel.resetMissedCallsCount() + } + }, label: { + VStack { + Image("phone") + .renderingMode(.template) + .resizable() + .foregroundStyle(self.index == 1 ? Color.orangeMain500 : Color.grayMain2c600) + .frame(width: 25, height: 25) + if self.index == 1 { + Text("Calls") + .default_text_style_700(styleSize: 10) + } else { + Text("Calls") + .default_text_style(styleSize: 10) + } + } + }) + .padding(.top) + } Spacer() @@ -475,27 +501,52 @@ struct ContentView: View { Spacer() - Button(action: { - self.index = 1 - contactViewModel.indexDisplayedFriend = nil - }, label: { - VStack { - Image("phone") - .renderingMode(.template) - .resizable() - .foregroundStyle(self.index == 1 ? Color.orangeMain500 : Color.grayMain2c600) - .frame(width: 25, height: 25) - if self.index == 1 { - Text("Calls") - .default_text_style_700(styleSize: 10) - } else { - Text("Calls") + ZStack { + if historyListViewModel.missedCallsCount > 0 { + VStack { + HStack { + Text( + historyListViewModel.missedCallsCount < 99 + ? String(historyListViewModel.missedCallsCount) + : "99+" + ) + .foregroundStyle(.white) .default_text_style(styleSize: 10) + .lineLimit(1) + } + .frame(width: 18, height: 18) + .background(Color.redDanger500) + .cornerRadius(50) } + .padding(.bottom, 30) + .padding(.leading, 30) } - }) - .padding(.top) - .frame(width: 100) + + Button(action: { + self.index = 1 + contactViewModel.indexDisplayedFriend = nil + if historyListViewModel.missedCallsCount > 0 { + historyListViewModel.resetMissedCallsCount() + } + }, label: { + VStack { + Image("phone") + .renderingMode(.template) + .resizable() + .foregroundStyle(self.index == 1 ? Color.orangeMain500 : Color.grayMain2c600) + .frame(width: 25, height: 25) + if self.index == 1 { + Text("Calls") + .default_text_style_700(styleSize: 10) + } else { + Text("Calls") + .default_text_style(styleSize: 10) + } + } + }) + .padding(.top) + .frame(width: 100) + } Spacer() diff --git a/Linphone/UI/Main/History/ViewModel/HistoryListViewModel.swift b/Linphone/UI/Main/History/ViewModel/HistoryListViewModel.swift index f82122892..cf9132158 100644 --- a/Linphone/UI/Main/History/ViewModel/HistoryListViewModel.swift +++ b/Linphone/UI/Main/History/ViewModel/HistoryListViewModel.swift @@ -30,8 +30,11 @@ class HistoryListViewModel: ObservableObject { var callLogsAddressToDelete = "" var callLogSubscription: AnyCancellable? + @Published var missedCallsCount: Int = 0 + init() { computeCallLogsList() + updateMissedCallsCount() } func computeCallLogsList() { @@ -62,6 +65,41 @@ class HistoryListViewModel: ObservableObject { self.callLogsTmp.append(log) } } + + self.updateMissedCallsCount() + } + } + } + + func resetMissedCallsCount() { + coreContext.doOnCoreQueue { core in + let account = core.defaultAccount + if account != nil { + account?.resetMissedCallsCount() + DispatchQueue.main.async { + self.missedCallsCount = 0 + } + } else { + DispatchQueue.main.async { + self.missedCallsCount = 0 + } + } + } + } + + func updateMissedCallsCount() { + coreContext.doOnCoreQueue { core in + let account = core.defaultAccount + if account != nil { + let count = account?.missedCallsCount != nil ? account!.missedCallsCount : core.missedCallsCount + + DispatchQueue.main.async { + self.missedCallsCount = count + } + } else { + DispatchQueue.main.async { + self.missedCallsCount = 0 + } } } }