Skip to content

Commit

Permalink
Fixes on yarn format:all:check
Browse files Browse the repository at this point in the history
  • Loading branch information
dprevost-LMI committed Nov 3, 2024
1 parent 1817d5e commit e28e820
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,43 @@

import android.app.PendingIntent;
import android.os.Bundle;

import java.util.Objects;

import app.notifee.core.model.NotificationModel;
import java.util.Objects;

public class CallStyleNotificationPendingIntent {

public static PendingIntent getAnswerIntent(Bundle callTypeActionsBundle, NotificationModel notificationModel) {
Bundle answerActionBundle = Objects.requireNonNull(callTypeActionsBundle.getBundle("answerAction"));
public static PendingIntent getAnswerIntent(
Bundle callTypeActionsBundle, NotificationModel notificationModel) {
Bundle answerActionBundle =
Objects.requireNonNull(callTypeActionsBundle.getBundle("answerAction"));
return getPendingIntent(answerActionBundle, notificationModel.getHashCode(), notificationModel);
}

public static PendingIntent getDeclineIntent(Bundle callTypeActionsBundle, NotificationModel notificationModel) {
Bundle declineActionBundle = Objects.requireNonNull(callTypeActionsBundle.getBundle("declineAction"));
return getPendingIntent(declineActionBundle, notificationModel.getHashCode() + 1, notificationModel);
public static PendingIntent getDeclineIntent(
Bundle callTypeActionsBundle, NotificationModel notificationModel) {
Bundle declineActionBundle =
Objects.requireNonNull(callTypeActionsBundle.getBundle("declineAction"));
return getPendingIntent(
declineActionBundle, notificationModel.getHashCode() + 1, notificationModel);
}

public static PendingIntent getHangupIntent(Bundle callTypeActionsBundle, NotificationModel notificationModel) {
Bundle hangUpActionBundle = Objects.requireNonNull(callTypeActionsBundle.getBundle("hangUpAction"));
return getPendingIntent(hangUpActionBundle, notificationModel.getHashCode() + 1, notificationModel);
public static PendingIntent getHangupIntent(
Bundle callTypeActionsBundle, NotificationModel notificationModel) {
Bundle hangUpActionBundle =
Objects.requireNonNull(callTypeActionsBundle.getBundle("hangUpAction"));
return getPendingIntent(
hangUpActionBundle, notificationModel.getHashCode() + 1, notificationModel);
}

private static PendingIntent getPendingIntent(Bundle hangUpActionBundle, int notificationModel, NotificationModel notificationModel1) {
private static PendingIntent getPendingIntent(
Bundle hangUpActionBundle, int notificationModel, NotificationModel notificationModel1) {
Bundle pressActionBundle = hangUpActionBundle.getBundle("pressAction");
return NotificationPendingIntent.createIntent(
notificationModel,
pressActionBundle,
TYPE_ACTION_PRESS,
new String[]{"notification", "pressAction"},
notificationModel1.toBundle(),
pressActionBundle);
notificationModel,
pressActionBundle,
TYPE_ACTION_PRESS,
new String[] {"notification", "pressAction"},
notificationModel1.toBundle(),
pressActionBundle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ private static ListenableFuture<NotificationCompat.Builder> notificationBundleTo
}

ListenableFuture<NotificationCompat.Style> styleTask =
androidStyleBundle.getStyleTask(LISTENING_CACHED_THREAD_POOL, notificationModel);
androidStyleBundle.getStyleTask(
LISTENING_CACHED_THREAD_POOL, notificationModel);
if (styleTask == null) {
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@
*
*/

import static app.notifee.core.event.NotificationEvent.TYPE_ACTION_PRESS;

import android.app.PendingIntent;
import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.Keep;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
import androidx.core.app.Person;
import androidx.core.graphics.drawable.IconCompat;

import app.notifee.core.CallStyleNotificationPendingIntent;
import app.notifee.core.Logger;
import app.notifee.core.NotificationPendingIntent;
import app.notifee.core.utility.ObjectUtils;
import app.notifee.core.utility.ResourceUtils;
import app.notifee.core.utility.TextUtils;
Expand Down Expand Up @@ -124,7 +119,9 @@ public Bundle toBundle() {
@Nullable
public ListenableFuture<NotificationCompat.Style> getStyleTask(
ListeningExecutorService lExecutor, NotificationModel notificationModel) {
NotificationAndroidStyleType type = NotificationAndroidStyleType.values()[ObjectUtils.getInt(mNotificationAndroidStyleBundle.get("type"))];
NotificationAndroidStyleType type =
NotificationAndroidStyleType.values()[
ObjectUtils.getInt(mNotificationAndroidStyleBundle.get("type"))];
ListenableFuture<NotificationCompat.Style> styleTask = null;

switch (type) {
Expand Down Expand Up @@ -351,48 +348,64 @@ private ListenableFuture<NotificationCompat.Style> getMessagingStyleTask(
});
}


/**
* Gets a CallStyle for a notification
*
* @return NotificationCompat.CallStyle
*/
@RequiresApi(31)
private ListenableFuture<NotificationCompat.Style> getCallStyleTask(
ListeningExecutorService lExecutor, NotificationModel notificationModel) {
ListeningExecutorService lExecutor, NotificationModel notificationModel) {
return lExecutor.submit(
() -> {
Person caller =
getPerson(
lExecutor,
Objects.requireNonNull(mNotificationAndroidStyleBundle.getBundle("person")))
.get(20, TimeUnit.SECONDS);

Bundle callTypeActionsBundle = Objects.requireNonNull(mNotificationAndroidStyleBundle.getBundle("callTypeActions"));
() -> {
Person caller =
getPerson(
lExecutor,
Objects.requireNonNull(mNotificationAndroidStyleBundle.getBundle("person")))
.get(20, TimeUnit.SECONDS);

CallType callType = CallType.values()[ObjectUtils.getInt(callTypeActionsBundle.get("callType"))];
Bundle callTypeActionsBundle =
Objects.requireNonNull(mNotificationAndroidStyleBundle.getBundle("callTypeActions"));

switch (callType) {
case INCOMING: {
PendingIntent answerIntent = CallStyleNotificationPendingIntent.getAnswerIntent(callTypeActionsBundle, notificationModel);
PendingIntent declineIntent = CallStyleNotificationPendingIntent.getDeclineIntent(callTypeActionsBundle, notificationModel);
CallType callType =
CallType.values()[ObjectUtils.getInt(callTypeActionsBundle.get("callType"))];

return NotificationCompat.CallStyle.forIncomingCall(caller, declineIntent, answerIntent);
}
case ONGOING: {
PendingIntent hangupIntent = CallStyleNotificationPendingIntent.getHangupIntent(callTypeActionsBundle, notificationModel);
switch (callType) {
case INCOMING:
{
PendingIntent answerIntent =
CallStyleNotificationPendingIntent.getAnswerIntent(
callTypeActionsBundle, notificationModel);
PendingIntent declineIntent =
CallStyleNotificationPendingIntent.getDeclineIntent(
callTypeActionsBundle, notificationModel);

return NotificationCompat.CallStyle.forOngoingCall(caller, hangupIntent);
}
case SCREENING: {
PendingIntent answerIntent = CallStyleNotificationPendingIntent.getAnswerIntent(callTypeActionsBundle, notificationModel);
PendingIntent hangupIntent = CallStyleNotificationPendingIntent.getHangupIntent(callTypeActionsBundle, notificationModel);
return NotificationCompat.CallStyle.forIncomingCall(
caller, declineIntent, answerIntent);
}
case ONGOING:
{
PendingIntent hangupIntent =
CallStyleNotificationPendingIntent.getHangupIntent(
callTypeActionsBundle, notificationModel);

return NotificationCompat.CallStyle.forScreeningCall(caller, hangupIntent, answerIntent);
return NotificationCompat.CallStyle.forOngoingCall(caller, hangupIntent);
}
case SCREENING:
{
PendingIntent answerIntent =
CallStyleNotificationPendingIntent.getAnswerIntent(
callTypeActionsBundle, notificationModel);
PendingIntent hangupIntent =
CallStyleNotificationPendingIntent.getHangupIntent(
callTypeActionsBundle, notificationModel);

return NotificationCompat.CallStyle.forScreeningCall(
caller, hangupIntent, answerIntent);
}
default:
throw new RuntimeException("CallStyleTask: Invalid callType " + callType);
}
default:
throw new RuntimeException("CallStyleTask: Invalid callType " + callType);
}
});
}
});
}
}

0 comments on commit e28e820

Please sign in to comment.