Display caller avatar when showing CallStyle notification.

This commit is contained in:
Alex Hart
2023-04-21 14:34:47 -03:00
committed by GitHub
parent f14bce9849
commit 211d79d14d
2 changed files with 46 additions and 19 deletions

View File

@@ -10,15 +10,19 @@ import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
import org.signal.core.util.PendingIntentFlags;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.MainActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.WebRtcCallActivity;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.service.webrtc.WebRtcCallService;
import org.thoughtcrime.securesms.util.ConversationUtil;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.schedulers.Schedulers;
/**
* Manages the state of the WebRtc items in the Android notification bar.
*
@@ -46,7 +50,7 @@ public class CallNotificationBuilder {
*/
public static final int API_LEVEL_CALL_STYLE = 29;
public static Notification getCallInProgressNotification(Context context, int type, Recipient recipient) {
public static Single<Notification> getCallInProgressNotification(Context context, int type, Recipient recipient) {
Intent contentIntent = new Intent(context, WebRtcCallActivity.class);
contentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
contentIntent.putExtra(WebRtcCallActivity.EXTRA_STARTED_FROM_FULLSCREEN, true);
@@ -63,32 +67,46 @@ public class CallNotificationBuilder {
builder.setContentText(context.getString(R.string.CallNotificationBuilder_connecting));
builder.setPriority(NotificationCompat.PRIORITY_MIN);
builder.setContentIntent(null);
return Single.just(builder.build());
} else if (type == TYPE_INCOMING_RINGING) {
builder.setContentText(context.getString(recipient.isGroup() ? R.string.NotificationBarManager__incoming_signal_group_call : R.string.NotificationBarManager__incoming_signal_call));
builder.setStyle(NotificationCompat.CallStyle.forIncomingCall(
ConversationUtil.buildPersonWithoutIcon(context, recipient),
getServicePendingIntent(context, WebRtcCallService.denyCallIntent(context)),
getActivityPendingIntent(context, WebRtcCallActivity.ANSWER_ACTION)
));
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setCategory(NotificationCompat.CATEGORY_CALL);
return Single.fromCallable(() -> ConversationUtil.buildPerson(context, recipient))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(person -> {
builder.setStyle(NotificationCompat.CallStyle.forIncomingCall(
person,
getServicePendingIntent(context, WebRtcCallService.denyCallIntent(context)),
getActivityPendingIntent(context, WebRtcCallActivity.ANSWER_ACTION)
));
return builder.build();
});
} else if (type == TYPE_OUTGOING_RINGING) {
builder.setContentText(context.getString(R.string.NotificationBarManager__establishing_signal_call));
builder.addAction(getServiceNotificationAction(context, WebRtcCallService.hangupIntent(context), R.drawable.ic_call_end_grey600_32dp, R.string.NotificationBarManager__cancel_call));
return Single.just(builder.build());
} else {
builder.setContentText(context.getString(R.string.NotificationBarManager_signal_call_in_progress));
builder.setOnlyAlertOnce(true);
builder.setStyle(NotificationCompat.CallStyle.forOngoingCall(
ConversationUtil.buildPersonWithoutIcon(context, recipient),
getServicePendingIntent(context, WebRtcCallService.hangupIntent(context))
));
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setCategory(NotificationCompat.CATEGORY_CALL);
}
return builder.build();
return Single.fromCallable(() -> ConversationUtil.buildPerson(context, recipient))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(person -> {
builder.setStyle(NotificationCompat.CallStyle.forOngoingCall(
person,
getServicePendingIntent(context, WebRtcCallService.hangupIntent(context))
));
return builder.build();
});
}
}
public static int getNotificationId(int type) {