Missed calls counter added to bottom navigation bar

This commit is contained in:
Benoit Martins 2024-02-15 16:49:06 +01:00
parent 61c2c048bb
commit d91996c351
2 changed files with 123 additions and 34 deletions

View file

@ -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()

View file

@ -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
}
}
}
}