From 56e93a77a704b194be42d83e26e348cdc1fb2a3e 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.xcodeproj/project.pbxproj | 4 + Linphone/Localizable.xcstrings | 6 - Linphone/UI/Main/ContentView.swift | 119 +++++++++++++----- .../Fragments/ConversationFragment.swift | 18 +++ .../ViewModel/HistoryListViewModel.swift | 38 ++++++ 5 files changed, 145 insertions(+), 40 deletions(-) create mode 100644 Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift diff --git a/Linphone.xcodeproj/project.pbxproj b/Linphone.xcodeproj/project.pbxproj index d7d34d2da..46ca823f7 100644 --- a/Linphone.xcodeproj/project.pbxproj +++ b/Linphone.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ D706BA822ADD72D100278F45 /* DeviceRotationViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = D706BA812ADD72D100278F45 /* DeviceRotationViewModifier.swift */; }; D70A26EE2B7CF60B006CC8FC /* ConversationsListBottomSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70A26ED2B7CF60B006CC8FC /* ConversationsListBottomSheet.swift */; }; D70A26F02B7D02E6006CC8FC /* ConversationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70A26EF2B7D02E6006CC8FC /* ConversationViewModel.swift */; }; + D70A26F22B7F5D95006CC8FC /* ConversationFragment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70A26F12B7F5D95006CC8FC /* ConversationFragment.swift */; }; D70C93DE2AC2D0F60063CA3B /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = D70C93DD2AC2D0F60063CA3B /* Localizable.xcstrings */; }; D717071E2AC5922E0037746F /* ColorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D717071D2AC5922E0037746F /* ColorExtension.swift */; }; D71707202AC5989C0037746F /* TextExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D717071F2AC5989C0037746F /* TextExtension.swift */; }; @@ -118,6 +119,7 @@ D706BA812ADD72D100278F45 /* DeviceRotationViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceRotationViewModifier.swift; sourceTree = ""; }; D70A26ED2B7CF60B006CC8FC /* ConversationsListBottomSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationsListBottomSheet.swift; sourceTree = ""; }; D70A26EF2B7D02E6006CC8FC /* ConversationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationViewModel.swift; sourceTree = ""; }; + D70A26F12B7F5D95006CC8FC /* ConversationFragment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationFragment.swift; sourceTree = ""; }; D70C93DD2AC2D0F60063CA3B /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = ""; }; D717071D2AC5922E0037746F /* ColorExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorExtension.swift; sourceTree = ""; }; D717071F2AC5989C0037746F /* TextExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextExtension.swift; sourceTree = ""; }; @@ -559,6 +561,7 @@ D7CEE03A2B7A234200FD79B7 /* ConversationsFragment.swift */, D7CEE03C2B7A23B200FD79B7 /* ConversationsListFragment.swift */, D70A26ED2B7CF60B006CC8FC /* ConversationsListBottomSheet.swift */, + D70A26F12B7F5D95006CC8FC /* ConversationFragment.swift */, ); path = Fragments; sourceTree = ""; @@ -735,6 +738,7 @@ D706BA822ADD72D100278F45 /* DeviceRotationViewModifier.swift in Sources */, D732A9132B04C7A300DB42BA /* HistoryListFragment.swift in Sources */, D719ABC92ABC6FD700B41C10 /* CoreContext.swift in Sources */, + D70A26F22B7F5D95006CC8FC /* ConversationFragment.swift in Sources */, 66C491FD2B24D36500CEA16D /* AudioRouteUtils.swift in Sources */, D7EAACCF2AD6ED8000AA6A8A /* PermissionsFragment.swift in Sources */, D777DBB32AE12C5900565A99 /* ContactsManager.swift in Sources */, diff --git a/Linphone/Localizable.xcstrings b/Linphone/Localizable.xcstrings index 7c0dabc93..3b9a04413 100644 --- a/Linphone/Localizable.xcstrings +++ b/Linphone/Localizable.xcstrings @@ -244,9 +244,6 @@ }, "Contacts" : { - }, - "Content" : { - }, "Continue" : { @@ -588,9 +585,6 @@ }, "This contact will be deleted definitively." : { - }, - "Title" : { - }, "TLS" : { 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/Conversations/Fragments/ConversationFragment.swift b/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift new file mode 100644 index 000000000..86db6c6e1 --- /dev/null +++ b/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift @@ -0,0 +1,18 @@ +// +// ConversationFragment.swift +// Linphone +// +// Created by Martins BenoƮt on 16/02/2024. +// + +import SwiftUI + +struct ConversationFragment: View { + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + } +} + +#Preview { + ConversationFragment() +} 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 + } } } }