If more than one missed call, show number of missed calls in notify

Moved baresip service constants to constants class
This commit is contained in:
Juha Heinanen
2021-10-16 14:09:20 +03:00
parent 3c8778cb13
commit df6045980b
4 changed files with 48 additions and 28 deletions

View File

@ -770,20 +770,35 @@ class BaresipService: Service() {
PendingIntent.FLAG_UPDATE_CURRENT)
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
nb.setSmallIcon(R.drawable.ic_stat)
.setColor(ContextCompat.getColor(this,
R.color.colorBaresip))
.setContentIntent(pi)
.setCategory(Notification.CATEGORY_CALL)
.setAutoCancel(true)
.setContentTitle(getString(R.string.missed_call_from))
.setContentText(caller)
.setColor(ContextCompat.getColor(this, R.color.colorBaresip))
.setContentIntent(pi)
.setCategory(Notification.CATEGORY_CALL)
.setAutoCancel(true)
if (VERSION.SDK_INT < 23) {
nb.setContentTitle(getString(R.string.missed_call_from))
nb.setContentText(caller)
} else {
var missedCalls = 0
for (notification in nm.activeNotifications)
if (notification.id == CALL_MISSED_NOTIFICATION_ID)
missedCalls++
if (missedCalls == 0) {
nb.setContentTitle(getString(R.string.missed_call_from))
nb.setContentText(caller)
} else {
nb.setContentTitle(getString(R.string.missed_calls))
nb.setContentText(
String.format(getString(R.string.missed_calls_count),
missedCalls + 1))
}
}
if (VERSION.SDK_INT < 26) {
@Suppress("DEPRECATION")
nb.setVibrate(LongArray(0))
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
.priority = Notification.PRIORITY_HIGH
}
nm.notify(CALL_NOTIFICATION_ID, nb.build())
nm.notify(CALL_MISSED_NOTIFICATION_ID, nb.build())
return
}
}
@ -1306,26 +1321,6 @@ class BaresipService: Service() {
companion object {
const val STATUS_NOTIFICATION_ID = 101
const val CALL_NOTIFICATION_ID = 102
const val TRANSFER_NOTIFICATION_ID = 103
const val MESSAGE_NOTIFICATION_ID = 104
const val STATUS_REQ_CODE = 1
const val CALL_REQ_CODE = 2
const val ANSWER_REQ_CODE = 3
const val REJECT_REQ_CODE = 4
const val TRANSFER_REQ_CODE = 5
const val ACCEPT_REQ_CODE = 6
const val DENY_REQ_CODE = 7
const val MESSAGE_REQ_CODE = 8
const val REPLY_REQ_CODE = 9
const val SAVE_REQ_CODE = 10
const val DELETE_REQ_CODE = 11
const val DEFAULT_CHANNEL_ID = "com.tutpro.baresip.default"
const val HIGH_CHANNEL_ID = "com.tutpro.baresip.high"
var isServiceRunning = false
var isConfigInitialized = false
var libraryLoaded = false

View File

@ -2,9 +2,30 @@ package com.tutpro.baresip
const val TAG = "Baresip"
const val DEFAULT_CHANNEL_ID = "com.tutpro.baresip.default"
const val HIGH_CHANNEL_ID = "com.tutpro.baresip.high"
const val BACKUP_PERMISSION_REQUEST_CODE = 1
const val RESTORE_PERMISSION_REQUEST_CODE = 2
const val RECORD_PERMISSION_REQUEST_CODE = 3
const val CONTACTS_PERMISSION_REQUEST_CODE = 4
const val READ_CERT_PERMISSION_CODE = 5
const val READ_CA_PERMISSION_CODE = 6
const val STATUS_NOTIFICATION_ID = 101
const val CALL_NOTIFICATION_ID = 102
const val CALL_MISSED_NOTIFICATION_ID = 103
const val TRANSFER_NOTIFICATION_ID = 104
const val MESSAGE_NOTIFICATION_ID = 105
const val STATUS_REQ_CODE = 1
const val CALL_REQ_CODE = 2
const val ANSWER_REQ_CODE = 3
const val REJECT_REQ_CODE = 4
const val TRANSFER_REQ_CODE = 5
const val ACCEPT_REQ_CODE = 6
const val DENY_REQ_CODE = 7
const val MESSAGE_REQ_CODE = 8
const val REPLY_REQ_CODE = 9
const val SAVE_REQ_CODE = 10
const val DELETE_REQ_CODE = 11

View File

@ -242,6 +242,8 @@
<string name="reject">Hylkää</string>
<string name="incoming_call_from">Puhelu soittajalta</string>
<string name="missed_call_from">Vastaamaton puhelu soittajalta</string>
<string name="missed_calls">Vastaamattomia puheluita</string>
<string name="missed_calls_count">%1$d vastaamatonta puhelua</string>
<string name="transfer_request_to">Puhelun siirtopyyntö kohteeseen</string>
<string name="message_from">Viesti lähettäjältä</string>
<!-- Boot Completed Receiver -->

View File

@ -220,6 +220,8 @@
<string name="reject">Reject</string>
<string name="incoming_call_from">Incoming call from</string>
<string name="missed_call_from">Missed call from</string>
<string name="missed_calls">Missed calls</string>
<string name="missed_calls_count">%1$d missed calls</string>
<string name="transfer_request_to">Call transfer request to</string>
<string name="message_from">Message from</string>
<!-- Boot Completed Receiver -->