Skip to content

Commit

Permalink
Default to default icon if the specified one doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
remcoanker committed Jul 8, 2024
1 parent d879284 commit a145c8a
Showing 1 changed file with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,20 +452,24 @@ private static void setSmallIcon(
NotificationDetails notificationDetails,
NotificationCompat.Builder builder) {
if (!StringUtils.isNullOrEmpty(notificationDetails.icon)) {
builder.setSmallIcon(getDrawableResourceId(context, notificationDetails.icon));
} else {
SharedPreferences sharedPreferences =
context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE);
String defaultIcon = sharedPreferences.getString(DEFAULT_ICON, null);
if (StringUtils.isNullOrEmpty(defaultIcon)) {
// for backwards compatibility: this is for handling the old way references to the icon used
// to be kept but should be removed in future
builder.setSmallIcon(notificationDetails.iconResourceId);

} else {
builder.setSmallIcon(getDrawableResourceId(context, defaultIcon));
int icon = getDrawableResourceId(context, notificationDetails.icon);
if(icon != 0) {
builder.setSmallIcon(icon);
return;
}
}

SharedPreferences sharedPreferences =
context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE);
String defaultIcon = sharedPreferences.getString(DEFAULT_ICON, null);
if (StringUtils.isNullOrEmpty(defaultIcon)) {
// for backwards compatibility: this is for handling the old way references to the icon used
// to be kept but should be removed in future
builder.setSmallIcon(notificationDetails.iconResourceId);

} else {
builder.setSmallIcon(getDrawableResourceId(context, defaultIcon));
}
}

@NonNull
Expand Down Expand Up @@ -1639,8 +1643,7 @@ private void getCallbackHandle(Result result) {
private NotificationDetails extractNotificationDetails(
Result result, Map<String, Object> arguments) {
NotificationDetails notificationDetails = NotificationDetails.from(arguments);
if (hasInvalidIcon(result, notificationDetails.icon)
|| hasInvalidLargeIcon(
if (hasInvalidLargeIcon(
result, notificationDetails.largeIcon, notificationDetails.largeIconBitmapSource)
|| hasInvalidBigPictureResources(result, notificationDetails)
|| hasInvalidRawSoundResource(result, notificationDetails)
Expand Down

0 comments on commit a145c8a

Please sign in to comment.