Skip to content

Commit 6f538bb

Browse files
committed
Switch call notification to NotificationCompat.CallStyle. This adds answer/decline buttons to the notification so that users can answer incoming calls.
Signed-off-by: Jens Zalzala <jens@shakingearthdigital.com>
1 parent 680549f commit 6f538bb

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_THREAD_ID
9797
import com.nextcloud.talk.utils.preferences.AppPreferences
9898
import io.reactivex.Observable
9999
import io.reactivex.Observer
100-
import io.reactivex.android.schedulers.AndroidSchedulers
101100
import io.reactivex.disposables.Disposable
102101
import io.reactivex.schedulers.Schedulers
103102
import okhttp3.JavaNetCookieJar
@@ -313,6 +312,23 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
313312
val uri = signatureVerification.user!!.baseUrl!!.toUri()
314313
val baseUrl = uri.host
315314

315+
val callerPersonBuilder = Person.Builder()
316+
.setName(conversation.displayName)
317+
.setImportant(true)
318+
if (conversation.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) {
319+
val avatarUrl = ApiUtils.getUrlForAvatar(
320+
signatureVerification.user!!.baseUrl!!,
321+
conversation.name,
322+
false,
323+
darkMode = DisplayUtils.isDarkModeOn(applicationContext)
324+
)
325+
loadAvatarSync(avatarUrl, applicationContext)?.let { callerPersonBuilder.setIcon(it) }
326+
}
327+
val callerPerson = callerPersonBuilder.build()
328+
329+
val isVideoCall = (conversation.callFlag and Participant.InCallFlags.WITH_VIDEO) > 0
330+
val primaryAnswerIntent = if (isVideoCall) answerVideoPendingIntent else answerVoicePendingIntent
331+
316332
val notification =
317333
NotificationCompat.Builder(applicationContext, notificationChannelId)
318334
.setPriority(NotificationCompat.PRIORITY_HIGH)
@@ -329,9 +345,10 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
329345
.setContentIntent(fullScreenPendingIntent)
330346
.setFullScreenIntent(fullScreenPendingIntent, true)
331347
.setSound(soundUri)
332-
.addAction(R.drawable.ic_call_white_24dp, applicationContext.getString(R.string.nc_call_action_answer_audio), answerVoicePendingIntent)
333-
.addAction(R.drawable.ic_videocam_white_24px, applicationContext.getString(R.string.nc_call_action_answer_video), answerVideoPendingIntent)
334-
.addAction(R.drawable.ic_call_end_white_24px, applicationContext.getString(R.string.nc_call_action_decline), declinePendingIntent)
348+
.setStyle(
349+
NotificationCompat.CallStyle.forIncomingCall(callerPerson, declinePendingIntent, primaryAnswerIntent)
350+
.setIsVideo(isVideoCall)
351+
)
335352
.build()
336353
notification.flags = notification.flags or Notification.FLAG_INSISTENT
337354

@@ -342,7 +359,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
342359

343360
chatNetworkDataSource?.getRoom(userBeingCalled, roomToken = pushMessage.id!!)
344361
?.subscribeOn(Schedulers.io())
345-
?.observeOn(AndroidSchedulers.mainThread())
362+
?.observeOn(Schedulers.io())
346363
?.subscribe(object : Observer<ConversationModel> {
347364
override fun onSubscribe(d: Disposable) {
348365
// unused atm

0 commit comments

Comments
 (0)