mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Added missed call(s) notification
This commit is contained in:
parent
2f18ecb562
commit
991a5e695a
4 changed files with 88 additions and 1 deletions
|
|
@ -88,7 +88,10 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
const val INTENT_REMOTE_ADDRESS = "REMOTE_ADDRESS"
|
||||
|
||||
const val CHAT_TAG = "Chat"
|
||||
private const val MISSED_CALL_TAG = "Missed call"
|
||||
const val CHAT_NOTIFICATIONS_GROUP = "CHAT_NOTIF_GROUP"
|
||||
|
||||
private const val MISSED_CALL_ID = 10
|
||||
}
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
|
|
@ -124,6 +127,11 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
)
|
||||
dismissCallNotification(call)
|
||||
}
|
||||
Call.State.Released -> {
|
||||
if (LinphoneUtils.isCallLogMissed(call.callLog)) {
|
||||
showMissedCallNotification(call)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
|
|
@ -320,6 +328,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
init {
|
||||
createServiceChannel()
|
||||
createIncomingCallNotificationChannel()
|
||||
createMissedCallNotificationChannel()
|
||||
createActiveCallNotificationChannel()
|
||||
createMessageChannel()
|
||||
|
||||
|
|
@ -409,6 +418,47 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
notify(notifiable.notificationId, notification)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun showMissedCallNotification(call: Call) {
|
||||
val missedCallCount: Int = coreContext.core.missedCallsCount
|
||||
val body: String
|
||||
if (missedCallCount > 1) {
|
||||
body = context.getString(R.string.notification_missed_calls)
|
||||
.format(missedCallCount.toString())
|
||||
Log.i("$TAG Updating missed calls notification count to $missedCallCount")
|
||||
} else {
|
||||
val remoteAddress = call.remoteAddress
|
||||
val friend: Friend? = coreContext.contactsManager.findContactByAddress(remoteAddress)
|
||||
body = context.getString(R.string.notification_missed_call)
|
||||
.format(friend?.name ?: LinphoneUtils.getDisplayName(remoteAddress))
|
||||
Log.i("$TAG Creating missed call notification")
|
||||
}
|
||||
|
||||
val pendingIntent = NavDeepLinkBuilder(context)
|
||||
.setComponentName(MainActivity::class.java)
|
||||
.setGraph(R.navigation.main_nav_graph)
|
||||
.setDestination(R.id.historyListFragment)
|
||||
.createPendingIntent()
|
||||
|
||||
val builder = NotificationCompat.Builder(
|
||||
context,
|
||||
context.getString(R.string.notification_channel_missed_call_id)
|
||||
)
|
||||
.setContentTitle(context.getString(R.string.notification_missed_call_title))
|
||||
.setContentText(body)
|
||||
.setSmallIcon(R.drawable.phone_x)
|
||||
.setAutoCancel(true)
|
||||
.setCategory(NotificationCompat.CATEGORY_MISSED_CALL)
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setShowWhen(true)
|
||||
.setNumber(missedCallCount)
|
||||
.setContentIntent(pendingIntent)
|
||||
|
||||
val notification = builder.build()
|
||||
notify(MISSED_CALL_ID, notification, MISSED_CALL_TAG)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun startCallForeground() {
|
||||
Log.i("$TAG Trying to start foreground Service using call notification")
|
||||
|
|
@ -828,7 +878,6 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
.setSmallIcon(R.drawable.chat_teardrop_text)
|
||||
.setAutoCancel(true)
|
||||
.setLargeIcon(largeIcon)
|
||||
.setColor(AppUtils.getColor(R.color.orange_main_500))
|
||||
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
||||
.setGroup(CHAT_NOTIFICATIONS_GROUP)
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
||||
|
|
@ -1034,6 +1083,21 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
|
||||
@MainThread
|
||||
private fun createMissedCallNotificationChannel() {
|
||||
val id = context.getString(R.string.notification_channel_missed_call_id)
|
||||
val name = context.getString(R.string.notification_channel_missed_call_name)
|
||||
|
||||
val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH)
|
||||
channel.description = name
|
||||
channel.lightColor = context.getColor(R.color.orange_main_500)
|
||||
channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
|
||||
channel.enableVibration(true)
|
||||
channel.enableLights(true)
|
||||
channel.setShowBadge(false)
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
|
||||
@MainThread
|
||||
private fun createActiveCallNotificationChannel() {
|
||||
val id = context.getString(R.string.notification_channel_call_id)
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import org.linphone.core.Address
|
|||
import org.linphone.core.Call
|
||||
import org.linphone.core.Call.Dir
|
||||
import org.linphone.core.Call.Status
|
||||
import org.linphone.core.CallLog
|
||||
import org.linphone.core.ChatMessage
|
||||
import org.linphone.core.ChatRoom
|
||||
import org.linphone.core.ConferenceInfo
|
||||
|
|
@ -159,6 +160,14 @@ class LinphoneUtils {
|
|||
return true
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun isCallLogMissed(callLog: CallLog): Boolean {
|
||||
if (callLog.dir == Dir.Outgoing) return false
|
||||
return callLog.status == Status.Missed ||
|
||||
callLog.status == Status.Aborted ||
|
||||
callLog.status == Status.EarlyAborted
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
@IntegerRes
|
||||
fun getCallIconResId(callStatus: Status, callDir: Dir): Int {
|
||||
|
|
|
|||
9
app/src/main/res/drawable/phone_x.xml
Normal file
9
app/src/main/res/drawable/phone_x.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="256"
|
||||
android:viewportHeight="256">
|
||||
<path
|
||||
android:pathData="M154.34,90.34 L172.69,72 154.34,53.66a8,8 0,0 1,11.32 -11.32L184,60.69l18.34,-18.35a8,8 0,0 1,11.32 11.32L195.32,72l18.34,18.34a8,8 0,0 1,-11.32 11.32L184,83.31l-18.34,18.35a8,8 0,0 1,-11.32 -11.32ZM231.88,175.08A56.26,56.26 0,0 1,176 224C96.6,224 32,159.4 32,80A56.26,56.26 0,0 1,80.92 24.12a16,16 0,0 1,16.62 9.52l21.12,47.15 0,0.12A16,16 0,0 1,117.39 96c-0.18,0.27 -0.37,0.52 -0.57,0.77L96,121.45c7.49,15.22 23.41,31 38.83,38.51l24.34,-20.71a8.12,8.12 0,0 1,0.75 -0.56,16 16,0 0,1 15.17,-1.4l0.13,0.06 47.11,21.11A16,16 0,0 1,231.88 175.08ZM216,173.08s-0.07,0 -0.11,0h0l-47,-21.05 -24.35,20.71a8.44,8.44 0,0 1,-0.74 0.56,16 16,0 0,1 -15.75,1.14c-18.73,-9.05 -37.4,-27.58 -46.46,-46.11a16,16 0,0 1,1 -15.7,6.13 6.13,0 0,1 0.57,-0.77L104,87.15l-21,-47a0.61,0.61 0,0 1,0 -0.12A40.2,40.2 0,0 0,48 80,128.14 128.14,0 0,0 176,208 40.21,40.21 0,0 0,216 173.07Z"
|
||||
android:fillColor="#4e6074"/>
|
||||
</vector>
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
<string name="assistant_linphone_contact_us_link" translatable="false">linphone.org/contact</string>
|
||||
<string name="notification_channel_call_id" translatable="false">linphone_notification_call_id</string>
|
||||
<string name="notification_channel_incoming_call_id" translatable="false">linphone_notification_incoming_call_id</string>
|
||||
<string name="notification_channel_missed_call_id" translatable="false">linphone_notification_missed_call_id</string>
|
||||
<string name="notification_channel_service_id" translatable="false">linphone_notification_service_id</string>
|
||||
<string name="notification_channel_chat_id" translatable="false">linphone_notification_chat_id</string>
|
||||
|
||||
|
|
@ -56,11 +57,15 @@
|
|||
|
||||
<string name="notification_channel_call_name">&appName; active calls notifications</string>
|
||||
<string name="notification_channel_incoming_call_name">&appName; incoming calls notifications</string>
|
||||
<string name="notification_channel_missed_call_name">&appName; missed calls notifications</string>
|
||||
<string name="notification_channel_service_name">&appName; service notification</string>
|
||||
<string name="notification_channel_chat_name">&appName; instant messages notifications</string>
|
||||
<string name="notification_chat_message_reaction_received">%s has reacted by %s to: %s</string>
|
||||
<string name="notification_mark_message_as_read">Mark as read</string>
|
||||
<string name="notification_reply_to_message">Reply</string>
|
||||
<string name="notification_missed_call">Missed call from %s</string>
|
||||
<string name="notification_missed_calls">%s missed calls</string>
|
||||
<string name="notification_missed_call_title">Missed call</string>
|
||||
|
||||
<string name="welcome_page_title">Welcome</string>
|
||||
<string name="welcome_page_subtitle">in Linphone</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue